Skip to content

Commit 274e026

Browse files
committed
use capi machine name as hostname and k8s node name
1 parent d96124b commit 274e026

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

controllers/cloudstackmachine_controller.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"math/rand"
2323
"reflect"
24+
"strings"
2425

2526
"github.com/pkg/errors"
2627
corev1 "k8s.io/api/core/v1"
@@ -169,7 +170,12 @@ func (r *CloudStackMachineReconciliationRunner) GetOrCreateVMInstance() (retRes
169170
return ctrl.Result{}, errors.New("bootstrap secret data not yet set")
170171
}
171172

172-
err := r.CSUser.GetOrCreateVMInstance(r.ReconciliationSubject, r.CAPIMachine, r.CSCluster, r.FailureDomain, r.AffinityGroup, string(data))
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+
178+
err := r.CSUser.GetOrCreateVMInstance(r.ReconciliationSubject, r.CAPIMachine, r.CSCluster, r.FailureDomain, r.AffinityGroup, userData)
173179

174180
if err == nil && !controllerutil.ContainsFinalizer(r.ReconciliationSubject, infrav1.MachineFinalizer) { // Fetched or Created?
175181
r.Log.Info("CloudStack instance Created", "instanceStatus", r.ReconciliationSubject.Status)

pkg/cloud/instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func (c *client) GetOrCreateVMInstance(
237237
p := c.cs.VirtualMachine.NewDeployVirtualMachineParams(offeringID, templateID, fd.Spec.Zone.ID)
238238
p.SetNetworkids([]string{fd.Spec.Zone.Network.ID})
239239
setIfNotEmpty(csMachine.Name, p.SetName)
240-
setIfNotEmpty(csMachine.Name, p.SetDisplayname)
240+
setIfNotEmpty(capiMachine.Name, p.SetDisplayname)
241241
setIfNotEmpty(diskOfferingID, p.SetDiskofferingid)
242242
setIntIfPositive(csMachine.Spec.DiskOffering.CustomSize, p.SetSize)
243243

0 commit comments

Comments
 (0)