Skip to content

Commit 02d5ff0

Browse files
Merge pull request #2742 from Nordix/add-v1beta2-conditions-cluster
✨ Add v1beta2 conditions for Metal3Cluster
2 parents 64274f2 + bbd7ae7 commit 02d5ff0

10 files changed

+249
-43
lines changed

.golangci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ linters-settings:
110110
- pkg: "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions"
111111
alias: v1beta1conditions
112112
- pkg: sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions/v1beta2
113-
alias: deprecatedv1beta2conditions
113+
alias: v1beta2conditions
114114
- pkg: sigs.k8s.io/cluster-api/util/conditions/deprecated/v1beta1
115115
alias: deprecatedv1beta1conditions
116116
- pkg: sigs.k8s.io/cluster-api/util/deprecated/v1beta1/patch

api/v1beta1/metal3cluster_types.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ const (
2929
ClusterFinalizer = "metal3cluster.infrastructure.cluster.x-k8s.io"
3030
)
3131

32+
// Metal3Cluster Conditions and Reasons.
33+
const (
34+
Metal3ClusterReadyV1Beta2Condition = clusterv1beta1.ReadyV1Beta2Condition
35+
Metal3ClusterReadyV1Beta2Reason = clusterv1beta1.ReadyV1Beta2Reason
36+
Metal3ClusterNotReadyV1Beta2Reason = clusterv1beta1.NotReadyV1Beta2Reason
37+
Metal3ClusterReadyUnknownV1Beta2Reason = clusterv1beta1.ReadyUnknownV1Beta2Reason
38+
)
39+
40+
const (
41+
BaremetalInfrastructureReadyV1Beta2Condition = "BaremetalInfrastructureReady"
42+
BaremetalInfrastructureReadyV1Beta2Reason = clusterv1beta1.ReadyV1Beta2Reason
43+
ControlPlaneEndpointFailedV1Beta2Reason = "ControlPlaneEndpointFailed"
44+
FailedToGetOwnerClusterReasonV1Beta2Reason = "FailedToGetOwnerCluster"
45+
Metal3ClusterDeletingV1Beta2Reason = clusterv1beta1.DeletingReason
46+
)
47+
3248
// Metal3ClusterSpec defines the desired state of Metal3Cluster.
3349
type Metal3ClusterSpec struct {
3450
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
@@ -96,6 +112,21 @@ type Metal3ClusterStatus struct {
96112
// Conditions defines current service state of the Metal3Cluster.
97113
// +optional
98114
Conditions clusterv1beta1.Conditions `json:"conditions,omitempty"`
115+
// v1beta2 groups all the fields that will be added or modified in Metal3Cluster's status with the V1Beta2 version.
116+
// +optional
117+
V1Beta2 *Metal3ClusterV1Beta2Status `json:"v1beta2,omitempty"`
118+
}
119+
120+
// Metal3ClusterV1Beta2Status groups all the fields that will be added or modified in Metal3ClusterStatus with the V1Beta2 version.
121+
// See https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md for more context.
122+
type Metal3ClusterV1Beta2Status struct {
123+
// conditions represents the observations of a Metal3Cluster's current state.
124+
// Known condition types are Ready, and Paused, BareMetalInfraStructureReady.
125+
// +optional
126+
// +listType=map
127+
// +listMapKey=type
128+
// +kubebuilder:validation:MaxItems=32
129+
Conditions []metav1.Condition `json:"conditions,omitempty"`
99130
}
100131

101132
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@@ -140,6 +171,22 @@ func (c *Metal3Cluster) SetConditions(conditions clusterv1beta1.Conditions) {
140171
c.Status.Conditions = conditions
141172
}
142173

174+
// GetV1Beta2Conditions returns the set of conditions for this object.
175+
func (c *Metal3Cluster) GetV1Beta2Conditions() []metav1.Condition {
176+
if c.Status.V1Beta2 == nil {
177+
return nil
178+
}
179+
return c.Status.V1Beta2.Conditions
180+
}
181+
182+
// SetV1Beta2Conditions sets conditions for an API object.
183+
func (c *Metal3Cluster) SetV1Beta2Conditions(conditions []metav1.Condition) {
184+
if c.Status.V1Beta2 == nil {
185+
c.Status.V1Beta2 = &Metal3ClusterV1Beta2Status{}
186+
}
187+
c.Status.V1Beta2.Conditions = conditions
188+
}
189+
143190
func init() {
144191
objectTypes = append(objectTypes, &Metal3Cluster{}, &Metal3ClusterList{})
145192
}

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 46 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

baremetal/metal3cluster_manager.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
capierrors "sigs.k8s.io/cluster-api/errors"
3030
"sigs.k8s.io/cluster-api/util"
3131
v1beta1conditions "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions"
32+
v1beta2conditions "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions/v1beta2"
3233
"sigs.k8s.io/controller-runtime/pkg/client"
3334
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3435
)
@@ -132,12 +133,22 @@ func (s *ClusterManager) UpdateClusterStatus() error {
132133
s.Metal3Cluster.Status.Ready = false
133134
s.setError("Invalid ControlPlaneEndpoint values", capierrors.InvalidConfigurationClusterError)
134135
v1beta1conditions.MarkFalse(s.Metal3Cluster, infrav1.BaremetalInfrastructureReadyCondition, infrav1.ControlPlaneEndpointFailedReason, clusterv1beta1.ConditionSeverityError, "%s", err.Error())
136+
v1beta2conditions.Set(s.Metal3Cluster, metav1.Condition{
137+
Type: infrav1.BaremetalInfrastructureReadyV1Beta2Condition,
138+
Status: metav1.ConditionFalse,
139+
Reason: infrav1.ControlPlaneEndpointFailedReason,
140+
})
135141
return err
136142
}
137143

138144
// Mark the metal3Cluster ready.
139145
s.Metal3Cluster.Status.Ready = true
140146
v1beta1conditions.MarkTrue(s.Metal3Cluster, infrav1.BaremetalInfrastructureReadyCondition)
147+
v1beta2conditions.Set(s.Metal3Cluster, metav1.Condition{
148+
Type: infrav1.BaremetalInfrastructureReadyV1Beta2Condition,
149+
Status: metav1.ConditionTrue,
150+
Reason: infrav1.BaremetalInfrastructureReadyV1Beta2Reason,
151+
})
141152
now := metav1.Now()
142153
s.Metal3Cluster.Status.LastUpdated = &now
143154
return nil

baremetal/metal3machine_manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import (
5252
"sigs.k8s.io/cluster-api/util"
5353
deprecatedv1beta1conditions "sigs.k8s.io/cluster-api/util/conditions/deprecated/v1beta1"
5454
v1beta1conditions "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions"
55-
deprecatedv1beta2conditions "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions/v1beta2"
55+
v1beta2conditions "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions/v1beta2"
5656
v1beta1patch "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/patch"
5757
"sigs.k8s.io/controller-runtime/pkg/client"
5858
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -1211,7 +1211,7 @@ func (m *MachineManager) SetConditionMetal3MachineToFalse(t clusterv1beta1.Condi
12111211

12121212
// SetV1beta2Condition sets v1beta2 condition in Metal3Machine status.
12131213
func (m *MachineManager) SetV1beta2Condition(conditionType string, status metav1.ConditionStatus, reason string, message string) {
1214-
deprecatedv1beta2conditions.Set(m.Metal3Machine, metav1.Condition{
1214+
v1beta2conditions.Set(m.Metal3Machine, metav1.Condition{
12151215
Type: conditionType,
12161216
Status: status,
12171217
Reason: reason,
@@ -1244,7 +1244,7 @@ func (m *MachineManager) updateMachineStatus(_ context.Context, host *bmov1alpha
12441244

12451245
m.Metal3Machine.Status.Addresses = addrs
12461246
v1beta1conditions.MarkTrue(m.Metal3Machine, infrav1.AssociateBMHCondition)
1247-
deprecatedv1beta2conditions.Set(m.Metal3Machine, metav1.Condition{
1247+
v1beta2conditions.Set(m.Metal3Machine, metav1.Condition{
12481248
Type: infrav1.AssociateBareMetalHostV1Beta2Condition,
12491249
Status: metav1.ConditionTrue,
12501250
Reason: infrav1.AssociateBareMetalHostSuccessV1Beta2Reason,

config/crd/bases/infrastructure.cluster.x-k8s.io_metal3clusters.yaml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,75 @@ spec:
175175
steps need to be performed. Required by Cluster API. Set to True by the
176176
metal3Cluster controller after creation.
177177
type: boolean
178+
v1beta2:
179+
description: v1beta2 groups all the fields that will be added or modified
180+
in Metal3Cluster's status with the V1Beta2 version.
181+
properties:
182+
conditions:
183+
description: |-
184+
conditions represents the observations of a Metal3Cluster's current state.
185+
Known condition types are Ready, and Paused, BareMetalInfraStructureReady.
186+
items:
187+
description: Condition contains details for one aspect of the
188+
current state of this API Resource.
189+
properties:
190+
lastTransitionTime:
191+
description: |-
192+
lastTransitionTime is the last time the condition transitioned from one status to another.
193+
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
194+
format: date-time
195+
type: string
196+
message:
197+
description: |-
198+
message is a human readable message indicating details about the transition.
199+
This may be an empty string.
200+
maxLength: 32768
201+
type: string
202+
observedGeneration:
203+
description: |-
204+
observedGeneration represents the .metadata.generation that the condition was set based upon.
205+
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
206+
with respect to the current state of the instance.
207+
format: int64
208+
minimum: 0
209+
type: integer
210+
reason:
211+
description: |-
212+
reason contains a programmatic identifier indicating the reason for the condition's last transition.
213+
Producers of specific condition types may define expected values and meanings for this field,
214+
and whether the values are considered a guaranteed API.
215+
The value should be a CamelCase string.
216+
This field may not be empty.
217+
maxLength: 1024
218+
minLength: 1
219+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
220+
type: string
221+
status:
222+
description: status of the condition, one of True, False,
223+
Unknown.
224+
enum:
225+
- "True"
226+
- "False"
227+
- Unknown
228+
type: string
229+
type:
230+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
231+
maxLength: 316
232+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
233+
type: string
234+
required:
235+
- lastTransitionTime
236+
- message
237+
- reason
238+
- status
239+
- type
240+
type: object
241+
maxItems: 32
242+
type: array
243+
x-kubernetes-list-map-keys:
244+
- type
245+
x-kubernetes-list-type: map
246+
type: object
178247
type: object
179248
type: object
180249
served: true

0 commit comments

Comments
 (0)