Skip to content

Commit 48790f4

Browse files
authored
Add conditions (#508)
1 parent 6ebefa3 commit 48790f4

9 files changed

+336
-43
lines changed

api/v1alpha4/ibmpowervs_conversion.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha4
1818

1919
import (
20+
apiconversion "k8s.io/apimachinery/pkg/conversion"
2021
"sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1beta1"
2122
"sigs.k8s.io/controller-runtime/pkg/conversion"
2223
)
@@ -92,3 +93,9 @@ func (dst *IBMPowerVSMachineTemplateList) ConvertFrom(srcRaw conversion.Hub) err
9293

9394
return Convert_v1beta1_IBMPowerVSMachineTemplateList_To_v1alpha4_IBMPowerVSMachineTemplateList(src, dst, nil)
9495
}
96+
97+
// Convert_v1beta1_IBMPowerVSMachineStatus_To_v1alpha4_IBMPowerVSMachineStatus is an autogenerated conversion function.
98+
// Requires manual conversion as FailureReason, FailureMessage and Conditions does not exist in v1alpha4 version of IBMPowerVSMachineStatus.
99+
func Convert_v1beta1_IBMPowerVSMachineStatus_To_v1alpha4_IBMPowerVSMachineStatus(in *v1beta1.IBMPowerVSMachineStatus, out *IBMPowerVSMachineStatus, s apiconversion.Scope) error {
100+
return autoConvert_v1beta1_IBMPowerVSMachineStatus_To_v1alpha4_IBMPowerVSMachineStatus(in, out, s)
101+
}

api/v1alpha4/zz_generated.conversion.go

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

api/v1beta1/conditions_consts.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright 2022 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 v1beta1
18+
19+
import (
20+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
21+
)
22+
23+
const (
24+
// InstanceProvisionFailedReason used for failures during instance provisioning.
25+
InstanceProvisionFailedReason = "InstanceProvisionFailed"
26+
// WaitingForClusterInfrastructureReason used when machine is waiting for cluster infrastructure to be ready before proceeding.
27+
WaitingForClusterInfrastructureReason = "WaitingForClusterInfrastructure"
28+
// WaitingForBootstrapDataReason used when machine is waiting for bootstrap data to be ready before proceeding.
29+
WaitingForBootstrapDataReason = "WaitingForBootstrapData"
30+
)
31+
32+
const (
33+
// InstanceStoppedReason instance is in a stopped state.
34+
InstanceStoppedReason = "InstanceStopped"
35+
36+
// InstanceNotReadyReason used when the instance is in a pending state.
37+
InstanceNotReadyReason = "InstanceNotReady"
38+
)
39+
40+
const (
41+
// InstanceReadyCondition reports on current status of the instance. Ready indicates the instance is in a Running state.
42+
InstanceReadyCondition clusterv1.ConditionType = "InstanceReady"
43+
)

api/v1beta1/ibmpowervsmachine_types.go

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package v1beta1
1919
import (
2020
v1 "k8s.io/api/core/v1"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
23+
"sigs.k8s.io/cluster-api/errors"
2224
)
2325

2426
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
@@ -99,11 +101,54 @@ type IBMPowerVSMachineStatus struct {
99101
Health string `json:"health,omitempty"`
100102

101103
// InstanceState is the status of the vsi
102-
InstanceState string `json:"instanceState"`
104+
// +optional
105+
InstanceState PowerVSInstanceState `json:"instanceState,omitempty"`
103106

104107
// Fault will report if any fault messages for the vsi
105108
// +optional
106109
Fault string `json:"fault,omitempty"`
110+
111+
// FailureReason will be set in the event that there is a terminal problem
112+
// reconciling the Machine and will contain a succinct value suitable
113+
// for machine interpretation.
114+
//
115+
// This field should not be set for transitive errors that a controller
116+
// faces that are expected to be fixed automatically over
117+
// time (like service outages), but instead indicate that something is
118+
// fundamentally wrong with the Machine's spec or the configuration of
119+
// the controller, and that manual intervention is required. Examples
120+
// of terminal errors would be invalid combinations of settings in the
121+
// spec, values that are unsupported by the controller, or the
122+
// responsible controller itself being critically misconfigured.
123+
//
124+
// Any transient errors that occur during the reconciliation of Machines
125+
// can be added as events to the Machine object and/or logged in the
126+
// controller's output.
127+
// +optional
128+
FailureReason *errors.MachineStatusError `json:"failureReason,omitempty"`
129+
130+
// FailureMessage will be set in the event that there is a terminal problem
131+
// reconciling the Machine and will contain a more verbose string suitable
132+
// for logging and human consumption.
133+
//
134+
// This field should not be set for transitive errors that a controller
135+
// faces that are expected to be fixed automatically over
136+
// time (like service outages), but instead indicate that something is
137+
// fundamentally wrong with the Machine's spec or the configuration of
138+
// the controller, and that manual intervention is required. Examples
139+
// of terminal errors would be invalid combinations of settings in the
140+
// spec, values that are unsupported by the controller, or the
141+
// responsible controller itself being critically misconfigured.
142+
//
143+
// Any transient errors that occur during the reconciliation of Machines
144+
// can be added as events to the Machine object and/or logged in the
145+
// controller's output.
146+
// +optional
147+
FailureMessage *string `json:"failureMessage,omitempty"`
148+
149+
// Conditions defines current service state of the IBMPowerVSMachine.
150+
// +optional
151+
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
107152
}
108153

109154
//+kubebuilder:object:root=true
@@ -123,6 +168,16 @@ type IBMPowerVSMachine struct {
123168
Status IBMPowerVSMachineStatus `json:"status,omitempty"`
124169
}
125170

171+
// GetConditions returns the observations of the operational state of the IBMPowerVSMachine resource.
172+
func (r *IBMPowerVSMachine) GetConditions() clusterv1.Conditions {
173+
return r.Status.Conditions
174+
}
175+
176+
// SetConditions sets the underlying service state of the IBMPowerVSMachine to the predescribed clusterv1.Conditions.
177+
func (r *IBMPowerVSMachine) SetConditions(conditions clusterv1.Conditions) {
178+
r.Status.Conditions = conditions
179+
}
180+
126181
//+kubebuilder:object:root=true
127182

128183
// IBMPowerVSMachineList contains a list of IBMPowerVSMachine

api/v1beta1/types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ limitations under the License.
1616

1717
package v1beta1
1818

19+
// PowerVSInstanceState describes the state of an IBM Power VS instance.
20+
type PowerVSInstanceState string
21+
22+
var (
23+
// PowerVSInstanceStateACTIVE is the string representing an instance in a ACTIVE state.
24+
PowerVSInstanceStateACTIVE = PowerVSInstanceState("ACTIVE")
25+
26+
// PowerVSInstanceStateBUILD is the string representing an instance in a BUILD state.
27+
PowerVSInstanceStateBUILD = PowerVSInstanceState("BUILD")
28+
29+
// PowerVSInstanceStateSHUTOFF is the string representing an instance in a SHUTOFF state.
30+
PowerVSInstanceStateSHUTOFF = PowerVSInstanceState("SHUTOFF")
31+
32+
// PowerVSInstanceStateREBOOT is the string representing an instance in a REBOOT state.
33+
PowerVSInstanceStateREBOOT = PowerVSInstanceState("REBOOT")
34+
)
35+
1936
// NetworkInterface holds the network interface information like subnet id.
2037
type NetworkInterface struct {
2138
// Subnet ID of the network interface

api/v1beta1/zz_generated.deepcopy.go

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

cloud/scope/powervs_machine.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"encoding/base64"
2222
"fmt"
23+
"k8s.io/utils/pointer"
2324
"strconv"
2425

2526
"github.com/go-logr/logr"
@@ -307,3 +308,56 @@ func getNetworkID(network v1beta1.IBMPowerVSResourceReference, m *PowerVSMachine
307308
func (m *PowerVSMachineScope) GetNetworks() (*models.Networks, error) {
308309
return m.IBMPowerVSClient.GetAllNetwork()
309310
}
311+
312+
func (m *PowerVSMachineScope) SetReady() {
313+
m.IBMPowerVSMachine.Status.Ready = true
314+
}
315+
316+
func (m *PowerVSMachineScope) SetNotReady() {
317+
m.IBMPowerVSMachine.Status.Ready = false
318+
}
319+
320+
func (m *PowerVSMachineScope) SetInstanceID(id *string) {
321+
if id != nil {
322+
m.IBMPowerVSMachine.Status.InstanceID = *id
323+
}
324+
}
325+
326+
func (m *PowerVSMachineScope) GetInstanceID() string {
327+
return m.IBMPowerVSMachine.Status.InstanceID
328+
}
329+
330+
func (m *PowerVSMachineScope) SetHealth(health *models.PVMInstanceHealth) {
331+
if health != nil {
332+
m.IBMPowerVSMachine.Status.Health = health.Status
333+
}
334+
}
335+
336+
func (m *PowerVSMachineScope) SetAddresses(networks []*models.PVMInstanceNetwork) {
337+
var addresses []corev1.NodeAddress
338+
for _, network := range networks {
339+
addresses = append(addresses, corev1.NodeAddress{
340+
Type: corev1.NodeInternalIP,
341+
Address: network.IPAddress,
342+
})
343+
if network.ExternalIP != "" {
344+
addresses = append(addresses, corev1.NodeAddress{
345+
Type: corev1.NodeExternalIP,
346+
Address: network.ExternalIP,
347+
})
348+
}
349+
}
350+
m.IBMPowerVSMachine.Status.Addresses = addresses
351+
}
352+
353+
func (m *PowerVSMachineScope) SetInstanceState(status *string) {
354+
m.IBMPowerVSMachine.Status.InstanceState = v1beta1.PowerVSInstanceState(*status)
355+
}
356+
357+
func (m *PowerVSMachineScope) GetInstanceState() v1beta1.PowerVSInstanceState {
358+
return m.IBMPowerVSMachine.Status.InstanceState
359+
}
360+
361+
func (m *PowerVSMachineScope) SetProviderID() {
362+
m.IBMPowerVSMachine.Spec.ProviderID = pointer.StringPtr(fmt.Sprintf("ibmpowervs://%s/%s", m.Machine.Spec.ClusterName, m.IBMPowerVSMachine.Name))
363+
}

0 commit comments

Comments
 (0)