From 600970459ebda95116f6e029e61f3a0e0117e9c9 Mon Sep 17 00:00:00 2001 From: Phil Grayson Date: Wed, 1 Jan 2020 21:32:25 +0000 Subject: [PATCH] Do not delete templated CRDs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes issue #7279. Prevent the deletion of CRDs that were defined in the `templates/` directory. This makes CRD deletion behaviour consistent with Helm documentation: > CRDs are never deleted. Deleting a CRD automatically deletes all of the > CRD’s contents across all namespaces in the cluster. Consequently, Helm > will not delete CRDs. Previous the documentation only applied to CRDs that were defined in the `crds/` directory. It did not consider that Charts could have CRDs in the `templates/` directory (for example charts that were written before the `crds/` directory feature or if the Chart author needed templated CRDs). Signed-off-by: Phil Grayson --- pkg/kube/client.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/kube/client.go b/pkg/kube/client.go index 07962faac..be13f237d 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -197,6 +197,11 @@ func (c *Client) Update(original, target ResourceList, force bool) (*Result, err } for _, info := range original.Difference(target) { + if info.Mapping.GroupVersionKind.Kind == "CustomResourceDefinition" { + c.Log("Skipping the deletion of CustomResourceDefinition %q", info.Name) + continue + } + c.Log("Deleting %q in %s...", info.Name, info.Namespace) res.Deleted = append(res.Deleted, info) if err := deleteResource(info); err != nil { @@ -219,6 +224,11 @@ func (c *Client) Delete(resources ResourceList) (*Result, []error) { var errs []error res := &Result{} err := perform(resources, func(info *resource.Info) error { + if info.Mapping.GroupVersionKind.Kind == "CustomResourceDefinition" { + c.Log("Skipping the deletion of CustomResourceDefinition %q", info.Name) + return nil + } + c.Log("Starting delete for %q %s", info.Name, info.Mapping.GroupVersionKind.Kind) if err := c.skipIfNotFound(deleteResource(info)); err != nil { // Collect the error and continue on