@@ -170,11 +170,7 @@ func (r *CloudStackMachineReconciliationRunner) GetOrCreateVMInstance() (retRes
170
170
return ctrl.Result {}, errors .New ("bootstrap secret data not yet set" )
171
171
}
172
172
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 )
178
174
err := r .CSUser .GetOrCreateVMInstance (r .ReconciliationSubject , r .CAPIMachine , r .CSCluster , r .FailureDomain , r .AffinityGroup , userData )
179
175
180
176
if err == nil && ! controllerutil .ContainsFinalizer (r .ReconciliationSubject , infrav1 .MachineFinalizer ) { // Fetched or Created?
@@ -185,6 +181,15 @@ func (r *CloudStackMachineReconciliationRunner) GetOrCreateVMInstance() (retRes
185
181
return ctrl.Result {}, err
186
182
}
187
183
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
+
188
193
// ConfirmVMStatus checks the Instance's status for running state and requeues otherwise.
189
194
func (r * CloudStackMachineReconciliationRunner ) RequeueIfInstanceNotRunning () (retRes ctrl.Result , reterr error ) {
190
195
if r .ReconciliationSubject .Status .InstanceState == "Running" {
0 commit comments