-
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
🌱 Use openAPI scheme for defaulting replicas #4164
🌱 Use openAPI scheme for defaulting replicas #4164
Conversation
Hi @alexander-demichev. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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/test-infra repository. |
The changes seem fine to me, though, the first commit seems a little unrelated, perhaps that should be separated into a separate PR? Secondly, I think this change is effectively a no-op since CAPI clusters should be defaulting the replicas anyway, but what happens in particular with this field if the webhooks aren't running, does it break machinesets somehow? I'm thinking about whether there's someone out there running without webhooks that maybe this would break 🤔 |
controllers/machineset_controller.go
Outdated
if machineSet.Spec.Selector.MatchLabels == nil { | ||
machineSet.Spec.Selector.MatchLabels = make(map[string]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.
why is this change in this PR?
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.
+1
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.
seems like they are two different commits with two separate descriptions in PR description
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'll open a separate PR for the second commit so we can keep it cleaner.
// +kubebuilder:default=1 | ||
Replicas *int32 `json:"replicas,omitempty"` |
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.
Does this allow us to specify Replicas = 0?
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 it does, we use this in openshift already and you can have any valid value that is an integer. This only gets defaulted when there is no replicas field at all (eg if you patch to delete the replicas field it would be re-added by openAPI and set to value 1, or you omit it when creating the resource)
@@ -36,7 +35,6 @@ func TestMachineSetDefault(t *testing.T) { | |||
md.Default() | |||
|
|||
g.Expect(md.Labels[ClusterLabelName]).To(Equal(md.Spec.ClusterName)) | |||
g.Expect(md.Spec.Replicas).To(Equal(pointer.Int32Ptr(1))) |
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.
The test should probably be moved elsewhere
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.
Is there a way to test validation/default kubebuilder rules? I haven't seen any place where projects do that. We currently have make verify
that can catch this.
Perhaps this could be included in the e2e tests but I don't see a clear place to include it.
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.
Creating the resource through a test env environment should do it
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.
@vincepri Yeah that makes sense.
@alexander-demichev We can either include a similar suite_test.go
that we have in the controllers
package in the v1alpha4
or just include a schema_test.go
in the controllers
package perhaps.
WDYT?
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.
@wfernandes I think it's easier to include a schema_test.go in controllers package.
controllers/machineset_controller.go
Outdated
if machineSet.Spec.Selector.MatchLabels == nil { | ||
machineSet.Spec.Selector.MatchLabels = make(map[string]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.
+1
/ok-to-test |
@@ -95,7 +95,7 @@ func (fi bindataFileInfo) Sys() interface{} { | |||
return nil | |||
} | |||
|
|||
var _cmdClusterctlConfigManifestClusterctlApiYaml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x56\x4d\x6f\x1b\x37\x10\xbd\xeb\x57\x0c\xd2\x43\x2e\xd5\x6a\xed\x34\x75\xb1\xb7\xc2\xed\x21\xe8\x07\x8c\xd8\x70\x0e\x45\x0f\x23\x72\x24\x31\xe6\x92\x2c\x67\xa8\x44\x2d\xfa\xdf\x0b\x92\xda\xd5\xae\xdc\x2a\xbe\x54\x27\xf1\x71\xbe\xf8\x38\xf3\xb8\x18\xcc\x23\x45\x36\xde\x75\x80\xc1\xd0\x67\x21\x97\x57\xdc\x3c\x7d\xc7\x8d\xf1\xab\xfd\xd5\xe2\xc9\x38\xdd\xc1\x6d\x62\xf1\xfd\x7b\x62\x9f\xa2\xa2\x1f\x68\x63\x9c\x11\xe3\xdd\xa2\x27\x41\x8d\x82\xdd\x02\x00\x9d\xf3\x82\x19\xe6\xbc\x04\x50\xde\x49\xf4\xd6\x52\x5c\x6e\xc9\x35\x4f\x69\x4d\xeb\x64\xac\xa6\x58\x82\x0f\xa9\xf7\x6d\xf3\x4d\x73\xb5\x6c\x9b\xeb\xf6\xba\xbd\x6a\xdb\xeb\xb6\x6d\x6f\xae\xdb\xe5\xdb\x9b\xeb\xb7\x2d\xa2\xba\xba\xd9\x7c\xbb\x00\x50\x91\x4a\xf0\x07\xd3\x13\x0b\xf6\xa1\x03\x97\xac\x5d\x00\x38\xec\xa9\x83\x10\xfd\xde\x68\x8a\xdc\x28\x9b\x58\x28\x2a\xb1\xc3\xdf\xe6\xf3\xb2\x1e\x69\xc1\x81\x54\xae\x6e\x1b\x7d\x0a\x1d\x5c\x32\xad\x81\x87\xb3\xa0\xd0\xd6\x47\x33\xac\x97\x83\xeb\x12\x83\x29\x48\x65\xea\xee\x58\x45\x81\xac\x61\xf9\x69\x06\xff\x6c\x58\xca\x56\xb0\x29\xa2\x9d\x54\x5d\x50\x36\x6e\x9b\x2c\xc6\x13\xbe\x00\x60\xe5\x03\x75\xf0\x6b\x2e\x26\xa0\x22\xbd\x00\x38\x92\x57\x8a\x59\x02\x6a\x5d\xae\x03\xed\x5d\x34\x4e\x28\xde\x7a\x9b\x7a\x37\x96\xfa\x91\xbd\xbb\x43\xd9\x75\xd0\xc8\x21\x50\x41\x07\xda\x1e\x4e\x40\xde\xeb\x80\x25\x1a\xb7\x7d\xee\x39\x54\x94\xeb\x98\x45\x98\x1d\xf9\x4b\x51\x8e\x85\xcf\x02\x3c\xce\xb0\xcb\xfe\x9f\x50\xd4\x8e\xf4\x48\xc6\x2c\xd0\x87\xbc\x09\xe7\x7b\xcf\x02\x56\xe3\xfd\x15\xda\xb0\xc3\x37\x95\x78\xb5\xa3\x1e\xbb\xa3\x87\x0f\xe4\xbe\xbf\x7b\xf7\xf8\xe6\x7e\x06\x03\x68\x62\x15\x4d\x90\xd2\xb7\xc3\xb9\x41\xe7\x79\x20\x06\x74\x40\x4e\xe2\x01\x8c\x03\xd9\xd1\x78\x87\x60\xdc\x9e\x9c\xf8\x78\x68\xc6\x48\x21\xfa\x40\x51\xc6\x7e\xaa\xbf\xc9\x44\x4e\xd0\xb3\xbc\xaf\x73\x69\xd5\x6a\x4c\x9d\xd3\x1d\xa9\x25\x7d\x3c\x0d\xf8\x0d\xc8\xce\x30\x44\x0a\x91\x98\x5c\x1d\xce\x0c\xa3\x03\xbf\xfe\x48\x4a\x1a\xb8\xa7\x98\x1d\x81\x77\x3e\x59\x9d\x67\x76\x4f\x51\x20\x92\xf2\x5b\x67\xfe\x1c\xa3\x31\x88\x2f\x69\x2c\x0a\xb1\x40\xe9\x33\x87\x16\xf6\x68\x13\x7d\x0d\xe8\x34\xf4\x78\x80\x48\x39\x2e\x24\x37\x89\x50\x4c\xb8\x81\x5f\x7c\x24\x30\x6e\xe3\x3b\xd8\x89\x04\xee\x56\xab\xad\x91\x41\x6d\x94\xef\xfb\xe4\x8c\x1c\x56\x45\x38\xcc\x3a\x89\x8f\xbc\xd2\xb4\x27\xbb\x62\xb3\x5d\x62\x54\x3b\x23\xa4\x24\x45\x5a\x61\x30\xcb\x52\xac\x2b\x8a\xd3\xf4\xfa\xab\x78\xd4\x27\x7e\x3d\x23\xef\xd9\xfd\xd7\x5f\x99\xd7\x0b\x2c\xe7\xc1\x05\xc3\x80\x47\xd7\x7a\x8a\x13\x99\x19\xca\x7c\xbc\xff\xf1\xfe\x01\x86\xd4\x95\xf0\xca\xed\xc9\x94\x4f\x34\x67\x8a\x8c\xdb\x50\xac\x96\x9b\xe8\xfb\x12\x85\x9c\x0e\xde\x38\x29\x0b\x65\x0d\x39\x01\x4e\xeb\xde\x48\xbe\xbf\x3f\x12\xb1\xe4\x1b\x68\xe0\xb6\xc8\x2c\xac\x09\x52\xd0\x28\xa4\x1b\x78\xe7\xe0\x16\x7b\xb2\xb7\xc8\xf4\xbf\x93\x9c\xd9\xe4\x65\x26\xef\x65\x34\x4f\x5f\x88\x73\xe3\xca\xd3\x64\x63\xaa\x31\x17\xee\xe6\x6e\x62\x06\xc6\x69\x93\xd5\xb9\x0e\x41\x9e\xed\xda\xf8\xa7\xf9\x6b\x5e\x52\x67\x81\xff\x3b\x65\x96\xc9\xb3\x54\xd9\xe3\x59\x2a\xb8\x27\x1a\xeb\x2b\x4e\x1b\x1f\x01\xcb\x53\x90\x8d\x39\x85\xe0\xa3\x8c\x43\xf1\x92\xd2\xf6\x5f\x94\x84\x41\x0e\xe6\x05\x2a\xdf\x07\xef\x72\x27\x1d\x23\xbc\x88\x88\x73\x85\xbd\x90\xf6\xc3\x99\xe9\xbf\xdc\x45\xc5\x3f\xed\x28\xd2\x5c\x13\x4f\x1f\x07\x79\xc8\x0c\xd7\xbc\xc6\x6d\x1b\x30\x1b\xa0\x3e\xc8\xe1\x92\xc3\x60\x5d\xe8\xad\x7d\xc4\x59\x77\xd1\xda\x53\x5e\x7e\xc1\x81\x9f\x75\x22\xe7\x49\xd5\x1d\x48\x4c\xf5\x05\x61\xf1\x11\xb7\x34\x45\xd2\x7a\xd4\x9a\x0e\xfe\xfa\x7b\xc1\x82\x92\x8a\x92\xa3\x52\x14\xe4\xc8\x49\x37\xf9\x30\x78\xf5\x6a\xf6\xee\x97\xa5\xf2\xae\x3e\xdc\xdc\xc1\x6f\xbf\x2f\x6a\x2a\xd2\x8f\xc3\xe3\x9e\xc1\x7f\x02\x00\x00\xff\xff\xe0\xbc\x87\x06\xa5\x09\x00\x00") | |||
var _cmdClusterctlConfigManifestClusterctlApiYaml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x56\x4d\x73\x1b\x37\x0f\xbe\xeb\x57\x60\xf2\x1e\x72\x79\xb5\x5a\x3b\x4d\xd3\xd9\x5b\xc7\xed\x21\xd3\x8f\xf1\xc4\x19\xe7\xd0\xe9\x01\x22\x21\x89\x31\x17\x64\x09\x50\x89\xda\xe9\x7f\xef\x90\xab\x95\x76\xe5\xd4\xf1\xa5\x7b\x12\x41\x7c\x3c\x7c\x40\x3c\x22\x46\x77\x4f\x49\x5c\xe0\x0e\x30\x3a\xfa\xac\xc4\x65\x25\xcd\xc3\x77\xd2\xb8\xb0\xda\x5f\x2d\x1e\x1c\xdb\x0e\x6e\xb2\x68\xe8\xdf\x91\x84\x9c\x0c\xfd\x40\x1b\xc7\x4e\x5d\xe0\x45\x4f\x8a\x16\x15\xbb\x05\x00\x32\x07\xc5\x62\x96\xb2\x04\x30\x81\x35\x05\xef\x29\x2d\xb7\xc4\xcd\x43\x5e\xd3\x3a\x3b\x6f\x29\xd5\xe4\x63\xe9\x7d\xdb\x7c\xd3\x5c\x2d\xdb\xe6\xba\xbd\x6e\xaf\xda\xf6\xba\x6d\xdb\x37\xd7\xed\xf2\xf5\x9b\xeb\xd7\x2d\xa2\xb9\x7a\xb3\xf9\x76\x01\x60\x12\xd5\xe4\xef\x5d\x4f\xa2\xd8\xc7\x0e\x38\x7b\xbf\x00\x60\xec\xa9\x83\x98\xc2\xde\x59\x4a\xd2\x18\x9f\x45\x29\x19\xf5\xe3\xcf\xe6\xf3\x72\x38\xd2\x42\x22\x99\x82\x6e\x9b\x42\x8e\x1d\x3c\xe5\x3a\x24\x1e\xcf\x82\x4a\xdb\x90\xdc\xb8\x5e\x8e\xa1\x4b\x8c\xae\x5a\x06\xa6\x6e\x8f\x28\xaa\xc9\x3b\xd1\x9f\x66\xe6\x9f\x9d\x68\xdd\x8a\x3e\x27\xf4\x13\xd4\xd5\x2a\x8e\xb7\xd9\x63\x3a\xdb\x17\x00\x62\x42\xa4\x0e\x7e\x2d\x60\x22\x1a\xb2\x0b\x80\x23\x79\x15\xcc\x12\xd0\xda\xda\x0e\xf4\xb7\xc9\xb1\x52\xba\x09\x3e\xf7\x7c\x82\xfa\x51\x02\xdf\xa2\xee\x3a\x68\xf4\x10\xa9\x5a\x47\xda\xde\x9f\x0d\x65\xaf\x03\xd1\xe4\x78\xfb\x38\x72\x44\x54\x70\xcc\x32\xcc\x8e\xfc\xb5\x2c\x47\xe0\xb3\x04\xf7\x33\xdb\xd3\xf1\x9f\x50\xcd\x8e\xec\x89\x8c\x59\xa2\x0f\x65\x13\x2e\xf7\x1e\x25\x1c\x9c\xf7\x57\xe8\xe3\x0e\x5f\x0d\xc4\x9b\x1d\xf5\xd8\x1d\x23\x42\x24\xfe\xfe\xf6\xed\xfd\xab\xbb\x99\x19\xc0\x92\x98\xe4\xa2\xd6\x7b\x3b\x9e\x1b\x6c\x99\x07\x12\x40\x06\x62\x4d\x07\x70\x0c\xba\xa3\x53\x0f\xc1\xf1\x9e\x58\x43\x3a\x34\xa7\x4c\x31\x85\x48\x49\x4f\xf7\x69\xf8\x26\x13\x39\xb1\x5e\xd4\x7d\x59\xa0\x0d\x5e\xa7\xd2\xa5\xdc\x91\x5a\xb2\xc7\xd3\x40\xd8\x80\xee\x9c\x40\xa2\x98\x48\x88\x87\xe1\x9c\x25\x86\xe2\x84\x0c\x61\xfd\x91\x8c\x36\x70\x47\xa9\xa4\x01\xd9\x85\xec\x6d\x99\xe0\x3d\x25\x85\x44\x26\x6c\xd9\xfd\x79\xca\x2d\xa0\xa1\x16\xf5\xa8\x74\xbc\xd2\xe7\xaf\xde\x41\x46\x0f\x7b\xf4\x99\xfe\x0f\xc8\x16\x7a\x3c\x40\xa2\x52\x05\x32\x4f\xf2\x55\x17\x69\xe0\x97\x90\x08\x1c\x6f\x42\x07\x3b\xd5\x28\xdd\x6a\xb5\x75\x3a\x2a\x91\x09\x7d\x9f\xd9\xe9\x61\x55\x45\xc5\xad\xb3\x86\x24\x2b\x4b\x7b\xf2\x2b\x71\xdb\x25\x26\xb3\x73\x4a\x46\x73\xa2\x15\x46\xb7\xac\xd0\xb9\xaa\x51\xd3\xdb\xff\xa5\xa3\x76\xc9\xcb\x19\xd6\x47\x77\x63\xf8\xea\x2c\x3f\xd1\x81\x32\xd4\xe0\x04\xf0\x18\x3a\x9c\xe2\x4c\x74\x31\x15\x76\xde\xfd\x78\xf7\x1e\xc6\xd2\xb5\x19\x97\xec\x57\xde\xcf\x81\x72\x6e\x41\x21\xcc\xf1\x86\xd2\xd0\xc4\x4d\x0a\x7d\xcd\x49\x6c\x63\x70\xac\x75\x61\xbc\x23\xbe\xa4\x5f\xf2\xba\x77\x5a\xfa\xfe\x47\x26\xd1\xd2\xab\x06\x6e\xaa\x3c\xc3\x9a\x20\x47\x8b\x4a\xb6\x81\xb7\x0c\x37\xd8\x93\xbf\x41\xa1\xff\xbc\x01\x85\x69\x59\x16\x62\x9f\xd7\x82\xe9\x3f\xcb\xa5\xf3\xc0\xda\x64\x63\xaa\x4d\x4f\xf4\xed\x76\xe2\x06\x8e\xad\x2b\xaa\x3e\x0c\x4f\xd1\x84\x61\x60\xce\x73\xdb\x3c\x07\x67\x35\xff\x7b\xc9\x22\xaf\x17\xa5\x4a\xc4\xa3\x52\x70\x47\x74\xc2\x37\xd1\xe4\xf1\xdb\x84\x04\x58\xff\x50\x4a\xa8\xe4\x18\x43\xd2\xd3\xf8\x3c\x07\xe8\xfe\xab\xc2\x32\x8a\xca\x1c\xae\x09\x7d\x0c\x4c\xac\x63\x86\x67\xd1\x72\xa9\xd3\x4f\x94\xfd\x70\xe1\xfa\x85\xce\x0c\xf6\x4f\x3b\x4a\x34\xa3\xed\x82\xa4\xf3\x83\xa3\x0c\xa7\x93\x01\x85\xe3\x6d\x03\x6e\x03\xd4\x47\x3d\xcc\x85\x79\x1e\x30\x7a\x7f\x81\xfa\xe1\xc6\x49\x51\x76\xf4\xfe\x8c\x49\x9e\x41\xc6\xa3\x3b\x2b\x65\xc2\x6d\x07\x9a\xf2\xd0\x66\xd1\x90\x70\x4b\x53\x4b\x5e\x9f\x14\xab\x83\xbf\xfe\x5e\x88\xa2\xe6\xfa\x5f\x81\xc6\x50\xd4\x23\x5f\xdd\xe4\xe9\xf1\xe2\xc5\xec\x65\x51\x97\x26\xf0\xf0\x34\x90\x0e\x7e\xfb\x7d\x31\x94\x22\x7b\x3f\x3e\x1f\x8a\xf1\x9f\x00\x00\x00\xff\xff\x0c\x4b\x3d\xcf\x07\x0a\x00\x00") |
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 this can be excluded from this PR as well. See #4162 (comment)
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, make clean generate-bindata
should fix it, I ran into the same issue
@@ -36,7 +35,6 @@ func TestMachineSetDefault(t *testing.T) { | |||
md.Default() | |||
|
|||
g.Expect(md.Labels[ClusterLabelName]).To(Equal(md.Spec.ClusterName)) | |||
g.Expect(md.Spec.Replicas).To(Equal(pointer.Int32Ptr(1))) |
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.
Is there a way to test validation/default kubebuilder rules? I haven't seen any place where projects do that. We currently have make verify
that can catch this.
Perhaps this could be included in the e2e tests but I don't see a clear place to include it.
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 besides extra clusterctl generated stuff checked in
/retest |
/lgtm As a follow up, is there any other OpenAPI defaulting that we can test in the new tests you've added? Would be good to cover those too |
@JoelSpeed Yes, there are more cases to test. This can be done in a follow-up PR. |
/lgtm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: CecileRobertMichon 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 |
/test pull-cluster-api-test-main |
What this PR does / why we need it:
Use openAPI scheme for defaulting machineset and machinedeployment replicas. This is a trivial validation that can be without usage of webhooks and it doesn't need to be unit tested.