createNode: do not copy '--cluster-init' when creating a new master node, as this will break the node

This commit is contained in:
iwilltry42 2020-06-03 13:40:13 +02:00
parent d0c24fed99
commit ee8b34d9f6
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
4 changed files with 35 additions and 1 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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