Skip to content

Commit d2cd66d

Browse files
Add initialization to Machine Status
1 parent 296cbc0 commit d2cd66d

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
@@ -478,6 +478,12 @@ func Convert_v1beta2_MachineStatus_To_v1beta1_MachineStatus(in *clusterv1.Machin
478478
out.FailureMessage = in.Deprecated.V1Beta1.FailureMessage
479479
}
480480

481+
// Move initialization to old fields
482+
if in.Initialization != nil {
483+
out.BootstrapReady = in.Initialization.BootstrapDataSecretCreated
484+
out.InfrastructureReady = in.Initialization.InfrastructureProvisioned
485+
}
486+
481487
// Move new conditions (v1beta2) to the v1beta2 field.
482488
if in.Conditions == nil {
483489
return nil
@@ -501,6 +507,15 @@ func Convert_v1beta1_MachineStatus_To_v1beta2_MachineStatus(in *MachineStatus, o
501507
out.Conditions = in.V1Beta2.Conditions
502508
}
503509

510+
// Move BootstrapReady and InfrastructureReady to Initialization
511+
if in.BootstrapReady || in.InfrastructureReady {
512+
if out.Initialization == nil {
513+
out.Initialization = &clusterv1.MachineInitializationStatus{}
514+
}
515+
out.Initialization.BootstrapDataSecretCreated = in.BootstrapReady
516+
out.Initialization.InfrastructureProvisioned = in.InfrastructureReady
517+
}
518+
504519
// Move legacy conditions (v1beta1), failureReason and failureMessage to the deprecated field.
505520
if in.Conditions == nil && in.FailureReason == nil && in.FailureMessage == nil {
506521
return nil

api/v1beta1/conversion_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ func hubMachineStatus(in *clusterv1.MachineStatus, c fuzz.Continue) {
225225
in.Deprecated = nil
226226
}
227227
}
228+
229+
// Drop empty structs with only omit empty fields.
230+
if in.Initialization != nil {
231+
if reflect.DeepEqual(in.Initialization, &clusterv1.MachineInitializationStatus{}) {
232+
in.Initialization = nil
233+
}
234+
}
228235
}
229236

230237
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
@@ -1166,12 +1166,16 @@ func TestBootstrapTokenTTLExtension(t *testing.T) {
11661166

11671167
patchHelper, err := patch.NewHelper(workerMachine, myclient)
11681168
g.Expect(err).ShouldNot(HaveOccurred())
1169-
workerMachine.Status.InfrastructureReady = true
1169+
workerMachine.Status.Initialization = &clusterv1.MachineInitializationStatus{
1170+
InfrastructureProvisioned: true,
1171+
}
11701172
g.Expect(patchHelper.Patch(ctx, workerMachine)).To(Succeed())
11711173

11721174
patchHelper, err = patch.NewHelper(controlPlaneJoinMachine, myclient)
11731175
g.Expect(err).ShouldNot(HaveOccurred())
1174-
controlPlaneJoinMachine.Status.InfrastructureReady = true
1176+
controlPlaneJoinMachine.Status.Initialization = &clusterv1.MachineInitializationStatus{
1177+
InfrastructureProvisioned: true,
1178+
}
11751179
g.Expect(patchHelper.Patch(ctx, controlPlaneJoinMachine)).To(Succeed())
11761180

11771181
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
@@ -131,6 +131,15 @@ func (src *Machine) ConvertTo(dstRaw conversion.Hub) error {
131131
dst.Status.Deprecated.V1Beta1.FailureMessage = src.Status.FailureMessage
132132
}
133133

134+
// Move BootstrapReady and InfrastructureReady to Initialization
135+
if src.Status.BootstrapReady || src.Status.InfrastructureReady {
136+
if dst.Status.Initialization == nil {
137+
dst.Status.Initialization = &clusterv1.MachineInitializationStatus{}
138+
}
139+
dst.Status.Initialization.BootstrapDataSecretCreated = src.Status.BootstrapReady
140+
dst.Status.Initialization.InfrastructureProvisioned = src.Status.InfrastructureReady
141+
}
142+
134143
// Manually restore data.
135144
restored := &clusterv1.Machine{}
136145
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
@@ -170,6 +179,12 @@ func (dst *Machine) ConvertFrom(srcRaw conversion.Hub) error {
170179
}
171180
}
172181

182+
// Move initialization to old fields
183+
if src.Status.Initialization != nil {
184+
dst.Status.BootstrapReady = src.Status.Initialization.BootstrapDataSecretCreated
185+
dst.Status.InfrastructureReady = src.Status.Initialization.InfrastructureProvisioned
186+
}
187+
173188
// Preserve Hub data on down-conversion except for metadata
174189
if err := utilconversion.MarshalData(src, dst); err != nil {
175190
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)