clusterStart: only run necessary actions

- e.g. can only wait for specific log messages, if the nodes have been
restarted for real and not if they were already running

fixes #847
pull/871/head
iwilltry42 3 years ago
parent d78ef48932
commit 23ddbf67b1
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
  1. 22
      pkg/client/cluster.go

@ -848,6 +848,7 @@ func ClusterStart(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clust
var agents []*k3d.Node var agents []*k3d.Node
var aux []*k3d.Node var aux []*k3d.Node
for _, n := range cluster.Nodes { for _, n := range cluster.Nodes {
if !n.State.Running {
if n.Role == k3d.ServerRole { if n.Role == k3d.ServerRole {
if n.ServerOpts.IsInit { if n.ServerOpts.IsInit {
initNode = n initNode = n
@ -859,6 +860,9 @@ func ClusterStart(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clust
} else { } else {
aux = append(aux, n) aux = append(aux, n)
} }
} else {
l.Log().Tracef("Node %s already running.", n.Name)
}
} }
// sort list of servers for properly ordered sequential start // sort list of servers for properly ordered sequential start
@ -884,6 +888,7 @@ func ClusterStart(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clust
/* /*
* Server Nodes * Server Nodes
*/ */
if len(servers) > 0 {
l.Log().Infoln("Starting servers...") l.Log().Infoln("Starting servers...")
for _, serverNode := range servers { for _, serverNode := range servers {
if err := NodeStart(ctx, runtime, serverNode, &k3d.NodeStartOpts{ if err := NodeStart(ctx, runtime, serverNode, &k3d.NodeStartOpts{
@ -894,11 +899,14 @@ func ClusterStart(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clust
return fmt.Errorf("Failed to start server %s: %+v", serverNode.Name, err) return fmt.Errorf("Failed to start server %s: %+v", serverNode.Name, err)
} }
} }
} else {
l.Log().Infoln("All servers already running.")
}
/* /*
* Agent Nodes * Agent Nodes
*/ */
if len(agents) > 0 {
agentWG, aCtx := errgroup.WithContext(ctx) agentWG, aCtx := errgroup.WithContext(ctx)
l.Log().Infoln("Starting agents...") l.Log().Infoln("Starting agents...")
@ -915,11 +923,15 @@ func ClusterStart(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clust
if err := agentWG.Wait(); err != nil { if err := agentWG.Wait(); err != nil {
return fmt.Errorf("Failed to add one or more agents: %w", err) return fmt.Errorf("Failed to add one or more agents: %w", err)
} }
} else {
l.Log().Infoln("All agents already running.")
}
/* /*
* Auxiliary/Helper Nodes * Auxiliary/Helper Nodes
*/ */
if len(aux) > 0 {
helperWG, hCtx := errgroup.WithContext(ctx) helperWG, hCtx := errgroup.WithContext(ctx)
l.Log().Infoln("Starting helpers...") l.Log().Infoln("Starting helpers...")
for _, helperNode := range aux { for _, helperNode := range aux {
@ -941,11 +953,16 @@ func ClusterStart(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clust
if err := helperWG.Wait(); err != nil { if err := helperWG.Wait(); err != nil {
return fmt.Errorf("Failed to add one or more helper nodes: %w", err) return fmt.Errorf("Failed to add one or more helper nodes: %w", err)
} }
} else {
l.Log().Infoln("All helpers already running.")
}
/* /*
* Additional Cluster Preparation (post start) * Additional Cluster Preparation (post start)
*/ */
if len(servers) > 0 || len(agents) > 0 { // TODO: make checks for required cluster start actions cleaner
postStartErrgrp, postStartErrgrpCtx := errgroup.WithContext(ctx) postStartErrgrp, postStartErrgrpCtx := errgroup.WithContext(ctx)
/*** DNS ***/ /*** DNS ***/
@ -955,6 +972,7 @@ func ClusterStart(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clust
return prepInjectHostIP(postStartErrgrpCtx, runtime, cluster, &clusterStartOpts) return prepInjectHostIP(postStartErrgrpCtx, runtime, cluster, &clusterStartOpts)
}) })
if len(servers) > 0 {
postStartErrgrp.Go(func() error { postStartErrgrp.Go(func() error {
if cluster.Network.Name == "host" { if cluster.Network.Name == "host" {
@ -1021,10 +1039,12 @@ func ClusterStart(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clust
} }
return nil return nil
}) })
}
if err := postStartErrgrp.Wait(); err != nil { if err := postStartErrgrp.Wait(); err != nil {
return fmt.Errorf("error during post-start cluster preparation: %w", err) return fmt.Errorf("error during post-start cluster preparation: %w", err)
} }
}
return nil return nil
} }

Loading…
Cancel
Save