Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,12 @@ func Convert_v1beta2_MachineStatus_To_v1beta1_MachineStatus(in *clusterv1.Machin
out.FailureMessage = in.Deprecated.V1Beta1.FailureMessage
}

// Move initialization to old fields
if in.Initialization != nil {
out.BootstrapReady = in.Initialization.BootstrapDataSecretCreated
out.InfrastructureReady = in.Initialization.InfrastructureProvisioned
}

// Move new conditions (v1beta2) to the v1beta2 field.
if in.Conditions == nil {
return nil
Expand All @@ -501,6 +507,15 @@ func Convert_v1beta1_MachineStatus_To_v1beta2_MachineStatus(in *MachineStatus, o
out.Conditions = in.V1Beta2.Conditions
}

// Move BootstrapReady and InfrastructureReady to Initialization
if in.BootstrapReady || in.InfrastructureReady {
if out.Initialization == nil {
out.Initialization = &clusterv1.MachineInitializationStatus{}
}
out.Initialization.BootstrapDataSecretCreated = in.BootstrapReady
out.Initialization.InfrastructureProvisioned = in.InfrastructureReady
}

// Move legacy conditions (v1beta1), failureReason and failureMessage to the deprecated field.
if in.Conditions == nil && in.FailureReason == nil && in.FailureMessage == nil {
return nil
Expand Down
7 changes: 7 additions & 0 deletions api/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ func hubMachineStatus(in *clusterv1.MachineStatus, c fuzz.Continue) {
in.Deprecated = nil
}
}

// Drop empty structs with only omit empty fields.
if in.Initialization != nil {
if reflect.DeepEqual(in.Initialization, &clusterv1.MachineInitializationStatus{}) {
in.Initialization = nil
}
}
}

func spokeMachineStatus(in *MachineStatus, c fuzz.Continue) {
Expand Down
7 changes: 3 additions & 4 deletions api/v1beta1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 21 additions & 8 deletions api/v1beta2/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,11 @@ type MachineStatus struct {
// +kubebuilder:validation:MaxItems=32
Conditions []metav1.Condition `json:"conditions,omitempty"`

// initialization provides observations of the Machine initialization process.
// NOTE: Fields in this struct are part of the Cluster API contract and are used to orchestrate initial Machine provisioning.
// +optional
Initialization *MachineInitializationStatus `json:"initialization,omitempty"`

// nodeRef will point to the corresponding Node if it exists.
// +optional
NodeRef *corev1.ObjectReference `json:"nodeRef,omitempty"`
Expand Down Expand Up @@ -537,14 +542,6 @@ type MachineStatus struct {
// +optional
CertificatesExpiryDate *metav1.Time `json:"certificatesExpiryDate,omitempty"`

// bootstrapReady is the state of the bootstrap provider.
// +optional
BootstrapReady bool `json:"bootstrapReady"`

// infrastructureReady is the state of the infrastructure provider.
// +optional
InfrastructureReady bool `json:"infrastructureReady"`

// observedGeneration is the latest generation observed by the controller.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Expand All @@ -559,6 +556,22 @@ type MachineStatus struct {
Deprecated *MachineDeprecatedStatus `json:"deprecated,omitempty"`
}

// MachineInitializationStatus provides observations of the Machine initialization process.
// NOTE: Fields in this struct are part of the Cluster API contract and are used to orchestrate initial Machine provisioning.
type MachineInitializationStatus struct {
// infrastructureProvisioned is true when the infrastructure provider reports that Machine's infrastructure is fully provisioned.
// NOTE: this field is part of the Cluster API contract, and it is used to orchestrate provisioning.
// The value of this field is never updated after provisioning is completed.
// +optional
InfrastructureProvisioned bool `json:"infrastructureProvisioned"`

// bootstrapDataSecretCreated is true when the bootstrap provider reports that the Machine's boostrap secret is created.
// NOTE: this field is part of the Cluster API contract, and it is used to orchestrate provisioning.
// The value of this field is never updated after provisioning is completed.
// +optional
BootstrapDataSecretCreated bool `json:"bootstrapDataSecretCreated"`
}

// MachineDeprecatedStatus groups all the status fields that are deprecated and will be removed in a future version.
// See https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md for more context.
type MachineDeprecatedStatus struct {
Expand Down
20 changes: 20 additions & 0 deletions api/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 37 additions & 17 deletions api/v1beta2/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1166,12 +1166,16 @@ func TestBootstrapTokenTTLExtension(t *testing.T) {

patchHelper, err := patch.NewHelper(workerMachine, myclient)
g.Expect(err).ShouldNot(HaveOccurred())
workerMachine.Status.InfrastructureReady = true
workerMachine.Status.Initialization = &clusterv1.MachineInitializationStatus{
InfrastructureProvisioned: true,
}
g.Expect(patchHelper.Patch(ctx, workerMachine)).To(Succeed())

patchHelper, err = patch.NewHelper(controlPlaneJoinMachine, myclient)
g.Expect(err).ShouldNot(HaveOccurred())
controlPlaneJoinMachine.Status.InfrastructureReady = true
controlPlaneJoinMachine.Status.Initialization = &clusterv1.MachineInitializationStatus{
InfrastructureProvisioned: true,
}
g.Expect(patchHelper.Patch(ctx, controlPlaneJoinMachine)).To(Succeed())

for _, req := range []ctrl.Request{
Expand Down
9 changes: 8 additions & 1 deletion bootstrap/util/configowner.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ type ConfigOwner struct {

// IsInfrastructureReady extracts infrastructure status from the config owner.
func (co ConfigOwner) IsInfrastructureReady() bool {
infrastructureReady, _, err := unstructured.NestedBool(co.Object, "status", "infrastructureReady")
if co.IsMachinePool() {
infrastructureReady, _, err := unstructured.NestedBool(co.Object, "status", "infrastructureReady")
if err != nil {
return false
}
return infrastructureReady
}
infrastructureReady, _, err := unstructured.NestedBool(co.Object, "status", "initialization", "infrastructureProvisioned")
if err != nil {
return false
}
Expand Down
8 changes: 6 additions & 2 deletions bootstrap/util/configowner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ func TestGetConfigOwner(t *testing.T) {
Version: ptr.To("v1.19.6"),
},
Status: clusterv1.MachineStatus{
InfrastructureReady: true,
Initialization: &clusterv1.MachineInitializationStatus{
InfrastructureProvisioned: true,
},
},
}

Expand Down Expand Up @@ -215,7 +217,9 @@ func TestHasNodeRefs(t *testing.T) {
Namespace: metav1.NamespaceDefault,
},
Status: clusterv1.MachineStatus{
InfrastructureReady: true,
Initialization: &clusterv1.MachineInitializationStatus{
InfrastructureProvisioned: true,
},
NodeRef: &corev1.ObjectReference{
Kind: "Node",
Namespace: metav1.NamespaceDefault,
Expand Down
25 changes: 18 additions & 7 deletions config/crd/bases/cluster.x-k8s.io_machines.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions internal/apis/core/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ func (src *Machine) ConvertTo(dstRaw conversion.Hub) error {
dst.Status.Deprecated.V1Beta1.FailureMessage = src.Status.FailureMessage
}

// Move BootstrapReady and InfrastructureReady to Initialization
if src.Status.BootstrapReady || src.Status.InfrastructureReady {
if dst.Status.Initialization == nil {
dst.Status.Initialization = &clusterv1.MachineInitializationStatus{}
}
dst.Status.Initialization.BootstrapDataSecretCreated = src.Status.BootstrapReady
dst.Status.Initialization.InfrastructureProvisioned = src.Status.InfrastructureReady
}

// Manually restore data.
restored := &clusterv1.Machine{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
Expand Down Expand Up @@ -170,6 +179,12 @@ func (dst *Machine) ConvertFrom(srcRaw conversion.Hub) error {
}
}

// Move initialization to old fields
if src.Status.Initialization != nil {
dst.Status.BootstrapReady = src.Status.Initialization.BootstrapDataSecretCreated
dst.Status.InfrastructureReady = src.Status.Initialization.InfrastructureProvisioned
}

// Preserve Hub data on down-conversion except for metadata
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
Expand Down
7 changes: 7 additions & 0 deletions internal/apis/core/v1alpha3/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ func hubMachineStatus(in *clusterv1.MachineStatus, c fuzz.Continue) {
in.Deprecated = nil
}
}

// Drop empty structs with only omit empty fields.
if in.Initialization != nil {
if reflect.DeepEqual(in.Initialization, &clusterv1.MachineInitializationStatus{}) {
in.Initialization = nil
}
}
}

func spokeMachineStatus(in *MachineStatus, c fuzz.Continue) {
Expand Down
Loading