Skip to content

Commit 73687b9

Browse files
committed
Fix naming of isolated network if the network name contains an underscore
1 parent 53105d4 commit 73687b9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

controllers/utils/isolated_network.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,25 @@ package utils
1818

1919
import (
2020
"fmt"
21+
"regexp"
2122
"strings"
2223

2324
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
2425
ctrl "sigs.k8s.io/controller-runtime"
2526
)
2627

2728
func (r *ReconciliationRunner) IsoNetMetaName(name string) string {
28-
return fmt.Sprintf("%s-%s", r.CSCluster.Name, strings.ToLower(name))
29+
str := fmt.Sprintf("%s-%s", r.CSCluster.Name, strings.ToLower(name))
30+
reg, _ := regexp.Compile(`[^a-z0-9-]+`)
31+
str = reg.ReplaceAllString(str, "-")
32+
return strings.TrimSuffix(str, "-")
2933
}
3034

3135
// GenerateIsolatedNetwork of the passed name that's owned by the ReconciliationSubject.
3236
func (r *ReconciliationRunner) GenerateIsolatedNetwork(name string, fdNameFunc func() string) CloudStackReconcilerMethod {
3337
return func() (ctrl.Result, error) {
3438
lowerName := strings.ToLower(name)
35-
metaName := fmt.Sprintf("%s-%s", r.CSCluster.Name, lowerName)
39+
metaName := r.IsoNetMetaName(lowerName)
3640
csIsoNet := &infrav1.CloudStackIsolatedNetwork{}
3741
csIsoNet.ObjectMeta = r.NewChildObjectMeta(metaName)
3842
csIsoNet.Spec.Name = lowerName

0 commit comments

Comments
 (0)