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

🌱 Add unit test coverage for machineDeployments. reconcileNewMachineSet #4495

Merged
merged 1 commit into from
Apr 21, 2021

Conversation

enxebre
Copy link
Member

@enxebre enxebre commented Apr 20, 2021

What this PR does / why we need it:
Increase unit test coverage fo machineDeployments rolling upgrades.

First PR related to #4457

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 20, 2021
@enxebre enxebre changed the title Add unit test coverage for machineDeployments. reconcileNewMachineSet 🌱 Add unit test coverage for machineDeployments. reconcileNewMachineSet Apr 20, 2021
@enxebre enxebre force-pushed the unit-test-md-rolling branch 2 times, most recently from 8c64621 to cabf352 Compare April 20, 2021 09:41
@@ -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())
Copy link
Contributor

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

Suggested change
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())
Copy link
Contributor

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

Suggested change
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())

Comment on lines 199 to 202
if tc.error != nil {
g.Expect(err.Error()).To(BeEquivalentTo(tc.error.Error()))
}
Copy link
Contributor

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

Suggested change
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

@JoelSpeed
Copy link
Contributor

Looks great, added a few nits but nothing major to add from me

@enxebre enxebre force-pushed the unit-test-md-rolling branch from cabf352 to e949440 Compare April 20, 2021 11:34
Copy link
Contributor

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

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

/lgtm

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

@alexander-demicev alexander-demicev left a 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

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 Apr 20, 2021
Replicas: pointer.Int32Ptr(2),
},
},
newMachineSet: &clusterv1.MachineSet{
Copy link
Member

@sbueringer sbueringer Apr 20, 2021

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)

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

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 just renamed the field allMachineSets -> OldMachineSets to make this more obvious.

Copy link
Member

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

Copy link
Member Author

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!

@enxebre enxebre force-pushed the unit-test-md-rolling branch from e949440 to a641e30 Compare April 21, 2021 07:19
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 21, 2021
@JoelSpeed
Copy link
Contributor

/lgtm

/hold @sbueringer I think @enxebre has your comments covered, just wanted to get your ack before we merge

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Apr 21, 2021
@sbueringer
Copy link
Member

@JoelSpeed
Thx, fine fore me
/lgtm

@JoelSpeed
Copy link
Contributor

/hold cancel

Thanks @sbueringer

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 21, 2021
@k8s-ci-robot k8s-ci-robot merged commit a0c20fe into kubernetes-sigs:master Apr 21, 2021
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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants