Skip to content

Commit bc73be4

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

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

28+
var metaNameRegex = regexp.MustCompile(`[^a-z0-9-]+`)
29+
2730
func (r *ReconciliationRunner) IsoNetMetaName(name string) string {
28-
return fmt.Sprintf("%s-%s", r.CSCluster.Name, strings.ToLower(name))
31+
str := metaNameRegex.ReplaceAllString(fmt.Sprintf("%s-%s", r.CSCluster.Name, strings.ToLower(name)), "-")
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)