From 25561b045c6ec4f72623c29a85f9bb1472a69579 Mon Sep 17 00:00:00 2001 From: Ashley Dumaine Date: Fri, 1 Mar 2024 09:48:40 -0500 Subject: [PATCH] fix ip type setting on machine controller --- controller/linodemachine_controller.go | 10 +++++++--- templates/flavors/rke2/rke2ConfigTemplate.yaml | 5 ----- templates/flavors/rke2/rke2ControlPlane.yaml | 5 ----- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/controller/linodemachine_controller.go b/controller/linodemachine_controller.go index c5bda5468..75465d3fe 100644 --- a/controller/linodemachine_controller.go +++ b/controller/linodemachine_controller.go @@ -378,10 +378,14 @@ func (r *LinodeMachineReconciler) reconcileCreate( machineScope.LinodeMachine.Spec.ProviderID = util.Pointer(fmt.Sprintf("linode://%d", linodeInstance.ID)) machineScope.LinodeMachine.Status.Addresses = []clusterv1.MachineAddress{} - for _, add := range linodeInstance.IPv4 { + for _, addr := range linodeInstance.IPv4 { + addrType := clusterv1.MachineExternalIP + if addr.IsPrivate() { + addrType = clusterv1.MachineInternalIP + } machineScope.LinodeMachine.Status.Addresses = append(machineScope.LinodeMachine.Status.Addresses, clusterv1.MachineAddress{ - Type: clusterv1.MachineExternalIP, - Address: add.String(), + Type: addrType, + Address: addr.String(), }) } diff --git a/templates/flavors/rke2/rke2ConfigTemplate.yaml b/templates/flavors/rke2/rke2ConfigTemplate.yaml index 31d541cb6..61d2db041 100644 --- a/templates/flavors/rke2/rke2ConfigTemplate.yaml +++ b/templates/flavors/rke2/rke2ConfigTemplate.yaml @@ -12,12 +12,7 @@ spec: kubelet: extraArgs: - "provider-id=linode://{{ ds.meta_data.id }}" - # TODO: use MDS to get public and private IP instead because hostname ordering can't always be assumed preRKE2Commands: - - | - mkdir -p /etc/rancher/rke2/config.yaml.d/ - echo "node-ip: $(hostname -I | awk '{print $2}')" >> /etc/rancher/rke2/config.yaml.d/capi-config.yaml - sed -i "/tls-san:/a - $(hostname -I | awk '{print $1}')" /etc/rancher/rke2/config.yaml - sed -i '/swap/d' /etc/fstab - swapoff -a - hostnamectl set-hostname '{{ ds.meta_data.label }}' && hostname -F /etc/hostname diff --git a/templates/flavors/rke2/rke2ControlPlane.yaml b/templates/flavors/rke2/rke2ControlPlane.yaml index f0cd65e53..f066303fc 100644 --- a/templates/flavors/rke2/rke2ControlPlane.yaml +++ b/templates/flavors/rke2/rke2ControlPlane.yaml @@ -35,12 +35,7 @@ spec: kubelet: extraArgs: - "provider-id=linode://{{ ds.meta_data.id }}" - # TODO: use MDS to get public and private IP instead because hostname ordering can't always be assumed preRKE2Commands: - - | - mkdir -p /etc/rancher/rke2/config.yaml.d/ - echo "node-ip: $(hostname -I | awk '{print $2}')" >> /etc/rancher/rke2/config.yaml.d/capi-config.yaml - sed -i "/tls-san:/a - $(hostname -I | awk '{print $1}')" /etc/rancher/rke2/config.yaml - sed -i '/swap/d' /etc/fstab - swapoff -a - hostnamectl set-hostname '{{ ds.meta_data.label }}' && hostname -F /etc/hostname