Skip to content

Commit

Permalink
Merge pull request #6640 from prometherion/issues/6639
Browse files Browse the repository at this point in the history
✨ making SetNodeProviderID no more blocking although Control Plane is externally managed
  • Loading branch information
k8s-ci-robot authored Jun 17, 2022
2 parents 7c992e0 + 3ce889f commit 41664d9
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions test/infrastructure/docker/internal/docker/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,6 @@ func (m *Machine) SetNodeProviderID(ctx context.Context) error {
if err != nil {
return errors.Wrapf(err, "unable to set NodeProviderID. error getting a kubectl node")
}
if kubectlNode == nil {
return errors.New("unable to set NodeProviderID. there are no kubectl node available")
}
if !kubectlNode.IsRunning() {
return errors.Wrapf(ContainerNotRunningError{Name: kubectlNode.Name}, "unable to set NodeProviderID")
}
Expand All @@ -399,7 +396,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 +413,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, fmt.Errorf("there are no Kubernetes nodes matching the container name")
}

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

0 comments on commit 41664d9

Please sign in to comment.