Skip to content

Commit 4936a19

Browse files
authored
Merge pull request #12101 from fabriziopandini/add-status-initialization-to-Machine
⚠️ Add initialization to Machine Status
2 parents ca6acd4 + d2cd66d commit 4936a19

22 files changed

+279
-106
lines changed

api/v1beta1/conversion.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,12 @@ func Convert_v1beta2_MachineStatus_To_v1beta1_MachineStatus(in *clusterv1.Machin
493493
out.FailureMessage = in.Deprecated.V1Beta1.FailureMessage
494494
}
495495

496+
// Move initialization to old fields
497+
if in.Initialization != nil {
498+
out.BootstrapReady = in.Initialization.BootstrapDataSecretCreated
499+
out.InfrastructureReady = in.Initialization.InfrastructureProvisioned
500+
}
501+
496502
// Move new conditions (v1beta2) to the v1beta2 field.
497503
if in.Conditions == nil {
498504
return nil
@@ -516,6 +522,15 @@ func Convert_v1beta1_MachineStatus_To_v1beta2_MachineStatus(in *MachineStatus, o
516522
out.Conditions = in.V1Beta2.Conditions
517523
}
518524

525+
// Move BootstrapReady and InfrastructureReady to Initialization
526+
if in.BootstrapReady || in.InfrastructureReady {
527+
if out.Initialization == nil {
528+
out.Initialization = &clusterv1.MachineInitializationStatus{}
529+
}
530+
out.Initialization.BootstrapDataSecretCreated = in.BootstrapReady
531+
out.Initialization.InfrastructureProvisioned = in.InfrastructureReady
532+
}
533+
519534
// Move legacy conditions (v1beta1), failureReason and failureMessage to the deprecated field.
520535
if in.Conditions == nil && in.FailureReason == nil && in.FailureMessage == nil {
521536
return nil

api/v1beta1/conversion_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@ func hubMachineStatus(in *clusterv1.MachineStatus, c fuzz.Continue) {
232232
in.Deprecated = nil
233233
}
234234
}
235+
236+
// Drop empty structs with only omit empty fields.
237+
if in.Initialization != nil {
238+
if reflect.DeepEqual(in.Initialization, &clusterv1.MachineInitializationStatus{}) {
239+
in.Initialization = nil
240+
}
241+
}
235242
}
236243

237244
func spokeMachineStatus(in *MachineStatus, c fuzz.Continue) {

api/v1beta1/zz_generated.conversion.go

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

api/v1beta2/machine_types.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,11 @@ type MachineStatus struct {
509509
// +kubebuilder:validation:MaxItems=32
510510
Conditions []metav1.Condition `json:"conditions,omitempty"`
511511

512+
// initialization provides observations of the Machine initialization process.
513+
// NOTE: Fields in this struct are part of the Cluster API contract and are used to orchestrate initial Machine provisioning.
514+
// +optional
515+
Initialization *MachineInitializationStatus `json:"initialization,omitempty"`
516+
512517
// nodeRef will point to the corresponding Node if it exists.
513518
// +optional
514519
NodeRef *corev1.ObjectReference `json:"nodeRef,omitempty"`
@@ -537,14 +542,6 @@ type MachineStatus struct {
537542
// +optional
538543
CertificatesExpiryDate *metav1.Time `json:"certificatesExpiryDate,omitempty"`
539544

540-
// bootstrapReady is the state of the bootstrap provider.
541-
// +optional
542-
BootstrapReady bool `json:"bootstrapReady"`
543-
544-
// infrastructureReady is the state of the infrastructure provider.
545-
// +optional
546-
InfrastructureReady bool `json:"infrastructureReady"`
547-
548545
// observedGeneration is the latest generation observed by the controller.
549546
// +optional
550547
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
@@ -559,6 +556,22 @@ type MachineStatus struct {
559556
Deprecated *MachineDeprecatedStatus `json:"deprecated,omitempty"`
560557
}
561558

559+
// MachineInitializationStatus provides observations of the Machine initialization process.
560+
// NOTE: Fields in this struct are part of the Cluster API contract and are used to orchestrate initial Machine provisioning.
561+
type MachineInitializationStatus struct {
562+
// infrastructureProvisioned is true when the infrastructure provider reports that Machine's infrastructure is fully provisioned.
563+
// NOTE: this field is part of the Cluster API contract, and it is used to orchestrate provisioning.
564+
// The value of this field is never updated after provisioning is completed.
565+
// +optional
566+
InfrastructureProvisioned bool `json:"infrastructureProvisioned"`
567+
568+
// bootstrapDataSecretCreated is true when the bootstrap provider reports that the Machine's boostrap secret is created.
569+
// NOTE: this field is part of the Cluster API contract, and it is used to orchestrate provisioning.
570+
// The value of this field is never updated after provisioning is completed.
571+
// +optional
572+
BootstrapDataSecretCreated bool `json:"bootstrapDataSecretCreated"`
573+
}
574+
562575
// MachineDeprecatedStatus groups all the status fields that are deprecated and will be removed in a future version.
563576
// See https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md for more context.
564577
type MachineDeprecatedStatus struct {

api/v1beta2/zz_generated.deepcopy.go

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

api/v1beta2/zz_generated.openapi.go

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

bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,12 +1164,16 @@ func TestBootstrapTokenTTLExtension(t *testing.T) {
11641164

11651165
patchHelper, err := patch.NewHelper(workerMachine, myclient)
11661166
g.Expect(err).ShouldNot(HaveOccurred())
1167-
workerMachine.Status.InfrastructureReady = true
1167+
workerMachine.Status.Initialization = &clusterv1.MachineInitializationStatus{
1168+
InfrastructureProvisioned: true,
1169+
}
11681170
g.Expect(patchHelper.Patch(ctx, workerMachine)).To(Succeed())
11691171

11701172
patchHelper, err = patch.NewHelper(controlPlaneJoinMachine, myclient)
11711173
g.Expect(err).ShouldNot(HaveOccurred())
1172-
controlPlaneJoinMachine.Status.InfrastructureReady = true
1174+
controlPlaneJoinMachine.Status.Initialization = &clusterv1.MachineInitializationStatus{
1175+
InfrastructureProvisioned: true,
1176+
}
11731177
g.Expect(patchHelper.Patch(ctx, controlPlaneJoinMachine)).To(Succeed())
11741178

11751179
for _, req := range []ctrl.Request{

bootstrap/util/configowner.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ type ConfigOwner struct {
4242

4343
// IsInfrastructureReady extracts infrastructure status from the config owner.
4444
func (co ConfigOwner) IsInfrastructureReady() bool {
45-
infrastructureReady, _, err := unstructured.NestedBool(co.Object, "status", "infrastructureReady")
45+
if co.IsMachinePool() {
46+
infrastructureReady, _, err := unstructured.NestedBool(co.Object, "status", "infrastructureReady")
47+
if err != nil {
48+
return false
49+
}
50+
return infrastructureReady
51+
}
52+
infrastructureReady, _, err := unstructured.NestedBool(co.Object, "status", "initialization", "infrastructureProvisioned")
4653
if err != nil {
4754
return false
4855
}

bootstrap/util/configowner_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ func TestGetConfigOwner(t *testing.T) {
5858
Version: ptr.To("v1.19.6"),
5959
},
6060
Status: clusterv1.MachineStatus{
61-
InfrastructureReady: true,
61+
Initialization: &clusterv1.MachineInitializationStatus{
62+
InfrastructureProvisioned: true,
63+
},
6264
},
6365
}
6466

@@ -215,7 +217,9 @@ func TestHasNodeRefs(t *testing.T) {
215217
Namespace: metav1.NamespaceDefault,
216218
},
217219
Status: clusterv1.MachineStatus{
218-
InfrastructureReady: true,
220+
Initialization: &clusterv1.MachineInitializationStatus{
221+
InfrastructureProvisioned: true,
222+
},
219223
NodeRef: &corev1.ObjectReference{
220224
Kind: "Node",
221225
Namespace: metav1.NamespaceDefault,

config/crd/bases/cluster.x-k8s.io_machines.yaml

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

internal/apis/core/v1alpha3/conversion.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ func (src *Machine) ConvertTo(dstRaw conversion.Hub) error {
146146
dst.Status.Deprecated.V1Beta1.FailureMessage = src.Status.FailureMessage
147147
}
148148

149+
// Move BootstrapReady and InfrastructureReady to Initialization
150+
if src.Status.BootstrapReady || src.Status.InfrastructureReady {
151+
if dst.Status.Initialization == nil {
152+
dst.Status.Initialization = &clusterv1.MachineInitializationStatus{}
153+
}
154+
dst.Status.Initialization.BootstrapDataSecretCreated = src.Status.BootstrapReady
155+
dst.Status.Initialization.InfrastructureProvisioned = src.Status.InfrastructureReady
156+
}
157+
149158
// Manually restore data.
150159
restored := &clusterv1.Machine{}
151160
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
@@ -185,6 +194,12 @@ func (dst *Machine) ConvertFrom(srcRaw conversion.Hub) error {
185194
}
186195
}
187196

197+
// Move initialization to old fields
198+
if src.Status.Initialization != nil {
199+
dst.Status.BootstrapReady = src.Status.Initialization.BootstrapDataSecretCreated
200+
dst.Status.InfrastructureReady = src.Status.Initialization.InfrastructureProvisioned
201+
}
202+
188203
// Preserve Hub data on down-conversion except for metadata
189204
if err := utilconversion.MarshalData(src, dst); err != nil {
190205
return err

internal/apis/core/v1alpha3/conversion_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ func hubMachineStatus(in *clusterv1.MachineStatus, c fuzz.Continue) {
8383
in.Deprecated = nil
8484
}
8585
}
86+
87+
// Drop empty structs with only omit empty fields.
88+
if in.Initialization != nil {
89+
if reflect.DeepEqual(in.Initialization, &clusterv1.MachineInitializationStatus{}) {
90+
in.Initialization = nil
91+
}
92+
}
8693
}
8794

8895
func spokeMachineStatus(in *MachineStatus, c fuzz.Continue) {

0 commit comments

Comments
 (0)