Skip to content

Commit d8c84c5

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

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

api/v1beta2/awsmanagedcluster_types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ type AWSManagedClusterStatus 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 AWSManagedCluster.
43+
// +optional
44+
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
4145
}
4246

4347
// +kubebuilder:object:root=true
@@ -69,3 +73,15 @@ type AWSManagedClusterList struct {
6973
func init() {
7074
SchemeBuilder.Register(&AWSManagedCluster{}, &AWSManagedClusterList{})
7175
}
76+
77+
// GetConditions returns the observations of the operational state of the
78+
// AWSManagedCluster resource.
79+
func (r *AWSManagedCluster) GetConditions() clusterv1.Conditions {
80+
return r.Status.Conditions
81+
}
82+
83+
// SetConditions sets the underlying service state of the AWSManagedCluster to
84+
// the predescribed clusterv1.Conditions.
85+
func (r *AWSManagedCluster) SetConditions(conditions clusterv1.Conditions) {
86+
r.Status.Conditions = conditions
87+
}

controllers/awsmanagedcluster_controller.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ import (
3535
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
3636
ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2"
3737
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
38+
"sigs.k8s.io/cluster-api-provider-aws/v2/util/paused"
3839
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3940
"sigs.k8s.io/cluster-api/util"
40-
"sigs.k8s.io/cluster-api/util/annotations"
4141
"sigs.k8s.io/cluster-api/util/patch"
4242
"sigs.k8s.io/cluster-api/util/predicates"
4343
)
@@ -78,11 +78,6 @@ func (r *AWSManagedClusterReconciler) Reconcile(ctx context.Context, req ctrl.Re
7878
return reconcile.Result{}, nil
7979
}
8080

81-
if annotations.IsPaused(cluster, awsManagedCluster) {
82-
log.Info("AWSManagedCluster or linked Cluster is marked as paused. Won't reconcile")
83-
return reconcile.Result{}, nil
84-
}
85-
8681
log = log.WithValues("cluster", cluster.Name)
8782

8883
controlPlane := &ekscontrolplanev1.AWSManagedControlPlane{}
@@ -95,6 +90,10 @@ func (r *AWSManagedClusterReconciler) Reconcile(ctx context.Context, req ctrl.Re
9590
return reconcile.Result{}, fmt.Errorf("failed to get control plane ref: %w", err)
9691
}
9792

93+
if isPaused, conditionChanged, err := paused.EnsurePausedCondition(ctx, r.Client, cluster, awsManagedCluster); err != nil || isPaused || conditionChanged {
94+
return ctrl.Result{}, err
95+
}
96+
9897
log = log.WithValues("controlPlane", controlPlaneRef.Name)
9998

10099
patchHelper, err := patch.NewHelper(awsManagedCluster, r.Client)
@@ -124,19 +123,19 @@ func (r *AWSManagedClusterReconciler) SetupWithManager(ctx context.Context, mgr
124123
controller, err := ctrl.NewControllerManagedBy(mgr).
125124
WithOptions(options).
126125
For(awsManagedCluster).
127-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(mgr.GetScheme(), ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
126+
WithEventFilter(predicates.ResourceHasFilterLabel(mgr.GetScheme(), ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
128127
WithEventFilter(predicates.ResourceIsNotExternallyManaged(mgr.GetScheme(), log.GetLogger())).
129128
Build(r)
130129

131130
if err != nil {
132131
return fmt.Errorf("error creating controller: %w", err)
133132
}
134133

135-
// Add a watch for clusterv1.Cluster unpaise
134+
// Add a watch for clusterv1.Cluster unpause
136135
if err = controller.Watch(
137136
source.Kind[client.Object](mgr.GetCache(), &clusterv1.Cluster{},
138137
handler.EnqueueRequestsFromMapFunc(util.ClusterToInfrastructureMapFunc(ctx, infrav1.GroupVersion.WithKind("AWSManagedCluster"), mgr.GetClient(), &infrav1.AWSManagedCluster{})),
139-
predicates.ClusterUnpaused(mgr.GetScheme(), log.GetLogger())),
138+
predicates.ClusterPausedTransitions(mgr.GetScheme(), log.GetLogger())),
140139
); err != nil {
141140
return fmt.Errorf("failed adding a watch for ready clusters: %w", err)
142141
}

0 commit comments

Comments
 (0)