From 4a82e7ab4c49fbdb8781b9e9d649bacb74582c61 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Thu, 5 May 2016 11:10:16 -0700 Subject: [PATCH 1/2] feat(kube): add delete method --- pkg/kube/client.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/kube/client.go b/pkg/kube/client.go index 0fa72473d..0078bf12b 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -32,6 +32,14 @@ func (c *Client) Create(namespace string, reader io.Reader) error { return perform(f, namespace, reader, createResource) } +// Delete deletes kubernetes resources from an io.reader +// +// Namespace will set the namespace +func (c *Client) Delete(namespace string, reader io.Reader) error { + f := cmdutil.NewFactory(c.config) + return perform(f, namespace, reader, deleteResource) +} + const includeThirdPartyAPIs = false func perform(f *cmdutil.Factory, namespace string, reader io.Reader, fn ResourceActorFunc) error { @@ -73,3 +81,7 @@ func createResource(info *resource.Info) error { _, err := resource.NewHelper(info.Client, info.Mapping).Create(info.Namespace, true, info.Object) return err } + +func deleteResource(info *resource.Info) error { + return resource.NewHelper(info.Client, info.Mapping).Delete(info.Namespace, info.Name) +} From 00ff8acfdcbeb73da8d93ee1e86b318c1060983c Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Thu, 5 May 2016 13:36:17 -0700 Subject: [PATCH 2/2] feat(kube): delete test example --- pkg/kube/client_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/kube/client_test.go b/pkg/kube/client_test.go index a13d4c1ab..c3c81b4a2 100644 --- a/pkg/kube/client_test.go +++ b/pkg/kube/client_test.go @@ -65,6 +65,17 @@ func TestPerform(t *testing.T) { } } +func TestReal(t *testing.T) { + t.Skip("This is a live test, comment this line to run") + if err := New(nil).Create("test", strings.NewReader(guestbookManifest)); err != nil { + t.Fatal(err) + } + + if err := New(nil).Delete("test", strings.NewReader(guestbookManifest)); err != nil { + t.Fatal(err) + } +} + const guestbookManifest = ` apiVersion: v1 kind: Service