Skip to content

Commit 7de1351

Browse files
committed
Move WithClusterSuffix to utils package
1 parent 801294d commit 7de1351

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

api/v1beta1/conversion.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
corev1 "k8s.io/api/core/v1"
2323
conv "k8s.io/apimachinery/pkg/conversion"
2424
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta2"
25-
"sigs.k8s.io/cluster-api-provider-cloudstack/controllers"
25+
"sigs.k8s.io/cluster-api-provider-cloudstack/controllers/utils"
2626
"sigs.k8s.io/cluster-api-provider-cloudstack/pkg/cloud"
2727
"sigs.k8s.io/controller-runtime/pkg/client"
2828
)
@@ -142,7 +142,7 @@ func GetDefaultFailureDomainName(namespace string, clusterName string, zoneID st
142142
}
143143

144144
func WithZoneID(zoneID, clusterName string) string {
145-
return controllers.WithClusterSuffix(zoneID[len(zoneID)-8:], clusterName)
145+
return utils.WithClusterSuffix(zoneID[len(zoneID)-8:], clusterName)
146146
}
147147

148148
func fetchZoneIDUsingK8s(namespace string, zoneName string) (string, error) {

controllers/cloudstackcluster_controller.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"fmt"
2222
"reflect"
23-
"strings"
2423

2524
ctrl "sigs.k8s.io/controller-runtime"
2625
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -31,6 +30,7 @@ import (
3130

3231
"github.com/pkg/errors"
3332
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta2"
33+
"sigs.k8s.io/cluster-api-provider-cloudstack/controllers/utils"
3434
csCtrlrUtils "sigs.k8s.io/cluster-api-provider-cloudstack/controllers/utils"
3535
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3636
"sigs.k8s.io/cluster-api/util"
@@ -109,7 +109,7 @@ func (r *CloudStackClusterReconciliationRunner) VerifyFailureDomainCRDs() (ctrl.
109109
for _, requiredFd := range r.ReconciliationSubject.Spec.FailureDomains {
110110
found := false
111111
for _, fd := range r.FailureDomains.Items {
112-
requiredFDName := WithClusterSuffix(requiredFd.Name, r.CAPICluster.Name)
112+
requiredFDName := utils.WithClusterSuffix(requiredFd.Name, r.CAPICluster.Name)
113113
if requiredFDName == fd.Name {
114114
found = true
115115
if !fd.Status.Ready {
@@ -125,20 +125,11 @@ func (r *CloudStackClusterReconciliationRunner) VerifyFailureDomainCRDs() (ctrl.
125125
return ctrl.Result{}, nil
126126
}
127127

128-
// WithClusterSuffix appends a hyphen and the cluster name to a name if not already present.
129-
func WithClusterSuffix(name string, clusterName string) string {
130-
newName := name
131-
if !strings.HasSuffix(name, "-"+clusterName) { // Add cluster name suffix if missing.
132-
newName = name + "-" + clusterName
133-
}
134-
return newName
135-
}
136-
137128
// SetFailureDomainsStatusMap sets failure domains in CloudStackCluster status to be used for CAPI machine placement.
138129
func (r *CloudStackClusterReconciliationRunner) SetFailureDomainsStatusMap() (ctrl.Result, error) {
139130
r.ReconciliationSubject.Status.FailureDomains = clusterv1.FailureDomains{}
140131
for _, fdSpec := range r.ReconciliationSubject.Spec.FailureDomains {
141-
fdSpec.Name = WithClusterSuffix(fdSpec.Name, r.CAPICluster.Name)
132+
fdSpec.Name = utils.WithClusterSuffix(fdSpec.Name, r.CAPICluster.Name)
142133
r.ReconciliationSubject.Status.FailureDomains[fdSpec.Name] = clusterv1.FailureDomainSpec{ControlPlane: true}
143134
}
144135
return ctrl.Result{}, nil

controllers/utils/utils.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,12 @@ func ContainsNoMatchSubstring(err error) bool {
166166
func ContainsAlreadyExistsSubstring(err error) bool {
167167
return strings.Contains(strings.ToLower(err.Error()), "already exists")
168168
}
169+
170+
// WithClusterSuffix appends a hyphen and the cluster name to a name if not already present.
171+
func WithClusterSuffix(name string, clusterName string) string {
172+
newName := name
173+
if !strings.HasSuffix(name, "-"+clusterName) { // Add cluster name suffix if missing.
174+
newName = name + "-" + clusterName
175+
}
176+
return newName
177+
}

0 commit comments

Comments
 (0)