Skip to content

Commit

Permalink
feat: add MachineExternalIP to status
Browse files Browse the repository at this point in the history
add MachineExternalIP address to OCIMachine status
  • Loading branch information
BobyMCbobs committed Sep 2, 2024
1 parent ca7c47a commit 998129f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
17 changes: 15 additions & 2 deletions cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
}
}

Expand Down
9 changes: 2 additions & 7 deletions controllers/ocimachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 998129f

Please sign in to comment.