|
|
@ -57,6 +57,7 @@ import ( |
|
|
|
|
|
|
|
|
|
|
|
// NodeAddToCluster adds a node to an existing cluster
|
|
|
|
// 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 { |
|
|
|
func NodeAddToCluster(ctx context.Context, runtime runtimes.Runtime, node *k3d.Node, cluster *k3d.Cluster, createNodeOpts k3d.NodeCreateOpts) error { |
|
|
|
|
|
|
|
if createNodeOpts.EnvironmentInfo == nil { |
|
|
|
targetClusterName := cluster.Name |
|
|
|
targetClusterName := cluster.Name |
|
|
|
cluster, err := ClusterGet(ctx, runtime, cluster) |
|
|
|
cluster, err := ClusterGet(ctx, runtime, cluster) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -69,6 +70,7 @@ func NodeAddToCluster(ctx context.Context, runtime runtimes.Runtime, node *k3d.N |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
createNodeOpts.EnvironmentInfo = envInfo |
|
|
|
createNodeOpts.EnvironmentInfo = envInfo |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// networks: ensure that cluster network is on index 0
|
|
|
|
// networks: ensure that cluster network is on index 0
|
|
|
|
networks := []string{cluster.Network.Name} |
|
|
|
networks := []string{cluster.Network.Name} |
|
|
@ -106,7 +108,7 @@ func NodeAddToCluster(ctx context.Context, runtime runtimes.Runtime, node *k3d.N |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// get node details
|
|
|
|
// get node details
|
|
|
|
srcNode, err = NodeGet(ctx, runtime, srcNode) |
|
|
|
srcNode, err := NodeGet(ctx, runtime, srcNode) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
@ -262,7 +264,7 @@ func NodeAddToCluster(ctx context.Context, runtime runtimes.Runtime, node *k3d.N |
|
|
|
Runtime: runtime, |
|
|
|
Runtime: runtime, |
|
|
|
Command: []string{ |
|
|
|
Command: []string{ |
|
|
|
"sh", "-c", |
|
|
|
"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, |
|
|
|
Retries: 0, |
|
|
|
Description: fmt.Sprintf("Inject /etc/hosts record for %s", k3d.DefaultK3dInternalHostRecord), |
|
|
|
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() |
|
|
|
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) |
|
|
|
nodeWaitGroup, ctx := errgroup.WithContext(ctx) |
|
|
|
for _, node := range nodes { |
|
|
|
for _, node := range nodes { |
|
|
|
currentNode := node |
|
|
|
currentNode := node |
|
|
|