Preserve UID/ResourceVersion in the BindingREST endpoint

Change-Id: If4023da10c455963a320fdb9fc2a73c099bea3db

Kubernetes-commit: 62889f416cb60f66b3f04810ef2475c425b8394a
This commit is contained in:
Aldo Culquicondor 2023-03-16 16:35:39 -04:00 committed by Kubernetes Publisher
parent 0fc1d27cde
commit 62e2e0a1b7
2 changed files with 14 additions and 2 deletions

View File

@ -162,8 +162,13 @@ func createHandler(r rest.NamedCreater, scope *RequestScope, admit admission.Int
userInfo, _ := request.UserFrom(ctx)
if objectMeta, err := meta.Accessor(obj); err == nil {
// Wipe fields which cannot take user-provided values
rest.WipeObjectMetaSystemFields(objectMeta)
preserveObjectMetaSystemFields := false
if c, ok := r.(rest.SubresourceObjectMetaPreserver); ok && len(scope.Subresource) > 0 {
preserveObjectMetaSystemFields = c.PreserveRequestObjectMetaSystemFieldsOnSubresourceCreate()
}
if !preserveObjectMetaSystemFields {
rest.WipeObjectMetaSystemFields(objectMeta)
}
// ensure namespace on the object is correct, or error if a conflicting namespace was set in the object
if err := rest.EnsureObjectNamespaceMatchesRequestNamespace(rest.ExpectedNamespaceForResource(namespace, scope.Resource), objectMeta); err != nil {

View File

@ -209,6 +209,13 @@ type NamedCreater interface {
Create(ctx context.Context, name string, obj runtime.Object, createValidation ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error)
}
// SubresourceObjectMetaPreserver adds configuration options to a Creater for subresources.
type SubresourceObjectMetaPreserver interface {
// PreserveRequestObjectMetaSystemFieldsOnSubresourceCreate indicates that a
// handler should preserve fields of ObjectMeta that are managed by the system.
PreserveRequestObjectMetaSystemFieldsOnSubresourceCreate() bool
}
// UpdatedObjectInfo provides information about an updated object to an Updater.
// It requires access to the old object in order to return the newly updated object.
type UpdatedObjectInfo interface {