Skip to content

Commit 52f929e

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

File tree

5 files changed

+102
-19
lines changed

5 files changed

+102
-19
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,9 @@ spec:
590590
- address
591591
type: object
592592
type: array
593-
bootstrap:
593+
bootstrapReady:
594594
description: Bootstrap is the state of the bootstrap provider.
595-
type: string
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: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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
20+
type MachinePhase string
21+
22+
var (
23+
// MachinePhasePending is the first state a Machine is assigned by
24+
// Cluster API Machine controller after being created.
25+
MachinePhasePending = MachinePhase("pending")
26+
27+
// MachinePhaseProvisioning is the state when the
28+
// Machine infrastructure is being created.
29+
MachinePhaseProvisioning = MachinePhase("provisioning")
30+
31+
// MachinePhaseProvisioned is the state when its
32+
// infrastructure has been created and configured.
33+
MachinePhaseProvisioned = MachinePhase("provisioned")
34+
35+
// MachinePhaseRunning is the Machine state when it has
36+
// become a Kubernetes Node in a Ready state.
37+
MachinePhaseRunning = MachinePhase("running")
38+
39+
// MachinePhaseDeleting is the Machine state when a delete
40+
// request has been sent to the API Server,
41+
// but its infrastructure has not yet been fully deleted.
42+
MachinePhaseDeleting = MachinePhase("deleting")
43+
44+
// MachinePhaseDeleted is the Machine state when the object
45+
// and the related infrastructure is deleted and
46+
// ready to be garbage collected by the API Server.
47+
MachinePhaseDeleted = MachinePhase("deleted")
48+
49+
// MachinePhaseFailed is the Machine state when the system
50+
// might require user intervention.
51+
MachinePhaseFailed = MachinePhase("failed")
52+
53+
// MachinePhaseUnknown is returned if the Machine state cannot be determined.
54+
MachinePhaseUnknown = MachinePhase("")
55+
)
56+
57+
// MachinePhaseStringPtr is a helper method to convert MachinePhase to a string pointer.
58+
func MachinePhaseStringPtr(p MachinePhase) *string {
59+
s := string(p)
60+
return &s
61+
}

pkg/apis/cluster/v1alpha2/machine_types.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,38 @@ 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+
BootstrapReady bool `json:"bootstrapReady"`
168168

169-
// Infrastructure is the state of the infrastructure provider.
170-
Infrastructure *string `json:"infrastructure,omitempty"`
169+
// InfrastructureReady is the state of the infrastructure provider.
170+
InfrastructureReady bool `json:"infrastructureReady"`
171+
}
172+
173+
// SetTypedPhase sets the Phase field to the string representation of MachinePhase.
174+
func (m *MachineStatus) SetTypedPhase(p MachinePhase) {
175+
m.Phase = MachinePhaseStringPtr(p)
176+
}
177+
178+
// GetTypedPhase attempts to parse the Phase field and return
179+
// the typed MachinePhase representation as described in `machine_phase_types.go`.
180+
func (m *MachineStatus) GetTypedPhase() MachinePhase {
181+
if m.Phase == nil {
182+
return MachinePhaseUnknown
183+
}
184+
185+
switch phase := MachinePhase(*m.Phase); phase {
186+
case
187+
MachinePhasePending,
188+
MachinePhaseProvisioning,
189+
MachinePhaseProvisioned,
190+
MachinePhaseRunning,
191+
MachinePhaseDeleting,
192+
MachinePhaseDeleted,
193+
MachinePhaseFailed:
194+
return phase
195+
default:
196+
return MachinePhaseUnknown
197+
}
171198
}
172199

173200
// 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)