From 8747527e943d6dbbad042c5ccbb7296cb114c587 Mon Sep 17 00:00:00 2001 From: Jian Wang Date: Fri, 19 Apr 2024 21:13:23 +0200 Subject: [PATCH] Use go package storage Signed-off-by: Jian Wang --- go.mod | 1 + go.sum | 2 ++ pkg/controllers/chart/chart.go | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 6dfdba6a..300bdccb 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/stretchr/testify v1.8.1 k8s.io/api v0.25.4 k8s.io/apimachinery v0.25.4 + k8s.io/apiserver v0.25.4 k8s.io/client-go v0.25.4 k8s.io/klog v1.0.0 k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed diff --git a/go.sum b/go.sum index 2eff7d33..479f476f 100644 --- a/go.sum +++ b/go.sum @@ -599,6 +599,8 @@ k8s.io/apiextensions-apiserver v0.25.4 h1:7hu9pF+xikxQuQZ7/30z/qxIPZc2J1lFElPtr7 k8s.io/apiextensions-apiserver v0.25.4/go.mod h1:bkSGki5YBoZWdn5pWtNIdGvDrrsRWlmnvl9a+tAw5vQ= k8s.io/apimachinery v0.25.4 h1:CtXsuaitMESSu339tfhVXhQrPET+EiWnIY1rcurKnAc= k8s.io/apimachinery v0.25.4/go.mod h1:jaF9C/iPNM1FuLl7Zuy5b9v+n35HGSh6AQ4HYRkCqwo= +k8s.io/apiserver v0.25.4 h1:/3TwZcgLqX7wUxq7TtXOUqXeBTwXIblVMQdhR5XZ7yo= +k8s.io/apiserver v0.25.4/go.mod h1:rPcm567XxjOnnd7jedDUnGJGmDGAo+cT6H7QHAN+xV0= k8s.io/client-go v0.25.4 h1:3RNRDffAkNU56M/a7gUfXaEzdhZlYhoW8dgViGy5fn8= k8s.io/client-go v0.25.4/go.mod h1:8trHCAC83XKY0wsBIpbirZU4NTUpbuhc2JnI7OruGZw= k8s.io/code-generator v0.25.4 h1:tjQ7/+9eN7UOiU2DP+0v4ntTI4JZLi2c1N0WllpFhTc= diff --git a/pkg/controllers/chart/chart.go b/pkg/controllers/chart/chart.go index 08681fa0..da772e1d 100644 --- a/pkg/controllers/chart/chart.go +++ b/pkg/controllers/chart/chart.go @@ -28,6 +28,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/intstr" + storage "k8s.io/apiserver/pkg/storage" "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/record" "k8s.io/utils/pointer" @@ -290,7 +291,7 @@ func (c *Controller) OnRemove(key string, chart *v1.HelmChart) (*v1.HelmChart, e newChart, err := c.helms.Update(chartCopy) if err != nil { // if chart is gone, clean resources - if apierrors.IsNotFound(err) || strings.Contains(err.Error(), "StorageError") { + if apierrors.IsNotFound(err) || storage.IsInvalidObj(err) { // note: an empty apply removes all resources owned by this chart err = generic.ConfigureApplyForObject(c.apply, chart, &generic.GeneratingHandlerOptions{ AllowClusterScoped: true,