Skip to content

Commit a950d3a

Browse files
authored
Merge pull request #2994 from Nordix/lentzi90/osmt-conditions
✨ Add conditions for OpenStackMachineTemplate
2 parents 83bdbf0 + c563d5b commit a950d3a

14 files changed

+460
-12
lines changed

api/v1beta1/openstackmachinetemplate_types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1beta1
1919
import (
2020
corev1 "k8s.io/api/core/v1"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
2223
)
2324

2425
// OpenStackMachineTemplateSpec defines the desired state of OpenStackMachineTemplate.
@@ -35,6 +36,12 @@ type OpenStackMachineTemplateStatus struct {
3536
Capacity corev1.ResourceList `json:"capacity,omitempty"`
3637
// +optional
3738
NodeInfo NodeInfo `json:"nodeInfo,omitempty,omitzero"`
39+
40+
// Conditions defines current service state of the OpenStackMachineTemplate.
41+
// The Ready condition must surface issues during the entire lifecycle of the OpenStackMachineTemplate.
42+
// (both during initial provisioning and after the initial provisioning is completed).
43+
// +optional
44+
Conditions clusterv1beta1.Conditions `json:"conditions,omitempty"`
3845
}
3946

4047
// NodeInfo contains information about the node's architecture and operating system.
@@ -81,3 +88,13 @@ func (r *OpenStackMachineTemplate) GetIdentityRef() (*string, *OpenStackIdentity
8188
}
8289
return nil, nil
8390
}
91+
92+
// GetConditions returns the observations of the operational state of the OpenStackMachineTemplate resource.
93+
func (r *OpenStackMachineTemplate) GetConditions() clusterv1beta1.Conditions {
94+
return r.Status.Conditions
95+
}
96+
97+
// SetConditions sets the underlying service state of the OpenStackMachineTemplate to the predescribed clusterv1.Conditions.
98+
func (r *OpenStackMachineTemplate) SetConditions(conditions clusterv1beta1.Conditions) {
99+
r.Status.Conditions = conditions
100+
}

api/v1beta1/zz_generated.deepcopy.go

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

api/v1beta2/openstackmachinetemplate_types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ type OpenStackMachineTemplateStatus struct {
3535
Capacity corev1.ResourceList `json:"capacity,omitempty"`
3636
// +optional
3737
NodeInfo NodeInfo `json:"nodeInfo,omitempty,omitzero"`
38+
39+
// Conditions defines current service state of the OpenStackMachineTemplate.
40+
// The Ready condition must surface issues during the entire lifecycle of the OpenStackMachineTemplate.
41+
// (both during initial provisioning and after the initial provisioning is completed).
42+
// +optional
43+
Conditions []metav1.Condition `json:"conditions,omitempty"`
3844
}
3945

4046
// NodeInfo contains information about the node's architecture and operating system.
@@ -72,3 +78,13 @@ type OpenStackMachineTemplateList struct {
7278
func init() {
7379
objectTypes = append(objectTypes, &OpenStackMachineTemplate{}, &OpenStackMachineTemplateList{})
7480
}
81+
82+
// GetConditions returns the observations of the operational state of the OpenStackMachineTemplate resource.
83+
func (r *OpenStackMachineTemplate) GetConditions() []metav1.Condition {
84+
return r.Status.Conditions
85+
}
86+
87+
// SetConditions sets the underlying service state of the OpenStackMachineTemplate to the predescribed clusterv1.Conditions.
88+
func (r *OpenStackMachineTemplate) SetConditions(conditions []metav1.Condition) {
89+
r.Status.Conditions = conditions
90+
}

api/v1beta2/zz_generated.deepcopy.go

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

cmd/models-schema/zz_generated.openapi.go

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml

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

controllers/openstackcluster_controller_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ var (
5959
)
6060

6161
var _ = Describe("OpenStackCluster controller", func() {
62-
capiClusterName := "capi-cluster"
6362
testClusterName := "test-cluster"
6463
testNum := 0
6564
bastionSpec := infrav1.OpenStackMachineSpec{

controllers/openstackmachine_controller_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,6 @@ var _ = Describe("OpenStackMachine controller", func() {
675675
testNum int
676676
)
677677

678-
capiClusterName := "capi-cluster"
679678
testClusterName := "test-cluster"
680679
testMachineName := "test-machine"
681680
capiMachineName := "capi-machine"

controllers/openstackmachinetemplate_controller.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import (
2424
"k8s.io/apimachinery/pkg/api/resource"
2525
kerrors "k8s.io/apimachinery/pkg/util/errors"
2626
"k8s.io/client-go/tools/record"
27+
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
2728
"sigs.k8s.io/cluster-api/util"
2829
"sigs.k8s.io/cluster-api/util/annotations"
30+
v1beta1conditions "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions"
2931
"sigs.k8s.io/cluster-api/util/patch"
3032
"sigs.k8s.io/cluster-api/util/predicates"
3133
ctrl "sigs.k8s.io/controller-runtime"
@@ -106,12 +108,6 @@ func (r *OpenStackMachineTemplateReconciler) Reconcile(ctx context.Context, req
106108

107109
log = log.WithValues("openStackCluster", infraCluster.Name)
108110

109-
clientScope, err := r.ScopeFactory.NewClientScopeFromObject(ctx, r.Client, r.CaCertificates, log, openStackMachineTemplate, infraCluster)
110-
if err != nil {
111-
return ctrl.Result{}, err
112-
}
113-
scope := scope.NewWithLogger(clientScope, log)
114-
115111
// Initialize the patch helper
116112
patchHelper, err := patch.NewHelper(openStackMachineTemplate, r.Client)
117113
if err != nil {
@@ -127,6 +123,14 @@ func (r *OpenStackMachineTemplateReconciler) Reconcile(ctx context.Context, req
127123
}
128124
}()
129125

126+
clientScope, err := r.ScopeFactory.NewClientScopeFromObject(ctx, r.Client, r.CaCertificates, log, openStackMachineTemplate, infraCluster)
127+
if err != nil {
128+
v1beta1conditions.MarkFalse(openStackMachineTemplate, infrav1.OpenStackAuthenticationSucceeded, infrav1.OpenStackAuthenticationFailedReason, clusterv1beta1.ConditionSeverityError, "Failed to create OpenStack client scope: %v", err)
129+
return ctrl.Result{}, err
130+
}
131+
v1beta1conditions.MarkTrue(openStackMachineTemplate, infrav1.OpenStackAuthenticationSucceeded)
132+
scope := scope.NewWithLogger(clientScope, log)
133+
130134
// Handle non-deleted OpenStackMachineTemplates
131135
if err := r.reconcileNormal(ctx, scope, openStackMachineTemplate); err != nil {
132136
return ctrl.Result{}, err

0 commit comments

Comments
 (0)