mirror of https://github.com/k3s-io/k3s
check for ResourceVersion conflict in separate if block
parent
8f48d76271
commit
42f0a36f44
|
@ -139,7 +139,6 @@ func (r *REST) Delete(ctx context.Context, name string, options *metav1.DeleteOp
|
|||
}
|
||||
if options.Preconditions.UID == nil {
|
||||
options.Preconditions.UID = &namespace.UID
|
||||
options.Preconditions.ResourceVersion = &namespace.ResourceVersion
|
||||
} else if *options.Preconditions.UID != namespace.UID {
|
||||
err = apierrors.NewConflict(
|
||||
api.Resource("namespaces"),
|
||||
|
@ -147,6 +146,9 @@ func (r *REST) Delete(ctx context.Context, name string, options *metav1.DeleteOp
|
|||
fmt.Errorf("Precondition failed: UID in precondition: %v, UID in object meta: %v", *options.Preconditions.UID, namespace.UID),
|
||||
)
|
||||
return nil, false, err
|
||||
}
|
||||
if options.Preconditions.ResourceVersion == nil {
|
||||
options.Preconditions.ResourceVersion = &namespace.ResourceVersion
|
||||
} else if *options.Preconditions.ResourceVersion != namespace.ResourceVersion {
|
||||
err = apierrors.NewConflict(
|
||||
api.Resource("namespaces"),
|
||||
|
|
|
@ -84,7 +84,6 @@ func (r *REST) Delete(ctx context.Context, name string, options *metav1.DeleteOp
|
|||
}
|
||||
if options.Preconditions.UID == nil {
|
||||
options.Preconditions.UID = &crd.UID
|
||||
options.Preconditions.ResourceVersion = &crd.ResourceVersion
|
||||
} else if *options.Preconditions.UID != crd.UID {
|
||||
err = apierrors.NewConflict(
|
||||
apiextensions.Resource("customresourcedefinitions"),
|
||||
|
@ -92,6 +91,9 @@ func (r *REST) Delete(ctx context.Context, name string, options *metav1.DeleteOp
|
|||
fmt.Errorf("Precondition failed: UID in precondition: %v, UID in object meta: %v", *options.Preconditions.UID, crd.UID),
|
||||
)
|
||||
return nil, false, err
|
||||
}
|
||||
if options.Preconditions.ResourceVersion == nil {
|
||||
options.Preconditions.ResourceVersion = &crd.ResourceVersion
|
||||
} else if *options.Preconditions.ResourceVersion != crd.ResourceVersion {
|
||||
err = apierrors.NewConflict(
|
||||
apiextensions.Resource("customresourcedefinitions"),
|
||||
|
|
|
@ -228,7 +228,7 @@ func NewUIDPreconditions(uid string) *Preconditions {
|
|||
return &Preconditions{UID: &u}
|
||||
}
|
||||
|
||||
// NewPreconditionDeleteOptionsWithResourceVersion returns a DeleteOptions with a UID precondition set.
|
||||
// NewPreconditionDeleteOptionsWithResourceVersion returns a DeleteOptions with a ResourceVersion precondition set.
|
||||
func NewPreconditionDeleteOptionsWithResourceVersion(rv string) *DeleteOptions {
|
||||
p := Preconditions{ResourceVersion: &rv}
|
||||
return &DeleteOptions{Preconditions: &p}
|
||||
|
|
|
@ -82,7 +82,7 @@ func BeforeDelete(strategy RESTDeleteStrategy, ctx context.Context, obj runtime.
|
|||
return false, false, errors.NewConflict(schema.GroupResource{Group: gvk.Group, Resource: gvk.Kind}, objectMeta.GetName(), fmt.Errorf("the UID in the precondition (%s) does not match the UID in record (%s). The object might have been deleted and then recreated", *options.Preconditions.UID, objectMeta.GetUID()))
|
||||
}
|
||||
if options.Preconditions.ResourceVersion != nil && *options.Preconditions.ResourceVersion != objectMeta.GetResourceVersion() {
|
||||
return false, false, errors.NewConflict(schema.GroupResource{Group: gvk.Group, Resource: gvk.Kind}, objectMeta.GetName(), fmt.Errorf("the ResourceVersion in the precondition (%s) does not match the ResourceVersion in record (%s). The object might have been deleted and then recreated", *options.Preconditions.ResourceVersion, objectMeta.GetResourceVersion()))
|
||||
return false, false, errors.NewConflict(schema.GroupResource{Group: gvk.Group, Resource: gvk.Kind}, objectMeta.GetName(), fmt.Errorf("the ResourceVersion in the precondition (%s) does not match the ResourceVersion in record (%s). The object might have been modified", *options.Preconditions.ResourceVersion, objectMeta.GetResourceVersion()))
|
||||
}
|
||||
}
|
||||
gracefulStrategy, ok := strategy.(RESTGracefulDeleteStrategy)
|
||||
|
|
Loading…
Reference in New Issue