Skip to content

Commit 4baddf5

Browse files
committed
feat: add MachineExternalIP to status
add MachineExternalIP address to OCIMachine status
1 parent ca7c47a commit 4baddf5

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

cloud/scope/machine.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ func (m *MachineScope) GetMachineIPFromStatus() (string, error) {
464464
// GetInstanceIp returns the OCIMachine's instance IP from its primary VNIC attachment.
465465
//
466466
// See https://docs.oracle.com/en-us/iaas/Content/Network/Tasks/managingVNICs.htm for more on VNICs
467-
func (m *MachineScope) GetInstanceIp(ctx context.Context) (*string, error) {
467+
func (m *MachineScope) GetInstanceIPs(ctx context.Context) ([]clusterv1.MachineAddress, error) {
468+
addresses := []clusterv1.MachineAddress{}
468469
var page *string
469470
for {
470471
resp, err := m.ComputeClient.ListVnicAttachments(ctx, core.ListVnicAttachmentsRequest{
@@ -495,7 +496,20 @@ func (m *MachineScope) GetInstanceIp(ctx context.Context) (*string, error) {
495496
return nil, err
496497
}
497498
if vnic.IsPrimary != nil && *vnic.IsPrimary {
498-
return vnic.PrivateIp, nil
499+
if vnic.PublicIp != nil {
500+
publicIP := clusterv1.MachineAddress{
501+
Address: *vnic.PublicIp,
502+
Type: clusterv1.MachineExternalIP,
503+
}
504+
addresses = append(addresses, publicIP)
505+
return addresses, nil
506+
}
507+
privateIP := clusterv1.MachineAddress{
508+
Address: *vnic.PrivateIp,
509+
Type: clusterv1.MachineInternalIP,
510+
}
511+
addresses = append(addresses, privateIP)
512+
return addresses, nil
499513
}
500514
}
501515

controllers/ocimachine_controller.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -335,18 +335,13 @@ func (r *OCIMachineReconciler) reconcileNormal(ctx context.Context, logger logr.
335335
machineScope.Info("Instance is active")
336336
if machine.Status.Addresses == nil || len(machine.Status.Addresses) == 0 {
337337
machineScope.Info("IP address is not set on the instance, looking up the address")
338-
ipAddress, err := machineScope.GetInstanceIp(ctx)
338+
ipAddresses, err := machineScope.GetInstanceIPs(ctx)
339339
if err != nil {
340340
r.Recorder.Event(machine, corev1.EventTypeWarning, "ReconcileError", errors.Wrapf(err, "failed to reconcile OCIMachine").Error())
341341
conditions.MarkFalse(machineScope.OCIMachine, infrastructurev1beta2.InstanceReadyCondition, infrastructurev1beta2.InstanceIPAddressNotFound, clusterv1.ConditionSeverityError, "")
342342
return ctrl.Result{}, err
343343
}
344-
machine.Status.Addresses = []clusterv1.MachineAddress{
345-
{
346-
Address: *ipAddress,
347-
Type: clusterv1.MachineInternalIP,
348-
},
349-
}
344+
machine.Status.Addresses = ipAddresses
350345
}
351346
if machineScope.IsControlPlane() {
352347
err := machineScope.ReconcileCreateInstanceOnLB(ctx)

0 commit comments

Comments
 (0)