Skip to content

Commit baccf11

Browse files
committed
add failure domain replacement in capc
1 parent cf6a6ff commit baccf11

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

controllers/cloudstackmachine_controller.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,7 @@ func (r *CloudStackMachineReconciliationRunner) GetOrCreateVMInstance() (retRes
170170
return ctrl.Result{}, errors.New("bootstrap secret data not yet set")
171171
}
172172

173-
// since cloudstack metadata does not allow custom data added into meta_data, following line is a hack to specify a hostname name
174-
// {{ ds.meta_data.hostname }} is expected to be used as a name when kubelet register a node
175-
// if more custom data needed to injected, this can be refactored into a method -- processCustomMetadata()
176-
userData := strings.ReplaceAll(string(data), "{{ ds.meta_data.hostname }}", r.CAPIMachine.Name)
177-
173+
userData := processUserData(data, r)
178174
err := r.CSUser.GetOrCreateVMInstance(r.ReconciliationSubject, r.CAPIMachine, r.CSCluster, r.FailureDomain, r.AffinityGroup, userData)
179175

180176
if err == nil && !controllerutil.ContainsFinalizer(r.ReconciliationSubject, infrav1.MachineFinalizer) { // Fetched or Created?
@@ -185,6 +181,15 @@ func (r *CloudStackMachineReconciliationRunner) GetOrCreateVMInstance() (retRes
185181
return ctrl.Result{}, err
186182
}
187183

184+
func processUserData(data []byte, r *CloudStackMachineReconciliationRunner) string {
185+
// since cloudstack metadata does not allow custom data added into meta_data, following line is a hack to specify a hostname name
186+
// {{ ds.meta_data.hostname }} is expected to be used as a name when kubelet register a node
187+
// if more custom data needed to injected, this can be refactored into a method -- processCustomMetadata()
188+
userData := strings.ReplaceAll(string(data), "{{ ds.meta_data.hostname }}", r.CAPIMachine.Name)
189+
userData = strings.ReplaceAll(userData, "{{ds.meta_data.failuredomain}}", r.FailureDomain.Spec.Name)
190+
return userData
191+
}
192+
188193
// ConfirmVMStatus checks the Instance's status for running state and requeues otherwise.
189194
func (r *CloudStackMachineReconciliationRunner) RequeueIfInstanceNotRunning() (retRes ctrl.Result, reterr error) {
190195
if r.ReconciliationSubject.Status.InstanceState == "Running" {

0 commit comments

Comments
 (0)