diff --git a/pkg/cluster/node.go b/pkg/cluster/node.go index f7247950..3303eeb6 100644 --- a/pkg/cluster/node.go +++ b/pkg/cluster/node.go @@ -107,6 +107,25 @@ func AddNodeToCluster(ctx context.Context, runtime runtimes.Runtime, node *k3d.N } } + if node.Role == k3d.MasterRole { + for _, forbiddenCmd := range k3d.DoNotCopyMasterFlags { + for i, cmd := range node.Cmd { + // cut out the '--cluster-init' flag as this should only be done by the initializing master node + if cmd == forbiddenCmd { + log.Debugf("Dropping '%s' from node's cmd", forbiddenCmd) + node.Cmd = append(node.Cmd[:i], node.Cmd[i+1:]...) + } + } + for i, arg := range node.Args { + // cut out the '--cluster-init' flag as this should only be done by the initializing master node + if arg == forbiddenCmd { + log.Debugf("Dropping '%s' from node's args", forbiddenCmd) + node.Args = append(node.Args[:i], node.Args[i+1:]...) + } + } + } + } + if err := CreateNode(ctx, runtime, node); err != nil { return err } diff --git a/pkg/types/types.go b/pkg/types/types.go index e23bfa29..d919bc42 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -102,6 +102,11 @@ const DefaultAPIPort = "6443" // DefaultAPIHost defines the default host (IP) for the Kubernetes API const DefaultAPIHost = "0.0.0.0" +// DoNotCopyMasterFlags defines a list of commands/args that shouldn't be copied from an existing node when adding a similar node to a cluster +var DoNotCopyMasterFlags = []string{ + "--cluster-init", +} + // CreateClusterOpts describe a set of options one can set when creating a cluster type CreateClusterOpts struct { DisableImageVolume bool diff --git a/tests/common.sh b/tests/common.sh index a1f14d4c..c909cbf9 100755 --- a/tests/common.sh +++ b/tests/common.sh @@ -83,7 +83,7 @@ check_multi_node() { passed "cluster $cluster has $expectedNodeCount nodes, as expected" else warn "cluster $cluster has incorrect number of nodes: $nodeCount != $expectedNodeCount" - kubectl get nodes -o=custom-columns=NAME:.metadata.name --no-headers + kubectl get nodes docker ps -a return 1 fi diff --git a/tests/test_full_lifecycle.sh b/tests/test_full_lifecycle.sh index e73ebb01..54b2d078 100755 --- a/tests/test_full_lifecycle.sh +++ b/tests/test_full_lifecycle.sh @@ -38,6 +38,16 @@ check_clusters "$clustername" || failed "error checking cluster" info "Checking that we have 2 nodes online..." check_multi_node "$clustername" 2 || failed "failed to verify number of nodes" +# 4. adding another worker node +# info "Adding one worker node..." +# LOG_LEVEL=debug $EXE create node "extra-worker" --cluster "$clustername" --role "worker" || failed "failed to add worker node" +# +# info "Waiting for a bit to give the new node enough time to boot and register..." +# sleep 10 +# +# info "Checking that we have 3 nodes available now..." +# check_multi_node "$clustername" 3 || failed "failed to verify number of nodes" + # 4. load an image into the cluster info "Loading an image into the cluster..." docker pull nginx:latest > /dev/null