Skip to content

Commit d932f81

Browse files
author
Joshua Reed
committed
Working but needs cleanup.
1 parent b7187fc commit d932f81

13 files changed

+45
-152
lines changed

api/v1beta1/zz_generated.conversion.go

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

api/v1beta2/cloudstackfailuredomain_types.go

Lines changed: 11 additions & 0 deletions
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"
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)))
33+
}
34+
2435
const (
2536
FailureDomainFinalizer = "cloudstackfailuredomain.infrastructure.cluster.x-k8s.io"
2637
FailureDomainLabelName = "cloudstackfailuredomain.infrastructure.cluster.x-k8s.io/name"

api/v1beta2/cloudstackisolatednetwork_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type CloudStackIsolatedNetworkSpec struct {
4141

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

4747
// CloudStackIsolatedNetworkStatus defines the observed state of CloudStackIsolatedNetwork

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 0 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_cloudstackisolatednetworks.yaml

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -118,66 +118,10 @@ spec:
118118
- host
119119
- port
120120
type: object
121-
failureDomain:
121+
failureDomainName:
122122
description: FailureDomain -- the FailureDomain the network is placed
123123
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
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

controllers/cloudstackaffinitygroup_controller.go

Lines changed: 1 addition & 4 deletions
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/cloudstackcluster_controller.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030

3131
"github.com/pkg/errors"
3232
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta2"
33-
"sigs.k8s.io/cluster-api-provider-cloudstack/controllers/utils"
3433
csCtrlrUtils "sigs.k8s.io/cluster-api-provider-cloudstack/controllers/utils"
3534
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3635
"sigs.k8s.io/cluster-api/util"
@@ -106,20 +105,20 @@ func (r *CloudStackClusterReconciliationRunner) SetReady() (ctrl.Result, error)
106105
// VerifyFailureDomainCRDs verifies the FailureDomains found match against those requested.
107106
func (r *CloudStackClusterReconciliationRunner) VerifyFailureDomainCRDs() (ctrl.Result, error) {
108107
// Check that all required failure domains are present and ready.
109-
for _, requiredFd := range r.ReconciliationSubject.Spec.FailureDomains {
108+
fmt.Println(r.ReconciliationSubject.Spec.FailureDomains)
109+
for _, requiredFdSpec := range r.ReconciliationSubject.Spec.FailureDomains {
110110
found := false
111111
for _, fd := range r.FailureDomains.Items {
112-
requiredFDName := utils.WithClusterSuffix(requiredFd.Name, r.CAPICluster.Name)
113-
if requiredFDName == fd.Name {
112+
if requiredFdSpec.Name == fd.Spec.Name {
114113
found = true
115114
if !fd.Status.Ready {
116-
return r.RequeueWithMessage(fmt.Sprintf("Required FailureDomain %s not ready, requeueing.", fd.Name))
115+
return r.RequeueWithMessage(fmt.Sprintf("Required FailureDomain %s not ready, requeueing.", fd.Spec.Name))
117116
}
118117
break
119118
}
120119
}
121120
if !found {
122-
return r.RequeueWithMessage(fmt.Sprintf("Required FailureDomain %s not found, requeueing.", requiredFd.Name))
121+
return r.RequeueWithMessage(fmt.Sprintf("Required FailureDomain %s not found, requeueing.", requiredFdSpec.Name))
123122
}
124123
}
125124
return ctrl.Result{}, nil
@@ -129,8 +128,9 @@ func (r *CloudStackClusterReconciliationRunner) VerifyFailureDomainCRDs() (ctrl.
129128
func (r *CloudStackClusterReconciliationRunner) SetFailureDomainsStatusMap() (ctrl.Result, error) {
130129
r.ReconciliationSubject.Status.FailureDomains = clusterv1.FailureDomains{}
131130
for _, fdSpec := range r.ReconciliationSubject.Spec.FailureDomains {
132-
fdSpec.Name = utils.WithClusterSuffix(fdSpec.Name, r.CAPICluster.Name)
133-
r.ReconciliationSubject.Status.FailureDomains[fdSpec.Name] = clusterv1.FailureDomainSpec{ControlPlane: true}
131+
metaHashName := infrav1.FailureDomainHashedMetaName(fdSpec.Name, r.CAPICluster.Name)
132+
r.ReconciliationSubject.Status.FailureDomains[fdSpec.Name] = clusterv1.FailureDomainSpec{
133+
ControlPlane: true, Attributes: map[string]string{"MetaHashName": metaHashName}}
134134
}
135135
return ctrl.Result{}, nil
136136
}

controllers/cloudstackfailuredomain_controller.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,14 @@ func (r *CloudStackFailureDomainReconciliationRunner) Reconcile() (retRes ctrl.R
8484
!csCtrlrUtils.ContainsNoMatchSubstring(err) {
8585
return ctrl.Result{}, errors.Wrap(err, "resolving Cloudstack network information")
8686
}
87-
// Patch Zone ID back before potentially creating an isolated network.
88-
if err := r.Patcher.Patch(r.RequestCtx, r.ReconciliationSubject); err != nil {
89-
return ctrl.Result{}, err
90-
}
9187

9288
// Check if the passed network was an isolated network or the network was missing. In either case, create a
9389
// CloudStackIsolatedNetwork to manage the many intricacies and wait until CloudStackIsolatedNetwork is ready.
9490
if r.ReconciliationSubject.Spec.Zone.Network.ID == "" ||
9591
r.ReconciliationSubject.Spec.Zone.Network.Type == infrav1.NetworkTypeIsolated {
9692
netName := r.ReconciliationSubject.Spec.Zone.Network.Name
97-
if res, err := r.GenerateIsolatedNetwork(netName)(); r.ShouldReturn(res, err) {
93+
if res, err := r.GenerateIsolatedNetwork(
94+
netName, func() string { return r.ReconciliationSubject.Spec.Name })(); r.ShouldReturn(res, err) {
9895
return res, err
9996
} else if res, err := r.GetObjectByName(r.IsoNetMetaName(netName), r.IsoNet)(); r.ShouldReturn(res, err) {
10097
return res, err

controllers/cloudstackisolatednetwork_controller.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
"sigs.k8s.io/cluster-api/util/patch"
2424
ctrl "sigs.k8s.io/controller-runtime"
25-
"sigs.k8s.io/controller-runtime/pkg/client"
2625
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
2726

2827
"github.com/pkg/errors"
@@ -61,8 +60,7 @@ func (reconciler *CloudStackIsoNetReconciler) Reconcile(ctx context.Context, req
6160
r := NewCSIsoNetReconciliationRunner()
6261
r.UsingBaseReconciler(reconciler.ReconcilerBase).ForRequest(req).WithRequestCtx(ctx)
6362
r.WithAdditionalCommonStages(
64-
r.GetParent(r.ReconciliationSubject, r.FailureDomain),
65-
r.CheckPresent(map[string]client.Object{"CloudStackFailureDomain": r.FailureDomain}),
63+
r.GetFailureDomainByName(func() string { return r.ReconciliationSubject.Spec.FailureDomainName }, r.FailureDomain),
6664
r.AsFailureDomainUser(&r.FailureDomain.Spec),
6765
)
6866
return r.RunBaseReconciliationStages()

controllers/cloudstackmachine_controller.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222
"math/rand"
2323
"reflect"
24-
"strings"
2524

2625
"github.com/pkg/errors"
2726
corev1 "k8s.io/api/core/v1"
@@ -87,9 +86,7 @@ func (reconciler *CloudStackMachineReconciler) Reconcile(ctx context.Context, re
8786
r.GetParent(r.ReconciliationSubject, r.CAPIMachine),
8887
r.RequeueIfCloudStackClusterNotReady,
8988
r.SetFailureDomainOnCSMachine,
90-
r.GetObjectByName("placeholder", r.FailureDomain,
91-
func() string { return r.ReconciliationSubject.Spec.FailureDomainName }),
92-
r.CheckPresent(map[string]client.Object{"CloudStackFailureDomain": r.FailureDomain}),
89+
r.GetFailureDomainByName(func() string { return r.ReconciliationSubject.Spec.FailureDomainName }, r.FailureDomain),
9390
r.AsFailureDomainUser(&r.FailureDomain.Spec))
9491
return r.RunBaseReconciliationStages()
9592
}
@@ -147,9 +144,6 @@ func (r *CloudStackMachineReconciliationRunner) SetFailureDomainOnCSMachine() (r
147144
randNum := (rand.Int() % len(r.CSCluster.Spec.FailureDomains)) // #nosec G404 -- weak crypt rand doesn't matter here.
148145
name = r.CSCluster.Spec.FailureDomains[randNum].Name
149146
}
150-
if !strings.HasSuffix(name, "-"+r.CAPICluster.Name) { // Add cluster name suffix if missing.
151-
name = name + "-" + r.CAPICluster.Name
152-
}
153147
r.ReconciliationSubject.Spec.FailureDomainName = name
154148
r.ReconciliationSubject.Labels[infrav1.FailureDomainLabelName] = r.ReconciliationSubject.Spec.FailureDomainName
155149
}

0 commit comments

Comments
 (0)