diff --git a/pkg/client/node.go b/pkg/client/node.go index 066e9923..fe908d5b 100644 --- a/pkg/client/node.go +++ b/pkg/client/node.go @@ -57,18 +57,20 @@ import ( // NodeAddToCluster adds a node to an existing cluster func NodeAddToCluster(ctx context.Context, runtime runtimes.Runtime, node *k3d.Node, cluster *k3d.Cluster, createNodeOpts k3d.NodeCreateOpts) error { - targetClusterName := cluster.Name - cluster, err := ClusterGet(ctx, runtime, cluster) - if err != nil { - return fmt.Errorf("Failed to find specified cluster '%s': %w", targetClusterName, err) - } + if createNodeOpts.EnvironmentInfo == nil { + targetClusterName := cluster.Name + cluster, err := ClusterGet(ctx, runtime, cluster) + if err != nil { + return fmt.Errorf("Failed to find specified cluster '%s': %w", targetClusterName, err) + } - envInfo, err := GatherEnvironmentInfo(ctx, runtime, cluster) - if err != nil { - return fmt.Errorf("error gathering cluster environment info required to properly create the node: %w", err) - } + envInfo, err := GatherEnvironmentInfo(ctx, runtime, cluster) + if err != nil { + return fmt.Errorf("error gathering cluster environment info required to properly create the node: %w", err) + } - createNodeOpts.EnvironmentInfo = envInfo + createNodeOpts.EnvironmentInfo = envInfo + } // networks: ensure that cluster network is on index 0 networks := []string{cluster.Network.Name} @@ -106,7 +108,7 @@ func NodeAddToCluster(ctx context.Context, runtime runtimes.Runtime, node *k3d.N } // get node details - srcNode, err = NodeGet(ctx, runtime, srcNode) + srcNode, err := NodeGet(ctx, runtime, srcNode) if err != nil { return err } @@ -262,7 +264,7 @@ func NodeAddToCluster(ctx context.Context, runtime runtimes.Runtime, node *k3d.N Runtime: runtime, Command: []string{ "sh", "-c", - fmt.Sprintf("echo '%s %s' >> /etc/hosts", envInfo.HostGateway.String(), k3d.DefaultK3dInternalHostRecord), + fmt.Sprintf("echo '%s %s' >> /etc/hosts", createNodeOpts.EnvironmentInfo.HostGateway.String(), k3d.DefaultK3dInternalHostRecord), }, Retries: 0, Description: fmt.Sprintf("Inject /etc/hosts record for %s", k3d.DefaultK3dInternalHostRecord), @@ -333,6 +335,17 @@ func NodeAddToClusterMulti(ctx context.Context, runtime runtimes.Runtime, nodes defer cancel() } + targetClusterName := cluster.Name + cluster, err := ClusterGet(ctx, runtime, cluster) + if err != nil { + return fmt.Errorf("Failed to find specified cluster '%s': %w", targetClusterName, err) + } + + createNodeOpts.EnvironmentInfo, err = GatherEnvironmentInfo(ctx, runtime, cluster) + if err != nil { + return fmt.Errorf("error gathering cluster environment info required to properly create the node: %w", err) + } + nodeWaitGroup, ctx := errgroup.WithContext(ctx) for _, node := range nodes { currentNode := node