-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,7 +147,7 @@ func (r *ClusterReconciler) reconcileMachineDeployments(ctx context.Context, s * | |
for _, mdTopologyName := range diff.toUpdate { | ||
currentMD := s.Current.MachineDeployments[mdTopologyName] | ||
desiredMD := s.Desired.MachineDeployments[mdTopologyName] | ||
if err := r.updateMachineDeployment(ctx, s.Current.Cluster.Name, currentMD, desiredMD); err != nil { | ||
if err := r.updateMachineDeployment(ctx, s.Current.Cluster.Name, mdTopologyName, currentMD, desiredMD); err != nil { | ||
return err | ||
} | ||
} | ||
|
@@ -187,15 +187,15 @@ func (r *ClusterReconciler) createMachineDeployment(ctx context.Context, md *sco | |
} | ||
|
||
// updateMachineDeployment updates a MachineDeployment. Also rotates the corresponding Templates if necessary. | ||
func (r *ClusterReconciler) updateMachineDeployment(ctx context.Context, clusterName string, currentMD, desiredMD *scope.MachineDeploymentState) error { | ||
func (r *ClusterReconciler) updateMachineDeployment(ctx context.Context, clusterName string, mdTopologyName string, currentMD, desiredMD *scope.MachineDeploymentState) error { | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously after the first rotation the templates were looking like this: Now the name is calculated exactly the same way as during compute. |
||
}, | ||
compatibilityChecker: check.ReferencedObjectsAreCompatible, | ||
}) | ||
|
@@ -208,7 +208,7 @@ func (r *ClusterReconciler) updateMachineDeployment(ctx context.Context, cluster | |
current: currentMD.BootstrapTemplate, | ||
desired: desiredMD.BootstrapTemplate, | ||
templateNamer: func() string { | ||
return bootstrapTemplateNamePrefix(clusterName, desiredMD.Object.Name) | ||
return bootstrapTemplateNamePrefix(clusterName, mdTopologyName) | ||
}, | ||
compatibilityChecker: check.ObjectsAreInTheSameNamespace, | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,14 +267,6 @@ func TestReconcileControlPlaneObject(t *testing.T) { | |
want: &scope.ControlPlaneState{Object: controlPlane3, InfrastructureMachineTemplate: infrastructureMachineTemplate}, | ||
wantErr: false, | ||
}, | ||
{ | ||
// Will panic due to the design of logging. | ||
name: "Attempt to update controlPlane on controlPlaneState with no infrastructureMachineTemplate", | ||
class: ccWithControlPlaneInfrastructure, | ||
current: &scope.ControlPlaneState{Object: controlPlane1}, | ||
desired: &scope.ControlPlaneState{Object: controlPlane3}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "Update to ControlPlaneObject with no underlying infrastructure", | ||
class: ccWithoutControlPlaneInfrastructure, | ||
|
@@ -294,19 +286,19 @@ func TestReconcileControlPlaneObject(t *testing.T) { | |
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
// 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()) | ||
} | ||
} | ||
}() | ||
|
||
Comment on lines
-297
to
-307
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this hack was on my list too. Thanks for addressing it There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
fakeObjs := make([]client.Object, 0) | ||
s := scope.New(nil) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
s.Blueprint = &scope.ClusterBlueprint{ | ||
ClusterClass: &clusterv1.ClusterClass{}, | ||
} | ||
if tt.class.InfrastructureMachineTemplate != nil { | ||
s.Blueprint.ClusterClass.Spec.ControlPlane.MachineInfrastructure = &clusterv1.LocalObjectTemplate{ | ||
Ref: contract.ObjToRef(tt.class.InfrastructureMachineTemplate), | ||
} | ||
} | ||
|
||
s.Current.ControlPlane = &scope.ControlPlaneState{} | ||
if tt.current != nil { | ||
s.Current.ControlPlane = tt.current | ||
if tt.current.Object != nil { | ||
|
@@ -481,8 +473,7 @@ func TestReconcileControlPlaneInfrastructureMachineTemplate(t *testing.T) { | |
if tt.current.InfrastructureMachineTemplate != nil { | ||
item, err := contract.ControlPlane().InfrastructureMachineTemplate().Get(gotControlPlaneObject) | ||
g.Expect(err).ToNot(HaveOccurred()) | ||
// This pattern should match return value in controlPlaneinfrastructureMachineTemplateNamePrefix | ||
pattern := fmt.Sprintf("%s-controlplane-.*", s.Current.Cluster.Name) | ||
pattern := fmt.Sprintf("%s.*", controlPlaneInfrastructureMachineTemplateNamePrefix(s.Current.Cluster.Name)) | ||
fmt.Println(pattern, item.Name) | ||
ok, err := regexp.Match(pattern, []byte(item.Name)) | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
|
||
// getReference gets the object referenced in ref. | ||
|
There was a problem hiding this comment.
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? ^^^
There was a problem hiding this comment.
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.