-
Notifications
You must be signed in to change notification settings - Fork 40k
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
apiextensions: update CRD strategy #50764
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ package customresourcedefinition | |
import ( | ||
"fmt" | ||
|
||
apiequality "k8s.io/apimachinery/pkg/api/equality" | ||
"k8s.io/apimachinery/pkg/fields" | ||
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
|
@@ -46,9 +47,27 @@ func (strategy) NamespaceScoped() bool { | |
} | ||
|
||
func (strategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) { | ||
crd := obj.(*apiextensions.CustomResourceDefinition) | ||
crd.Status = apiextensions.CustomResourceDefinitionStatus{} | ||
crd.Generation = 1 | ||
} | ||
|
||
func (strategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) { | ||
newCRD := obj.(*apiextensions.CustomResourceDefinition) | ||
oldCRD := old.(*apiextensions.CustomResourceDefinition) | ||
newCRD.Status = oldCRD.Status | ||
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 does this work without updating the controllers to use the status subresource? Do we have that? Or do we use that already? 👀 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. 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. If the controllers use /status already, all this looks fine. |
||
|
||
// Any changes to the spec increment the generation number, any changes to the | ||
// status should reflect the generation number of the corresponding object. We push | ||
// the burden of managing the status onto the clients because we can't (in general) | ||
// know here what version of spec the writer of the status has seen. It may seem like | ||
// we can at first -- since obj contains spec -- but in the future we will probably make | ||
// status its own object, and even if we don't, writes may be the result of a | ||
// read-update-write loop, so the contents of spec may not actually be the spec that | ||
// the controller has *seen*. | ||
if !apiequality.Semantic.DeepEqual(oldCRD.Spec, newCRD.Spec) { | ||
newCRD.Generation = oldCRD.Generation + 1 | ||
} | ||
} | ||
|
||
func (strategy) Validate(ctx genericapirequest.Context, obj runtime.Object) field.ErrorList { | ||
|
@@ -87,9 +106,14 @@ func (statusStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old r | |
newObj := obj.(*apiextensions.CustomResourceDefinition) | ||
oldObj := old.(*apiextensions.CustomResourceDefinition) | ||
newObj.Spec = oldObj.Spec | ||
|
||
// Status updates are for only for updating status, not objectmeta. | ||
// TODO: Update after ResetObjectMetaForStatus is added to meta/v1. | ||
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. Deletion won't work without updating finalizers (it will time out). However, this means we are touching some part of objectmeta while updating status... Also, when |
||
newObj.Labels = oldObj.Labels | ||
newObj.Annotations = oldObj.Annotations | ||
newObj.OwnerReferences = oldObj.OwnerReferences | ||
newObj.Generation = oldObj.Generation | ||
newObj.SelfLink = oldObj.SelfLink | ||
} | ||
|
||
func (statusStrategy) AllowCreateOnUpdate() bool { | ||
|
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 reset the 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.
We don't allow end users to set status on creation.
We do that for core objects too: https://github.com/kubernetes/kubernetes/blob/master/pkg/registry/core/replicationcontroller/strategy.go#L64.