Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add MachineExternalIP to status #380

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 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,20 @@ 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)
return addresses, nil
}
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