Skip to content

Commit 4a47522

Browse files
authored
Merge pull request #147 from rejoshed/feature/hash-failure-domain-naming
Feature/hash failure domain naming
2 parents a541d71 + 9f10f03 commit 4a47522

File tree

52 files changed

+77
-3113
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+77
-3113
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ cluster-api
2929
# Ignore output of Makefile sed operations created when generating manifests.
3030
config/default/manager_image_patch_edited.yaml
3131

32+
# Ignore output of e2e kustomization of templates.
33+
test/e2e/data/infrastructure-cloudstack/v1beta*/*yaml
34+
3235
# Test binary, build with `go test -c`
3336
*.test
3437

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ clean: ## Clean.
188188
rm -rf $(RELEASE_DIR)
189189
rm -rf bin
190190
rm -rf cluster-api
191+
rm -rf test/e2e/data/infrastructure-cloudstack/*/*yaml
191192

192193
##@ Testing
193194

@@ -223,8 +224,7 @@ cluster-api/tilt-settings.json: hack/tilt-settings.json cluster-api
223224
cp ./hack/tilt-settings.json cluster-api
224225

225226
##@ End-to-End Testing
226-
227-
CLUSTER_TEMPLATES_INPUT_FILES=$(shell find test/e2e/data/infrastructure-cloudstack/v1beta2/*/cluster-template*/* test/e2e/data/infrastructure-cloudstack/*/bases/* -type f)
227+
CLUSTER_TEMPLATES_INPUT_FILES=$(shell find test/e2e/data/infrastructure-cloudstack/v1beta*/*/cluster-template* test/e2e/data/infrastructure-cloudstack/*/bases/* -type f)
228228
CLUSTER_TEMPLATES_OUTPUT_FILES=$(shell find test/e2e/data/infrastructure-cloudstack -type d -name "cluster-template*" -exec echo {}.yaml \;)
229229
.PHONY: e2e-cluster-templates
230230
e2e-cluster-templates: $(CLUSTER_TEMPLATES_OUTPUT_FILES) ## Generate cluster template files for e2e testing.

api/v1beta1/zz_generated.conversion.go

+1-53
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/cloudstackfailuredomain_types.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,21 @@ limitations under the License.
1717
package v1beta2
1818

1919
import (
20+
"crypto/md5" // #nosec G501 -- weak cryptographic primitive doesn't matter here. Not security related.
21+
"fmt"
22+
2023
corev1 "k8s.io/api/core/v1"
2124
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2225
)
2326

27+
// FailureDomainHashedMetaName returns an MD5 name generated from the FailureDomain and Cluster name.
28+
// FailureDomains must have a unique name even when potentially sharing a namespace with other clusters.
29+
// In the future we may remove the ability to run multiple clusters in a single namespace, but today
30+
// this is a consequence of being upstream of EKS-A which does run multiple clusters in a single namepace.
31+
func FailureDomainHashedMetaName(fdName, clusterName string) string {
32+
return fmt.Sprintf("%x", md5.Sum([]byte(fdName+clusterName))) // #nosec G401 -- weak cryptographic primitive doesn't matter here. Not security related.
33+
}
34+
2435
const (
2536
FailureDomainFinalizer = "cloudstackfailuredomain.infrastructure.cluster.x-k8s.io"
2637
FailureDomainLabelName = "cloudstackfailuredomain.infrastructure.cluster.x-k8s.io/name"
@@ -70,8 +81,9 @@ type CloudStackFailureDomainSpec struct {
7081
// CloudStack domain.
7182
// +optional
7283
Domain string `json:"domain,omitempty"`
84+
7385
// Apache CloudStack Endpoint secret reference.
74-
ACSEndpoint corev1.SecretReference `json:"acsendpoint"`
86+
ACSEndpoint corev1.SecretReference `json:"acsEndpoint"`
7587
}
7688

7789
// CloudStackFailureDomainStatus defines the observed state of CloudStackFailureDomain

api/v1beta2/cloudstackisolatednetwork_types.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ type CloudStackIsolatedNetworkSpec struct {
4040
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
4141

4242
//+k8s:conversion-gen=false
43-
// FailureDomain -- the FailureDomain the network is placed in.
44-
FailureDomain CloudStackFailureDomainSpec `json:"failureDomain"`
43+
// FailureDomainName -- the FailureDomain the network is placed in.
44+
FailureDomainName string `json:"failureDomainName"`
4545
}
4646

4747
// CloudStackIsolatedNetworkStatus defines the observed state of CloudStackIsolatedNetwork

api/v1beta2/cloudstackmachine_types.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type CloudStackMachineSpec struct {
6363

6464
// Optional affinitygroupids for deployVirtualMachine
6565
// +optional
66-
AffinityGroupIDs []string `json:"affinitygroupids,omitempty"`
66+
AffinityGroupIDs []string `json:"affinityGroupIDs,omitempty"`
6767

6868
// Mutually exclusive parameter with AffinityGroupIDs.
6969
// Defaults to `no`. Can be `pro` or `anti`. Will create an affinity group per machine set.
@@ -73,7 +73,7 @@ type CloudStackMachineSpec struct {
7373
// Mutually exclusive parameter with AffinityGroupIDs.
7474
// Is a reference to a CloudStack affinity group CRD.
7575
// +optional
76-
AffinityGroupRef *corev1.ObjectReference `json:"cloudstackaffinityref,omitempty"`
76+
AffinityGroupRef *corev1.ObjectReference `json:"cloudstackAffinityRef,omitempty"`
7777

7878
// The CS specific unique identifier. Of the form: fmt.Sprintf("cloudstack:///%s", CS Machine ID)
7979
// +optional

api/v1beta2/zz_generated.deepcopy.go

-1
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_cloudstackclusters.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ spec:
223223
account:
224224
description: CloudStack account.
225225
type: string
226-
acsendpoint:
226+
acsEndpoint:
227227
description: Apache CloudStack Endpoint secret reference.
228228
properties:
229229
name:
@@ -272,7 +272,7 @@ spec:
272272
- network
273273
type: object
274274
required:
275-
- acsendpoint
275+
- acsEndpoint
276276
- name
277277
- zone
278278
type: object

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ spec:
4141
account:
4242
description: CloudStack account.
4343
type: string
44-
acsendpoint:
44+
acsEndpoint:
4545
description: Apache CloudStack Endpoint secret reference.
4646
properties:
4747
name:
@@ -89,7 +89,7 @@ spec:
8989
- network
9090
type: object
9191
required:
92-
- acsendpoint
92+
- acsEndpoint
9393
- name
9494
- zone
9595
type: object

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

+5-61
Original file line numberDiff line numberDiff line change
@@ -118,66 +118,10 @@ spec:
118118
- host
119119
- port
120120
type: object
121-
failureDomain:
122-
description: FailureDomain -- the FailureDomain the network is placed
123-
in.
124-
properties:
125-
account:
126-
description: CloudStack account.
127-
type: string
128-
acsendpoint:
129-
description: Apache CloudStack Endpoint secret reference.
130-
properties:
131-
name:
132-
description: Name is unique within a namespace to reference
133-
a secret resource.
134-
type: string
135-
namespace:
136-
description: Namespace defines the space within which the
137-
secret name must be unique.
138-
type: string
139-
type: object
140-
domain:
141-
description: CloudStack domain.
142-
type: string
143-
name:
144-
description: The failure domain unique name.
145-
type: string
146-
zone:
147-
description: The ACS Zone for this failure domain.
148-
properties:
149-
id:
150-
description: ID.
151-
type: string
152-
name:
153-
description: Name.
154-
type: string
155-
network:
156-
description: The network within the Zone to use.
157-
properties:
158-
id:
159-
description: Cloudstack Network ID the cluster is built
160-
in.
161-
type: string
162-
name:
163-
description: Cloudstack Network Name the cluster is built
164-
in.
165-
type: string
166-
type:
167-
description: Cloudstack Network Type the cluster is built
168-
in.
169-
type: string
170-
required:
171-
- name
172-
type: object
173-
required:
174-
- network
175-
type: object
176-
required:
177-
- acsendpoint
178-
- name
179-
- zone
180-
type: object
121+
failureDomainName:
122+
description: FailureDomainName -- the FailureDomain the network is
123+
placed in.
124+
type: string
181125
id:
182126
description: ID.
183127
type: string
@@ -186,7 +130,7 @@ spec:
186130
type: string
187131
required:
188132
- controlPlaneEndpoint
189-
- failureDomain
133+
- failureDomainName
190134
type: object
191135
status:
192136
description: CloudStackIsolatedNetworkStatus defines the observed state

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,12 @@ spec:
301301
to `no`. Can be `pro` or `anti`. Will create an affinity group per
302302
machine set.
303303
type: string
304-
affinitygroupids:
304+
affinityGroupIDs:
305305
description: Optional affinitygroupids for deployVirtualMachine
306306
items:
307307
type: string
308308
type: array
309-
cloudstackaffinityref:
309+
cloudstackAffinityRef:
310310
description: Mutually exclusive parameter with AffinityGroupIDs. Is
311311
a reference to a CloudStack affinity group CRD.
312312
properties:

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,12 @@ spec:
251251
Defaults to `no`. Can be `pro` or `anti`. Will create an
252252
affinity group per machine set.
253253
type: string
254-
affinitygroupids:
254+
affinityGroupIDs:
255255
description: Optional affinitygroupids for deployVirtualMachine
256256
items:
257257
type: string
258258
type: array
259-
cloudstackaffinityref:
259+
cloudstackAffinityRef:
260260
description: Mutually exclusive parameter with AffinityGroupIDs.
261261
Is a reference to a CloudStack affinity group CRD.
262262
properties:

controllers/cloudstackaffinitygroup_controller.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121

2222
ctrl "sigs.k8s.io/controller-runtime"
23-
"sigs.k8s.io/controller-runtime/pkg/client"
2423
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
2524

2625
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta2"
@@ -60,9 +59,7 @@ func (reconciler *CloudStackAffinityGroupReconciler) Reconcile(ctx context.Conte
6059
r := NewCSAGReconciliationRunner()
6160
r.UsingBaseReconciler(reconciler.ReconcilerBase).ForRequest(req).WithRequestCtx(ctx)
6261
r.WithAdditionalCommonStages(
63-
r.GetObjectByName("placeholder", r.FailureDomain,
64-
func() string { return r.ReconciliationSubject.Spec.FailureDomainName }),
65-
r.CheckPresent(map[string]client.Object{"CloudStackFailureDomain": r.FailureDomain}),
62+
r.GetFailureDomainByName(func() string { return r.ReconciliationSubject.Spec.FailureDomainName }, r.FailureDomain),
6663
r.AsFailureDomainUser(&r.FailureDomain.Spec))
6764
return r.RunBaseReconciliationStages()
6865
}

controllers/cloudstackaffinitygroup_controller_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ var _ = Describe("CloudStackAffinityGroupReconciler", func() {
3434

3535
It("Should patch back the affinity group as ready after calling GetOrCreateAffinityGroup.", func() {
3636
// Modify failure domain name the same way the cluster controller would.
37-
dummies.CSFailureDomain1.Name = dummies.CSFailureDomain1.Name + "-" + dummies.CSCluster.Name
38-
dummies.CSAffinityGroup.Spec.FailureDomainName = dummies.CSFailureDomain1.Name
37+
dummies.CSAffinityGroup.Spec.FailureDomainName = dummies.CSFailureDomain1.Spec.Name
3938

4039
Ω(k8sClient.Create(ctx, dummies.CSFailureDomain1))
4140
Ω(k8sClient.Create(ctx, dummies.CSAffinityGroup)).Should(Succeed())

controllers/cloudstackcluster_controller.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,19 @@ func (r *CloudStackClusterReconciliationRunner) SetReady() (ctrl.Result, error)
105105
// VerifyFailureDomainCRDs verifies the FailureDomains found match against those requested.
106106
func (r *CloudStackClusterReconciliationRunner) VerifyFailureDomainCRDs() (ctrl.Result, error) {
107107
// Check that all required failure domains are present and ready.
108-
for _, requiredFd := range r.ReconciliationSubject.Spec.FailureDomains {
108+
for _, requiredFdSpec := range r.ReconciliationSubject.Spec.FailureDomains {
109109
found := false
110110
for _, fd := range r.FailureDomains.Items {
111-
requiredFDName := csCtrlrUtils.WithClusterSuffix(requiredFd.Name, r.CAPICluster.Name)
112-
if requiredFDName == fd.Name {
111+
if requiredFdSpec.Name == fd.Spec.Name {
113112
found = true
114113
if !fd.Status.Ready {
115-
return r.RequeueWithMessage(fmt.Sprintf("Required FailureDomain %s not ready, requeueing.", fd.Name))
114+
return r.RequeueWithMessage(fmt.Sprintf("Required FailureDomain %s not ready, requeueing.", fd.Spec.Name))
116115
}
117116
break
118117
}
119118
}
120119
if !found {
121-
return r.RequeueWithMessage(fmt.Sprintf("Required FailureDomain %s not found, requeueing.", requiredFd.Name))
120+
return r.RequeueWithMessage(fmt.Sprintf("Required FailureDomain %s not found, requeueing.", requiredFdSpec.Name))
122121
}
123122
}
124123
return ctrl.Result{}, nil
@@ -128,8 +127,9 @@ func (r *CloudStackClusterReconciliationRunner) VerifyFailureDomainCRDs() (ctrl.
128127
func (r *CloudStackClusterReconciliationRunner) SetFailureDomainsStatusMap() (ctrl.Result, error) {
129128
r.ReconciliationSubject.Status.FailureDomains = clusterv1.FailureDomains{}
130129
for _, fdSpec := range r.ReconciliationSubject.Spec.FailureDomains {
131-
fdSpec.Name = csCtrlrUtils.WithClusterSuffix(fdSpec.Name, r.CAPICluster.Name)
132-
r.ReconciliationSubject.Status.FailureDomains[fdSpec.Name] = clusterv1.FailureDomainSpec{ControlPlane: true}
130+
metaHashName := infrav1.FailureDomainHashedMetaName(fdSpec.Name, r.CAPICluster.Name)
131+
r.ReconciliationSubject.Status.FailureDomains[fdSpec.Name] = clusterv1.FailureDomainSpec{
132+
ControlPlane: true, Attributes: map[string]string{"MetaHashName": metaHashName}}
133133
}
134134
return ctrl.Result{}, nil
135135
}

0 commit comments

Comments
 (0)