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 26, 2019
1 parent 377ad4e commit 52f929e
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 19 deletions.
14 changes: 9 additions & 5 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:
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
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 Expand Up @@ -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:
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
61 changes: 61 additions & 0 deletions pkg/apis/cluster/v1alpha2/machine_phase_types.go
Original file line number Diff line number Diff line change
@@ -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
}
35 changes: 31 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,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.
Expand Down
10 changes: 0 additions & 10 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 52f929e

Please sign in to comment.