From 6b68e7891ffe1e49b3399f6dffcf54ef724c18f2 Mon Sep 17 00:00:00 2001 From: Matt Butcher Date: Thu, 5 May 2016 16:46:31 -0600 Subject: [PATCH] feat(tiller): delete operation runs against Kubernetes Also fixed a minor formatting issue with Alpine chart in docs. --- cmd/helm/remove.go | 2 +- cmd/tiller/environment/environment.go | 16 ++++++++++++---- cmd/tiller/environment/environment_test.go | 3 +++ cmd/tiller/release_server.go | 8 ++++++-- docs/examples/alpine/templates/alpine-pod.yaml | 4 ++-- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/cmd/helm/remove.go b/cmd/helm/remove.go index 900c1f06d..3d412d358 100644 --- a/cmd/helm/remove.go +++ b/cmd/helm/remove.go @@ -39,7 +39,7 @@ func rmRelease(cmd *cobra.Command, args []string) error { // TODO: Handle dry run use case. if removeDryRun { - fmt.Printf("Deleting %s\n", args[0]) + fmt.Printf("DRY RUN: Deleting %s\n", args[0]) return nil } diff --git a/cmd/tiller/environment/environment.go b/cmd/tiller/environment/environment.go index 34b39fed2..5d904af11 100644 --- a/cmd/tiller/environment/environment.go +++ b/cmd/tiller/environment/environment.go @@ -128,11 +128,15 @@ type KubeClient interface { // // reader must contain a YAML stream (one or more YAML documents separated // by "\n---\n"). - // - // config is optional. If nil, the client will use its existing configuration. - // If set, the client will override its default configuration with the - // passed in one. Create(namespace string, reader io.Reader) error + + // Delete destroys one or more resources. + // + // namespace must contain a valid existing namespace. + // + // reader must contain a YAML stream (one or more YAML documents separated + // by "\n---\n"). + Delete(namespace string, reader io.Reader) error } // PrintingKubeClient implements KubeClient, but simply prints the reader to @@ -146,6 +150,10 @@ func (p *PrintingKubeClient) Create(ns string, r io.Reader) error { _, err := io.Copy(p.Out, r) return err } +func (p *PrintingKubeClient) Delete(ns string, r io.Reader) error { + _, err := io.Copy(p.Out, r) + return err +} // Environment provides the context for executing a client request. // diff --git a/cmd/tiller/environment/environment_test.go b/cmd/tiller/environment/environment_test.go index 78e7b8cda..8f0d3511a 100644 --- a/cmd/tiller/environment/environment_test.go +++ b/cmd/tiller/environment/environment_test.go @@ -53,6 +53,9 @@ type mockKubeClient struct { func (k *mockKubeClient) Create(ns string, r io.Reader) error { return nil } +func (k *mockKubeClient) Delete(ns string, r io.Reader) error { + return nil +} var _ Engine = &mockEngine{} var _ ReleaseStorage = &mockReleaseStorage{} diff --git a/cmd/tiller/release_server.go b/cmd/tiller/release_server.go index aee3da927..fbbe73ce9 100644 --- a/cmd/tiller/release_server.go +++ b/cmd/tiller/release_server.go @@ -207,8 +207,12 @@ func (s *releaseServer) UninstallRelease(c ctx.Context, req *services.UninstallR rel.Info.Status.Code = release.Status_DELETED rel.Info.Deleted = timeconv.Now() - // TODO: Once KubeClient is ready, delete the resources. - log.Println("WARNING: Currently not deleting resources from k8s") + b := bytes.NewBuffer([]byte(rel.Manifest)) + + if err := s.env.KubeClient.Delete(s.env.Namespace, b); err != nil { + log.Printf("uninstall: Failed deletion of %q: %s", req.Name, err) + return nil, err + } if err := s.env.Releases.Update(rel); err != nil { log.Printf("uninstall: Failed to store updated release: %s", err) diff --git a/docs/examples/alpine/templates/alpine-pod.yaml b/docs/examples/alpine/templates/alpine-pod.yaml index 81e712723..08cf3c2c1 100644 --- a/docs/examples/alpine/templates/alpine-pod.yaml +++ b/docs/examples/alpine/templates/alpine-pod.yaml @@ -5,9 +5,9 @@ metadata: labels: heritage: {{.Release.Service}} chartName: {{.Chart.Name}} - chartVersion: {{.Chart.Version}} + chartVersion: {{.Chart.Version | quote}} annotations: - "helm.sh/created": {{.Release.Time.Seconds}} + "helm.sh/created": "{{.Release.Time.Seconds}}" spec: restartPolicy: {{default "Never" .restart_policy}} containers: