Skip to content

Commit

Permalink
feat: retrieving first available docker-based node for provider id co…
Browse files Browse the repository at this point in the history
…nfiguration
  • Loading branch information
prometherion committed Jun 14, 2022
1 parent a425d76 commit a8b832f
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions test/infrastructure/docker/internal/docker/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func (m *Machine) SetNodeProviderID(ctx context.Context) error {
patch := fmt.Sprintf(`{"spec": {"providerID": %q}}`, m.ProviderID())
cmd := kubectlNode.Commander.Command(
"kubectl",
"--kubeconfig", "/etc/kubernetes/admin.conf",
"--kubeconfig", "/etc/kubernetes/kubelet.conf",
"patch",
"node", m.ContainerName(),
"--patch", patch,
Expand All @@ -416,28 +416,22 @@ func (m *Machine) SetNodeProviderID(ctx context.Context) error {
}

func (m *Machine) getKubectlNode(ctx context.Context) (*types.Node, error) {
// collect info about the existing controlplane nodes
// collect info about the existing nodes
filters := container.FilterBuilder{}
filters.AddKeyNameValue(filterLabel, clusterLabelKey, m.cluster)
filters.AddKeyNameValue(filterLabel, nodeRoleLabelKey, constants.ControlPlaneNodeRoleValue)

kubectlNodes, err := listContainers(ctx, filters)
if err != nil {
return nil, errors.WithStack(err)
}
if len(kubectlNodes) == 0 {
return nil, nil
}
// Return the first node that is not the current machine.
// The assumption being made is that the existing control planes will already be ready.
// This is true when we are using kubeadm control plane.
// Return the node matching the current machine, required to patch itself using its kubelet config
for _, node := range kubectlNodes {
if node.Name != m.container.Name {
if node.Name == m.container.Name {
return node, nil
}
}
// This will happen when the current machine is the only machine.
return kubectlNodes[0], nil

return nil, nil
}

// Delete deletes a docker container hosting a Kubernetes node.
Expand Down

0 comments on commit a8b832f

Please sign in to comment.