Skip to content

Commit

Permalink
Add MachinePhase type and helper functions
Browse files Browse the repository at this point in the history
Signed-off-by: Vince Prignano <vincepri@vmware.com>
  • Loading branch information
vincepri committed Jun 27, 2019
1 parent 377ad4e commit 3003102
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 16 deletions.
13 changes: 7 additions & 6 deletions config/crds/cluster.sigs.k8s.io_machines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,9 @@ spec:
- address
type: object
type: array
bootstrap:
description: Bootstrap is the state of the bootstrap provider.
type: string
bootstrapReady:
description: BootstrapReady is the state of the bootstrap provider.
type: boolean
conditions:
description: 'Conditions lists the conditions synced from the node conditions
of the corresponding node-object. Machine-controller is responsible
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/cluster/v1alpha2/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
70 changes: 70 additions & 0 deletions pkg/apis/cluster/v1alpha2/machine_phase_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
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 is a string representation of a Machine Phase.
//
// This type is a high-level indicator of the status of the Machine as it is provisioned,
// from the API user’s perspective.
//
// The value should not be interpreted by any software components as a reliable indication
// of the actual state of the Machine, and controllers should not use the Machine Phase field
// value when making decisions about what action to take.
//
// Controllers should always look at the actual state of the Machine’s fields to make those decisions.
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
}
37 changes: 33 additions & 4 deletions pkg/apis/cluster/v1alpha2/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,40 @@ 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.
// +optional
BootstrapReady *bool `json:"bootstrapReady,omitempty"`

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

// SetTypedPhase sets the Phase field to the string representation of MachinePhase.
func (m *MachineStatus) SetTypedPhase(p MachinePhase) {
m.Phase = MachinePhaseStringPtr(p)
}

// Infrastructure is the state of the infrastructure provider.
Infrastructure *string `json:"infrastructure,omitempty"`
// 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.
Expand Down
12 changes: 6 additions & 6 deletions pkg/apis/cluster/v1alpha2/zz_generated.deepcopy.go

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

0 comments on commit 3003102

Please sign in to comment.