Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix naming of isolated network if the network name contains an underscore #361

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
)

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.
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
Loading