diff --git a/config/crds/cluster.sigs.k8s.io_machines.yaml b/config/crds/cluster.sigs.k8s.io_machines.yaml index d52320fd2b63..c5e0efdff012 100644 --- a/config/crds/cluster.sigs.k8s.io_machines.yaml +++ b/config/crds/cluster.sigs.k8s.io_machines.yaml @@ -590,9 +590,9 @@ spec: - address type: object type: array - bootstrap: + bootstrapReady: description: Bootstrap is the state of the bootstrap provider. - type: string + type: boolean conditions: description: 'Conditions lists the conditions synced from the node conditions of the corresponding node-object. Machine-controller is responsible @@ -658,9 +658,10 @@ spec: can be added as events to the Machine object and/or logged in the controller's output." type: string - infrastructure: - description: Infrastructure is the state of the infrastructure provider. - type: string + infrastructureReady: + description: InfrastructureReady is the state of the infrastructure + provider. + type: boolean lastUpdated: description: LastUpdated identifies when this status was last observed. format: date-time @@ -711,6 +712,9 @@ spec: up status from the Node to the Machine. It is entirely optional, but useful for end-user UX if it’s present. type: string + required: + - bootstrapReady + - infrastructureReady type: object type: object versions: diff --git a/pkg/apis/cluster/v1alpha2/BUILD.bazel b/pkg/apis/cluster/v1alpha2/BUILD.bazel index d0497c2c6912..6f426819bdbd 100644 --- a/pkg/apis/cluster/v1alpha2/BUILD.bazel +++ b/pkg/apis/cluster/v1alpha2/BUILD.bazel @@ -7,6 +7,7 @@ go_library( "common_type.go", "defaults.go", "doc.go", + "machine_phase_types.go", "machine_types.go", "machinedeployment_types.go", "machineset_types.go", diff --git a/pkg/apis/cluster/v1alpha2/machine_phase_types.go b/pkg/apis/cluster/v1alpha2/machine_phase_types.go new file mode 100644 index 000000000000..4fdb4b023134 --- /dev/null +++ b/pkg/apis/cluster/v1alpha2/machine_phase_types.go @@ -0,0 +1,61 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha2 + +// MachinePhase +type MachinePhase string + +var ( + // MachinePhasePending is the first state a Machine is assigned by + // Cluster API Machine controller after being created. + MachinePhasePending = MachinePhase("pending") + + // MachinePhaseProvisioning is the state when the + // Machine infrastructure is being created. + MachinePhaseProvisioning = MachinePhase("provisioning") + + // MachinePhaseProvisioned is the state when its + // infrastructure has been created and configured. + MachinePhaseProvisioned = MachinePhase("provisioned") + + // MachinePhaseRunning is the Machine state when it has + // become a Kubernetes Node in a Ready state. + MachinePhaseRunning = MachinePhase("running") + + // MachinePhaseDeleting is the Machine state when a delete + // request has been sent to the API Server, + // but its infrastructure has not yet been fully deleted. + MachinePhaseDeleting = MachinePhase("deleting") + + // MachinePhaseDeleted is the Machine state when the object + // and the related infrastructure is deleted and + // ready to be garbage collected by the API Server. + MachinePhaseDeleted = MachinePhase("deleted") + + // MachinePhaseFailed is the Machine state when the system + // might require user intervention. + MachinePhaseFailed = MachinePhase("failed") + + // MachinePhaseUnknown is returned if the Machine state cannot be determined. + MachinePhaseUnknown = MachinePhase("") +) + +// MachinePhaseStringPtr is a helper method to convert MachinePhase to a string pointer. +func MachinePhaseStringPtr(p MachinePhase) *string { + s := string(p) + return &s +} diff --git a/pkg/apis/cluster/v1alpha2/machine_types.go b/pkg/apis/cluster/v1alpha2/machine_types.go index d3541b6951fb..2743293cb30c 100644 --- a/pkg/apis/cluster/v1alpha2/machine_types.go +++ b/pkg/apis/cluster/v1alpha2/machine_types.go @@ -163,11 +163,38 @@ type MachineStatus struct { // +optional Phase *string `json:"phase,omitempty"` - // Bootstrap is the state of the bootstrap provider. - Bootstrap *string `json:"bootstrap,omitempty"` + // BootstrapReady is the state of the bootstrap provider. + BootstrapReady bool `json:"bootstrapReady"` - // Infrastructure is the state of the infrastructure provider. - Infrastructure *string `json:"infrastructure,omitempty"` + // InfrastructureReady is the state of the infrastructure provider. + InfrastructureReady bool `json:"infrastructureReady"` +} + +// SetTypedPhase sets the Phase field to the string representation of MachinePhase. +func (m *MachineStatus) SetTypedPhase(p MachinePhase) { + m.Phase = MachinePhaseStringPtr(p) +} + +// GetTypedPhase attempts to parse the Phase field and return +// the typed MachinePhase representation as described in `machine_phase_types.go`. +func (m *MachineStatus) GetTypedPhase() MachinePhase { + if m.Phase == nil { + return MachinePhaseUnknown + } + + switch phase := MachinePhase(*m.Phase); phase { + case + MachinePhasePending, + MachinePhaseProvisioning, + MachinePhaseProvisioned, + MachinePhaseRunning, + MachinePhaseDeleting, + MachinePhaseDeleted, + MachinePhaseFailed: + return phase + default: + return MachinePhaseUnknown + } } // Bootstrap capsulates fields to configure the Machine’s bootstrapping mechanism. diff --git a/pkg/apis/cluster/v1alpha2/zz_generated.deepcopy.go b/pkg/apis/cluster/v1alpha2/zz_generated.deepcopy.go index dd47b9a40492..4cca2112840a 100644 --- a/pkg/apis/cluster/v1alpha2/zz_generated.deepcopy.go +++ b/pkg/apis/cluster/v1alpha2/zz_generated.deepcopy.go @@ -608,16 +608,6 @@ func (in *MachineStatus) DeepCopyInto(out *MachineStatus) { *out = new(string) **out = **in } - if in.Bootstrap != nil { - in, out := &in.Bootstrap, &out.Bootstrap - *out = new(string) - **out = **in - } - if in.Infrastructure != nil { - in, out := &in.Infrastructure, &out.Infrastructure - *out = new(string) - **out = **in - } return }