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

🐛 fix: KubeadmControlPlane controller crash if infra template is not found #2755

Closed

Conversation

MartinForReal
Copy link
Contributor

What this PR does / why we need it:
KubeadmControlPlane controller should not crash if infra template is not found

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 #2751

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

Welcome @MartinForReal!

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 @MartinForReal. 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 Mar 23, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: MartinForReal
To complete the pull request process, please assign neolit123
You can assign the PR to them by writing /assign @neolit123 in a comment when ready.

The full list of commands accepted by this bot can be found 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 size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Mar 23, 2020
@@ -150,6 +154,11 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(req ctrl.Request) (res ctrl.Re
return ctrl.Result{}, nil
}

// Make sure to reconcile the external infrastructure reference.
if err := r.reconcileExternalReference(ctx, cluster, kcp.Spec.InfrastructureTemplate); err != nil {
return ctrl.Result{RequeueAfter: DependentInfraTemplateRequeueAfter}, err
Copy link
Member

Choose a reason for hiding this comment

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

If the error is not nil, the reconciler will go in exponential backoff. What's the reasoning around moving the call outside of the reconcile method?

Copy link
Contributor Author

@MartinForReal MartinForReal Mar 23, 2020

Choose a reason for hiding this comment

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

Here we will get following errors:

  • InfrastructureTemplate is not found, will be created in the future.
  • failed to set ownerReference to InfrastructureTemplate
  • connection issue

under such situations, we should retry reconciling InfrastructureTemplate.

For(&controlplanev1.KubeadmControlPlane{}).
Owns(&clusterv1.Machine{}).
Watches(
&source.Kind{Type: &clusterv1.Cluster{}},
&handler.EnqueueRequestsFromMapFunc{ToRequests: handler.ToRequestsFunc(r.ClusterToKubeadmControlPlane)},
).
WithOptions(options).
Build(r)

From the code above we can see that InfrastructureTemplate is not watched. And we will never know template is created

I think it is a good idea to make sure InfrastructureTemplate exists before reconcile is called
because we can make sure that the dependency of machine object is ready as long as reconcile is called.

Copy link
Member

Choose a reason for hiding this comment

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

That should be ok, the err is returned and the reconciler will go in exponential backoff. From the trace posted in your issue, it seems like this should be fixed in #2754

@MartinForReal
Copy link
Contributor Author

/lifecycle active

@k8s-ci-robot k8s-ci-robot added the lifecycle/active Indicates that an issue or PR is actively being worked on by a contributor. label Mar 23, 2020
@MartinForReal
Copy link
Contributor Author

/assign @neolit123

@MartinForReal
Copy link
Contributor Author

/assign vincepri

@@ -119,7 +119,6 @@ func Convert_v1alpha3_KubeadmConfigStatus_To_v1alpha2_KubeadmConfigStatus(in *ku
return nil
}


Copy link
Member

Choose a reason for hiding this comment

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

this whitespace change is not needed. was it generated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was removed after I executed gofmt -w .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And I believe it was not generated by codegen because generated code starts with "// +build !ignore_autogenerated"

@vincepri
Copy link
Member

@MartinForReal are you able to test with the fix that went in #2757 ?

@MartinForReal
Copy link
Contributor Author

Yes, it is fixed. Thanks~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/active Indicates that an issue or PR is actively being worked on by a contributor. needs-ok-to-test Indicates a PR that requires an org member to verify it 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.

kubeadmControlPlane controller crashed if infrastructure template is not found
4 participants