-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
📖 Update test examples not to set Status on create #4016
📖 Update test examples not to set Status on create #4016
Conversation
Welcome @hsadoyan! |
Hi @hsadoyan. 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-sigs/prow repository. |
@@ -194,6 +191,9 @@ var _ = Describe("CronJob controller", func() { | |||
controllerRef := metav1.NewControllerRef(createdCronjob, gvk) | |||
testJob.SetOwnerReferences([]metav1.OwnerReference{*controllerRef}) | |||
Expect(k8sClient.Create(ctx, testJob)).Should(Succeed()) | |||
// Note that you can't set the status while creating the resource. It needs to be updated after |
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.
Do we need the comment?
I think we can leave it without the comment right
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.
IHMO just remove the comment and then we can get this one merged
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 wouldn't have this comment in production code, but figured it might be worth it for a tutorial example. I can remove it though. Will submit PR update in a bit
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 if we add a comment we need to refine that with something like
// Note that you should not manage the status values while creating the resource.
// The status field is managed separately to reflect the current state of the resource.
// Therefore, it should be updated using a PATCH or PUT operation after the resource has been created.
// Additionally, it is recommended to use StatusConditions to manage the status. For further information see:
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
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.
Pushed the new comment!
@@ -194,6 +191,9 @@ var _ = Describe("CronJob controller", func() { | |||
controllerRef := metav1.NewControllerRef(createdCronjob, gvk) | |||
testJob.SetOwnerReferences([]metav1.OwnerReference{*controllerRef}) | |||
Expect(k8sClient.Create(ctx, testJob)).Should(Succeed()) | |||
// Note that you can't set the status while creating the resource. It needs to be updated after | |||
testJob.Status.Active = 2 |
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.
Also. we can do that in a follow up. It does not need to be in the PR we need to change this example in order to promote the good practices. Following the k8s API convention we should use status conditions, see: #4019
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.
Just for you know :-)
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.
Good point. That should probably be a followup though since it'll require a bigger refactor
cc5145f
to
aff89b0
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
/ok-to-test
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" |
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.
hi @hsadoyan
See: https://github.com/kubernetes-sigs/kubebuilder/actions/runs/9996175604/job/27630173536?pr=4016
It is failing in the testdata
So, you need to:
- rebase your branch with master
- then, run make generate locally. This target will update all places and docs with the changes.
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.
Require changes ( rebase and run make generate
)
aff89b0
to
90ce1b6
Compare
Done. Should be ready to merge 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.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: camilamacedo86, hsadoyan 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 |
66d6b4f
into
kubernetes-sigs:master
Change the example tests not to attempt to set Status on Create. The kubernetes api will ignore the status field on creation, leaving it blank. A new user trying to follow the book might be surprised to find their tests failing because of an empty status.
Instead the example will update the Status immediately after creation.
Per conversation in the slack
Related to #1778. Updates the book documentation to match the issue resolution.