-
Notifications
You must be signed in to change notification settings - Fork 1.8k
sdk/action: implement kube delete #61
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
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 |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import ( | |
|
|
||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| "k8s.io/apimachinery/pkg/api/meta" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| const ( | ||
|
|
@@ -81,9 +82,32 @@ func KubeApply(object sdkTypes.Object) (err error) { | |
| return nil | ||
| } | ||
|
|
||
| // KubeDelete deletes an object | ||
| // KubeDelete deletes an object if it still exists | ||
| func KubeDelete(object sdkTypes.Object) (err error) { | ||
| panic("TODO") | ||
| defer func() { | ||
| if err != nil { | ||
| err = fmt.Errorf("kube-delete failed: %v", err) | ||
| } | ||
| }() | ||
|
|
||
| name, namespace, err := getNameAndNamespace(object) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| gvk := object.GetObjectKind().GroupVersionKind() | ||
| apiVersion, kind := gvk.ToAPIVersionAndKind() | ||
| objectInfo := objectInfoString(kind, name, namespace) | ||
|
|
||
| resourceClient, _, err := k8sclient.GetResourceClient(apiVersion, kind, namespace) | ||
|
Contributor
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. just curious if
Contributor
Author
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. Yes the dynamic ClientPool implementation already does that.
Contributor
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. nice! |
||
| if err != nil { | ||
| return fmt.Errorf("failed to get resource client for object: %v", err) | ||
| } | ||
|
|
||
| err = resourceClient.Delete(name, &metav1.DeleteOptions{}) | ||
| if err != nil && !apierrors.IsNotFound(err) { | ||
| return fmt.Errorf("failed to delete object (%s): %v", objectInfo, err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func getNameAndNamespace(object sdkTypes.Object) (string, string, error) { | ||
|
|
||
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.
if it still exists->if exists?seems more concise
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.
I agree but I'm pretty sure the latter statement is grammatically incorrect. So probably have to keep it as it is.
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.
on a second thought, i think you are right.