MCPcopy
hub / github.com/operator-framework/operator-sdk / Run

Method Run

internal/olm/operator/uninstall.go:72–183  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

70}
71
72func (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

Callers 4

NewCmdFunction · 0.95
InstallReleaseMethod · 0.95
UninstallReleaseMethod · 0.95
RenderRefsFunction · 0.45

Calls 6

deleteObjectsMethod · 0.95
deleteOperatorGroupMethod · 0.95
CatalogNameForPackageFunction · 0.85
getCRDsFunction · 0.85
ListMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected