diff --git a/controllers/utils/isolated_network.go b/controllers/utils/isolated_network.go index 63a581c5..ef91e0ed 100644 --- a/controllers/utils/isolated_network.go +++ b/controllers/utils/isolated_network.go @@ -18,14 +18,18 @@ package utils import ( "fmt" + "regexp" "strings" infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3" ctrl "sigs.k8s.io/controller-runtime" ) +var metaNameRegex = regexp.MustCompile(`[^a-z0-9-]+`) + func (r *ReconciliationRunner) IsoNetMetaName(name string) string { - return fmt.Sprintf("%s-%s", r.CSCluster.Name, strings.ToLower(name)) + str := metaNameRegex.ReplaceAllString(fmt.Sprintf("%s-%s", r.CSCluster.Name, strings.ToLower(name)), "-") + return strings.TrimSuffix(str, "-") } // GenerateIsolatedNetwork of the passed name that's owned by the ReconciliationSubject.