Skip to content

Commit a11fb5c

Browse files
authoredMar 18, 2025··
Merge pull request #5394 from theobarberbany/awsmanagedcluster-paused
✨ Updates AWSManagedCluster, ROSACluster with Paused Condition
2 parents e4961f8 + b9aa06b commit a11fb5c

8 files changed

+149
-15
lines changed
 

‎api/v1beta2/awsmanagedcluster_types.go

+16
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+
}

‎api/v1beta2/zz_generated.deepcopy.go

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎config/crd/bases/infrastructure.cluster.x-k8s.io_awsmanagedclusters.yaml

+45
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,51 @@ spec:
7676
status:
7777
description: AWSManagedClusterStatus defines the observed state of AWSManagedCluster
7878
properties:
79+
conditions:
80+
description: Conditions defines current service state of the AWSManagedCluster.
81+
items:
82+
description: Condition defines an observation of a Cluster API resource
83+
operational state.
84+
properties:
85+
lastTransitionTime:
86+
description: |-
87+
Last time the condition transitioned from one status to another.
88+
This should be when the underlying condition changed. If that is not known, then using the time when
89+
the API field changed is acceptable.
90+
format: date-time
91+
type: string
92+
message:
93+
description: |-
94+
A human readable message indicating details about the transition.
95+
This field may be empty.
96+
type: string
97+
reason:
98+
description: |-
99+
The reason for the condition's last transition in CamelCase.
100+
The specific API may choose whether or not this field is considered a guaranteed API.
101+
This field may be empty.
102+
type: string
103+
severity:
104+
description: |-
105+
severity provides an explicit classification of Reason code, so the users or machines can immediately
106+
understand the current situation and act accordingly.
107+
The Severity field MUST be set only when Status=False.
108+
type: string
109+
status:
110+
description: status of the condition, one of True, False, Unknown.
111+
type: string
112+
type:
113+
description: |-
114+
type of condition in CamelCase or in foo.example.com/CamelCase.
115+
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions
116+
can be useful (see .node.status.conditions), the ability to deconflict is important.
117+
type: string
118+
required:
119+
- lastTransitionTime
120+
- status
121+
- type
122+
type: object
123+
type: array
79124
failureDomains:
80125
additionalProperties:
81126
description: |-

‎config/crd/bases/infrastructure.cluster.x-k8s.io_rosaclusters.yaml

+45
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,51 @@ spec:
7676
status:
7777
description: ROSAClusterStatus defines the observed state of ROSACluster.
7878
properties:
79+
conditions:
80+
description: Conditions defines current service state of the ROSACluster.
81+
items:
82+
description: Condition defines an observation of a Cluster API resource
83+
operational state.
84+
properties:
85+
lastTransitionTime:
86+
description: |-
87+
Last time the condition transitioned from one status to another.
88+
This should be when the underlying condition changed. If that is not known, then using the time when
89+
the API field changed is acceptable.
90+
format: date-time
91+
type: string
92+
message:
93+
description: |-
94+
A human readable message indicating details about the transition.
95+
This field may be empty.
96+
type: string
97+
reason:
98+
description: |-
99+
The reason for the condition's last transition in CamelCase.
100+
The specific API may choose whether or not this field is considered a guaranteed API.
101+
This field may be empty.
102+
type: string
103+
severity:
104+
description: |-
105+
severity provides an explicit classification of Reason code, so the users or machines can immediately
106+
understand the current situation and act accordingly.
107+
The Severity field MUST be set only when Status=False.
108+
type: string
109+
status:
110+
description: status of the condition, one of True, False, Unknown.
111+
type: string
112+
type:
113+
description: |-
114+
type of condition in CamelCase or in foo.example.com/CamelCase.
115+
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions
116+
can be useful (see .node.status.conditions), the ability to deconflict is important.
117+
type: string
118+
required:
119+
- lastTransitionTime
120+
- status
121+
- type
122+
type: object
123+
type: array
79124
failureDomains:
80125
additionalProperties:
81126
description: |-

‎controllers/awsmanagedcluster_controller.go

+8-9
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
}

‎controllers/rosacluster_controller.go

+5-6
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

+16
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
}

‎exp/api/v1beta2/zz_generated.deepcopy.go

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.