Skip to content

Commit 25407c3

Browse files
authored
pkg/action: various operator uninstall and catalog improvements (#15)
- new helper to get object key from object - new helper to re-use code that waits for object deletion - operator uninstall: add DeleteOperatorGroupNames option that is used to filter which operator groups are deleted. - operator uninstall: always wait for objects to be deleted.
1 parent 5ac9c8d commit 25407c3

File tree

5 files changed

+95
-73
lines changed

5 files changed

+95
-73
lines changed

go.sum

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwo
204204
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
205205
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
206206
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
207+
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
207208
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
208209
github.com/fsouza/fake-gcs-server v1.7.0/go.mod h1:5XIRs4YvwNbNoz+1JF8j6KLAyDh7RHGAyAK3EP2EsNk=
209210
github.com/garyburd/redigo v0.0.0-20150301180006-535138d7bcd7/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
@@ -375,6 +376,7 @@ github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHh
375376
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
376377
github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU=
377378
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
379+
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
378380
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
379381
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
380382
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
@@ -478,6 +480,7 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
478480
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
479481
github.com/nakagami/firebirdsql v0.0.0-20190310045651-3c02a58cfed8/go.mod h1:86wM1zFnC6/uDBfZGNwB65O+pR2OFi5q/YQaEUid1qA=
480482
github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM=
483+
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
481484
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
482485
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
483486
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
@@ -490,6 +493,7 @@ github.com/onsi/ginkgo v1.11.0 h1:JAKSXpt1YjtLA7YpPiqO9ss6sNXEsPfSGdwN0UHqzrw=
490493
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
491494
github.com/onsi/ginkgo v1.12.0 h1:Iw5WCbBcaAAd0fpRb1c9r5YCylv4XDoCSigm1zLevwU=
492495
github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg=
496+
github.com/onsi/ginkgo v1.12.1 h1:mFwc4LvZ0xpSvDZ3E+k8Yte0hLOMxXUlP+yXtJqkYfQ=
493497
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
494498
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
495499
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
@@ -957,8 +961,6 @@ k8s.io/api v0.16.7/go.mod h1:oUAiGRgo4t+5yqcxjOu5LoHT3wJ8JSbgczkaFYS5L7I=
957961
k8s.io/api v0.17.2/go.mod h1:BS9fjjLc4CMuqfSO8vgbHPKMt5+SF0ET6u/RVDihTo4=
958962
k8s.io/api v0.18.0/go.mod h1:q2HRQkfDzHMBZL9l/y9rH63PkQl4vae0xRT+8prbrK8=
959963
k8s.io/api v0.18.2/go.mod h1:SJCWI7OLzhZSvbY7U8zwNl9UA4o1fizoug34OV/2r78=
960-
k8s.io/api v0.18.4 h1:8x49nBRxuXGUlDlwlWd3RMY1SayZrzFfxea3UZSkFw4=
961-
k8s.io/api v0.18.4/go.mod h1:lOIQAKYgai1+vz9J7YcDZwC26Z0zQewYOGWdyIPUUQ4=
962964
k8s.io/api v0.18.6 h1:osqrAXbOQjkKIWDTjrqxWQ3w0GkKb1KA1XkUGHHYpeE=
963965
k8s.io/api v0.18.6/go.mod h1:eeyxr+cwCjMdLAmr2W3RyDI0VvTawSg/3RFFBEnmZGI=
964966
k8s.io/apiextensions-apiserver v0.0.0-20190918161926-8f644eb6e783/go.mod h1:xvae1SZB3E17UpV59AWc271W/Ph25N+bjPyR63X6tPY=
@@ -975,8 +977,6 @@ k8s.io/apimachinery v0.17.0/go.mod h1:b9qmWdKlLuU9EBh+06BtLcSf/Mu89rWL33naRxs1uZ
975977
k8s.io/apimachinery v0.17.2/go.mod h1:b9qmWdKlLuU9EBh+06BtLcSf/Mu89rWL33naRxs1uZg=
976978
k8s.io/apimachinery v0.18.0/go.mod h1:9SnR/e11v5IbyPCGbvJViimtJ0SwHG4nfZFjU77ftcA=
977979
k8s.io/apimachinery v0.18.2/go.mod h1:9SnR/e11v5IbyPCGbvJViimtJ0SwHG4nfZFjU77ftcA=
978-
k8s.io/apimachinery v0.18.4 h1:ST2beySjhqwJoIFk6p7Hp5v5O0hYY6Gngq/gUYXTPIA=
979-
k8s.io/apimachinery v0.18.4/go.mod h1:OaXp26zu/5J7p0f92ASynJa1pZo06YlV9fG7BoWbCko=
980980
k8s.io/apimachinery v0.18.6 h1:RtFHnfGNfd1N0LeSrKCUznz5xtUP1elRGvHJbL3Ntag=
981981
k8s.io/apimachinery v0.18.6/go.mod h1:OaXp26zu/5J7p0f92ASynJa1pZo06YlV9fG7BoWbCko=
982982
k8s.io/apiserver v0.0.0-20190918160949-bfa5e2e684ad/go.mod h1:XPCXEwhjaFN29a8NldXA901ElnKeKLrLtREO9ZhFyhg=
@@ -993,8 +993,6 @@ k8s.io/client-go v0.16.7/go.mod h1:9kEMEeuy2LdsHHXoU2Skqh+SDso+Yhkxd/0tltvswDE=
993993
k8s.io/client-go v0.17.2/go.mod h1:QAzRgsa0C2xl4/eVpeVAZMvikCn8Nm81yqVx3Kk9XYI=
994994
k8s.io/client-go v0.18.0/go.mod h1:uQSYDYs4WhVZ9i6AIoEZuwUggLVEF64HOD37boKAtF8=
995995
k8s.io/client-go v0.18.2/go.mod h1:Xcm5wVGXX9HAA2JJ2sSBUn3tCJ+4SVlCbl2MNNv+CIU=
996-
k8s.io/client-go v0.18.4 h1:un55V1Q/B3JO3A76eS0kUSywgGK/WR3BQ8fHQjNa6Zc=
997-
k8s.io/client-go v0.18.4/go.mod h1:f5sXwL4yAZRkAtzOxRWUhA/N8XzGCb+nPZI8PfobZ9g=
998996
k8s.io/client-go v0.18.6 h1:I+oWqJbibLSGsZj8Xs8F0aWVXJVIoUHWaaJV3kUN/Zw=
999997
k8s.io/client-go v0.18.6/go.mod h1:/fwtGLjYMS1MaM5oi+eXhKwG+1UHidUEXRh6cNsdO0Q=
1000998
k8s.io/code-generator v0.0.0-20190912054826-cd179ad6a269/go.mod h1:V5BD6M4CyaN5m+VthcclXWsVcT1Hu+glwa1bi3MIsyE=
@@ -1017,6 +1015,7 @@ k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
10171015
k8s.io/klog v0.4.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
10181016
k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
10191017
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
1018+
k8s.io/klog/v2 v2.0.0 h1:Foj74zO6RbjjP4hBEKjnYtjjAhGg4jNynUdYF6fJrok=
10201019
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
10211020
k8s.io/kube-aggregator v0.18.0/go.mod h1:ateewQ5QbjMZF/dihEFXwaEwoA4v/mayRvzfmvb6eqI=
10221021
k8s.io/kube-openapi v0.0.0-20190816220812-743ec37842bf/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E=

internal/pkg/action/catalog_add.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"k8s.io/apimachinery/pkg/util/rand"
1919
"k8s.io/apimachinery/pkg/util/wait"
2020
"k8s.io/client-go/util/retry"
21-
"sigs.k8s.io/controller-runtime/pkg/client"
2221
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
2322

2423
"github.com/operator-framework/kubectl-operator/internal/pkg/catalog"
@@ -189,11 +188,7 @@ func (a *CatalogAdd) createRegistryPod(ctx context.Context, cs *v1alpha1.Catalog
189188
return nil, fmt.Errorf("create registry pod: %v", err)
190189
}
191190

192-
podKey, err := client.ObjectKeyFromObject(pod)
193-
if err != nil {
194-
return nil, fmt.Errorf("get registry pod key: %v", err)
195-
}
196-
191+
podKey := objectKeyForObject(pod)
197192
if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
198193
if err := a.config.Client.Get(ctx, podKey, pod); err != nil {
199194
return fmt.Errorf("get registry pod: %v", err)
@@ -235,10 +230,7 @@ func (a *CatalogAdd) updateCatalogSource(ctx context.Context, cs *v1alpha1.Catal
235230
"operators.operatorframework.io/inject-bundle-mode": a.InjectBundleMode,
236231
"operators.operatorframework.io/injected-bundles": string(injectedBundlesJSON),
237232
}
238-
csKey, err := client.ObjectKeyFromObject(cs)
239-
if err != nil {
240-
return fmt.Errorf("get catalogsource key: %v", err)
241-
}
233+
csKey := objectKeyForObject(cs)
242234
if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
243235
if err := a.config.Client.Get(ctx, csKey, cs); err != nil {
244236
return fmt.Errorf("get catalog source: %v", err)
@@ -254,10 +246,7 @@ func (a *CatalogAdd) updateCatalogSource(ctx context.Context, cs *v1alpha1.Catal
254246
}
255247

256248
func (a *CatalogAdd) waitForCatalogSourceReady(ctx context.Context, cs *v1alpha1.CatalogSource) error {
257-
csKey, err := client.ObjectKeyFromObject(cs)
258-
if err != nil {
259-
return fmt.Errorf("get catalogsource key: %v", err)
260-
}
249+
csKey := objectKeyForObject(cs)
261250
if err := wait.PollImmediateUntil(time.Millisecond*250, func() (bool, error) {
262251
if err := a.config.Client.Get(ctx, csKey, cs); err != nil {
263252
return false, err

internal/pkg/action/catalog_remove.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ func (r *CatalogRemove) Run(ctx context.Context) error {
2626
if err := r.config.Client.Delete(ctx, &cs); err != nil {
2727
return fmt.Errorf("delete catalogsource %q: %v", cs.Name, err)
2828
}
29-
return nil
29+
return waitForDeletion(ctx, r.config.Client, &cs)
3030
}

internal/pkg/action/helpers.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package action
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"strings"
7+
"time"
8+
9+
apierrors "k8s.io/apimachinery/pkg/api/errors"
10+
"k8s.io/apimachinery/pkg/types"
11+
"k8s.io/apimachinery/pkg/util/wait"
12+
"sigs.k8s.io/controller-runtime/pkg/client"
13+
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
14+
)
15+
16+
func objectKeyForObject(obj controllerutil.Object) types.NamespacedName {
17+
return types.NamespacedName{
18+
Namespace: obj.GetNamespace(),
19+
Name: obj.GetName(),
20+
}
21+
}
22+
23+
func waitForDeletion(ctx context.Context, cl client.Client, objs ...controllerutil.Object) error {
24+
for _, obj := range objs {
25+
obj := obj
26+
lowerKind := strings.ToLower(obj.GetObjectKind().GroupVersionKind().Kind)
27+
key := objectKeyForObject(obj)
28+
if err := wait.PollImmediateUntil(250*time.Millisecond, func() (bool, error) {
29+
if err := cl.Get(ctx, key, obj); apierrors.IsNotFound(err) {
30+
return true, nil
31+
} else if err != nil {
32+
return false, err
33+
}
34+
return false, nil
35+
}, ctx.Done()); err != nil {
36+
return fmt.Errorf("wait for %s %q deleted: %v", lowerKind, key.Name, err)
37+
}
38+
}
39+
return nil
40+
}

internal/pkg/action/operator_uninstall.go

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"strings"
7-
"time"
87

98
v1 "github.com/operator-framework/api/pkg/operators/v1"
109
"github.com/operator-framework/api/pkg/operators/v1alpha1"
@@ -13,7 +12,6 @@ import (
1312
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1413
"k8s.io/apimachinery/pkg/runtime/schema"
1514
"k8s.io/apimachinery/pkg/types"
16-
"k8s.io/apimachinery/pkg/util/wait"
1715
"sigs.k8s.io/controller-runtime/pkg/client"
1816
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
1917
"sigs.k8s.io/yaml"
@@ -22,10 +20,11 @@ import (
2220
type OperatorUninstall struct {
2321
config *Configuration
2422

25-
Package string
26-
DeleteOperatorGroup bool
27-
DeleteCRDs bool
28-
DeleteAll bool
23+
Package string
24+
DeleteAll bool
25+
DeleteCRDs bool
26+
DeleteOperatorGroups bool
27+
DeleteOperatorGroupNames []string
2928

3029
Logf func(string, ...interface{})
3130
}
@@ -38,15 +37,16 @@ func NewOperatorUninstall(cfg *Configuration) *OperatorUninstall {
3837
}
3938

4039
func (u *OperatorUninstall) BindFlags(fs *pflag.FlagSet) {
41-
fs.BoolVar(&u.DeleteOperatorGroup, "delete-operator-group", false, "delete operator group if no other operators remain")
40+
fs.BoolVarP(&u.DeleteAll, "delete-all", "X", false, "enable all delete flags")
4241
fs.BoolVar(&u.DeleteCRDs, "delete-crds", false, "delete all owned CRDs and all CRs")
43-
fs.BoolVarP(&u.DeleteAll, "delete-add", "X", false, "enable all delete flags")
42+
fs.BoolVar(&u.DeleteOperatorGroups, "delete-operator-groups", false, "delete operator group if no other operators remain")
43+
fs.StringSliceVar(&u.DeleteOperatorGroupNames, "delete-operator-group-names", nil, "delete operator group if no other operators remain")
4444
}
4545

4646
func (u *OperatorUninstall) Run(ctx context.Context) error {
4747
if u.DeleteAll {
4848
u.DeleteCRDs = true
49-
u.DeleteOperatorGroup = true
49+
u.DeleteOperatorGroups = true
5050
}
5151

5252
subs := v1alpha1.SubscriptionList{}
@@ -66,6 +66,9 @@ func (u *OperatorUninstall) Run(ctx context.Context) error {
6666
return fmt.Errorf("operator package %q not found", u.Package)
6767
}
6868

69+
// Since the install plan is owned by the subscription, we need to
70+
// read all of the resource references from the install plan before
71+
// deleting the subscription.
6972
var crds, csvs, others []controllerutil.Object
7073
if sub.Status.InstallPlanRef != nil {
7174
ipKey := types.NamespacedName{
@@ -79,56 +82,52 @@ func (u *OperatorUninstall) Run(ctx context.Context) error {
7982
}
8083
}
8184

82-
if err := u.config.Client.Delete(ctx, sub); err != nil {
83-
return fmt.Errorf("delete subscription %q: %v", sub.Name, err)
85+
// Delete the subscription first, so that no further installs or upgrades
86+
// of the operator occur while we're cleaning up.
87+
if err := u.deleteObjects(ctx, sub); err != nil {
88+
return err
8489
}
85-
u.Logf("subscription %q deleted", sub.Name)
8690

8791
if u.DeleteCRDs {
88-
if err := u.deleteCRDs(ctx, crds); err != nil {
92+
// Ensure CustomResourceDefinitions are deleted next, so that the operator
93+
// has a chance to handle CRs that have finalizers.
94+
if err := u.deleteObjects(ctx, crds...); err != nil {
8995
return err
9096
}
9197
}
9298

93-
if err := u.deleteObjects(ctx, false, csvs); err != nil {
94-
return err
95-
}
96-
97-
if err := u.deleteObjects(ctx, false, others); err != nil {
99+
// Delete CSVs and all other objects created by the install plan.
100+
objects := append(csvs, others...)
101+
if err := u.deleteObjects(ctx, objects...); err != nil {
98102
return err
99103
}
100104

101-
if u.DeleteOperatorGroup {
105+
if u.DeleteOperatorGroups {
102106
subs := v1alpha1.SubscriptionList{}
103107
if err := u.config.Client.List(ctx, &subs, client.InNamespace(u.config.Namespace)); err != nil {
104-
return fmt.Errorf("list clusterserviceversions: %v", err)
108+
return fmt.Errorf("list subscriptions: %v", err)
105109
}
110+
// If there are no subscriptions left, delete the operator group(s).
106111
if len(subs.Items) == 0 {
107112
ogs := v1.OperatorGroupList{}
108113
if err := u.config.Client.List(ctx, &ogs, client.InNamespace(u.config.Namespace)); err != nil {
109114
return fmt.Errorf("list operatorgroups: %v", err)
110115
}
111116
for _, og := range ogs.Items {
112117
og := og
113-
if err := u.config.Client.Delete(ctx, &og); err != nil {
114-
return fmt.Errorf("delete operatorgroup %q: %v", og.Name, err)
118+
if len(u.DeleteOperatorGroupNames) == 0 || contains(u.DeleteOperatorGroupNames, og.GetName()) {
119+
if err := u.deleteObjects(ctx, &og); err != nil {
120+
return err
121+
}
115122
}
116-
u.Logf("operatorgroup %q deleted", og.Name)
117123
}
118124
}
119125
}
120126

121127
return nil
122128
}
123129

124-
func (u *OperatorUninstall) deleteCRDs(ctx context.Context, crds []controllerutil.Object) error {
125-
if err := u.deleteObjects(ctx, true, crds); err != nil {
126-
return err
127-
}
128-
return nil
129-
}
130-
131-
func (u *OperatorUninstall) deleteObjects(ctx context.Context, waitForDelete bool, objs []controllerutil.Object) error {
130+
func (u *OperatorUninstall) deleteObjects(ctx context.Context, objs ...controllerutil.Object) error {
132131
for _, obj := range objs {
133132
obj := obj
134133
lowerKind := strings.ToLower(obj.GetObjectKind().GroupVersionKind().Kind)
@@ -137,24 +136,8 @@ func (u *OperatorUninstall) deleteObjects(ctx context.Context, waitForDelete boo
137136
} else if err == nil {
138137
u.Logf("%s %q deleted", lowerKind, obj.GetName())
139138
}
140-
if waitForDelete {
141-
key, err := client.ObjectKeyFromObject(obj)
142-
if err != nil {
143-
return fmt.Errorf("get %s key: %v", lowerKind, err)
144-
}
145-
if err := wait.PollImmediateUntil(250*time.Millisecond, func() (bool, error) {
146-
if err := u.config.Client.Get(ctx, key, obj); apierrors.IsNotFound(err) {
147-
return true, nil
148-
} else if err != nil {
149-
return false, err
150-
}
151-
return false, nil
152-
}, ctx.Done()); err != nil {
153-
return fmt.Errorf("wait for %s deleted: %v", lowerKind, err)
154-
}
155-
}
156139
}
157-
return nil
140+
return waitForDeletion(ctx, u.config.Client, objs...)
158141
}
159142

160143
func (u *OperatorUninstall) getInstallPlanResources(ctx context.Context, installPlanKey types.NamespacedName) (crds, csvs, others []controllerutil.Object, err error) {
@@ -164,11 +147,8 @@ func (u *OperatorUninstall) getInstallPlanResources(ctx context.Context, install
164147
}
165148

166149
for _, step := range installPlan.Status.Plan {
167-
if step.Status != v1alpha1.StepStatusCreated {
168-
continue
169-
}
170-
obj := &unstructured.Unstructured{Object: map[string]interface{}{}}
171150
lowerKind := strings.ToLower(step.Resource.Kind)
151+
obj := &unstructured.Unstructured{Object: map[string]interface{}{}}
172152
if err := yaml.Unmarshal([]byte(step.Resource.Manifest), &obj.Object); err != nil {
173153
return nil, nil, nil, fmt.Errorf("parse %s manifest %q: %v", lowerKind, step.Resource.Name, err)
174154
}
@@ -191,8 +171,22 @@ func (u *OperatorUninstall) getInstallPlanResources(ctx context.Context, install
191171
case csvKind:
192172
csvs = append(csvs, obj)
193173
default:
174+
// Skip non-CRD/non-CSV resources in the install plan that were not created by the install plan.
175+
// This means we avoid deleting things like the default service account.
176+
if step.Status != v1alpha1.StepStatusCreated {
177+
continue
178+
}
194179
others = append(others, obj)
195180
}
196181
}
197182
return crds, csvs, others, nil
198183
}
184+
185+
func contains(haystack []string, needle string) bool {
186+
for _, n := range haystack {
187+
if n == needle {
188+
return true
189+
}
190+
}
191+
return false
192+
}

0 commit comments

Comments
 (0)