Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ making SetNodeProviderID no more blocking although Control Plane is externally managed #6640

Merged
merged 1 commit into from
Jun 17, 2022

Conversation

prometherion
Copy link
Contributor

What this PR does / why we need it:

The current code-base gave for granted that in a Docker-based CAPI installation, the Control Plane is managed in the same infrastructure. However, this assumption couldn't be entirely correct, and due to this, the reconciliation is blocking the operations required to assign the Provider IDs to the machines.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):

Fixes #6639

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 13, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @prometherion!

It looks like this is your first PR to kubernetes-sigs/cluster-api 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/cluster-api has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @prometherion. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 13, 2022
@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jun 13, 2022
Copy link
Contributor

@killianmuldoon killianmuldoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 13, 2022
@@ -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",
Copy link
Member

@sbueringer sbueringer Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the kubelet.conf on any machine have the rights to patch any other node?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why we are doing this via kubectl. Is there something which prevents us from simply using a Client configured against the workload cluster API server in the controller?
(maybe it doesn't work for the first control plane node and we get stuck?)

(cc @fabriziopandini)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any kubelet.conf seems not work, I think the kubelet.conf of a node is only able to patch himself:

Trying to patch itself: allowed (still throws an error due to invalid patch, could be ignored in this case)

root@capi-quickstart-md-0-bj6ch-79956b7999-dvpx9:/# kubectl --kubeconfig /etc/kubernetes/kubelet.conf patch no capi-quickstart-md-0-bj6ch-79956b7999-dvpx9 -p '{"spec": {"providerID": "docker:////capi-quickstart-md-0-bj6ch-79956b7999-dvpx9-foo"}}'
The Node "capi-quickstart-md-0-bj6ch-79956b7999-dvpx9" is invalid: spec.providerID: Forbidden: node updates may not change providerID except from "" to valid

Trying to patch other node: fails because forbidden

root@capi-quickstart-md-0-bj6ch-79956b7999-dvpx9:/# kubectl --kubeconfig /etc/kubernetes/kubelet.conf patch no capi-quickstart-md-0-bj6ch-79956b7999-7hpkk -p '{"spec": {"providerID": "docker:////capi-quickstart-md-0-bj6ch-79956b7999-7hpkk-foo"}}'
Error from server (Forbidden): nodes "capi-quickstart-md-0-bj6ch-79956b7999-7hpkk" is forbidden: node "capi-quickstart-md-0-bj6ch-79956b7999-dvpx9" is not allowed to modify node "capi-quickstart-md-0-bj6ch-79956b7999-7hpkk"

This is due to the Node authorization mode in kube-apiserver: --authorization-mode=Node,RBAC

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. That's what I expected

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the code to launch the patch command from the node itself. CI is green now.

However, I don't see a real benefit here on launching the command from the node, besides reducing the number of lines of code. If we all agree on using the controller-runtime client, I can rework the PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I'm not really sure about why we use kubectl I would say let's just keep it that way (at least for this PR) as the current PR will definitely already fix your issue and is an improvement

@sbueringer
Copy link
Member

/retest

@sbueringer
Copy link
Member

/test pull-cluster-api-e2e-full-main

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jun 14, 2022
@sbueringer
Copy link
Member

/test pull-cluster-api-e2e-full-main

@sbueringer
Copy link
Member

/lgtm
(assuming e2e-full-main will succeed)

/assign @fabriziopandini

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 15, 2022
@chrischdi
Copy link
Member

/lgtm

// This will happen when the current machine is the only machine.
return kubectlNodes[0], nil

return nil, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid returning nil, nil, shouldn't we have an error if we haven't found the node?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. We also did this before, but let's fix / improve it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address with d4b2a03, let me know if it should be squashed in a single commit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Yup, please squash

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, squashed.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 17, 2022
@sbueringer
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 17, 2022
Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vincepri

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 17, 2022
@k8s-ci-robot k8s-ci-robot merged commit 41664d9 into kubernetes-sigs:main Jun 17, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.2 milestone Jun 17, 2022
@prometherion prometherion deleted the issues/6639 branch June 17, 2022 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docker-based worker nodes never get backed with providerID
7 participants