Skip to content

Commit 949e43a

Browse files
committed
action: add delete
1 parent 6a0e29e commit 949e43a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pkg/sdk/action/api.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,26 @@ func Update(object sdkTypes.Object) (err error) {
8585
}
8686
return nil
8787
}
88+
89+
// Delete deletes the specified object
90+
// Returns an error if the object’s TypeMeta(Kind, APIVersion) or ObjectMeta(Name, Namespace) is missing or incorrect.
91+
// e.g NotFound https://github.com/kubernetes/apimachinery/blob/master/pkg/api/errors/errors.go#L418
92+
// “opts” configures the DeleteOptions
93+
// When passed WithDeleteOptions(o), the specified metav1.DeleteOptions are set.
94+
func Delete(object sdkTypes.Object, opts ...DeleteOption) (err error) {
95+
name, namespace, err := k8sutil.GetNameAndNamespace(object)
96+
if err != nil {
97+
return err
98+
}
99+
gvk := object.GetObjectKind().GroupVersionKind()
100+
apiVersion, kind := gvk.ToAPIVersionAndKind()
101+
102+
resourceClient, _, err := k8sclient.GetResourceClient(apiVersion, kind, namespace)
103+
if err != nil {
104+
return fmt.Errorf("failed to get resource client: %v", err)
105+
}
106+
107+
o := NewDeleteOp()
108+
o.applyOpts(opts)
109+
return resourceClient.Delete(name, o.metaDeleteOptions)
110+
}

0 commit comments

Comments
 (0)