Skip to content

Commit 18c4917

Browse files
authored
Merge pull request #181 from wanyufe/updateRegexp
update regexp for ds.meta_data.failuredomain replacement
2 parents 0388cc9 + 301be09 commit 18c4917

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

controllers/cloudstackmachine_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import (
4343

4444
var (
4545
hostnameMatcher = regexp.MustCompile(`\{\{\s*ds\.meta_data\.hostname\s*\}\}`)
46-
failuredomainMatcher = regexp.MustCompile(`\{\{\s*ds\.meta_data\.failuredomain\s*\}\}`)
46+
failuredomainMatcher = regexp.MustCompile(`ds\.meta_data\.failuredomain`)
4747
)
4848

4949
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=cloudstackmachines,verbs=get;list;watch;create;update;patch;delete

controllers/cloudstackmachine_controller_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package controllers_test
1818

1919
import (
20+
"fmt"
2021
"github.com/golang/mock/gomock"
2122
. "github.com/onsi/ginkgo/v2"
2223
. "github.com/onsi/gomega"
@@ -73,13 +74,14 @@ var _ = Describe("CloudStackMachineReconciler", func() {
7374
}, timeout).WithPolling(pollInterval).Should(BeTrue())
7475
})
7576

76-
It("Should replace ds.meta_data.hostname with capi machine name.", func() {
77+
It("Should replace ds.meta_data.xxx with proper values.", func() {
7778
// Mock a call to GetOrCreateVMInstance and set the machine to running.
7879
mockCloudClient.EXPECT().GetOrCreateVMInstance(
7980
gomock.Any(), gomock.Any(), gomock.Any(),
8081
gomock.Any(), gomock.Any(), gomock.Any()).Do(
8182
func(arg1, _, _, _, _, userdata interface{}) {
82-
Ω(userdata == dummies.CAPIMachine.Name).Should(BeTrue())
83+
expectedUserdata := fmt.Sprintf("%s{{%s}}", dummies.CAPIMachine.Name, dummies.CSMachine1.Spec.FailureDomainName)
84+
Ω(userdata == expectedUserdata).Should(BeTrue())
8385
arg1.(*infrav1.CloudStackMachine).Status.InstanceState = "Running"
8486
}).AnyTimes()
8587

test/dummies/v1beta2/vars.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,9 @@ func SetDummyCSMachineVars() {
227227
Labels: ClusterLabel,
228228
},
229229
Spec: infrav1.CloudStackMachineSpec{
230-
Name: "test-machine-1",
231-
InstanceID: pointer.String("Instance1"),
230+
Name: "test-machine-1",
231+
InstanceID: pointer.String("Instance1"),
232+
FailureDomainName: GetYamlVal("CLOUDSTACK_FD1_NAME"),
232233
Template: infrav1.CloudStackResourceIdentifier{
233234
Name: GetYamlVal("CLOUDSTACK_TEMPLATE_NAME"),
234235
},
@@ -398,7 +399,7 @@ func SetDummyIsoNetToNameOnly() {
398399

399400
func SetDummyBootstrapSecretVar() {
400401
BootstrapSecretName := "such-secret-much-wow"
401-
BootstrapSecretValue := "{{ ds.meta_data.hostname }}"
402+
BootstrapSecretValue := "{{ ds.meta_data.hostname }}{{ds.meta_data.failuredomain}}"
402403
BootstrapSecret = &corev1.Secret{
403404
ObjectMeta: metav1.ObjectMeta{
404405
Namespace: ClusterNameSpace,

0 commit comments

Comments
 (0)