Skip to content

Commit

Permalink
Fix naming of isolated network if the network name contains an unders…
Browse files Browse the repository at this point in the history
…core
  • Loading branch information
vishesh92 committed Jun 3, 2024
1 parent 53105d4 commit 73687b9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions controllers/utils/isolated_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,25 @@ package utils

import (
"fmt"
"regexp"
"strings"

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

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
Expand Down

0 comments on commit 73687b9

Please sign in to comment.