Skip to content

Commit 33639d3

Browse files
Merge pull request #2713 from Nordix/add-v1beta2-conditions-metal3machine
✨ Add v1beta2 conditions for metal3machine
2 parents e01689e + 1f1a11b commit 33639d3

File tree

7 files changed

+368
-7
lines changed

7 files changed

+368
-7
lines changed

api/v1beta1/metal3machine_types.go

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,85 @@ const (
3333
LiveIsoDiskFormat = "live-iso"
3434
)
3535

36+
// Metal3Machine's Ready condition and corresponding reasons that will be used in v1Beta2 API version.
37+
const (
38+
// Metal3MachineReadyV1Beta2Condition is true if the Metal3Machine's deletionTimestamp is not set, Metal3Machine's
39+
// BareMetalHostProvisioned is true.
40+
Metal3MachineReadyV1Beta2Condition = clusterv1beta1.ReadyV1Beta2Condition
41+
42+
// Metal3MachineReadyV1Beta2Reason surfaces when the Metal3Machine readiness criteria is met.
43+
Metal3MachineReadyV1Beta2Reason = clusterv1beta1.ReadyV1Beta2Reason
44+
45+
// Metal3MachineNotReadyV1Beta2Reason surfaces when the Metal3Machine readiness criteria is not met.
46+
Metal3MachineNotReadyV1Beta2Reason = clusterv1beta1.NotReadyV1Beta2Reason
47+
48+
// Metal3MachineReadyUnknownV1Beta2Reason surfaces when at least one Metal3Machine readiness criteria is unknown
49+
// and no Metal3Machine readiness criteria is not met.
50+
Metal3MachineReadyUnknownV1Beta2Reason = clusterv1beta1.ReadyUnknownV1Beta2Reason
51+
)
52+
53+
// Metal3Machine condition and corresponding reasons that will be used in v1Beta2 API version.
54+
const (
55+
// AssociateBareMetalHostV1Beta2Condition documents the status of the association of Metal3Machine with a BareMetalHost.
56+
AssociateBareMetalHostV1Beta2Condition = "AssociateBareMetalHost"
57+
58+
// AssociateBareMetalHostFailedV1Beta2Reason documents any errors while associating Metal3Machine with a BareMetalHost.
59+
AssociateBareMetalHostFailedV1Beta2Reason = "AssociateBareMetalHostFailed"
60+
61+
// AssociateBareMetalHostSuccessV1Beta2Reason surfaces when the Metal3Machine is successfully associated with a BareMetalHost.
62+
AssociateBareMetalHostSuccessV1Beta2Reason = "AssociateBareMetalHostSuccess"
63+
64+
// WaitingForClusterInfrastructureReadyV1Beta2Reason used when waiting for cluster
65+
// infrastructure to be ready before proceeding.
66+
WaitingForClusterInfrastructureReadyV1Beta2Reason = clusterv1beta1.WaitingForClusterInfrastructureReadyV1Beta2Reason
67+
68+
// WaitingForBootstrapDataV1Beta2Reason used when waiting for bootstrap to be ready before proceeding.
69+
WaitingForBootstrapDataV1Beta2Reason = clusterv1beta1.WaitingForBootstrapDataV1Beta2Reason
70+
71+
// WaitingForMetal3MachineOwnerRefV1Beta2Reason is used when Metal3Machine is waiting for OwnerReference to be
72+
// set before proceeding.
73+
WaitingForMetal3MachineOwnerRefV1Beta2Reason = "WaitingForMetal3MachineOwnerRef"
74+
75+
// WaitingforMetal3ClusterReason is used when Metal3Machine is waiting for Metal3Cluster.
76+
WaitingforMetal3ClusterV1Beta2Reason = "WaitingforMetal3Cluster"
77+
78+
// BareMetalHostPauseAnnotationRemoveFailedV1Beta2Reason is used when failed to remove/check pause annotation on associated BareMetalHost.
79+
BareMetalHostPauseAnnotationRemoveFailedV1Beta2Reason = "BareMetalHostPauseAnnotationRemoveFailed"
80+
81+
// BareMetalHostPauseAnnotationSetFailedV1Beta2Reason is used when failed to set pause annotation on associated BareMetalHost.
82+
BareMetalHostPauseAnnotationSetFailedV1Beta2Reason = "BareMetalHostPauseAnnotationSetFailed"
83+
84+
// AssociateMetal3MachineMetaDataV1Beta2Condition documents the transition of a Metal3Machine into a Kubernetes Node.
85+
AssociateMetal3MachineMetaDataV1Beta2Condition = "AssociateMetal3MachineMetaData"
86+
87+
// AssociateMetal3MachineMetaDataFailedV1Beta2Reason is used when failed to associate Metadata to Metal3Machine.
88+
AssociateMetal3MachineMetaDataFailedV1Beta2Reason = "AssociateMetal3MachineMetaDataFailed"
89+
90+
// AssociateMetal3MachineMetaDataSuccessV1Beta2Reason is used when successfully associated Metadata to Metal3Machine.
91+
AssociateMetal3MachineMetaDataSuccessV1Beta2Reason = "AssociateMetal3MachineMetaDataSuccess"
92+
93+
// Metal3DataReadyV1Beta2Condition reports a summary of Metal3Data status.
94+
Metal3DataReadyV1Beta2Condition = "Metal3DataReady"
95+
96+
// WaitingForMetal3DataV1Beta2Reason used when waiting for Metal3Data
97+
// to be ready before proceeding.
98+
WaitingForMetal3DataV1Beta2Reason = "WaitingForMetal3Data"
99+
100+
// Metal3DataSecretsReadyV1Beta2Reason used when metal3data secrets are ready
101+
// to be ready before proceeding.
102+
Metal3DataSecretsReadyV1Beta2Reason = "Metal3DataSecretsReady"
103+
104+
// DisassociateM3MetaDataFailedReason is used when failed to remove OwnerReference of Meta3DataTemplate.
105+
DisassociateM3MetaDataFailedV1Beta2Reason = "DisassociateM3MetaDataFailed"
106+
107+
// DeletingV1Beta2Reason (Severity=Info) documents a condition not in Status=True because the underlying object it is currently being deleted.
108+
Metal3MachineDeletingV1Beta2Reason = clusterv1beta1.DeletingV1Beta2Reason
109+
110+
// Metal3MachineDeletingFailedV1Beta2Reason (Severity=Warning) documents a condition not in Status=True because the underlying object
111+
// encountered problems during deletion. This is a warning because the reconciler will retry deletion.
112+
Metal3MachineDeletingFailedV1Beta2Reason = "DeletionFailed"
113+
)
114+
36115
// Metal3MachineSpec defines the desired state of Metal3Machine.
37116
type Metal3MachineSpec struct {
38117
// ProviderID will be the Metal3 machine in ProviderID format
@@ -168,6 +247,22 @@ type Metal3MachineStatus struct {
168247
// Conditions defines current service state of the Metal3Machine.
169248
// +optional
170249
Conditions clusterv1beta1.Conditions `json:"conditions,omitempty"`
250+
251+
// v1beta2 groups all the fields that will be added or modified in Metal3Machine's status with the V1Beta2 version.
252+
// +optional
253+
V1Beta2 *Metal3MachineV1Beta2Status `json:"v1beta2,omitempty"`
254+
}
255+
256+
// Metal3MachineV1Beta2Status groups all the fields that will be added or modified in Metal3MachineStatus with the V1Beta2 version.
257+
// See https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md for more context.
258+
type Metal3MachineV1Beta2Status struct {
259+
// conditions represents the observations of a Metal3Machine's current state.
260+
// Known condition types are Ready, AssociateBareMetalHost, KubernetesNodeReady, Metal3DataReady and Paused.
261+
// +optional
262+
// +listType=map
263+
// +listMapKey=type
264+
// +kubebuilder:validation:MaxItems=32
265+
Conditions []metav1.Condition `json:"conditions,omitempty"`
171266
}
172267

173268
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@@ -216,3 +311,19 @@ func (c *Metal3Machine) SetConditions(conditions clusterv1beta1.Conditions) {
216311
func init() {
217312
objectTypes = append(objectTypes, &Metal3Machine{}, &Metal3MachineList{})
218313
}
314+
315+
// GetV1Beta2Conditions returns the set of conditions for this object.
316+
func (c *Metal3Machine) GetV1Beta2Conditions() []metav1.Condition {
317+
if c.Status.V1Beta2 == nil {
318+
return nil
319+
}
320+
return c.Status.V1Beta2.Conditions
321+
}
322+
323+
// SetV1Beta2Conditions sets conditions for an API object.
324+
func (c *Metal3Machine) SetV1Beta2Conditions(conditions []metav1.Condition) {
325+
if c.Status.V1Beta2 == nil {
326+
c.Status.V1Beta2 = &Metal3MachineV1Beta2Status{}
327+
}
328+
c.Status.V1Beta2.Conditions = conditions
329+
}

api/v1beta1/zz_generated.deepcopy.go

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

baremetal/metal3machine_manager.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +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"
5556
v1beta1patch "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/patch"
5657
"sigs.k8s.io/controller-runtime/pkg/client"
5758
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -110,6 +111,7 @@ type MachineManagerInterface interface {
110111
SetError(string, capierrors.MachineStatusError)
111112
SetConditionMetal3MachineToFalse(clusterv1beta1.ConditionType, string, clusterv1beta1.ConditionSeverity, string, ...interface{})
112113
SetConditionMetal3MachineToTrue(clusterv1beta1.ConditionType)
114+
SetV1beta2Condition(string, metav1.ConditionStatus, string, string)
113115
CloudProviderEnabled() bool
114116
SetReadyTrue()
115117
}
@@ -1207,6 +1209,16 @@ func (m *MachineManager) SetConditionMetal3MachineToFalse(t clusterv1beta1.Condi
12071209
v1beta1conditions.MarkFalse(m.Metal3Machine, t, reason, severity, messageFormat, messageArgs...)
12081210
}
12091211

1212+
// SetV1beta2Condition sets v1beta2 condition in Metal3Machine status.
1213+
func (m *MachineManager) SetV1beta2Condition(conditionType string, status metav1.ConditionStatus, reason string, message string) {
1214+
deprecatedv1beta2conditions.Set(m.Metal3Machine, metav1.Condition{
1215+
Type: conditionType,
1216+
Status: status,
1217+
Reason: reason,
1218+
Message: message,
1219+
})
1220+
}
1221+
12101222
// SetConditionMetal3MachineToTrue sets Metal3Machine condition status to True.
12111223
func (m *MachineManager) SetConditionMetal3MachineToTrue(t clusterv1beta1.ConditionType) {
12121224
v1beta1conditions.MarkTrue(m.Metal3Machine, t)
@@ -1232,6 +1244,11 @@ func (m *MachineManager) updateMachineStatus(_ context.Context, host *bmov1alpha
12321244

12331245
m.Metal3Machine.Status.Addresses = addrs
12341246
v1beta1conditions.MarkTrue(m.Metal3Machine, infrav1.AssociateBMHCondition)
1247+
deprecatedv1beta2conditions.Set(m.Metal3Machine, metav1.Condition{
1248+
Type: infrav1.AssociateBareMetalHostV1Beta2Condition,
1249+
Status: metav1.ConditionTrue,
1250+
Reason: infrav1.AssociateBareMetalHostSuccessV1Beta2Reason,
1251+
})
12351252

12361253
if equality.Semantic.DeepEqual(m.Metal3Machine.Status, metal3MachineOld.Status) {
12371254
// Status did not change
@@ -1717,13 +1734,16 @@ func (m *MachineManager) WaitForM3Metadata(ctx context.Context) error {
17171734
errMessage := "Waiting for Metal3Data to become ready"
17181735
m.Log.Info(errMessage)
17191736
m.SetConditionMetal3MachineToFalse(infrav1.Metal3DataReadyCondition, infrav1.WaitingForMetal3DataReason, clusterv1beta1.ConditionSeverityInfo, "")
1737+
m.SetV1beta2Condition(infrav1.Metal3DataReadyV1Beta2Condition, metav1.ConditionFalse, infrav1.WaitingForMetal3DataV1Beta2Reason, "")
1738+
17201739
// Secret generation not ready
17211740
return WithTransientError(errors.New(errMessage), requeueAfter)
17221741
}
17231742

17241743
// At this point, Metal3Data is ready
17251744
m.Log.Info("Metal3data is ready")
17261745
m.SetConditionMetal3MachineToTrue(infrav1.Metal3DataReadyCondition)
1746+
m.SetV1beta2Condition(infrav1.Metal3DataReadyV1Beta2Condition, metav1.ConditionTrue, infrav1.Metal3DataSecretsReadyV1Beta2Reason, "")
17271747

17281748
// Get the secrets if given in Metal3Data and not already set.
17291749
if m.Metal3Machine.Status.MetaData == nil &&

baremetal/mocks/zz_generated.metal3machine_manager.go

Lines changed: 13 additions & 0 deletions
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_metal3machines.yaml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,75 @@ spec:
480480
type: string
481481
type: object
482482
x-kubernetes-map-type: atomic
483+
v1beta2:
484+
description: v1beta2 groups all the fields that will be added or modified
485+
in Metal3Machine's status with the V1Beta2 version.
486+
properties:
487+
conditions:
488+
description: |-
489+
conditions represents the observations of a Metal3Machine's current state.
490+
Known condition types are Ready, AssociateBareMetalHost, KubernetesNodeReady, Metal3DataReady and Paused.
491+
items:
492+
description: Condition contains details for one aspect of the
493+
current state of this API Resource.
494+
properties:
495+
lastTransitionTime:
496+
description: |-
497+
lastTransitionTime is the last time the condition transitioned from one status to another.
498+
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
499+
format: date-time
500+
type: string
501+
message:
502+
description: |-
503+
message is a human readable message indicating details about the transition.
504+
This may be an empty string.
505+
maxLength: 32768
506+
type: string
507+
observedGeneration:
508+
description: |-
509+
observedGeneration represents the .metadata.generation that the condition was set based upon.
510+
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
511+
with respect to the current state of the instance.
512+
format: int64
513+
minimum: 0
514+
type: integer
515+
reason:
516+
description: |-
517+
reason contains a programmatic identifier indicating the reason for the condition's last transition.
518+
Producers of specific condition types may define expected values and meanings for this field,
519+
and whether the values are considered a guaranteed API.
520+
The value should be a CamelCase string.
521+
This field may not be empty.
522+
maxLength: 1024
523+
minLength: 1
524+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
525+
type: string
526+
status:
527+
description: status of the condition, one of True, False,
528+
Unknown.
529+
enum:
530+
- "True"
531+
- "False"
532+
- Unknown
533+
type: string
534+
type:
535+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
536+
maxLength: 316
537+
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])$
538+
type: string
539+
required:
540+
- lastTransitionTime
541+
- message
542+
- reason
543+
- status
544+
- type
545+
type: object
546+
maxItems: 32
547+
type: array
548+
x-kubernetes-list-map-keys:
549+
- type
550+
x-kubernetes-list-type: map
551+
type: object
483552
type: object
484553
type: object
485554
served: true

0 commit comments

Comments
 (0)