(ctx context.Context)
| 70 | } |
| 71 | |
| 72 | func (u *Uninstall) Run(ctx context.Context) error { |
| 73 | if u.DeleteAll { |
| 74 | u.DeleteCRDs = true |
| 75 | u.DeleteOperatorGroups = true |
| 76 | } |
| 77 | |
| 78 | subs := v1alpha1.SubscriptionList{} |
| 79 | if err := u.config.Client.List(ctx, &subs, client.InNamespace(u.config.Namespace)); err != nil { |
| 80 | return fmt.Errorf("list subscriptions: %v", err) |
| 81 | } |
| 82 | |
| 83 | // Use nil objects to determine if the underlying was found. |
| 84 | // If it was, the object will != nil. |
| 85 | var subObj, csvObj, csObj client.Object |
| 86 | var sub *v1alpha1.Subscription |
| 87 | var crds []client.Object |
| 88 | catsrc := &v1alpha1.CatalogSource{} |
| 89 | catsrc.SetNamespace(u.config.Namespace) |
| 90 | catsrc.SetName(CatalogNameForPackage(u.Package)) |
| 91 | |
| 92 | for i := range subs.Items { |
| 93 | s := subs.Items[i] |
| 94 | if u.Package == s.Spec.Package { |
| 95 | sub = &s |
| 96 | break |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | catsrcKey := client.ObjectKeyFromObject(catsrc) |
| 101 | if sub != nil { |
| 102 | subObj = sub |
| 103 | // Use the subscription's catalog source data only if available. |
| 104 | keyFromSpec := types.NamespacedName{ |
| 105 | Namespace: sub.Spec.CatalogSourceNamespace, |
| 106 | Name: sub.Spec.CatalogSource, |
| 107 | } |
| 108 | if catsrcKey.Name != "" && catsrcKey.Namespace != "" { |
| 109 | catsrcKey = keyFromSpec |
| 110 | } |
| 111 | |
| 112 | // CSV name may either be the installed or current name in a subscription's status, |
| 113 | // depending on installation state. |
| 114 | csvKey := types.NamespacedName{ |
| 115 | Name: sub.Status.InstalledCSV, |
| 116 | Namespace: u.config.Namespace, |
| 117 | } |
| 118 | if csvKey.Name == "" { |
| 119 | csvKey.Name = sub.Status.CurrentCSV |
| 120 | } |
| 121 | // This value can be empty which will cause errors. |
| 122 | if csvKey.Name != "" { |
| 123 | csv := &v1alpha1.ClusterServiceVersion{} |
| 124 | if err := u.config.Client.Get(ctx, csvKey, csv); err != nil && !apierrors.IsNotFound(err) { |
| 125 | return fmt.Errorf("error getting installed CSV %q: %v", csvKey.Name, err) |
| 126 | } else if err == nil { |
| 127 | crds = getCRDs(csv) |
| 128 | } |
| 129 | csvObj = csv |
no test coverage detected