Skip to content

Commit

Permalink
Handle machine deletion when NLB/LB has been deleted (oracle#350)
Browse files Browse the repository at this point in the history
* Handle machine deletion when NLB/LB has been deleted
  • Loading branch information
shyamradhakrishnan committed Mar 29, 2024
1 parent 97fbd21 commit 20ecae2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,10 @@ func (m *MachineScope) ReconcileDeleteInstanceOnLB(ctx context.Context) error {
LoadBalancerId: loadbalancerId,
})
if err != nil {
if ociutil.IsNotFound(err) {
m.Logger.Info("LB has been deleted", "lb", *loadbalancerId)
return nil
}
return err
}
backendSet := lb.BackendSets[APIServerLBBackendSetName]
Expand Down Expand Up @@ -665,6 +669,10 @@ func (m *MachineScope) ReconcileDeleteInstanceOnLB(ctx context.Context) error {
NetworkLoadBalancerId: loadbalancerId,
})
if err != nil {
if ociutil.IsNotFound(err) {
m.Logger.Info("NLB has been deleted", "nlb", *loadbalancerId)
return nil
}
return err
}
backendSet := lb.BackendSets[APIServerLBBackendSetName]
Expand Down
26 changes: 26 additions & 0 deletions cloud/scope/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,16 @@ func TestNLBReconciliationDeletion(t *testing.T) {
NetworkLoadBalancer: networkloadbalancer.NetworkLoadBalancer{}}, errors.New("could not get nlb"))
},
},
{
name: "get nlb error, not found",
errorExpected: false,
testSpecificSetup: func(machineScope *MachineScope, nlbClient *mock_nlb.MockNetworkLoadBalancerClient) {
nlbClient.EXPECT().GetNetworkLoadBalancer(gomock.Any(), gomock.Eq(networkloadbalancer.GetNetworkLoadBalancerRequest{
NetworkLoadBalancerId: common.String("nlbid"),
})).Return(networkloadbalancer.GetNetworkLoadBalancerResponse{
NetworkLoadBalancer: networkloadbalancer.NetworkLoadBalancer{}}, ociutil.ErrNotFound)
},
},
{
name: "backend exists",
errorExpected: false,
Expand Down Expand Up @@ -2178,6 +2188,22 @@ func TestLBReconciliationDeletion(t *testing.T) {
errorSubStringMatch bool
testSpecificSetup func(machineScope *MachineScope, lbClient *mock_lb.MockLoadBalancerClient)
}{
{
name: "get lb error",
errorExpected: false,
testSpecificSetup: func(machineScope *MachineScope, nlbClient *mock_lb.MockLoadBalancerClient) {
machineScope.OCIMachine.Status.Addresses = []clusterv1.MachineAddress{
{
Type: clusterv1.MachineInternalIP,
Address: "1.1.1.1",
},
}
nlbClient.EXPECT().GetLoadBalancer(gomock.Any(), gomock.Eq(loadbalancer.GetLoadBalancerRequest{
LoadBalancerId: common.String("lbid"),
})).Return(loadbalancer.GetLoadBalancerResponse{
LoadBalancer: loadbalancer.LoadBalancer{}}, ociutil.ErrNotFound)
},
},
{
name: "get lb error",
errorExpected: true,
Expand Down

0 comments on commit 20ecae2

Please sign in to comment.