Created
September 25, 2019 09:24
-
-
Save mfojtik/328d053319edf631d44a5d344ec32187 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (s *REST) Delete(ctx context.Context, name string, validateObjectFunc rest.ValidateObjectFunc, options *metav1.DeleteOptions) (runtime.Object, bool, error) { | |
client, err := s.getImpersonatingClient(ctx) | |
if err != nil { | |
return nil, false, err | |
} | |
var resourceVersion string | |
if options != nil && options.Preconditions != nil && options.Preconditions.ResourceVersion != nil { | |
resourceVersion = *options.Preconditions.ResourceVersion | |
} | |
cur, err := client.Get(name, metav1.GetOptions{ResourceVersion: resourceVersion}) | |
if err != nil { | |
return nil, false, err | |
} | |
if options != nil && options.Preconditions != nil && options.Preconditions.UID != nil && cur.UID != *options.Preconditions.UID { | |
return &metav1.Status{Status: metav1.StatusFailure, Reason: metav1.StatusReasonConflict, Message: "UID does not match"}, true, nil | |
} | |
if err := validateObjectFunc(ctx, cur); err != nil { | |
return nil, false, err | |
} | |
if options == nil { | |
options = &metav1.DeleteOptions{ | |
Preconditions: &metav1.Preconditions{ | |
UID: &cur.UID, | |
ResourceVersion: &cur.ResourceVersion, | |
}, | |
} | |
} else { | |
if options.Preconditions != nil && options.Preconditions.ResourceVersion != nil && *options.Preconditions.ResourceVersion != cur.ResourceVersion { | |
return &metav1.Status{Status: metav1.StatusFailure, Reason: metav1.StatusReasonConflict, Message: "ResourceVersion does not match"}, true, nil | |
} | |
} | |
if err := client.Delete(name, options); err != nil { | |
return nil, false, err | |
} | |
return &metav1.Status{Status: metav1.StatusSuccess}, true, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment