Skip to content

Commit 275af43

Browse files
authored
ROX-15806: Remove pause reconcile annotation before Central deletion (#905)
1 parent 92ce0f4 commit 275af43

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

fleetshard/pkg/central/reconciler/reconciler.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const (
3939
helmReleaseName = "tenant-resources"
4040

4141
managedServicesAnnotation = "platform.stackrox.io/managed-services"
42+
pauseReconcileAnnotation = "stackrox.io/pause-reconcile"
4243
envAnnotationKey = "rhacs.redhat.com/environment"
4344
clusterNameAnnotationKey = "rhacs.redhat.com/cluster-name"
4445
orgNameAnnotationKey = "rhacs.redhat.com/org-name"
@@ -722,13 +723,38 @@ func (r *CentralReconciler) ensureCentralCRDeleted(ctx context.Context, central
722723

723724
return false, errors.Wrapf(err, "delete central CR %s/%s", central.GetNamespace(), central.GetName())
724725
}
726+
727+
// avoid being stuck in a deprovisioning state due to the pause reconcile annotation
728+
err = r.disablePauseReconcileIfPresent(ctx, central)
729+
if err != nil {
730+
return false, err
731+
}
732+
725733
if err := r.client.Delete(ctx, central); err != nil {
726734
return false, errors.Wrapf(err, "delete central CR %s/%s", central.GetNamespace(), central.GetName())
727735
}
728736
glog.Infof("Central CR %s/%s is marked for deletion", central.GetNamespace(), central.GetName())
729737
return false, nil
730738
}
731739

740+
func (r *CentralReconciler) disablePauseReconcileIfPresent(ctx context.Context, central *v1alpha1.Central) error {
741+
if central.Annotations == nil {
742+
return nil
743+
}
744+
745+
if value, exists := central.Annotations[pauseReconcileAnnotation]; !exists || value != "true" {
746+
return nil
747+
}
748+
749+
central.Annotations[pauseReconcileAnnotation] = "false"
750+
err := r.client.Update(ctx, central)
751+
if err != nil {
752+
return fmt.Errorf("removing pause reconcile annotation: %v", err)
753+
}
754+
755+
return nil
756+
}
757+
732758
func (r *CentralReconciler) ensureChartResourcesExist(ctx context.Context, remoteCentral private.ManagedCentral) error {
733759
vals, err := r.chartValues(remoteCentral)
734760
if err != nil {

fleetshard/pkg/central/reconciler/reconciler_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,28 @@ func TestReconcileDelete(t *testing.T) {
335335
assert.True(t, k8sErrors.IsNotFound(err))
336336
}
337337

338+
func TestDisablePauseAnnotation(t *testing.T) {
339+
fakeClient := testutils.NewFakeClientBuilder(t).Build()
340+
r := NewCentralReconciler(fakeClient, private.ManagedCentral{}, nil, centralDBInitFunc, CentralReconcilerOptions{UseRoutes: true})
341+
342+
_, err := r.Reconcile(context.TODO(), simpleManagedCentral)
343+
require.NoError(t, err)
344+
345+
central := &v1alpha1.Central{}
346+
err = fakeClient.Get(context.TODO(), client.ObjectKey{Name: centralName, Namespace: centralNamespace}, central)
347+
require.NoError(t, err)
348+
central.Annotations[pauseReconcileAnnotation] = "true"
349+
err = fakeClient.Update(context.TODO(), central)
350+
require.NoError(t, err)
351+
352+
err = r.disablePauseReconcileIfPresent(context.TODO(), central)
353+
require.NoError(t, err)
354+
355+
err = fakeClient.Get(context.TODO(), client.ObjectKey{Name: centralName, Namespace: centralNamespace}, central)
356+
require.NoError(t, err)
357+
require.Equal(t, "false", central.Annotations[pauseReconcileAnnotation])
358+
}
359+
338360
func TestReconcileDeleteWithManagedDB(t *testing.T) {
339361
fakeClient := testutils.NewFakeClientBuilder(t).Build()
340362

0 commit comments

Comments
 (0)