-
Notifications
You must be signed in to change notification settings - Fork 1.6k
📖 (docs/tutorials): ensure all fields follow Kubernetes API conventions #4942
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
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 |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ spec: | |
| spec: | ||
| properties: | ||
| concurrencyPolicy: | ||
| default: Allow | ||
|
Member
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. Maybe I missed the context. Why it's allowed as default?
Member
Author
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. Because of the type: By default, in the example, we want to allow. |
||
| enum: | ||
| - Allow | ||
| - Forbid | ||
|
|
@@ -3835,7 +3836,10 @@ spec: | |
| type: string | ||
| type: object | ||
| x-kubernetes-map-type: atomic | ||
| maxItems: 10 | ||
| minItems: 1 | ||
| type: array | ||
| x-kubernetes-list-type: atomic | ||
| conditions: | ||
| items: | ||
| properties: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import ( | |
|
|
||
| batchv1 "tutorial.kubebuilder.io/project/api/v1" | ||
| // TODO (user): Add any additional imports if needed | ||
| "k8s.io/utils/ptr" | ||
| ) | ||
|
|
||
| var _ = Describe("CronJob Webhook", func() { | ||
|
|
@@ -40,8 +41,8 @@ var _ = Describe("CronJob Webhook", func() { | |
| Spec: batchv1.CronJobSpec{ | ||
| Schedule: schedule, | ||
| ConcurrencyPolicy: batchv1.AllowConcurrent, | ||
|
Member
Author
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. Why is it not a pointer? |
||
| SuccessfulJobsHistoryLimit: new(int32), | ||
| FailedJobsHistoryLimit: new(int32), | ||
| SuccessfulJobsHistoryLimit: ptr.To(int32(3)), | ||
| FailedJobsHistoryLimit: ptr.To(int32(1)), | ||
| }, | ||
| } | ||
| *obj.Spec.SuccessfulJobsHistoryLimit = 3 | ||
|
|
@@ -51,8 +52,8 @@ var _ = Describe("CronJob Webhook", func() { | |
| Spec: batchv1.CronJobSpec{ | ||
| Schedule: schedule, | ||
| ConcurrencyPolicy: batchv1.AllowConcurrent, | ||
| SuccessfulJobsHistoryLimit: new(int32), | ||
| FailedJobsHistoryLimit: new(int32), | ||
| SuccessfulJobsHistoryLimit: ptr.To(int32(3)), | ||
| FailedJobsHistoryLimit: ptr.To(int32(1)), | ||
| }, | ||
| } | ||
| *oldObj.Spec.SuccessfulJobsHistoryLimit = 3 | ||
|
|
@@ -95,20 +96,20 @@ var _ = Describe("CronJob Webhook", func() { | |
| It("Should not overwrite fields that are already set", func() { | ||
| By("setting fields that would normally get a default") | ||
| obj.Spec.ConcurrencyPolicy = batchv1.ForbidConcurrent | ||
| obj.Spec.Suspend = new(bool) | ||
| *obj.Spec.Suspend = true | ||
| obj.Spec.SuccessfulJobsHistoryLimit = new(int32) | ||
| *obj.Spec.SuccessfulJobsHistoryLimit = 5 | ||
| obj.Spec.FailedJobsHistoryLimit = new(int32) | ||
| *obj.Spec.FailedJobsHistoryLimit = 2 | ||
| obj.Spec.Suspend = ptr.To(true) | ||
| obj.Spec.SuccessfulJobsHistoryLimit = ptr.To(int32(5)) | ||
| obj.Spec.FailedJobsHistoryLimit = ptr.To(int32(2)) | ||
|
|
||
| By("calling the Default method to apply defaults") | ||
| _ = defaulter.Default(ctx, obj) | ||
|
|
||
| By("checking that the fields were not overwritten") | ||
| Expect(obj.Spec.ConcurrencyPolicy).To(Equal(batchv1.ForbidConcurrent), "Expected ConcurrencyPolicy to retain its set value") | ||
| Expect(obj.Spec.Suspend).NotTo(BeNil()) | ||
| Expect(*obj.Spec.Suspend).To(BeTrue(), "Expected Suspend to retain its set value") | ||
| Expect(obj.Spec.SuccessfulJobsHistoryLimit).NotTo(BeNil()) | ||
| Expect(*obj.Spec.SuccessfulJobsHistoryLimit).To(Equal(int32(5)), "Expected SuccessfulJobsHistoryLimit to retain its set value") | ||
| Expect(obj.Spec.FailedJobsHistoryLimit).NotTo(BeNil()) | ||
| Expect(*obj.Spec.FailedJobsHistoryLimit).To(Equal(int32(2)), "Expected FailedJobsHistoryLimit to retain its set value") | ||
| }) | ||
| }) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.