-
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
🌱 Add unit test coverage for machineDeployments. reconcileNewMachineSet #4495
🌱 Add unit test coverage for machineDeployments. reconcileNewMachineSet #4495
Conversation
8c64621
to
cabf352
Compare
@@ -72,11 +73,11 @@ func (r *MachineDeploymentReconciler) rolloutRolling(ctx context.Context, d *clu | |||
|
|||
func (r *MachineDeploymentReconciler) reconcileNewMachineSet(ctx context.Context, allMSs []*clusterv1.MachineSet, newMS *clusterv1.MachineSet, deployment *clusterv1.MachineDeployment) error { | |||
if deployment.Spec.Replicas == nil { | |||
return errors.Errorf("spec replicas for deployment set %v is nil, this is unexpected", deployment.Name) | |||
return errors.Errorf("spec replicas for machineDeployment %s is nil, this is unexpected", client.ObjectKeyFromObject(deployment).String()) |
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.
Other logging/errors predominantly seem to capitalise as MachineDeployment
, we should try make all the logging consistent case wise
return errors.Errorf("spec replicas for machineDeployment %s is nil, this is unexpected", client.ObjectKeyFromObject(deployment).String()) | |
return errors.Errorf("spec replicas for MachineDeployment %s is nil, this is unexpected", client.ObjectKeyFromObject(deployment).String()) |
} | ||
|
||
if newMS.Spec.Replicas == nil { | ||
return errors.Errorf("spec replicas for machine set %v is nil, this is unexpected", newMS.Name) | ||
return errors.Errorf("spec replicas for machineSet %s is nil, this is unexpected", client.ObjectKeyFromObject(newMS).String()) |
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.
Other logging/errors predominantly seem to capitalise as MachineSet
, we should try make all the logging consistent case wise
return errors.Errorf("spec replicas for machineSet %s is nil, this is unexpected", client.ObjectKeyFromObject(newMS).String()) | |
return errors.Errorf("spec replicas for MachineSet %s is nil, this is unexpected", client.ObjectKeyFromObject(newMS).String()) |
if tc.error != nil { | ||
g.Expect(err.Error()).To(BeEquivalentTo(tc.error.Error())) | ||
} |
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.
Nit: If you were to return here, you wouldn't need the next if block and could unindent the rest of the test
if tc.error != nil { | |
g.Expect(err.Error()).To(BeEquivalentTo(tc.error.Error())) | |
} | |
if tc.error != nil { | |
g.Expect(err.Error()).To(BeEquivalentTo(tc.error.Error())) | |
return | |
} |
Might make the test a bit more readable? 🤷 Seems odd that we basically have if/else here
Looks great, added a few nits but nothing major to add from me |
cabf352
to
e949440
Compare
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.
/lgtm
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.
looks like a nice test improvement
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.
/approve
[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 |
Replicas: pointer.Int32Ptr(2), | ||
}, | ||
}, | ||
newMachineSet: &clusterv1.MachineSet{ |
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.
I'm pretty unfamiliar with this code, so I might be missing something entirely.
To me it looks like allMS is always append(oldMSs, newMS)
cluster-api/controllers/machinedeployment_rolling.go
Lines 45 to 48 in e949440
allMSs := append(oldMSs, newMS) | |
// Scale up, if we can. | |
if err := r.reconcileNewMachineSet(ctx, allMSs, newMS, d); err != nil { |
I think we should also have test cases for this. As far as I can see the current tests all have disjunct newMS/allMS, is this intended?
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.
This is actually already being ensured for every testCase, see https://github.com/kubernetes-sigs/cluster-api/pull/4495/files#diff-a70da8885988c24ea4a35f7c1291f24a99f8c5ffdedf2f27864b90575afc2312R188
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.
I just renamed the field allMachineSets -> OldMachineSets to make this more obvious.
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.
Oh, shouldn't have missed that :/
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.
you raised a good point which resulted in better naming, thanks!
e949440
to
a641e30
Compare
/lgtm /hold @sbueringer I think @enxebre has your comments covered, just wanted to get your ack before we merge |
@JoelSpeed |
/hold cancel Thanks @sbueringer |
What this PR does / why we need it:
Increase unit test coverage fo machineDeployments rolling upgrades.
First PR related to #4457