Skip to content

Commit c3e6961

Browse files
committed
move regexp out of methods
1 parent b19df2f commit c3e6961

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

controllers/cloudstackmachine_controller.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ import (
4141
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
4242
)
4343

44+
var (
45+
hostnameMatcher = regexp.MustCompile(`\{\{\s*ds\.meta_data\.hostname\s*\}\}`)
46+
failuredomainMatcher = regexp.MustCompile(`\{\{\s*ds\.meta_data\.failuredomain\s*\}\}`)
47+
)
4448
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=cloudstackmachines,verbs=get;list;watch;create;update;patch;delete
4549
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=cloudstackmachines/status,verbs=get;update;patch
4650
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=cloudstackmachines/finalizers,verbs=update
@@ -185,8 +189,6 @@ func processUserData(data []byte, r *CloudStackMachineReconciliationRunner) stri
185189
// since cloudstack metadata does not allow custom data added into meta_data, following line is a hack to specify a hostname name
186190
// {{ ds.meta_data.hostname }} is expected to be used as a name when kubelet register a node
187191
// if more custom data needed to injected, this can be refactored into a method -- processCustomMetadata()
188-
hostnameMatcher := regexp.MustCompile(`\{\{\s*ds\.meta_data\.hostname\s*\}\}`)
189-
failuredomainMatcher := regexp.MustCompile(`\{\{\s*ds\.meta_data\.failuredomain\s*\}\}`)
190192
userData := hostnameMatcher.ReplaceAllString(string(data), r.CAPIMachine.Name)
191193
userData = failuredomainMatcher.ReplaceAllString(userData, r.FailureDomain.Spec.Name)
192194
return userData

0 commit comments

Comments
 (0)