From 998129fcde7d178af882398793e105c3969c4661 Mon Sep 17 00:00:00 2001 From: Caleb Woodbine Date: Tue, 3 Sep 2024 10:34:13 +1200 Subject: [PATCH] feat: add MachineExternalIP to status add MachineExternalIP address to OCIMachine status --- cloud/scope/machine.go | 17 +++++++++++++++-- controllers/ocimachine_controller.go | 9 ++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/cloud/scope/machine.go b/cloud/scope/machine.go index 3371ffd6..fe0433ba 100644 --- a/cloud/scope/machine.go +++ b/cloud/scope/machine.go @@ -464,7 +464,8 @@ func (m *MachineScope) GetMachineIPFromStatus() (string, error) { // GetInstanceIp returns the OCIMachine's instance IP from its primary VNIC attachment. // // See https://docs.oracle.com/en-us/iaas/Content/Network/Tasks/managingVNICs.htm for more on VNICs -func (m *MachineScope) GetInstanceIp(ctx context.Context) (*string, error) { +func (m *MachineScope) GetInstanceIPs(ctx context.Context) ([]clusterv1.MachineAddress, error) { + addresses := []clusterv1.MachineAddress{} var page *string for { resp, err := m.ComputeClient.ListVnicAttachments(ctx, core.ListVnicAttachmentsRequest{ @@ -495,7 +496,19 @@ func (m *MachineScope) GetInstanceIp(ctx context.Context) (*string, error) { return nil, err } if vnic.IsPrimary != nil && *vnic.IsPrimary { - return vnic.PrivateIp, nil + if vnic.PublicIp != nil { + publicIP := clusterv1.MachineAddress{ + Address: *vnic.PublicIp, + Type: clusterv1.MachineExternalIP, + } + addresses = append(addresses, publicIP) + } + privateIP := clusterv1.MachineAddress{ + Address: *vnic.PrivateIp, + Type: clusterv1.MachineInternalIP, + } + addresses = append(addresses, privateIP) + return addresses, nil } } diff --git a/controllers/ocimachine_controller.go b/controllers/ocimachine_controller.go index 7cf01262..fc93637f 100644 --- a/controllers/ocimachine_controller.go +++ b/controllers/ocimachine_controller.go @@ -335,18 +335,13 @@ func (r *OCIMachineReconciler) reconcileNormal(ctx context.Context, logger logr. machineScope.Info("Instance is active") if machine.Status.Addresses == nil || len(machine.Status.Addresses) == 0 { machineScope.Info("IP address is not set on the instance, looking up the address") - ipAddress, err := machineScope.GetInstanceIp(ctx) + ipAddresses, err := machineScope.GetInstanceIPs(ctx) if err != nil { r.Recorder.Event(machine, corev1.EventTypeWarning, "ReconcileError", errors.Wrapf(err, "failed to reconcile OCIMachine").Error()) conditions.MarkFalse(machineScope.OCIMachine, infrastructurev1beta2.InstanceReadyCondition, infrastructurev1beta2.InstanceIPAddressNotFound, clusterv1.ConditionSeverityError, "") return ctrl.Result{}, err } - machine.Status.Addresses = []clusterv1.MachineAddress{ - { - Address: *ipAddress, - Type: clusterv1.MachineInternalIP, - }, - } + machine.Status.Addresses = ipAddresses } if machineScope.IsControlPlane() { err := machineScope.ReconcileCreateInstanceOnLB(ctx)