diff --git a/controllers/utils/isolated_network.go b/controllers/utils/isolated_network.go index 9380bd60..e6012c41 100644 --- a/controllers/utils/isolated_network.go +++ b/controllers/utils/isolated_network.go @@ -18,6 +18,7 @@ package utils import ( "fmt" + "regexp" "strings" infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3" @@ -25,14 +26,17 @@ import ( ) func (r *ReconciliationRunner) IsoNetMetaName(name string) string { - return fmt.Sprintf("%s-%s", r.CSCluster.Name, strings.ToLower(name)) + str := fmt.Sprintf("%s-%s", r.CSCluster.Name, strings.ToLower(name)) + reg, _ := regexp.Compile(`[^a-z0-9-]+`) + str = reg.ReplaceAllString(str, "-") + return strings.TrimSuffix(str, "-") } // GenerateIsolatedNetwork of the passed name that's owned by the ReconciliationSubject. func (r *ReconciliationRunner) GenerateIsolatedNetwork(name string, fdNameFunc func() string) CloudStackReconcilerMethod { return func() (ctrl.Result, error) { lowerName := strings.ToLower(name) - metaName := fmt.Sprintf("%s-%s", r.CSCluster.Name, lowerName) + metaName := r.IsoNetMetaName(lowerName) csIsoNet := &infrav1.CloudStackIsolatedNetwork{} csIsoNet.ObjectMeta = r.NewChildObjectMeta(metaName) csIsoNet.Spec.Name = lowerName