Skip to content

Commit 165ba6b

Browse files
authored
Merge pull request #83 from aws/fix/add-cluster-to-cr-naming
Prepend Cluster Name to Zone and Iso Network CRs
2 parents 4a1451f + 7dac510 commit 165ba6b

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

controllers/cloudstackmachine_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (r *CloudStackMachineReconciliationRunner) Reconcile() (retRes ctrl.Result,
9696
r.RequeueIfCloudStackClusterNotReady,
9797
r.ConsiderAffinity,
9898
r.SetFailureDomainOnCSMachine,
99-
r.GetObjectByName("placeholder", r.IsoNet, func() string { return r.FailureDomain.Spec.Network.Name }),
99+
r.GetObjectByName("placeholder", r.IsoNet, func() string { return r.IsoNetMetaName(r.FailureDomain.Spec.Network.Name) }),
100100
r.GetOrCreateVMInstance,
101101
r.RequeueIfInstanceNotRunning,
102102
r.AddToLBIfNeeded,

controllers/cloudstackzone_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (r *CloudStackZoneReconciliationRunner) Reconcile() (retRes ctrl.Result, re
9696
netName := r.ReconciliationSubject.Spec.Network.Name
9797
if res, err := r.GenerateIsolatedNetwork(netName)(); r.ShouldReturn(res, err) {
9898
return res, err
99-
} else if res, err := r.GetObjectByName(netName, r.IsoNet)(); r.ShouldReturn(res, err) {
99+
} else if res, err := r.GetObjectByName(r.IsoNetMetaName(netName), r.IsoNet)(); r.ShouldReturn(res, err) {
100100
return res, err
101101
}
102102
if r.IsoNet.Name == "" {

controllers/utils/affinity_group.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
// GenerateIsolatedNetwork of the passed name that's owned by the ReconciliationSubject.
3232
func (r *ReconciliationRunner) GetOrCreateAffinityGroup(name string, affinityType string, ag *infrav1.CloudStackAffinityGroup) CloudStackReconcilerMethod {
3333
return func() (ctrl.Result, error) {
34+
3435
// Start by attempting a fetch.
3536
lowerName := strings.ToLower(name)
3637
namespace := r.ReconciliationSubject.GetNamespace()

controllers/utils/isolated_network.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,24 @@ limitations under the License.
1717
package utils
1818

1919
import (
20+
"fmt"
2021
"strings"
2122

2223
infrav1 "github.com/aws/cluster-api-provider-cloudstack/api/v1beta1"
2324
ctrl "sigs.k8s.io/controller-runtime"
2425
)
2526

27+
func (r *ReconciliationRunner) IsoNetMetaName(name string) string {
28+
return fmt.Sprintf("%s-%s", r.CSCluster.Name, strings.ToLower(name))
29+
}
30+
2631
// GenerateIsolatedNetwork of the passed name that's owned by the ReconciliationSubject.
2732
func (r *ReconciliationRunner) GenerateIsolatedNetwork(name string) CloudStackReconcilerMethod {
2833
return func() (ctrl.Result, error) {
2934
lowerName := strings.ToLower(name)
35+
metaName := fmt.Sprintf("%s-%s", r.CSCluster.Name, lowerName)
3036
csIsoNet := &infrav1.CloudStackIsolatedNetwork{}
31-
csIsoNet.ObjectMeta = r.NewChildObjectMeta(lowerName)
37+
csIsoNet.ObjectMeta = r.NewChildObjectMeta(metaName)
3238
csIsoNet.Spec.Name = lowerName
3339
csIsoNet.Spec.ControlPlaneEndpoint.Host = r.CSCluster.Spec.ControlPlaneEndpoint.Host
3440
csIsoNet.Spec.ControlPlaneEndpoint.Port = r.CSCluster.Spec.ControlPlaneEndpoint.Port

controllers/utils/zones.go

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

1919
import (
20+
"fmt"
2021
"strings"
2122

2223
infrav1 "github.com/aws/cluster-api-provider-cloudstack/api/v1beta1"
@@ -28,12 +29,18 @@ import (
2829
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2930
)
3031

31-
// CreateZone generates a specified CloudStackZone CRD owned by the ReconcilationSubject.
32-
func (r *ReconciliationRunner) CreateZone(zoneSpec infrav1.Zone) error {
32+
// ZoneMetaName creates a meta name for a zone based on the cluster and zone information.
33+
func (r *ReconciliationRunner) ZoneMetaName(zoneSpec infrav1.Zone) string {
3334
metaName := zoneSpec.Name
3435
if metaName == "" {
3536
metaName = zoneSpec.ID
3637
}
38+
return fmt.Sprintf("%s-%s", r.CSCluster.Name, metaName)
39+
}
40+
41+
// CreateZone generates a specified CloudStackZone CRD owned by the ReconcilationSubject.
42+
func (r *ReconciliationRunner) CreateZone(zoneSpec infrav1.Zone) error {
43+
metaName := r.ZoneMetaName(zoneSpec)
3744
csZone := &infrav1.CloudStackZone{
3845
ObjectMeta: r.NewChildObjectMeta(metaName),
3946
Spec: infrav1.CloudStackZoneSpec(zoneSpec),

0 commit comments

Comments
 (0)