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

🐛 ClusterClass: use namePrefix func consistently, fix MachineDeployment template rotation #5164

Merged

Conversation

sbueringer
Copy link
Member

Signed-off-by: Stefan Büringer [email protected]

What this PR does / why we need it:
A few fixes from issues found today during manual testing.

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 #

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 26, 2021
… template rotation, fix unit test panic

Signed-off-by: Stefan Büringer [email protected]
@sbueringer sbueringer force-pushed the pr-misc-clusterclass-fixes branch from de069d9 to cf6797b Compare August 26, 2021 18:07
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 26, 2021
@sbueringer sbueringer changed the title ClusterClass: use namePrefix func consistently, fix MachineDeployment template rotation 🐛 ClusterClass: use namePrefix func consistently, fix MachineDeployment template rotation Aug 26, 2021
log := ctrl.LoggerFrom(ctx)

cleanupOldInfrastructureTemplate, err := r.reconcileReferencedTemplate(ctx, reconcileReferencedTemplateInput{
ref: &desiredMD.Object.Spec.Template.Spec.InfrastructureRef,
current: currentMD.InfrastructureMachineTemplate,
desired: desiredMD.InfrastructureMachineTemplate,
templateNamer: func() string {
return infrastructureMachineTemplateNamePrefix(clusterName, desiredMD.Object.Name)
return infrastructureMachineTemplateNamePrefix(clusterName, mdTopologyName)
Copy link
Member Author

Choose a reason for hiding this comment

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

Previously after the first rotation the templates were looking like this: my-cluster-my-cluster-mdTopologyName...

Now the name is calculated exactly the same way as during compute.

fakeObjs := make([]client.Object, 0)
s := scope.New(nil)

Copy link
Member Author

@sbueringer sbueringer Aug 26, 2021

Choose a reason for hiding this comment

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

  1. The defer above wasn't really intended to be merged that way
  2. Through a few refactorings we hit a new panic because ClusterClass was nil (and it didn't surface because of the defer above)

@@ -39,7 +39,7 @@ func infrastructureMachineTemplateNamePrefix(clusterName, machineDeploymentTopol

// infrastructureMachineTemplateNamePrefix calculates the name prefix for a InfrastructureMachineTemplate.
func controlPlaneInfrastructureMachineTemplateNamePrefix(clusterName string) string {
return fmt.Sprintf("%s-controlplane-", clusterName)
return fmt.Sprintf("%s-control-plane-", clusterName)
Copy link
Member Author

@sbueringer sbueringer Aug 26, 2021

Choose a reason for hiding this comment

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

I think it's better to align to how we call it in our existing CAPD templates. And it matches how we "camelcase" our func/variable names as well.

Copy link
Member

@fabriziopandini fabriziopandini left a comment

Choose a reason for hiding this comment

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

/lgtm

ClusterName: s.Current.Cluster.Name,
ClusterName: s.Current.Cluster.Name,
// Sets the desired Kubernetes version for the MachineDeployment.
// TODO: improve this logic by adding support for version upgrade component by component
Copy link
Member

Choose a reason for hiding this comment

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

@ykakarap this should be already in your radar, right? ^^^

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. The cluster class upgrade PR that I am working on also deals with machine deployments.

Comment on lines -297 to -307
// this panic catcher catches the case when there is some issue with the clusterClass controlPlaneInfrastructureCheck that causes it to falsely proceed
// the test case that throws this panic shows that the structure of our logs is prone to panic if some of our assumptions are off.
defer func() {
if r := recover(); r != nil {
if tt.wantErr {
err := fmt.Errorf("panic occurred during testing")
g.Expect(err).To(HaveOccurred())
}
}
}()

Copy link
Member

Choose a reason for hiding this comment

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

Removing this hack was on my list too. Thanks for addressing it

Copy link
Member Author

Choose a reason for hiding this comment

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

I cleaned it up together with Killian :)

I actually only found it because I wanted to run all tests of this package at once via Intellij to make sure they all still work and then my Intellij panic break point found it.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 26, 2021
@killianmuldoon
Copy link
Contributor

/lgtm thanks for this!

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
/lgtm

@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 Aug 27, 2021
@k8s-ci-robot k8s-ci-robot merged commit cdc9347 into kubernetes-sigs:master Aug 27, 2021
@k8s-ci-robot k8s-ci-robot added this to the v0.4 milestone Aug 27, 2021
@sbueringer sbueringer deleted the pr-misc-clusterclass-fixes branch August 27, 2021 15:45
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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants