mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 18:02:01 +00:00
Preserve UID/ResourceVersion in the BindingREST endpoint
Change-Id: If4023da10c455963a320fdb9fc2a73c099bea3db
This commit is contained in:
parent
d1dfa89953
commit
62889f416c
@ -163,6 +163,7 @@ func (r *BindingREST) Destroy() {
|
||||
}
|
||||
|
||||
var _ = rest.NamedCreater(&BindingREST{})
|
||||
var _ = rest.SubresourceObjectMetaPreserver(&BindingREST{})
|
||||
|
||||
// Create ensures a pod is bound to a specific host.
|
||||
func (r *BindingREST) Create(ctx context.Context, name string, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (out runtime.Object, err error) {
|
||||
@ -191,6 +192,13 @@ func (r *BindingREST) Create(ctx context.Context, name string, obj runtime.Objec
|
||||
return
|
||||
}
|
||||
|
||||
// PreserveRequestObjectMetaSystemFieldsOnSubresourceCreate indicates to a
|
||||
// handler that this endpoint requires the UID and ResourceVersion to use as
|
||||
// preconditions. Other fields, such as timestamp, are ignored.
|
||||
func (r *BindingREST) PreserveRequestObjectMetaSystemFieldsOnSubresourceCreate() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// setPodHostAndAnnotations sets the given pod's host to 'machine' if and only if
|
||||
// the pod is unassigned and merges the provided annotations with those of the pod.
|
||||
// Returns the current state of the pod, or an error.
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user