Skip to content

Commit f4721a8

Browse files
Updates ROSACluster with Paused Condition
This change: - Updates the API for ROSACluster to include a conditions field. - Sets `Paused` in the conditions if the controller is paused.
1 parent d8c84c5 commit f4721a8

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

controllers/rosacluster_controller.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ import (
3737
expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
3838
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
3939
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
40+
"sigs.k8s.io/cluster-api-provider-aws/v2/util/paused"
4041
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
4142
"sigs.k8s.io/cluster-api/util"
42-
"sigs.k8s.io/cluster-api/util/annotations"
4343
"sigs.k8s.io/cluster-api/util/patch"
4444
"sigs.k8s.io/cluster-api/util/predicates"
4545
)
@@ -82,9 +82,8 @@ func (r *ROSAClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
8282
return reconcile.Result{}, nil
8383
}
8484

85-
if annotations.IsPaused(cluster, rosaCluster) {
86-
log.Info("ROSACluster or linked Cluster is marked as paused. Won't reconcile")
87-
return reconcile.Result{}, nil
85+
if isPaused, conditionChanged, err := paused.EnsurePausedCondition(ctx, r.Client, cluster, rosaCluster); err != nil || isPaused || conditionChanged {
86+
return ctrl.Result{}, err
8887
}
8988

9089
log = log.WithValues("cluster", cluster.Name)
@@ -127,7 +126,7 @@ func (r *ROSAClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
127126
controller, err := ctrl.NewControllerManagedBy(mgr).
128127
WithOptions(options).
129128
For(rosaCluster).
130-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(mgr.GetScheme(), ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
129+
WithEventFilter(predicates.ResourceHasFilterLabel(mgr.GetScheme(), ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
131130
Build(r)
132131

133132
if err != nil {
@@ -138,7 +137,7 @@ func (r *ROSAClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
138137
if err = controller.Watch(
139138
source.Kind[client.Object](mgr.GetCache(), &clusterv1.Cluster{},
140139
handler.EnqueueRequestsFromMapFunc(util.ClusterToInfrastructureMapFunc(ctx, infrav1.GroupVersion.WithKind("ROSACluster"), mgr.GetClient(), &expinfrav1.ROSACluster{})),
141-
predicates.ClusterUnpaused(mgr.GetScheme(), log.GetLogger())),
140+
predicates.ClusterPausedTransitions(mgr.GetScheme(), log.GetLogger())),
142141
); err != nil {
143142
return fmt.Errorf("failed adding a watch for ready clusters: %w", err)
144143
}

exp/api/v1beta2/rosacluster_types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ type ROSAClusterStatus struct {
3838
// FailureDomains specifies a list fo available availability zones that can be used
3939
// +optional
4040
FailureDomains clusterv1.FailureDomains `json:"failureDomains,omitempty"`
41+
42+
// Conditions defines current service state of the ROSACluster.
43+
// +optional
44+
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
4145
}
4246

4347
// +kubebuilder:object:root=true
@@ -66,6 +70,18 @@ type ROSAClusterList struct {
6670
Items []ROSACluster `json:"items"`
6771
}
6872

73+
// GetConditions returns the observations of the operational state of the
74+
// ROSACluster resource.
75+
func (r *ROSACluster) GetConditions() clusterv1.Conditions {
76+
return r.Status.Conditions
77+
}
78+
79+
// SetConditions sets the underlying service state of the ROSACluster to the
80+
// predescribed clusterv1.Conditions.
81+
func (r *ROSACluster) SetConditions(conditions clusterv1.Conditions) {
82+
r.Status.Conditions = conditions
83+
}
84+
6985
func init() {
7086
SchemeBuilder.Register(&ROSACluster{}, &ROSAClusterList{})
7187
}

0 commit comments

Comments
 (0)