Skip to content

Commit 40fcaec

Browse files
Merge pull request openshift#1927 from 2uasimojo/HIVE-2064/pause-cd
Pause ClusterDeployment reconciliation
2 parents 206ec60 + 1476eed commit 40fcaec

13 files changed

Lines changed: 88 additions & 0 deletions

File tree

pkg/constants/constants.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ const (
134134
// the cluster, causing its machines to remain in their current state (unless acted on externally) regardless of CD.Spec.PowerState.
135135
PowerStatePauseAnnotation = "hive.openshift.io/powerstate-pause"
136136

137+
// ReconcilePauseAnnotation is an annotation used by ClusterDeployment. If "true", (most) controllers will (mostly) ignore the CD until
138+
// the annotation is cleared/non-truthy. Exceptions:
139+
// - clusterclaim: We'll still mark the CD for deletion by the clusterpool controller when the claim is deleted.
140+
// - clusterpool:
141+
// - We'll still delete CDs* for various reasons, including
142+
// - Associated claim is deleted (per above)
143+
// - To satisfy pool capacity constraints
144+
// - To flush out broken or stale clusters
145+
// - We'll still update CD PowerState when it's time to hibernate or resume a pool cluster. But the hibernation controller won't
146+
// effect that change while the annotation is still set.
147+
// - We'll still create new ClusterDeployments to satisfy pool capacities. If you include this annotation in
148+
// ClusterPool.Spec.Annotations, those ClusterDeployments will be created with it set, so we won't do anything (like provision the
149+
// cluster) until it's unset.
150+
// - clusterpoolnamespace: We'll still delete CDs*.
151+
// *Note that this only entails setting the deletionTimestamp; the other controllers won't do anything about it (like deprovisioning
152+
// the cluster) while the annotation is still set.
153+
ReconcilePauseAnnotation = "hive.openshift.io/reconcile-pause"
154+
137155
// HiveManagedLabel is a label added to any resources we sync to the remote cluster to help identify that they are
138156
// managed by Hive, and any manual changes may be undone the next time the resource is reconciled.
139157
HiveManagedLabel = "hive.openshift.io/managed"

pkg/controller/argocdregister/argocdregister_controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"net/url"
2727
"os"
2828
"reflect"
29+
"strconv"
2930
"strings"
3031

3132
log "github.com/sirupsen/logrus"
@@ -153,6 +154,11 @@ func (r *ArgoCDRegisterController) Reconcile(ctx context.Context, request reconc
153154
}
154155
cdLog = controllerutils.AddLogFields(controllerutils.MetaObjectLogTagger{Object: cd}, cdLog)
155156

157+
if paused, err := strconv.ParseBool(cd.Annotations[constants.ReconcilePauseAnnotation]); err == nil && paused {
158+
cdLog.Info("skipping reconcile due to ClusterDeployment pause annotation")
159+
return reconcile.Result{}, nil
160+
}
161+
156162
if !cd.Spec.Installed {
157163
cdLog.Info("cluster installation is not complete")
158164
return reconcile.Result{}, nil

pkg/controller/awsprivatelink/awsprivatelink_controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"regexp"
1010
"sort"
11+
"strconv"
1112
"strings"
1213
"time"
1314

@@ -173,6 +174,11 @@ func (r *ReconcileAWSPrivateLink) Reconcile(ctx context.Context, request reconci
173174
}
174175
logger = controllerutils.AddLogFields(controllerutils.MetaObjectLogTagger{Object: cd}, logger)
175176

177+
if paused, err := strconv.ParseBool(cd.Annotations[constants.ReconcilePauseAnnotation]); err == nil && paused {
178+
logger.Info("skipping reconcile due to ClusterDeployment pause annotation")
179+
return reconcile.Result{}, nil
180+
}
181+
176182
// Initialize cluster deployment conditions if not present
177183
newConditions, changed := controllerutils.InitializeClusterDeploymentConditions(cd.Status.Conditions, clusterDeploymentAWSPrivateLinkConditions)
178184
if changed {

pkg/controller/clusterdeployment/clusterdeployment_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ func (r *ReconcileClusterDeployment) Reconcile(ctx context.Context, request reco
299299
}
300300
cdLog = controllerutils.AddLogFields(controllerutils.MetaObjectLogTagger{Object: cd}, cdLog)
301301

302+
if paused, err := strconv.ParseBool(cd.Annotations[constants.ReconcilePauseAnnotation]); err == nil && paused {
303+
cdLog.Info("skipping reconcile due to ClusterDeployment pause annotation")
304+
return reconcile.Result{}, nil
305+
}
306+
302307
// Ensure owner references are correctly set
303308
err = controllerutils.ReconcileOwnerReferences(cd, generateOwnershipUniqueKeys(cd), r, r.scheme, r.logger)
304309
if err != nil {

pkg/controller/clusterrelocate/clusterrelocate_controller.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"reflect"
7+
"strconv"
78
"strings"
89

910
"github.com/pkg/errors"
@@ -27,6 +28,7 @@ import (
2728
"sigs.k8s.io/controller-runtime/pkg/source"
2829

2930
hivev1 "github.com/openshift/hive/apis/hive/v1"
31+
"github.com/openshift/hive/pkg/constants"
3032
hivemetrics "github.com/openshift/hive/pkg/controller/metrics"
3133
controllerutils "github.com/openshift/hive/pkg/controller/utils"
3234
"github.com/openshift/hive/pkg/remoteclient"
@@ -174,6 +176,11 @@ func (r *ReconcileClusterRelocate) Reconcile(ctx context.Context, request reconc
174176
}
175177
logger = controllerutils.AddLogFields(controllerutils.MetaObjectLogTagger{Object: cd}, logger)
176178

179+
if paused, err := strconv.ParseBool(cd.Annotations[constants.ReconcilePauseAnnotation]); err == nil && paused {
180+
logger.Info("skipping reconcile due to ClusterDeployment pause annotation")
181+
return reconcile.Result{}, nil
182+
}
183+
177184
// Initialize cluster deployment conditions if not present
178185
newConditions, changed := controllerutils.InitializeClusterDeploymentConditions(cd.Status.Conditions,
179186
clusterDeploymentClusterRelocateConditions)

pkg/controller/clusterstate/clusterstate_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"reflect"
7+
"strconv"
78
"time"
89

910
log "github.com/sirupsen/logrus"
@@ -121,6 +122,10 @@ func (r *ReconcileClusterState) Reconcile(ctx context.Context, request reconcile
121122
return reconcile.Result{}, err
122123
}
123124
logger = controllerutils.AddLogFields(controllerutils.MetaObjectLogTagger{Object: cd}, logger)
125+
if paused, err := strconv.ParseBool(cd.Annotations[constants.ReconcilePauseAnnotation]); err == nil && paused {
126+
logger.Info("skipping reconcile due to ClusterDeployment pause annotation")
127+
return reconcile.Result{}, nil
128+
}
124129

125130
// Ensure owner references are correctly set
126131
err = controllerutils.ReconcileOwnerReferences(cd, generateOwnershipUniqueKeys(cd), r, r.scheme, logger)

pkg/controller/clusterversion/clusterversion_controller.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package clusterversion
33
import (
44
"context"
55
"fmt"
6+
"strconv"
67

78
"github.com/blang/semver/v4"
89
log "github.com/sirupsen/logrus"
@@ -111,6 +112,12 @@ func (r *ReconcileClusterVersion) Reconcile(ctx context.Context, request reconci
111112
return reconcile.Result{}, err
112113
}
113114
cdLog = controllerutils.AddLogFields(controllerutils.MetaObjectLogTagger{Object: cd}, cdLog)
115+
116+
if paused, err := strconv.ParseBool(cd.Annotations[constants.ReconcilePauseAnnotation]); err == nil && paused {
117+
cdLog.Info("skipping reconcile due to ClusterDeployment pause annotation")
118+
return reconcile.Result{}, nil
119+
}
120+
114121
// If the clusterdeployment is deleted, do not reconcile.
115122
if cd.DeletionTimestamp != nil {
116123
return reconcile.Result{}, nil

pkg/controller/controlplanecerts/controlplanecerts_controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88
"net/url"
99
"sort"
10+
"strconv"
1011
"strings"
1112
"time"
1213

@@ -144,6 +145,11 @@ func (r *ReconcileControlPlaneCerts) Reconcile(ctx context.Context, request reco
144145
}
145146
cdLog = controllerutils.AddLogFields(controllerutils.MetaObjectLogTagger{Object: cd}, cdLog)
146147

148+
if paused, err := strconv.ParseBool(cd.Annotations[constants.ReconcilePauseAnnotation]); err == nil && paused {
149+
cdLog.Info("skipping reconcile due to ClusterDeployment pause annotation")
150+
return reconcile.Result{}, nil
151+
}
152+
147153
// Initialize cluster deployment conditions if not present
148154
newConditions, changed := controllerutils.InitializeClusterDeploymentConditions(cd.Status.Conditions, clusterDeploymentControlPlaneCertsConditions)
149155
if changed {

pkg/controller/hibernation/hibernation_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ func (r *hibernationReconciler) Reconcile(ctx context.Context, request reconcile
171171
}
172172
cdLog = controllerutils.AddLogFields(controllerutils.MetaObjectLogTagger{Object: cd}, cdLog)
173173

174+
if paused, err := strconv.ParseBool(cd.Annotations[constants.ReconcilePauseAnnotation]); err == nil && paused {
175+
cdLog.Info("skipping reconcile due to ClusterDeployment pause annotation")
176+
return reconcile.Result{}, nil
177+
}
178+
174179
// If cluster is already deleted, skip any processing
175180
if !cd.DeletionTimestamp.IsZero() {
176181
return reconcile.Result{}, nil

pkg/controller/remoteingress/remoteingress_controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"reflect"
99
"sort"
10+
"strconv"
1011
"time"
1112

1213
log "github.com/sirupsen/logrus"
@@ -156,6 +157,11 @@ func (r *ReconcileRemoteClusterIngress) Reconcile(ctx context.Context, request r
156157
return reconcile.Result{}, err
157158
}
158159
cdLog = controllerutils.AddLogFields(controllerutils.MetaObjectLogTagger{Object: cd}, cdLog)
160+
if paused, err := strconv.ParseBool(cd.Annotations[constants.ReconcilePauseAnnotation]); err == nil && paused {
161+
cdLog.Info("skipping reconcile due to ClusterDeployment pause annotation")
162+
return reconcile.Result{}, nil
163+
}
164+
159165
rContext.clusterDeployment = cd
160166

161167
// Initialize cluster deployment conditions if not present

0 commit comments

Comments
 (0)