Skip to content

Commit db22948

Browse files
author
Moritz Clasmeier
committed
Accept non-existant CRs
1 parent 1f7091a commit db22948

1 file changed

Lines changed: 49 additions & 24 deletions

File tree

internal/deployer/deployer.go

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,33 @@ func (d *Deployer) deleteResources(ctx context.Context, namespace string, resour
104104
// Expects that reconciliation for the RHACS operator is paused.
105105
func (d *Deployer) deleteCentralResources(ctx context.Context) error {
106106
d.logger.Info("Deleting Central resources")
107+
crExists := true
107108

108-
d.logger.Info("Removing any pause-reconcile annotation from Central")
109-
if err := d.removePauseReconcileAnnotation(ctx, "central", "stackrox-central-services", d.centralNamespace); err != nil {
110-
return err
111-
}
112-
if d.verbose {
113-
d.logger.Dim("Removed any pause-reconcile annotation from Central")
109+
if _, err := k8s.RetrieveResourceFromCluster(ctx, d.logger, d.centralNamespace, "central", "stackrox-central-services"); err != nil {
110+
if !k8s.IsResourceNotFound(err) {
111+
return fmt.Errorf("retrieving Central CR: %w", err)
112+
}
113+
crExists = false
114114
}
115115

116-
err := d.deleteResource(ctx, d.centralNamespace, "central", "stackrox-central-services", "--wait")
117-
if err != nil {
118-
return err
119-
}
120-
if d.verbose {
121-
d.logger.Dim("Deleted Central CR")
116+
if crExists {
117+
d.logger.Info("Removing any pause-reconcile annotation from Central")
118+
if err := d.removePauseReconcileAnnotation(ctx, "central", "stackrox-central-services", d.centralNamespace); err != nil {
119+
return err
120+
}
121+
if d.verbose {
122+
d.logger.Dim("Removed any pause-reconcile annotation from Central")
123+
}
124+
125+
err := d.deleteResource(ctx, d.centralNamespace, "central", "stackrox-central-services", "--wait")
126+
if err != nil {
127+
return err
128+
}
129+
if d.verbose {
130+
d.logger.Dim("Deleted Central CR")
131+
}
132+
} else {
133+
d.logger.Info("Deletion of Central resources requested, but Central CR is not present anymore")
122134
}
123135

124136
for _, resource := range []ResourceToDelete{
@@ -154,21 +166,33 @@ func (d *Deployer) deleteCentralResources(ctx context.Context) error {
154166

155167
func (d *Deployer) deleteSecuredClusterResources(ctx context.Context) error {
156168
d.logger.Info("Deleting SecuredCluster resources")
169+
crExists := true
157170

158-
d.logger.Info("Removing any pause-reconcile annotation from SecuredCluster")
159-
if err := d.removePauseReconcileAnnotation(ctx, "securedcluster", "stackrox-secured-cluster-services", d.sensorNamespace); err != nil {
160-
return err
161-
}
162-
if d.verbose {
163-
d.logger.Dim("Removed any pause-reconcile annotation from SecuredCluster")
171+
if _, err := k8s.RetrieveResourceFromCluster(ctx, d.logger, d.sensorNamespace, "securedcluster", "stackrox-secured-cluster-services"); err != nil {
172+
if !k8s.IsResourceNotFound(err) {
173+
return fmt.Errorf("retrieving SecuredCluster CR: %w", err)
174+
}
175+
crExists = false
164176
}
165177

166-
err := d.deleteResource(ctx, d.sensorNamespace, "securedcluster", "stackrox-secured-cluster-services", "--wait")
167-
if err != nil {
168-
return err
169-
}
170-
if d.verbose {
171-
d.logger.Dim("Deleted SecuredCluster CR")
178+
if crExists {
179+
d.logger.Info("Removing any pause-reconcile annotation from SecuredCluster")
180+
if err := d.removePauseReconcileAnnotation(ctx, "securedcluster", "stackrox-secured-cluster-services", d.sensorNamespace); err != nil {
181+
return err
182+
}
183+
if d.verbose {
184+
d.logger.Dim("Removed any pause-reconcile annotation from SecuredCluster")
185+
}
186+
187+
err := d.deleteResource(ctx, d.sensorNamespace, "securedcluster", "stackrox-secured-cluster-services", "--wait")
188+
if err != nil {
189+
return err
190+
}
191+
if d.verbose {
192+
d.logger.Dim("Deleted SecuredCluster CR")
193+
}
194+
} else {
195+
d.logger.Info("Deletion of SecuredCluster resources requested, but SecuredCluster CR is not present anymore")
172196
}
173197

174198
// Delete resources, which are treated special.
@@ -867,6 +891,7 @@ func (d *Deployer) removePauseReconcileAnnotation(ctx context.Context, resourceT
867891
"-n", namespace,
868892
fmt.Sprintf("%s-", pauseReconcileAnnotationKey),
869893
},
894+
IgnoreErrors: true,
870895
})
871896
if err != nil {
872897
return fmt.Errorf("failed to remove pause-reconcile annotation: %w", err)

0 commit comments

Comments
 (0)