From e3480c76e60f787d82cc610702212573482415ba Mon Sep 17 00:00:00 2001 From: Michelle Noorali Date: Wed, 7 Dec 2016 11:20:24 -0500 Subject: [PATCH] feat(tiller): add support for resource-policy keep satisfies #1326 --- _proto/hapi/services/tiller.proto | 2 + cmd/helm/delete.go | 7 +- pkg/proto/hapi/services/tiller.pb.go | 133 ++++++++++++++------------- pkg/tiller/release_server.go | 7 +- pkg/tiller/release_server_test.go | 67 ++++++++++++++ pkg/tiller/resource_policy.go | 65 +++++++++++++ 6 files changed, 214 insertions(+), 67 deletions(-) mode change 100755 => 100644 pkg/tiller/release_server.go create mode 100644 pkg/tiller/resource_policy.go diff --git a/_proto/hapi/services/tiller.proto b/_proto/hapi/services/tiller.proto index d3fd05337..ed2f3c700 100644 --- a/_proto/hapi/services/tiller.proto +++ b/_proto/hapi/services/tiller.proto @@ -256,6 +256,8 @@ message UninstallReleaseRequest { message UninstallReleaseResponse { // Release is the release that was marked deleted. hapi.release.Release release = 1; + // Info is an uninstall message + string info = 2; } // GetVersionRequest requests for version information. diff --git a/cmd/helm/delete.go b/cmd/helm/delete.go index 05db589c9..27c0c7bf4 100644 --- a/cmd/helm/delete.go +++ b/cmd/helm/delete.go @@ -18,6 +18,7 @@ package main import ( "errors" + "fmt" "io" "github.com/spf13/cobra" @@ -86,6 +87,10 @@ func (d *deleteCmd) run() error { helm.DeleteDisableHooks(d.disableHooks), helm.DeletePurge(d.purge), } - _, err := d.client.DeleteRelease(d.name, opts...) + res, err := d.client.DeleteRelease(d.name, opts...) + if res != nil && res.Info != "" { + fmt.Fprintln(d.out, res.Info) + } + return prettyError(err) } diff --git a/pkg/proto/hapi/services/tiller.pb.go b/pkg/proto/hapi/services/tiller.pb.go index 074418600..2c6ed8148 100644 --- a/pkg/proto/hapi/services/tiller.pb.go +++ b/pkg/proto/hapi/services/tiller.pb.go @@ -394,6 +394,8 @@ func (*UninstallReleaseRequest) Descriptor() ([]byte, []int) { return fileDescri type UninstallReleaseResponse struct { // Release is the release that was marked deleted. Release *hapi_release3.Release `protobuf:"bytes,1,opt,name=release" json:"release,omitempty"` + // Info is an uninstall message + Info string `protobuf:"bytes,2,opt,name=info" json:"info,omitempty"` } func (m *UninstallReleaseResponse) Reset() { *m = UninstallReleaseResponse{} } @@ -418,7 +420,7 @@ func (*GetVersionRequest) ProtoMessage() {} func (*GetVersionRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{15} } type GetVersionResponse struct { - Version *hapi_version.Version `protobuf:"bytes,1,opt,name=Version" json:"Version,omitempty"` + Version *hapi_version.Version `protobuf:"bytes,1,opt,name=Version,json=version" json:"Version,omitempty"` } func (m *GetVersionResponse) Reset() { *m = GetVersionResponse{} } @@ -878,68 +880,69 @@ var _ReleaseService_serviceDesc = grpc.ServiceDesc{ func init() { proto.RegisterFile("hapi/services/tiller.proto", fileDescriptor0) } var fileDescriptor0 = []byte{ - // 1004 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x9c, 0x57, 0xdf, 0x6f, 0xe3, 0xc4, - 0x13, 0xaf, 0x93, 0x34, 0x3f, 0xa6, 0x3f, 0xbe, 0xe9, 0x5e, 0xda, 0xb8, 0xd6, 0x17, 0x14, 0x19, - 0xc1, 0x85, 0x83, 0x4b, 0x21, 0x3c, 0x21, 0x21, 0xa4, 0x5e, 0x2e, 0x4a, 0xcb, 0x95, 0x9c, 0xb4, - 0xa1, 0x20, 0xf1, 0x40, 0xe4, 0x26, 0x9b, 0xab, 0x39, 0xc7, 0x1b, 0xbc, 0x9b, 0xea, 0xf2, 0xce, - 0x0b, 0xff, 0x06, 0xff, 0x07, 0xff, 0x13, 0xef, 0xbc, 0x20, 0xef, 0x0f, 0x37, 0x76, 0xec, 0x9c, - 0xc9, 0x8b, 0xed, 0xdd, 0x99, 0xfd, 0xcc, 0xcc, 0x67, 0x76, 0x66, 0x12, 0xb0, 0xee, 0x9d, 0x85, - 0x7b, 0xc1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b, 0xb1, 0x8b, 0x5c, 0x38, 0x5c, 0x9f, 0x58, 0xe8, - 0xd3, 0xec, 0xa9, 0x9c, 0xf8, 0x69, 0x61, 0x3d, 0xcb, 0xa3, 0x2a, 0x9d, 0xb5, 0xf7, 0xbe, 0x30, - 0x10, 0x83, 0x7a, 0x72, 0x90, 0xa0, 0xe7, 0xe9, 0x18, 0x19, 0x93, 0xcb, 0xea, 0xe4, 0x55, 0xd7, - 0x66, 0xd1, 0x83, 0xa0, 0x3d, 0xde, 0xfd, 0xd1, 0x7b, 0x61, 0xe2, 0x03, 0xc7, 0xba, 0xc8, 0xad, - 0x1f, 0xd9, 0xfd, 0x15, 0x8e, 0x62, 0x7d, 0x16, 0x65, 0xb0, 0x95, 0x36, 0x4b, 0xac, 0xcf, 0x72, - 0xe9, 0x46, 0xb6, 0xe6, 0x70, 0x1c, 0x2f, 0x5c, 0x94, 0x01, 0x90, 0xda, 0xdb, 0xac, 0xcf, 0xf3, - 0x29, 0x47, 0xe6, 0x18, 0xd4, 0x93, 0x25, 0x97, 0x95, 0xc7, 0x8c, 0x26, 0x90, 0x95, 0xc7, 0xac, - 0x4a, 0xb6, 0xf7, 0x90, 0x03, 0xf0, 0x58, 0x85, 0xe8, 0x69, 0x66, 0x42, 0xe2, 0xc5, 0x6b, 0xb5, - 0xdf, 0xaf, 0x18, 0x99, 0x58, 0xc0, 0xff, 0x12, 0x93, 0x04, 0x65, 0x50, 0x93, 0x3e, 0xf6, 0xac, - 0xe7, 0x39, 0xb5, 0x13, 0x41, 0xa9, 0xc2, 0xde, 0x12, 0x54, 0xbc, 0x6b, 0x6c, 0x09, 0x2a, 0xd1, - 0x23, 0xec, 0xbd, 0x17, 0xf0, 0x73, 0x55, 0xeb, 0xdd, 0x95, 0xc5, 0x5f, 0x85, 0xaf, 0xfe, 0x0d, - 0x00, 0x00, 0xff, 0xff, 0x9a, 0xb0, 0xe9, 0x29, 0xfb, 0x0c, 0x00, 0x00, + // 1010 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x9c, 0x57, 0x5f, 0x6f, 0xe3, 0x44, + 0x10, 0xaf, 0x93, 0x34, 0x7f, 0xa6, 0x7f, 0x48, 0xf7, 0xd2, 0xc6, 0xb5, 0x00, 0x45, 0x46, 0x70, + 0xe1, 0xe0, 0x52, 0x08, 0x4f, 0x48, 0x08, 0xa9, 0x97, 0x8b, 0xd2, 0x42, 0xc9, 0x49, 0x1b, 0x0a, + 0x12, 0x0f, 0x44, 0x6e, 0xb2, 0xb9, 0x9a, 0x73, 0xbc, 0xc1, 0xbb, 0xa9, 0x2e, 0xef, 0xbc, 0xf0, + 0x35, 0xf8, 0x1e, 0x7c, 0x27, 0xde, 0x79, 0x41, 0xde, 0x3f, 0x6e, 0xec, 0xd8, 0x39, 0x93, 0x17, + 0xdb, 0xbb, 0x33, 0x3b, 0xf3, 0x9b, 0xdf, 0xec, 0xcc, 0x24, 0x60, 0xdd, 0x3b, 0x0b, 0xf7, 0x82, + 0x91, 0xe0, 0xc1, 0x9d, 0x10, 0x76, 0xc1, 0x5d, 0xcf, 0x23, 0x41, 0x67, 0x11, 0x50, 0x4e, 0x51, + 0x23, 0x94, 0x75, 0xb4, 0xac, 0x23, 0x65, 0xd6, 0x99, 0x38, 0x31, 0xb9, 0x77, 0x02, 0x2e, 0x9f, + 0x52, 0xdb, 0x6a, 0xae, 0xef, 0x53, 0x7f, 0xe6, 0xbe, 0x56, 0x02, 0xe9, 0x22, 0x20, 0x1e, 0x71, + 0x18, 0xd1, 0xef, 0xd8, 0x21, 0x2d, 0x73, 0xfd, 0x19, 0x55, 0x82, 0xf3, 0x98, 0x80, 0x71, 0x87, + 0x2f, 0x59, 0xcc, 0xde, 0x03, 0x09, 0x98, 0x4b, 0x7d, 0xfd, 0x96, 0x32, 0xfb, 0xaf, 0x02, 0x3c, + 0xb9, 0x71, 0x19, 0xc7, 0xf2, 0x20, 0xc3, 0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98, 0x51, 0x86, + 0x81, 0xd4, 0x7e, 0x67, 0x7d, 0x9e, 0x4f, 0x39, 0x72, 0xc7, 0xa0, 0x9e, 0x2c, 0xc3, 0xac, 0x3c, + 0x66, 0x34, 0x86, 0xac, 0x3c, 0x66, 0x55, 0xb7, 0xbd, 0x87, 0x1c, 0x80, 0xc7, 0x2a, 0x44, 0x4f, + 0x33, 0x13, 0x12, 0x2f, 0x5e, 0xab, 0xfd, 0x6e, 0xc5, 0xc8, 0xc5, 0x02, 0xde, 0x4b, 0x4c, 0x17, + 0x94, 0x41, 0x4d, 0xfa, 0x28, 0xb4, 0x9e, 0xe7, 0xd4, 0x4e, 0x04, 0xa5, 0x0a, 0x7b, 0x4b, 0x50, + 0xf1, 0xae, 0xb1, 0x25, 0xa8, 0x44, 0x8f, 0xb0, 0xf7, 0x5e, 0xc0, 0x2f, 0x55, 0xad, 0x77, 0x57, + 0x16, 0x7f, 0x1f, 0xbe, 0xfa, 0x2f, 0x00, 0x00, 0xff, 0xff, 0xa9, 0xd1, 0x0e, 0x5d, 0x0f, 0x0d, + 0x00, 0x00, } diff --git a/pkg/tiller/release_server.go b/pkg/tiller/release_server.go old mode 100755 new mode 100644 index 7abca155a..f3ad0252f --- a/pkg/tiller/release_server.go +++ b/pkg/tiller/release_server.go @@ -980,9 +980,14 @@ func (s *ReleaseServer) UninstallRelease(c ctx.Context, req *services.UninstallR return nil, fmt.Errorf("corrupted release record. You must manually delete the resources: %s", err) } + filesToKeep, filesToDelete := filterManifestsToKeep(files) + if len(filesToKeep) > 0 { + res.Info = summarizeKeptManifests(filesToKeep) + } + // Collect the errors, and return them later. es := []string{} - for _, file := range files { + for _, file := range filesToDelete { b := bytes.NewBufferString(file.content) if err := s.env.KubeClient.Delete(rel.Namespace, b); err != nil { log.Printf("uninstall: Failed deletion of %q: %s", req.Name, err) diff --git a/pkg/tiller/release_server_test.go b/pkg/tiller/release_server_test.go index a0ce44ad7..6c5d8909d 100644 --- a/pkg/tiller/release_server_test.go +++ b/pkg/tiller/release_server_test.go @@ -50,6 +50,16 @@ data: name: value ` +var manifestWithKeep = `apiVersion: v1 +kind: ConfigMap +metadata: + name: test-cm-keep + annotations: + "helm.sh/resource-policy": keep +data: + name: value +` + var manifestWithUpgradeHooks = `apiVersion: v1 kind: ConfigMap metadata: @@ -1032,6 +1042,63 @@ func TestUninstallPurgeDeleteRelease(t *testing.T) { } } +func TestUninstallReleaseWithKeepPolicy(t *testing.T) { + c := helm.NewContext() + rs := rsFixture() + name := "angry-bunny" + rs.env.Releases.Create(releaseWithKeepStub(name)) + + req := &services.UninstallReleaseRequest{ + Name: name, + } + + res, err := rs.UninstallRelease(c, req) + if err != nil { + t.Fatalf("Failed uninstall: %s", err) + } + + if res.Release.Name != name { + t.Errorf("Expected angry-bunny, got %q", res.Release.Name) + } + + if res.Release.Info.Status.Code != release.Status_DELETED { + t.Errorf("Expected status code to be DELETED, got %d", res.Release.Info.Status.Code) + } + + if res.Info == "" { + t.Errorf("Expected response info to not be empty") + } else { + if !strings.Contains(res.Info, "[ConfigMap] test-cm-keep") { + t.Errorf("unexpected output: %s", res.Info) + } + } +} + +func releaseWithKeepStub(rlsName string) *release.Release { + ch := &chart.Chart{ + Metadata: &chart.Metadata{ + Name: "bunnychart", + }, + Templates: []*chart.Template{ + {Name: "templates/configmap", Data: []byte(manifestWithKeep)}, + }, + } + + date := timestamp.Timestamp{Seconds: 242085845, Nanos: 0} + return &release.Release{ + Name: rlsName, + Info: &release.Info{ + FirstDeployed: &date, + LastDeployed: &date, + Status: &release.Status{Code: release.Status_DEPLOYED}, + }, + Chart: ch, + Config: &chart.Config{Raw: `name: value`}, + Version: 1, + Manifest: manifestWithKeep, + } +} + func TestUninstallReleaseNoHooks(t *testing.T) { c := helm.NewContext() rs := rsFixture() diff --git a/pkg/tiller/resource_policy.go b/pkg/tiller/resource_policy.go new file mode 100644 index 000000000..89f303197 --- /dev/null +++ b/pkg/tiller/resource_policy.go @@ -0,0 +1,65 @@ +/* +Copyright 2016 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package tiller + +import ( + "strings" +) + +// resourcePolicyAnno is the annotation name for a resource policy +const resourcePolicyAnno = "helm.sh/resource-policy" + +// keepPolicy is the resource policy type for keep +// +// This resource policy type allows resources to skip being deleted +// during an uninstallRelease action. +const keepPolicy = "keep" + +func filterManifestsToKeep(manifests []manifest) ([]manifest, []manifest) { + remaining := []manifest{} + keep := []manifest{} + + for _, m := range manifests { + + if m.head.Metadata == nil || m.head.Metadata.Annotations == nil || len(m.head.Metadata.Annotations) == 0 { + remaining = append(remaining, m) + continue + } + + resourcePolicyType, ok := m.head.Metadata.Annotations[resourcePolicyAnno] + if !ok { + remaining = append(remaining, m) + continue + } + + resourcePolicyType = strings.ToLower(strings.TrimSpace(resourcePolicyType)) + if resourcePolicyType == keepPolicy { + keep = append(keep, m) + } + + } + return keep, remaining +} + +func summarizeKeptManifests(manifests []manifest) string { + message := "These resources were kept due to the resource policy:\n" + for _, m := range manifests { + details := "[" + m.head.Kind + "] " + m.head.Metadata.Name + "\n" + message = message + details + } + return message +}