@@ -387,11 +387,6 @@ func (m *MachineScope) Name() string {
387387 return m .OCIMachine .Name
388388}
389389
390- // IP returns the OCIMachine IP.
391- func (m * MachineScope ) IP () string {
392- return m .OCIMachine .Status .Addresses [0 ].Address
393- }
394-
395390// GetInstanceId returns the OCIMachine instance id.
396391func (m * MachineScope ) GetInstanceId () * string {
397392 return m .OCIMachine .Spec .InstanceId
@@ -515,7 +510,7 @@ func (m *MachineScope) ReconcileCreateInstanceOnLB(ctx context.Context) error {
515510 backendSet := lb .BackendSets [APIServerLBBackendSetName ]
516511 // When creating a LB, there is no way to set the backend Name, default backend name is the instance IP and port
517512 // So we use default backend name instead of machine name
518- backendName := m . IP () + ":" + strconv .Itoa (int (m .OCICluster .Spec .ControlPlaneEndpoint .Port ))
513+ backendName := instanceIp + ":" + strconv .Itoa (int (m .OCICluster .Spec .ControlPlaneEndpoint .Port ))
519514 if ! m .containsLBBackend (backendSet , backendName ) {
520515 logger := m .Logger .WithValues ("backend-set" , * backendSet .Name )
521516 workRequest := m .OCIMachine .Status .CreateBackendWorkRequestId
@@ -613,7 +608,17 @@ func (m *MachineScope) ReconcileDeleteInstanceOnLB(ctx context.Context) error {
613608 return err
614609 }
615610 backendSet := lb .BackendSets [APIServerLBBackendSetName ]
616- backendName := m .IP () + ":" + strconv .Itoa (int (m .OCICluster .Spec .ControlPlaneEndpoint .Port ))
611+ // in case of delete from LB backend, if the instance does not have an IP, we consider
612+ // the instance to not have been added in first place and hence return nil
613+ if len (m .OCIMachine .Status .Addresses ) <= 0 {
614+ m .Logger .Info ("Instance does not have IP Address, hence ignoring LBaaS reconciliation on delete" )
615+ return nil
616+ }
617+ instanceIp , err := m .GetMachineIPFromStatus ()
618+ if err != nil {
619+ return err
620+ }
621+ backendName := instanceIp + ":" + strconv .Itoa (int (m .OCICluster .Spec .ControlPlaneEndpoint .Port ))
617622 if m .containsLBBackend (backendSet , backendName ) {
618623 logger := m .Logger .WithValues ("backend-set" , * backendSet .Name )
619624 workRequest := m .OCIMachine .Status .DeleteBackendWorkRequestId
0 commit comments