Skip to content

Commit c7dfba5

Browse files
JustinKuliopenshift-merge-robot
authored andcommitted
Allow uninstall mode to be cancelled
Previously, the running container could only move *into* uninstallation mode - once it was in that mode, it needed to be restarted to restore normal operations. To improve the reliability of uninstall/reinstall scenarios, it can now move back into normal operations automatically. All reconciles that were skipped during uninstallation are now just delayed 5 minutes. A "normal" uninstallation should be completed within that amount of time. If the uninstallation was aborted, then this should ensure no reconciles are permanently missed. Refs: - https://issues.redhat.com/browse/ACM-6941 Signed-off-by: Justin Kulikauskas <[email protected]>
1 parent 75ac539 commit c7dfba5

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

controllers/gatekeepersync/gatekeeper_constraint_sync.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"fmt"
1212
"strings"
1313
"sync"
14+
"time"
1415

1516
depclient "github.com/stolostron/kubernetes-dependency-watches/client"
1617
admissionregistration "k8s.io/api/admissionregistration/v1"
@@ -93,7 +94,7 @@ func (r *GatekeeperConstraintReconciler) Reconcile(
9394
if uninstall.DeploymentIsUninstalling {
9495
log.Info("Skipping reconcile because the deployment is in uninstallation mode")
9596

96-
return reconcile.Result{}, nil
97+
return reconcile.Result{RequeueAfter: 5 * time.Minute}, nil
9798
}
9899

99100
log.Info("Reconciling a Policy with one or more Gatekeeper constraints")

controllers/secretsync/secret_sync.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package secretsync
55

66
import (
77
"context"
8+
"time"
89

910
corev1 "k8s.io/api/core/v1"
1011
"k8s.io/apimachinery/pkg/api/equality"
@@ -61,7 +62,7 @@ func (r *SecretReconciler) Reconcile(ctx context.Context, request reconcile.Requ
6162
if uninstall.DeploymentIsUninstalling {
6263
log.Info("Skipping reconcile because the deployment is in uninstallation mode")
6364

64-
return reconcile.Result{}, nil
65+
return reconcile.Result{RequeueAfter: 5 * time.Minute}, nil
6566
}
6667

6768
reqLogger.Info("Reconciling Secret")

controllers/specsync/policy_spec_sync.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package specsync
66
import (
77
"context"
88
"fmt"
9+
"time"
910

1011
"k8s.io/apimachinery/pkg/api/errors"
1112
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -70,7 +71,7 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
7071
if uninstall.DeploymentIsUninstalling {
7172
log.Info("Skipping reconcile because the deployment is in uninstallation mode")
7273

73-
return reconcile.Result{}, nil
74+
return reconcile.Result{RequeueAfter: 5 * time.Minute}, nil
7475
}
7576

7677
reqLogger.Info("Reconciling Policy...")

controllers/statussync/policy_status_sync.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"sort"
1212
"strconv"
1313
"strings"
14+
"time"
1415

1516
corev1 "k8s.io/api/core/v1"
1617
"k8s.io/apimachinery/pkg/api/equality"
@@ -84,7 +85,7 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
8485
if uninstall.DeploymentIsUninstalling {
8586
log.Info("Skipping reconcile because the deployment is in uninstallation mode")
8687

87-
return reconcile.Result{}, nil
88+
return reconcile.Result{RequeueAfter: 5 * time.Minute}, nil
8889
}
8990

9091
reqLogger.Info("Reconciling the policy")

controllers/templatesync/template_sync.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"regexp"
1212
"strings"
13+
"time"
1314

1415
"github.com/go-logr/logr"
1516
gktemplatesv1 "github.com/open-policy-agent/frameworks/constraint/pkg/apis/templates/v1"
@@ -218,7 +219,7 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
218219
if uninstall.DeploymentIsUninstalling {
219220
log.Info("Skipping reconcile because the deployment is in uninstallation mode")
220221

221-
return reconcile.Result{}, nil
222+
return reconcile.Result{RequeueAfter: 5 * time.Minute}, nil
222223
}
223224

224225
// Handle dependencies that apply to the parent policy

controllers/uninstall/watcher.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ type reconciler struct {
3232
func (r *reconciler) Reconcile(ctx context.Context, obj client.ObjectIdentifier) (reconcile.Result, error) {
3333
log := log.WithValues("name", obj.Name, "namespace", obj.Namespace)
3434

35-
if DeploymentIsUninstalling {
36-
log.Info("Skipping reconcile because the uninstall flag is already true. " +
37-
"To reset the flag, stop this container.")
38-
39-
return reconcile.Result{}, nil
40-
}
41-
4235
log.Info("Checking the deployment for the annotation " + AnnotationKey)
4336

4437
deployment, err := r.AppsV1().Deployments(obj.Namespace).Get(ctx, obj.Name, v1.GetOptions{})
@@ -57,14 +50,16 @@ func (r *reconciler) Reconcile(ctx context.Context, obj client.ObjectIdentifier)
5750
}
5851

5952
if deployment.GetAnnotations()[AnnotationKey] == "true" {
60-
log.Info("Annotation " + AnnotationKey + " found and was true. Setting the uninstall flag.")
53+
log.Info("Annotation " + AnnotationKey + " found and was true. Setting the uninstall flag to true.")
6154

6255
DeploymentIsUninstalling = true
6356

6457
return reconcile.Result{}, nil
6558
}
6659

67-
log.Info("Annotation " + AnnotationKey + " not found, or not true. No changes.")
60+
log.Info("Annotation " + AnnotationKey + " not found, or not true. Setting the uninstall flag to false.")
61+
62+
DeploymentIsUninstalling = false
6863

6964
return reconcile.Result{}, nil
7065
}

0 commit comments

Comments
 (0)