Skip to content

Commit b28618d

Browse files
Handle machine deletion when NLB/LB has been deleted (#350)
* Handle machine deletion when NLB/LB has been deleted
1 parent 91a9824 commit b28618d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

cloud/scope/machine.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,10 @@ func (m *MachineScope) ReconcileDeleteInstanceOnLB(ctx context.Context) error {
615615
LoadBalancerId: loadbalancerId,
616616
})
617617
if err != nil {
618+
if ociutil.IsNotFound(err) {
619+
m.Logger.Info("LB has been deleted", "lb", *loadbalancerId)
620+
return nil
621+
}
618622
return err
619623
}
620624
backendSet := lb.BackendSets[APIServerLBBackendSetName]
@@ -664,6 +668,10 @@ func (m *MachineScope) ReconcileDeleteInstanceOnLB(ctx context.Context) error {
664668
NetworkLoadBalancerId: loadbalancerId,
665669
})
666670
if err != nil {
671+
if ociutil.IsNotFound(err) {
672+
m.Logger.Info("NLB has been deleted", "nlb", *loadbalancerId)
673+
return nil
674+
}
667675
return err
668676
}
669677
backendSet := lb.BackendSets[APIServerLBBackendSetName]

cloud/scope/machine_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,16 @@ func TestNLBReconciliationDeletion(t *testing.T) {
16341634
NetworkLoadBalancer: networkloadbalancer.NetworkLoadBalancer{}}, errors.New("could not get nlb"))
16351635
},
16361636
},
1637+
{
1638+
name: "get nlb error, not found",
1639+
errorExpected: false,
1640+
testSpecificSetup: func(machineScope *MachineScope, nlbClient *mock_nlb.MockNetworkLoadBalancerClient) {
1641+
nlbClient.EXPECT().GetNetworkLoadBalancer(gomock.Any(), gomock.Eq(networkloadbalancer.GetNetworkLoadBalancerRequest{
1642+
NetworkLoadBalancerId: common.String("nlbid"),
1643+
})).Return(networkloadbalancer.GetNetworkLoadBalancerResponse{
1644+
NetworkLoadBalancer: networkloadbalancer.NetworkLoadBalancer{}}, ociutil.ErrNotFound)
1645+
},
1646+
},
16371647
{
16381648
name: "backend exists",
16391649
errorExpected: false,
@@ -2176,6 +2186,22 @@ func TestLBReconciliationDeletion(t *testing.T) {
21762186
errorSubStringMatch bool
21772187
testSpecificSetup func(machineScope *MachineScope, lbClient *mock_lb.MockLoadBalancerClient)
21782188
}{
2189+
{
2190+
name: "get lb error",
2191+
errorExpected: false,
2192+
testSpecificSetup: func(machineScope *MachineScope, nlbClient *mock_lb.MockLoadBalancerClient) {
2193+
machineScope.OCIMachine.Status.Addresses = []clusterv1.MachineAddress{
2194+
{
2195+
Type: clusterv1.MachineInternalIP,
2196+
Address: "1.1.1.1",
2197+
},
2198+
}
2199+
nlbClient.EXPECT().GetLoadBalancer(gomock.Any(), gomock.Eq(loadbalancer.GetLoadBalancerRequest{
2200+
LoadBalancerId: common.String("lbid"),
2201+
})).Return(loadbalancer.GetLoadBalancerResponse{
2202+
LoadBalancer: loadbalancer.LoadBalancer{}}, ociutil.ErrNotFound)
2203+
},
2204+
},
21792205
{
21802206
name: "get lb error",
21812207
errorExpected: true,

0 commit comments

Comments
 (0)