Skip to content

Commit 917c205

Browse files
author
Joshua Reed
committed
Failure domain fetches data and goes ready.
1 parent 0a82799 commit 917c205

12 files changed

+76
-46
lines changed

api/v1beta2/cloudstackcluster_webhook.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,7 @@ func (r *CloudStackCluster) Default() {
4545
// No defaulted values supported yet.
4646
}
4747

48-
// +kubebuilder:webhook:
49-
// name=vcloudstackcluster.kb.io
50-
// groups=infrastructure.cluster.x-k8s.io,resources=cloudstackclusters
51-
// versions=v1beta2
52-
// verbs=create;update
53-
// path=/validate-infrastructure-cluster-x-k8s-io-v1beta2-cloudstackcluster
54-
// mutating=false,failurePolicy=fail,sideEffects=None
55-
// admissionReviewVersions=v1beta2
48+
// +kubebuilder:webhook:name=vcloudstackcluster.kb.io,groups=infrastructure.cluster.x-k8s.io,resources=cloudstackclusters,versions=v1beta2,verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta2-cloudstackcluster,mutating=false,failurePolicy=fail,sideEffects=None,admissionReviewVersions=v1beta1
5649

5750
var _ webhook.Validator = &CloudStackCluster{}
5851

@@ -83,6 +76,11 @@ func (r *CloudStackCluster) ValidateCreate() error {
8376
field.NewPath("spec", "FailureDomains", "Zone", "Network"),
8477
"each Zone requires a Network specification"))
8578
}
79+
if fdSpec.ACSEndpoint.Name == "" || fdSpec.ACSEndpoint.Namespace == "" {
80+
errorList = append(errorList, field.Required(
81+
field.NewPath("spec", "FailureDomains", "ACSEndpoint"),
82+
"Name and Namespace are required"))
83+
}
8684
}
8785
}
8886

api/v1beta2/cloudstackfailuredomain_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type CloudStackFailureDomainSpec struct {
4343

4444
// Apache CloudStack Endpoint secret reference.
4545
// +optional
46-
ACSEndpoint corev1.SecretReference `json:"ACSEndpoint,omitempty"`
46+
ACSEndpoint corev1.SecretReference `json:"acsendpoint,omitempty"`
4747
}
4848

4949
// CloudStackFailureDomainStatus defines the observed state of CloudStackFailureDomain

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ spec:
226226
description: CloudStackFailureDomainSpec defines the desired state
227227
of CloudStackFailureDomain
228228
properties:
229-
ACSEndpoint:
229+
account:
230+
description: CloudStack account.
231+
type: string
232+
acsendpoint:
230233
description: Apache CloudStack Endpoint secret reference.
231234
properties:
232235
name:
@@ -238,9 +241,6 @@ spec:
238241
secret name must be unique.
239242
type: string
240243
type: object
241-
account:
242-
description: CloudStack account.
243-
type: string
244244
domain:
245245
description: CloudStack domain.
246246
type: string

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ spec:
3838
description: CloudStackFailureDomainSpec defines the desired state of
3939
CloudStackFailureDomain
4040
properties:
41-
ACSEndpoint:
41+
account:
42+
description: CloudStack account.
43+
type: string
44+
acsendpoint:
4245
description: Apache CloudStack Endpoint secret reference.
4346
properties:
4447
name:
@@ -50,9 +53,6 @@ spec:
5053
name must be unique.
5154
type: string
5255
type: object
53-
account:
54-
description: CloudStack account.
55-
type: string
5656
domain:
5757
description: CloudStack domain.
5858
type: string

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ spec:
122122
description: FailureDomain -- the FailureDomain the network is placed
123123
in.
124124
properties:
125-
ACSEndpoint:
125+
account:
126+
description: CloudStack account.
127+
type: string
128+
acsendpoint:
126129
description: Apache CloudStack Endpoint secret reference.
127130
properties:
128131
name:
@@ -134,9 +137,6 @@ spec:
134137
secret name must be unique.
135138
type: string
136139
type: object
137-
account:
138-
description: CloudStack account.
139-
type: string
140140
domain:
141141
description: CloudStack domain.
142142
type: string

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,10 @@ spec:
387387
description: FailureDomain -- the FailureDomain the machine is placed
388388
in.
389389
properties:
390-
ACSEndpoint:
390+
account:
391+
description: CloudStack account.
392+
type: string
393+
acsendpoint:
391394
description: Apache CloudStack Endpoint secret reference.
392395
properties:
393396
name:
@@ -399,9 +402,6 @@ spec:
399402
secret name must be unique.
400403
type: string
401404
type: object
402-
account:
403-
description: CloudStack account.
404-
type: string
405405
domain:
406406
description: CloudStack domain.
407407
type: string

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,10 @@ spec:
340340
description: FailureDomain -- the FailureDomain the machine
341341
is placed in.
342342
properties:
343-
ACSEndpoint:
343+
account:
344+
description: CloudStack account.
345+
type: string
346+
acsendpoint:
344347
description: Apache CloudStack Endpoint secret reference.
345348
properties:
346349
name:
@@ -352,9 +355,6 @@ spec:
352355
the secret name must be unique.
353356
type: string
354357
type: object
355-
account:
356-
description: CloudStack account.
357-
type: string
358358
domain:
359359
description: CloudStack domain.
360360
type: string

config/webhook/manifests.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,26 @@ metadata:
3434
creationTimestamp: null
3535
name: validating-webhook-configuration
3636
webhooks:
37+
- admissionReviewVersions:
38+
- v1beta1
39+
clientConfig:
40+
service:
41+
name: webhook-service
42+
namespace: system
43+
path: /validate-infrastructure-cluster-x-k8s-io-v1beta2-cloudstackcluster
44+
failurePolicy: Fail
45+
name: vcloudstackcluster.kb.io
46+
rules:
47+
- apiGroups:
48+
- infrastructure.cluster.x-k8s.io
49+
apiVersions:
50+
- v1beta2
51+
operations:
52+
- CREATE
53+
- UPDATE
54+
resources:
55+
- cloudstackclusters
56+
sideEffects: None
3757
- admissionReviewVersions:
3858
- v1beta1
3959
clientConfig:

controllers/cloudstackcluster_controller.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ func (r *CloudStackClusterReconciliationRunner) Reconcile() (res ctrl.Result, re
8888
return r.RunReconciliationStages(
8989
r.RequeueIfMissingBaseCRs,
9090
r.CreateFailureDomains(r.ReconciliationSubject.Spec.FailureDomains),
91-
r.CheckOwnedCRDsForReadiness(infrav1.GroupVersion.WithKind("CloudStackZone")),
91+
r.CheckOwnedCRDsForReadiness(infrav1.GroupVersion.WithKind("CloudStackFailureDomain")),
9292
r.GetFailureDomains(r.FailureDomains),
93-
r.VerifyZoneCRDs,
93+
r.VerifyFailureDomainCRDs,
9494
r.SetFailureDomains,
9595
r.SetReady)
9696
}
@@ -102,16 +102,16 @@ func (r *CloudStackClusterReconciliationRunner) SetReady() (ctrl.Result, error)
102102
return ctrl.Result{}, nil
103103
}
104104

105-
// VerifyFailureDomainCRDs verifies the Zone CRDs found match against those requested.
106-
func (r *CloudStackClusterReconciliationRunner) VerifyZoneCRDs() (ctrl.Result, error) {
105+
// VerifyFailureDomainCRDs verifies the FailureDomains found match against those requested.
106+
func (r *CloudStackClusterReconciliationRunner) VerifyFailureDomainCRDs() (ctrl.Result, error) {
107107
expected := len(r.ReconciliationSubject.Spec.FailureDomains)
108108
actual := len(r.FailureDomains.Items)
109109
if expected != actual {
110-
return r.RequeueWithMessage(fmt.Sprintf("Expected %d Zones, but found %d", expected, actual))
110+
return r.RequeueWithMessage(fmt.Sprintf("Expected %d FailureDomains, but found %d", expected, actual))
111111
}
112112
for _, fd := range r.FailureDomains.Items {
113113
if !fd.Status.Ready {
114-
return r.RequeueWithMessage(fmt.Sprintf("Zone %s/%s not ready, requeueing.", fd.Namespace, fd.Name))
114+
return r.RequeueWithMessage(fmt.Sprintf("FailureDomains %s/%s not ready, requeueing.", fd.Namespace, fd.Name))
115115
}
116116
}
117117
return ctrl.Result{}, nil
@@ -138,7 +138,7 @@ func (r *CloudStackClusterReconciliationRunner) ReconcileDelete() (ctrl.Result,
138138
return ctrl.Result{}, err
139139
}
140140
}
141-
return r.RequeueWithMessage("Child Zones still present, requeueing.")
141+
return r.RequeueWithMessage("Child FailureDomains still present, requeueing.")
142142
}
143143
controllerutil.RemoveFinalizer(r.ReconciliationSubject, infrav1.ClusterFinalizer)
144144
return ctrl.Result{}, nil

controllers/utils/failuredomains.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,33 @@ func (r *ReconciliationRunner) AsFailureDomainUser(fdSpec infrav1.CloudStackFail
9090
return ctrl.Result{}, errors.Wrapf(err, "getting ACSEndpoint secret with ref: %v", fdSpec.ACSEndpoint)
9191
}
9292

93+
config := map[string]interface{}{}
94+
for k, v := range endpointCredentials.Data {
95+
config[k] = string(v)
96+
}
97+
// TODO change secret parsing manner.
98+
if val, present := config["verify-ssl"]; present {
99+
if val == "true" {
100+
config["verify-ssl"] = true
101+
} else if val == "false" {
102+
config["verify-ssl"] = false
103+
}
104+
}
105+
93106
var err error
94-
if r.CSClient, err = cloud.NewClientFromMap(endpointCredentials.StringData); err != nil {
107+
if r.CSClient, err = cloud.NewClientFromMap(config); err != nil {
95108
return ctrl.Result{}, errors.Wrapf(err, "parsing ACSEndpoint secret with ref: %v", fdSpec.ACSEndpoint)
96109
}
97110

111+
// Transfer Cluster Domain & Account to FailureDomain as needed.
98112
if fdSpec.Account == "" {
99113
if r.CSCluster.Spec.Account != "" {
100114
fdSpec.Account = r.CSCluster.Spec.Account
101115
fdSpec.Domain = r.CSCluster.Spec.Domain
102116
}
103117
}
104118

105-
if r.CSCluster.Spec.Account != "" {
119+
if r.CSCluster.Spec.Account != "" { // Set r.CSUser CloudStack Client per Account and Domain.
106120
user := &cloud.User{}
107121
user.Account.Domain.Path = r.CSCluster.Spec.Domain
108122
user.Account.Name = r.CSCluster.Spec.Account
@@ -112,7 +126,7 @@ func (r *ReconciliationRunner) AsFailureDomainUser(fdSpec infrav1.CloudStackFail
112126
return ctrl.Result{}, errors.Errorf("could not find sufficient user (with API keys) in domain/account %s/%s",
113127
r.CSCluster.Spec.Domain, r.CSCluster.Spec.Account)
114128
}
115-
newUser := endpointCredentials.StringData
129+
newUser := config
116130
newUser["api-key"] = user.APIKey
117131
newUser["secret-key"] = user.SecretKey
118132

@@ -121,6 +135,8 @@ func (r *ReconciliationRunner) AsFailureDomainUser(fdSpec infrav1.CloudStackFail
121135
return ctrl.Result{}, err
122136
}
123137
r.CSUser = client
138+
} else { // Set r.CSUser CloudStack Client to r.CSClient since Account & Domain weren't provided.
139+
r.CSUser = r.CSClient
124140
}
125141

126142
return ctrl.Result{}, nil

0 commit comments

Comments
 (0)