Skip to content

Commit

Permalink
Merge pull request #24 from kubeshop/nicolae/feat/add-delete-functions
Browse files Browse the repository at this point in the history
feat: Add Delete and DeleteAll functions.
  • Loading branch information
nicufk authored Nov 1, 2021
2 parents f07c1bb + 934eb44 commit 257b7d6
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions client/scripts/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

scriptsAPI "github.com/kubeshop/testkube-operator/apis/script/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -33,3 +34,22 @@ func (s ScriptsClient) Create(scripts *scriptsAPI.Script) (*scriptsAPI.Script, e
err := s.Client.Create(context.Background(), scripts)
return scripts, err
}

func (s ScriptsClient) Delete(namespace, name string) error {
script, err := s.Get(namespace, name)
if err != nil {
return err
}

err = s.Client.Delete(context.Background(), script)
return err
}

func (s ScriptsClient) DeleteAll(namespace string) error {

u := &unstructured.Unstructured{}
u.SetKind("script")
u.SetAPIVersion("tests.testkube.io/v1")
err := s.Client.DeleteAllOf(context.Background(), u, client.InNamespace(namespace))
return err
}

0 comments on commit 257b7d6

Please sign in to comment.