[Enhancement] Create workers/helpers concurrently (#678)
This commit is contained in:
parent
607382056b
commit
6941159ac6
@ -1,7 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/rancher/k3d/v4/cmd"
|
"github.com/rancher/k3d/v4/cmd"
|
||||||
"github.com/spf13/cobra/doc"
|
"github.com/spf13/cobra/doc"
|
||||||
|
@ -46,6 +46,7 @@ import (
|
|||||||
"github.com/rancher/k3d/v4/pkg/types/k3s"
|
"github.com/rancher/k3d/v4/pkg/types/k3s"
|
||||||
"github.com/rancher/k3d/v4/pkg/util"
|
"github.com/rancher/k3d/v4/pkg/util"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"golang.org/x/sync/errgroup"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -893,37 +894,42 @@ func ClusterStart(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clust
|
|||||||
* Agent Nodes
|
* Agent Nodes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
failedAgents := 0
|
agentWG, aCtx := errgroup.WithContext(ctx)
|
||||||
|
|
||||||
log.Infoln("Starting agents...")
|
log.Infoln("Starting agents...")
|
||||||
for _, agentNode := range agents {
|
for _, agentNode := range agents {
|
||||||
if err := NodeStart(ctx, runtime, agentNode, nodeStartOpts); err != nil {
|
currentAgentNode := agentNode
|
||||||
log.Warnf("Failed to start agent %s: %+v", agentNode.Name, err)
|
agentWG.Go(func() error {
|
||||||
failedAgents++
|
return NodeStart(aCtx, runtime, currentAgentNode, nodeStartOpts)
|
||||||
}
|
})
|
||||||
|
}
|
||||||
|
if err := agentWG.Wait(); err != nil {
|
||||||
|
return fmt.Errorf("Failed to add one or more agents: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Auxiliary/Helper Nodes
|
* Auxiliary/Helper Nodes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
helperWG, hCtx := errgroup.WithContext(ctx)
|
||||||
log.Infoln("Starting helpers...")
|
log.Infoln("Starting helpers...")
|
||||||
failedHelpers := 0
|
|
||||||
for _, helperNode := range aux {
|
for _, helperNode := range aux {
|
||||||
nodeStartOpts := k3d.NodeStartOpts{
|
currentHelperNode := helperNode
|
||||||
NodeHooks: helperNode.HookActions,
|
|
||||||
}
|
helperWG.Go(func() error {
|
||||||
if helperNode.Role == k3d.LoadBalancerRole {
|
nodeStartOpts := k3d.NodeStartOpts{
|
||||||
nodeStartOpts.Wait = true
|
NodeHooks: currentHelperNode.HookActions,
|
||||||
}
|
}
|
||||||
if err := NodeStart(ctx, runtime, helperNode, nodeStartOpts); err != nil {
|
if currentHelperNode.Role == k3d.LoadBalancerRole {
|
||||||
log.Warnf("Failed to start helper %s: %+v", helperNode.Name, err)
|
nodeStartOpts.Wait = true
|
||||||
failedHelpers++
|
}
|
||||||
}
|
|
||||||
|
return NodeStart(hCtx, runtime, currentHelperNode, nodeStartOpts)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if failedAgents+failedHelpers > 0 {
|
if err := helperWG.Wait(); err != nil {
|
||||||
log.Warnf("%d non-critical (agent or helper) nodes failed to start. You may want to start them manually.", failedAgents+failedHelpers)
|
return fmt.Errorf("Failed to add one or more helper nodes: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -4,11 +4,12 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2,10 +2,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
run "github.com/rancher/k3d/tools/cmd"
|
run "github.com/rancher/k3d/tools/cmd"
|
||||||
"github.com/rancher/k3d/tools/version"
|
"github.com/rancher/k3d/tools/version"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
Loading…
Reference in New Issue
Block a user