Skip to content

Commit 444f83a

Browse files
committed
Add MachinePhase type and helper functions
Signed-off-by: Vince Prignano <[email protected]>
1 parent 377ad4e commit 444f83a

File tree

5 files changed

+114
-20
lines changed

5 files changed

+114
-20
lines changed

config/crds/cluster.sigs.k8s.io_machines.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,9 @@ spec:
590590
- address
591591
type: object
592592
type: array
593-
bootstrap:
594-
description: Bootstrap is the state of the bootstrap provider.
595-
type: string
593+
bootstrapReady:
594+
description: BootstrapReady is the state of the bootstrap provider.
595+
type: boolean
596596
conditions:
597597
description: 'Conditions lists the conditions synced from the node conditions
598598
of the corresponding node-object. Machine-controller is responsible
@@ -658,9 +658,10 @@ spec:
658658
can be added as events to the Machine object and/or logged in the
659659
controller's output."
660660
type: string
661-
infrastructure:
662-
description: Infrastructure is the state of the infrastructure provider.
663-
type: string
661+
infrastructureReady:
662+
description: InfrastructureReady is the state of the infrastructure
663+
provider.
664+
type: boolean
664665
lastUpdated:
665666
description: LastUpdated identifies when this status was last observed.
666667
format: date-time
@@ -711,6 +712,9 @@ spec:
711712
up status from the Node to the Machine. It is entirely optional, but
712713
useful for end-user UX if it’s present.
713714
type: string
715+
required:
716+
- bootstrapReady
717+
- infrastructureReady
714718
type: object
715719
type: object
716720
versions:

pkg/apis/cluster/v1alpha2/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ go_library(
77
"common_type.go",
88
"defaults.go",
99
"doc.go",
10+
"machine_phase_types.go",
1011
"machine_types.go",
1112
"machinedeployment_types.go",
1213
"machineset_types.go",
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha2
18+
19+
// MachinePhase is a string representation of a Machine Phase.
20+
//
21+
// This type is a high-level indicator of the status of the Machine as it is provisioned,
22+
// from the API user’s perspective.
23+
//
24+
// The value should not be interpreted by any software components as a reliable indication
25+
// of the actual state of the Machine, and controllers should not use the Machine Phase field
26+
// value when making decisions about what action to take.
27+
//
28+
// Controllers should always look at the actual state of the Machine’s fields to make those decisions.
29+
type MachinePhase string
30+
31+
var (
32+
// MachinePhasePending is the first state a Machine is assigned by
33+
// Cluster API Machine controller after being created.
34+
MachinePhasePending = MachinePhase("pending")
35+
36+
// MachinePhaseProvisioning is the state when the
37+
// Machine infrastructure is being created.
38+
MachinePhaseProvisioning = MachinePhase("provisioning")
39+
40+
// MachinePhaseProvisioned is the state when its
41+
// infrastructure has been created and configured.
42+
MachinePhaseProvisioned = MachinePhase("provisioned")
43+
44+
// MachinePhaseRunning is the Machine state when it has
45+
// become a Kubernetes Node in a Ready state.
46+
MachinePhaseRunning = MachinePhase("running")
47+
48+
// MachinePhaseDeleting is the Machine state when a delete
49+
// request has been sent to the API Server,
50+
// but its infrastructure has not yet been fully deleted.
51+
MachinePhaseDeleting = MachinePhase("deleting")
52+
53+
// MachinePhaseDeleted is the Machine state when the object
54+
// and the related infrastructure is deleted and
55+
// ready to be garbage collected by the API Server.
56+
MachinePhaseDeleted = MachinePhase("deleted")
57+
58+
// MachinePhaseFailed is the Machine state when the system
59+
// might require user intervention.
60+
MachinePhaseFailed = MachinePhase("failed")
61+
62+
// MachinePhaseUnknown is returned if the Machine state cannot be determined.
63+
MachinePhaseUnknown = MachinePhase("")
64+
)
65+
66+
// MachinePhaseStringPtr is a helper method to convert MachinePhase to a string pointer.
67+
func MachinePhaseStringPtr(p MachinePhase) *string {
68+
s := string(p)
69+
return &s
70+
}

pkg/apis/cluster/v1alpha2/machine_types.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,40 @@ type MachineStatus struct {
163163
// +optional
164164
Phase *string `json:"phase,omitempty"`
165165

166-
// Bootstrap is the state of the bootstrap provider.
167-
Bootstrap *string `json:"bootstrap,omitempty"`
166+
// BootstrapReady is the state of the bootstrap provider.
167+
// +optional
168+
BootstrapReady bool `json:"bootstrapReady"`
169+
170+
// InfrastructureReady is the state of the infrastructure provider.
171+
// +optional
172+
InfrastructureReady bool `json:"infrastructureReady"`
173+
}
174+
175+
// SetTypedPhase sets the Phase field to the string representation of MachinePhase.
176+
func (m *MachineStatus) SetTypedPhase(p MachinePhase) {
177+
m.Phase = MachinePhaseStringPtr(p)
178+
}
168179

169-
// Infrastructure is the state of the infrastructure provider.
170-
Infrastructure *string `json:"infrastructure,omitempty"`
180+
// GetTypedPhase attempts to parse the Phase field and return
181+
// the typed MachinePhase representation as described in `machine_phase_types.go`.
182+
func (m *MachineStatus) GetTypedPhase() MachinePhase {
183+
if m.Phase == nil {
184+
return MachinePhaseUnknown
185+
}
186+
187+
switch phase := MachinePhase(*m.Phase); phase {
188+
case
189+
MachinePhasePending,
190+
MachinePhaseProvisioning,
191+
MachinePhaseProvisioned,
192+
MachinePhaseRunning,
193+
MachinePhaseDeleting,
194+
MachinePhaseDeleted,
195+
MachinePhaseFailed:
196+
return phase
197+
default:
198+
return MachinePhaseUnknown
199+
}
171200
}
172201

173202
// Bootstrap capsulates fields to configure the Machine’s bootstrapping mechanism.

pkg/apis/cluster/v1alpha2/zz_generated.deepcopy.go

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)