From 8acfb468d51c4b5d08937fdfa4569b7970a72f1e Mon Sep 17 00:00:00 2001 From: tozastation Date: Thu, 8 Feb 2024 20:48:12 +0900 Subject: [PATCH] Fix: add nil check on Machine and Network Load Balancer (#349) * add: subnet id nil check on network load balancer --- cloud/scope/machine.go | 12 +++++++++--- cloud/scope/network_load_balancer_reconciler.go | 4 +++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cloud/scope/machine.go b/cloud/scope/machine.go index bfa713c0..920243b4 100644 --- a/cloud/scope/machine.go +++ b/cloud/scope/machine.go @@ -732,7 +732,9 @@ func (m *MachineScope) getGetControlPlaneMachineNSGs() []string { nsgs := make([]string, 0) for _, nsg := range m.OCIClusterAccessor.GetNetworkSpec().Vcn.NetworkSecurityGroup.List { if nsg.Role == infrastructurev1beta2.ControlPlaneRole { - nsgs = append(nsgs, *nsg.ID) + if nsg.ID != nil { + nsgs = append(nsgs, *nsg.ID) + } } } return nsgs @@ -771,7 +773,9 @@ func (m *MachineScope) getWorkerMachineNSGs() []string { for _, nsgName := range m.OCIMachine.Spec.NetworkDetails.NsgNames { for _, nsg := range m.OCIClusterAccessor.GetNetworkSpec().Vcn.NetworkSecurityGroup.List { if nsg.Name == nsgName { - nsgs = append(nsgs, *nsg.ID) + if nsg.ID != nil { + nsgs = append(nsgs, *nsg.ID) + } } } } @@ -780,7 +784,9 @@ func (m *MachineScope) getWorkerMachineNSGs() []string { nsgs := make([]string, 0) for _, nsg := range m.OCIClusterAccessor.GetNetworkSpec().Vcn.NetworkSecurityGroup.List { if nsg.Role == infrastructurev1beta2.WorkerRole { - nsgs = append(nsgs, *nsg.ID) + if nsg.ID != nil { + nsgs = append(nsgs, *nsg.ID) + } } } return nsgs diff --git a/cloud/scope/network_load_balancer_reconciler.go b/cloud/scope/network_load_balancer_reconciler.go index b10fc758..c52e2080 100644 --- a/cloud/scope/network_load_balancer_reconciler.go +++ b/cloud/scope/network_load_balancer_reconciler.go @@ -165,7 +165,9 @@ func (s *ClusterScope) CreateNLB(ctx context.Context, lb infrastructurev1beta2.L var controlPlaneEndpointSubnets []string for _, subnet := range s.OCIClusterAccessor.GetNetworkSpec().Vcn.Subnets { if subnet.Role == infrastructurev1beta2.ControlPlaneEndpointRole { - controlPlaneEndpointSubnets = append(controlPlaneEndpointSubnets, *subnet.ID) + if subnet.ID != nil { + controlPlaneEndpointSubnets = append(controlPlaneEndpointSubnets, *subnet.ID) + } } } if len(controlPlaneEndpointSubnets) < 1 {