-
Notifications
You must be signed in to change notification settings - Fork 37
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
OCPCLOUD-2646: MachineSetSync controller: tests #230
OCPCLOUD-2646: MachineSetSync controller: tests #230
Conversation
2d774b6
to
6e83d24
Compare
pkg/controllers/machinesetsync/machineset_sync_controller_test.go
Outdated
Show resolved
Hide resolved
pkg/controllers/machinesetsync/machineset_sync_controller_test.go
Outdated
Show resolved
Hide resolved
pkg/controllers/machinesetsync/machineset_sync_controller_test.go
Outdated
Show resolved
Hide resolved
// I think there may be another case here, where we have had it previously set - synchronized and then it gets unset. | ||
// We may want to ensure that we don't change resourceVersion, and that the condition does not change? | ||
// Changes to false with a failure reason? | ||
// | ||
// I'm not sure if we have an API validation that stops this. | ||
// TODO: clarify / work out |
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 believe we have validation to say that it cannot be cleared once populated, but lets check 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.
I don't think we have a validation currently, here's where I've looked:
https://github.com/openshift/api/blob/master/machine/v1beta1/types_machineset.go#L158-L167
looks like we've got one that forces moving through Migrating on the status.
https://github.com/openshift/api/blob/master/machine/v1beta1/types_machineset.go#L64-L77
on the spec we say it must be one of CAPI or MAPI.
I'm not sure I see anything stopping a particularly determined user from manually editing the status? Or am I missing something
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.
Perhaps we should add a validation to make sure the field cannot be removed once set 🤔
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.
So adding something like:
// +kubebuilder:validation:XValidation:rule="self != '' || oldSelf == ''",message="Once authoritativeAPI is set, it cannot be unset."
to the API?
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're very close to what we would need. But... if someone completely removes a field, then the validations do not run. So you need a validation similar to this on a higher level, nearest, absolutely required field, so that even if the field itself is attempted to be removed, the validation will still execute
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 see so setting this at the top of MachineSetStatus
and:
// +kubebuilder:validation:XValidation:rule="self.authoritativeAPI != '' || oldSelf.authoritativeAPI == ''",message="The authoritativeAPI field cannot be unset once it has been set."
?
And if this is the right approach, will this also pass validation in case of creation without authoritativeAPI set?
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, something like that should work. Since it includes oldSelf
, it's considered a transition rule, and therefore doesn't execute on create. So a status without a valid value on create will be accepted still, which is what we need
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.
See: openshift/api#2091
// Do we have another case here where we consistently want to not see a MAPI MachineSet created? | ||
// Not sure if this is overkill | ||
|
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'd say consistently no new MAPI MachineSets seems reasonable yes, in the future we may decide to change that behaviour so we should test it, as we have decided it for now
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.
most of a test for this in WIP commit.
pkg/controllers/machinesetsync/machineset_sync_controller_test.go
Outdated
Show resolved
Hide resolved
6e83d24
to
e42627c
Compare
e42627c
to
80fef1a
Compare
@theobarberbany: This pull request references OCPCLOUD-2646 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.18.0" version, but no target version was set. In response to this:
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 openshift-eng/jira-lifecycle-plugin repository. |
92de073
to
08e22ce
Compare
08e22ce
to
27d80e3
Compare
e2f7b4f
to
0cc991e
Compare
ad9ca6f
to
aaba899
Compare
// It("should not create a MAPI MachineSet", func() { | ||
// Consistently(k.ObjectList(&machinev1beta1.MachineSetList{}), timeout).ShouldNot( | ||
// ContainElement(WithTransform( | ||
// func(ms machinev1beta1.MachineSet) string { | ||
// return ms.GetName() | ||
// }, Equal(capiMachineSet.GetName())))) | ||
// }) |
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 think something along the lines of
// It("should not create a MAPI MachineSet", func() { | |
// Consistently(k.ObjectList(&machinev1beta1.MachineSetList{}), timeout).ShouldNot( | |
// ContainElement(WithTransform( | |
// func(ms machinev1beta1.MachineSet) string { | |
// return ms.GetName() | |
// }, Equal(capiMachineSet.GetName())))) | |
// }) | |
It("should not create a MAPI MachineSet", func() { | |
Consistently(k.ObjectList(&machinev1beta1.MachineSetList{}), timeout).ShouldNot( | |
ContainElement(HaveField("ObjectMeta.Name", Equal(capiMachineSet.GetName()))), | |
), | |
) | |
}) |
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.
Ended up with:
It("should not create a MAPI MachineSet", func() {
Consistently(k.ObjectList(&machinev1beta1.MachineSetList{}), timeout).ShouldNot(HaveField("Items",
ContainElement(HaveField("ObjectMeta.Name", Equal(capiMachineSet.GetName()))),
))
})
@JoelSpeed I pushed, in a new commit, the changes we agreed on and slightly reorged the contexts to deduplicate some setups like the MachineSet creation. LMK if they look ok and I'll cleanup the history and get ready for labelling. |
Co-authored-by: Damiano Donati <[email protected]>
9c517ae
to
393a17c
Compare
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JoelSpeed 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 |
/skip |
@theobarberbany: The following tests failed, say
Full PR test history. Your PR dashboard. 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-sigs/prow repository. I understand the commands that are listed here. |
[ART PR BUILD NOTIFIER] Distgit: ose-cluster-capi-operator |
This PR adds tests outside of the happy path for the MachineSetSync controller going in the direction from capi -> mapi
#221 should merge before this.