Skip to content

Commit e7de44e

Browse files
authored
added nil pointer checks (#440)
* added pointer checks * more pointer checks * added conditionals for pointer checks where missing * removed redundant checks and added missing nil checks * removed unnecesarry checks
1 parent f07abdc commit e7de44e

12 files changed

+58
-53
lines changed

cloud/scope/load_balancer_reconciler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func (s *ClusterScope) CreateLB(ctx context.Context, lb infrastructurev1beta2.Lo
161161
}
162162
var controlPlaneEndpointSubnets []string
163163
for _, subnet := range s.OCIClusterAccessor.GetNetworkSpec().Vcn.Subnets {
164-
if subnet.Role == infrastructurev1beta2.ControlPlaneEndpointRole {
164+
if subnet != nil && subnet.ID != nil && subnet.Role == infrastructurev1beta2.ControlPlaneEndpointRole {
165165
controlPlaneEndpointSubnets = append(controlPlaneEndpointSubnets, *subnet.ID)
166166
}
167167
}
@@ -184,7 +184,7 @@ func (s *ClusterScope) CreateLB(ctx context.Context, lb infrastructurev1beta2.Lo
184184
}
185185
nsgs := make([]string, 0)
186186
for _, nsg := range s.OCIClusterAccessor.GetNetworkSpec().Vcn.NetworkSecurityGroup.List {
187-
if nsg.Role == infrastructurev1beta2.ControlPlaneEndpointRole {
187+
if nsg != nil && nsg.Role == infrastructurev1beta2.ControlPlaneEndpointRole {
188188
if nsg.ID != nil {
189189
nsgs = append(nsgs, *nsg.ID)
190190
}

cloud/scope/machine.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ func (m *MachineScope) getCompartmentId() string {
744744

745745
func (m *MachineScope) getGetControlPlaneMachineSubnet() *string {
746746
for _, subnet := range m.OCIClusterAccessor.GetNetworkSpec().Vcn.Subnets {
747-
if subnet.Role == infrastructurev1beta2.ControlPlaneRole {
747+
if subnet != nil && subnet.Role == infrastructurev1beta2.ControlPlaneRole {
748748
return subnet.ID
749749
}
750750
}
@@ -754,7 +754,7 @@ func (m *MachineScope) getGetControlPlaneMachineSubnet() *string {
754754
func (m *MachineScope) getGetControlPlaneMachineNSGs() []string {
755755
nsgs := make([]string, 0)
756756
for _, nsg := range m.OCIClusterAccessor.GetNetworkSpec().Vcn.NetworkSecurityGroup.List {
757-
if nsg.Role == infrastructurev1beta2.ControlPlaneRole {
757+
if nsg != nil && nsg.Role == infrastructurev1beta2.ControlPlaneRole {
758758
if nsg.ID != nil {
759759
nsgs = append(nsgs, *nsg.ID)
760760
}
@@ -767,7 +767,7 @@ func (m *MachineScope) getGetControlPlaneMachineNSGs() []string {
767767
// and returns the subnet ID if the name matches
768768
func (m *MachineScope) getMachineSubnet(name string) (*string, error) {
769769
for _, subnet := range m.OCIClusterAccessor.GetNetworkSpec().Vcn.Subnets {
770-
if subnet.Name == name {
770+
if subnet != nil && subnet.Name == name {
771771
return subnet.ID, nil
772772
}
773773
}
@@ -776,7 +776,7 @@ func (m *MachineScope) getMachineSubnet(name string) (*string, error) {
776776

777777
func (m *MachineScope) getWorkerMachineSubnet() *string {
778778
for _, subnet := range m.OCIClusterAccessor.GetNetworkSpec().Vcn.Subnets {
779-
if subnet.Role == infrastructurev1beta2.WorkerRole {
779+
if subnet != nil && subnet.Role == infrastructurev1beta2.WorkerRole {
780780
// if a subnet name is defined, use the correct subnet
781781
if m.OCIMachine.Spec.SubnetName != "" {
782782
if m.OCIMachine.Spec.SubnetName == subnet.Name {
@@ -795,7 +795,7 @@ func (m *MachineScope) getWorkerMachineNSGs() []string {
795795
nsgs := make([]string, 0)
796796
for _, nsgName := range m.OCIMachine.Spec.NetworkDetails.NsgNames {
797797
for _, nsg := range m.OCIClusterAccessor.GetNetworkSpec().Vcn.NetworkSecurityGroup.List {
798-
if nsg.Name == nsgName {
798+
if nsg != nil && nsg.Name == nsgName {
799799
if nsg.ID != nil {
800800
nsgs = append(nsgs, *nsg.ID)
801801
}
@@ -806,7 +806,7 @@ func (m *MachineScope) getWorkerMachineNSGs() []string {
806806
} else {
807807
nsgs := make([]string, 0)
808808
for _, nsg := range m.OCIClusterAccessor.GetNetworkSpec().Vcn.NetworkSecurityGroup.List {
809-
if nsg.Role == infrastructurev1beta2.WorkerRole {
809+
if nsg != nil && nsg.Role == infrastructurev1beta2.WorkerRole {
810810
if nsg.ID != nil {
811811
nsgs = append(nsgs, *nsg.ID)
812812
}

cloud/scope/machine_pool.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ import (
2020
"context"
2121
"encoding/base64"
2222
"fmt"
23-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2423
"reflect"
2524
"strconv"
2625
"strings"
2726

27+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
2829
"github.com/go-logr/logr"
2930
infrastructurev1beta2 "github.com/oracle/cluster-api-provider-oci/api/v1beta2"
3031
"github.com/oracle/cluster-api-provider-oci/cloud/ociutil"
@@ -147,7 +148,7 @@ func (m *MachinePoolScope) SetReplicaCount(count int32) {
147148
// GetWorkerMachineSubnet returns the WorkerRole core.Subnet id for the cluster
148149
func (m *MachinePoolScope) GetWorkerMachineSubnet() *string {
149150
for _, subnet := range m.OCIClusterAccesor.GetNetworkSpec().Vcn.Subnets {
150-
if subnet.Role == infrastructurev1beta2.WorkerRole {
151+
if subnet != nil && subnet.Role == infrastructurev1beta2.WorkerRole {
151152
return subnet.ID
152153
}
153154
}
@@ -244,7 +245,7 @@ func (m *MachinePoolScope) GetBootstrapData() (string, error) {
244245
// GetWorkerMachineNSG returns the worker role core.NetworkSecurityGroup id for the cluster
245246
func (m *MachinePoolScope) GetWorkerMachineNSG() *string {
246247
for _, nsg := range m.OCIClusterAccesor.GetNetworkSpec().Vcn.NetworkSecurityGroup.List {
247-
if nsg.Role == infrastructurev1beta2.WorkerRole {
248+
if nsg != nil && nsg.Role == infrastructurev1beta2.WorkerRole {
248249
return nsg.ID
249250
}
250251
}
@@ -859,7 +860,7 @@ func (m *MachinePoolScope) getWorkerMachineNSGs() []string {
859860
nsgs := make([]string, 0)
860861
for _, nsgName := range instanceVnicConfiguration.NsgNames {
861862
for _, nsg := range m.OCIClusterAccesor.GetNetworkSpec().Vcn.NetworkSecurityGroup.List {
862-
if nsg.Name == nsgName {
863+
if nsg != nil && nsg.ID != nil && nsg.Name == nsgName {
863864
nsgs = append(nsgs, *nsg.ID)
864865
}
865866
}
@@ -868,7 +869,7 @@ func (m *MachinePoolScope) getWorkerMachineNSGs() []string {
868869
} else {
869870
nsgs := make([]string, 0)
870871
for _, nsg := range m.OCIClusterAccesor.GetNetworkSpec().Vcn.NetworkSecurityGroup.List {
871-
if nsg.Role == infrastructurev1beta2.WorkerRole {
872+
if nsg != nil && nsg.ID != nil && nsg.Role == infrastructurev1beta2.WorkerRole {
872873
nsgs = append(nsgs, *nsg.ID)
873874
}
874875
}

cloud/scope/managed_control_plane.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func (s *ManagedControlPlaneScope) getFreeFormTags() map[string]string {
388388
func (s *ManagedControlPlaneScope) getServiceLbSubnets() []string {
389389
subnets := make([]string, 0)
390390
for _, subnet := range s.OCIClusterAccessor.GetNetworkSpec().Vcn.Subnets {
391-
if subnet.Role == infrastructurev1beta2.ServiceLoadBalancerRole {
391+
if subnet != nil && subnet.Role == infrastructurev1beta2.ServiceLoadBalancerRole {
392392
subnets = append(subnets, *subnet.ID)
393393
}
394394
}
@@ -397,7 +397,7 @@ func (s *ManagedControlPlaneScope) getServiceLbSubnets() []string {
397397

398398
func (s *ManagedControlPlaneScope) getControlPlaneEndpointSubnet() *string {
399399
for _, subnet := range s.OCIClusterAccessor.GetNetworkSpec().Vcn.Subnets {
400-
if subnet.Role == infrastructurev1beta2.ControlPlaneEndpointRole {
400+
if subnet != nil && subnet.Role == infrastructurev1beta2.ControlPlaneEndpointRole {
401401
return subnet.ID
402402
}
403403
}
@@ -407,7 +407,7 @@ func (s *ManagedControlPlaneScope) getControlPlaneEndpointSubnet() *string {
407407
func (s *ManagedControlPlaneScope) getControlPlaneEndpointNSGList() []string {
408408
nsgs := make([]string, 0)
409409
for _, nsg := range s.OCIClusterAccessor.GetNetworkSpec().Vcn.NetworkSecurityGroup.List {
410-
if nsg.Role == infrastructurev1beta2.ControlPlaneEndpointRole {
410+
if nsg != nil && nsg.Role == infrastructurev1beta2.ControlPlaneEndpointRole {
411411
nsgs = append(nsgs, *nsg.ID)
412412
}
413413
}
@@ -417,7 +417,7 @@ func (s *ManagedControlPlaneScope) getControlPlaneEndpointNSGList() []string {
417417
// IsControlPlaneEndpointSubnetPublic returns true if the control plane endpoint subnet is public
418418
func (s *ManagedControlPlaneScope) IsControlPlaneEndpointSubnetPublic() bool {
419419
for _, subnet := range s.OCIClusterAccessor.GetNetworkSpec().Vcn.Subnets {
420-
if subnet.Role == infrastructurev1beta2.ControlPlaneEndpointRole && subnet.Type == infrastructurev1beta2.Public {
420+
if subnet != nil && subnet.Role == infrastructurev1beta2.ControlPlaneEndpointRole && subnet.Type == infrastructurev1beta2.Public {
421421
return true
422422
}
423423
}

cloud/scope/managed_machine_pool.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (m *ManagedMachinePoolScope) SetReplicaCount(count int32) {
129129
// GetWorkerMachineSubnet returns the WorkerRole core.Subnet id for the cluster
130130
func (m *ManagedMachinePoolScope) GetWorkerMachineSubnet() *string {
131131
for _, subnet := range m.OCIManagedCluster.Spec.NetworkSpec.Vcn.Subnets {
132-
if subnet.Role == infrastructurev1beta2.WorkerRole {
132+
if subnet != nil && subnet.Role == infrastructurev1beta2.WorkerRole {
133133
return subnet.ID
134134
}
135135
}
@@ -140,7 +140,7 @@ func (m *ManagedMachinePoolScope) GetWorkerMachineSubnet() *string {
140140
func (m *ManagedMachinePoolScope) SetListandSetMachinePoolInstances(ctx context.Context, nodePool *oke.NodePool) (int32, error) {
141141
providerIDList := make([]string, 0)
142142
for _, instance := range nodePool.Nodes {
143-
if instance.LifecycleState == oke.NodeLifecycleStateActive {
143+
if instance.Id != nil && instance.LifecycleState == oke.NodeLifecycleStateActive {
144144
providerIDList = append(providerIDList, *instance.Id)
145145
}
146146
}
@@ -484,7 +484,7 @@ func (m *ManagedMachinePoolScope) getFreeFormTags() map[string]string {
484484
func (m *ManagedMachinePoolScope) getWorkerMachineSubnets() []string {
485485
subnetList := make([]string, 0)
486486
for _, subnet := range m.OCIManagedCluster.Spec.NetworkSpec.Vcn.Subnets {
487-
if subnet.Role == infrastructurev1beta2.WorkerRole {
487+
if subnet != nil && subnet.Role == infrastructurev1beta2.WorkerRole {
488488
subnetList = append(subnetList, subnet.Name)
489489
}
490490
}
@@ -497,14 +497,14 @@ func (m *ManagedMachinePoolScope) getWorkerMachineNSGs() []string {
497497
if len(specNsgNames) > 0 {
498498
for _, nsgName := range specNsgNames {
499499
for _, nsg := range m.OCIManagedCluster.Spec.NetworkSpec.Vcn.NetworkSecurityGroup.List {
500-
if nsg.Name == nsgName {
500+
if nsg != nil && nsg.ID != nil && nsg.Name == nsgName {
501501
nsgList = append(nsgList, *nsg.ID)
502502
}
503503
}
504504
}
505505
} else {
506506
for _, nsg := range m.OCIManagedCluster.Spec.NetworkSpec.Vcn.NetworkSecurityGroup.List {
507-
if nsg.Role == infrastructurev1beta2.WorkerRole {
507+
if nsg != nil && nsg.ID != nil && nsg.Role == infrastructurev1beta2.WorkerRole {
508508
nsgList = append(nsgList, *nsg.ID)
509509
}
510510
}
@@ -515,7 +515,7 @@ func (m *ManagedMachinePoolScope) getWorkerMachineNSGs() []string {
515515
func (m *ManagedMachinePoolScope) getWorkerMachineNSGList() []string {
516516
nsgList := make([]string, 0)
517517
for _, nsg := range m.OCIManagedCluster.Spec.NetworkSpec.Vcn.NetworkSecurityGroup.List {
518-
if nsg.Role == infrastructurev1beta2.WorkerRole {
518+
if nsg != nil && nsg.Role == infrastructurev1beta2.WorkerRole {
519519
nsgList = append(nsgList, nsg.Name)
520520
}
521521
}
@@ -527,7 +527,7 @@ func (m *ManagedMachinePoolScope) getPodSubnets(subnets []string) []string {
527527
if len(subnets) > 0 {
528528
for _, subnetName := range subnets {
529529
for _, subnet := range m.OCIManagedCluster.Spec.NetworkSpec.Vcn.Subnets {
530-
if subnet.Name == subnetName {
530+
if subnet != nil && subnet.ID != nil && subnet.Name == subnetName {
531531
subnetList = append(subnetList, *subnet.ID)
532532
}
533533
}
@@ -541,7 +541,7 @@ func (m *ManagedMachinePoolScope) getPodNSGs(nsgs []string) []string {
541541
if len(nsgs) > 0 {
542542
for _, nsgName := range nsgs {
543543
for _, nsg := range m.OCIManagedCluster.Spec.NetworkSpec.Vcn.NetworkSecurityGroup.List {
544-
if nsg.Name == nsgName {
544+
if nsg != nil && nsg.ID != nil && nsg.Name == nsgName {
545545
nsgList = append(nsgList, *nsg.ID)
546546
}
547547
}
@@ -581,7 +581,7 @@ func (m *ManagedMachinePoolScope) getInitialNodeKeyValuePairs() []oke.KeyValue {
581581

582582
func (m *ManagedMachinePoolScope) getWorkerMachineSubnet(name *string) *string {
583583
for _, subnet := range m.OCIManagedCluster.Spec.NetworkSpec.Vcn.Subnets {
584-
if subnet.Name == *name {
584+
if subnet != nil && subnet.ID != nil && subnet.Name == *name {
585585
return subnet.ID
586586
}
587587
}

cloud/scope/network_load_balancer_reconciler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func (s *ClusterScope) CreateNLB(ctx context.Context, lb infrastructurev1beta2.L
176176

177177
var controlPlaneEndpointSubnets []string
178178
for _, subnet := range s.OCIClusterAccessor.GetNetworkSpec().Vcn.Subnets {
179-
if subnet.Role == infrastructurev1beta2.ControlPlaneEndpointRole {
179+
if subnet != nil && subnet.Role == infrastructurev1beta2.ControlPlaneEndpointRole {
180180
if subnet.ID != nil {
181181
controlPlaneEndpointSubnets = append(controlPlaneEndpointSubnets, *subnet.ID)
182182
}
@@ -201,7 +201,7 @@ func (s *ClusterScope) CreateNLB(ctx context.Context, lb infrastructurev1beta2.L
201201
}
202202
nsgs := make([]string, 0)
203203
for _, nsg := range s.OCIClusterAccessor.GetNetworkSpec().Vcn.NetworkSecurityGroup.List {
204-
if nsg.Role == infrastructurev1beta2.ControlPlaneEndpointRole {
204+
if nsg != nil && nsg.Role == infrastructurev1beta2.ControlPlaneEndpointRole {
205205
if nsg.ID != nil {
206206
nsgs = append(nsgs, *nsg.ID)
207207
}

cloud/scope/nsg_reconciler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (s *ClusterScope) GetNSG(ctx context.Context, spec infrastructurev1beta2.NS
120120
return nil, errors.Wrap(err, "failed to list network security groups")
121121
}
122122
for _, nsg := range nsgs.Items {
123-
if s.IsResourceCreatedByClusterAPI(nsg.FreeformTags) {
123+
if &nsg != nil && s.IsResourceCreatedByClusterAPI(nsg.FreeformTags) {
124124
return &nsg, nil
125125
}
126126
}
@@ -483,7 +483,7 @@ func getProtocolOptionsForSpec(icmp *core.IcmpOptions, tcp *core.TcpOptions, udp
483483

484484
func getNsgIdFromName(nsgName *string, list []*infrastructurev1beta2.NSG) *string {
485485
for _, nsg := range list {
486-
if nsg.Name == *nsgName {
486+
if nsg != nil && nsg.Name == *nsgName {
487487
return nsg.ID
488488
}
489489
}
@@ -495,7 +495,7 @@ func getNsgNameFromId(nsgId *string, list []*infrastructurev1beta2.NSG) *string
495495
return nil
496496
}
497497
for _, nsg := range list {
498-
if reflect.DeepEqual(nsg.ID, nsgId) {
498+
if nsg != nil && nsg.ID != nil && reflect.DeepEqual(nsg.ID, nsgId) {
499499
return &nsg.Name
500500
}
501501
}

cloud/scope/route_table_reconciler.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,15 @@ func (s *ClusterScope) getRouteTable(ctx context.Context, routeTableType string)
8989
}
9090

9191
}
92-
vcId := s.getVcnId()
92+
vcnId := s.getVcnId()
9393
routeTableName := PublicRouteTableName
9494
if routeTableType == infrastructurev1beta2.Private {
9595
routeTableName = PrivateRouteTableName
9696
}
97+
9798
rts, err := s.VCNClient.ListRouteTables(ctx, core.ListRouteTablesRequest{
9899
CompartmentId: common.String(s.GetCompartmentId()),
99-
VcnId: vcId,
100+
VcnId: vcnId,
100101
DisplayName: common.String(routeTableName),
101102
})
102103
if err != nil {
@@ -108,6 +109,7 @@ func (s *ClusterScope) getRouteTable(ctx context.Context, routeTableType string)
108109
return &rt, nil
109110
}
110111
}
112+
111113
return nil, nil
112114
}
113115

cloud/scope/security_list_reconciler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func getProtocolOptions(icmp *infrastructurev1beta2.IcmpOptions, tcp *infrastruc
246246

247247
func (s *ClusterScope) IsSecurityListExitsByRole(role infrastructurev1beta2.Role) bool {
248248
for _, subnet := range s.GetSubnetsSpec() {
249-
if role == subnet.Role {
249+
if subnet != nil && role == subnet.Role {
250250
if subnet.SecurityList != nil {
251251
return true
252252
}

cloud/scope/subnet_reconciler.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func (s *ClusterScope) GetSubnet(ctx context.Context, spec infrastructurev1beta2
251251

252252
func (s *ClusterScope) GetControlPlaneEndpointSubnet() *infrastructurev1beta2.Subnet {
253253
for _, subnet := range s.GetSubnetsSpec() {
254-
if subnet.Role == infrastructurev1beta2.ControlPlaneEndpointRole {
254+
if subnet != nil && subnet.Role == infrastructurev1beta2.ControlPlaneEndpointRole {
255255
return subnet
256256
}
257257
}
@@ -260,7 +260,7 @@ func (s *ClusterScope) GetControlPlaneEndpointSubnet() *infrastructurev1beta2.Su
260260

261261
func (s *ClusterScope) GetControlPlaneMachineSubnet() *infrastructurev1beta2.Subnet {
262262
for _, subnet := range s.GetSubnetsSpec() {
263-
if subnet.Role == infrastructurev1beta2.ControlPlaneRole {
263+
if subnet != nil && subnet.Role == infrastructurev1beta2.ControlPlaneRole {
264264
return subnet
265265
}
266266
}
@@ -269,7 +269,7 @@ func (s *ClusterScope) GetControlPlaneMachineSubnet() *infrastructurev1beta2.Sub
269269

270270
func (s *ClusterScope) GetServiceLoadBalancerSubnet() *infrastructurev1beta2.Subnet {
271271
for _, subnet := range s.GetSubnetsSpec() {
272-
if subnet.Role == infrastructurev1beta2.ServiceLoadBalancerRole {
272+
if subnet != nil && subnet.Role == infrastructurev1beta2.ServiceLoadBalancerRole {
273273
return subnet
274274
}
275275
}
@@ -279,7 +279,7 @@ func (s *ClusterScope) GetServiceLoadBalancerSubnet() *infrastructurev1beta2.Sub
279279
func (s *ClusterScope) GetNodeSubnet() []*infrastructurev1beta2.Subnet {
280280
var nodeSubnets []*infrastructurev1beta2.Subnet
281281
for _, subnet := range s.GetSubnetsSpec() {
282-
if subnet.Role == infrastructurev1beta2.WorkerRole {
282+
if subnet != nil && subnet.Role == infrastructurev1beta2.WorkerRole {
283283
nodeSubnets = append(nodeSubnets, subnet)
284284
}
285285
}
@@ -307,7 +307,7 @@ func (s *ClusterScope) IsSubnetsEqual(actual *core.Subnet, desired infrastructur
307307

308308
func (s *ClusterScope) isControlPlaneEndpointSubnetPrivate() bool {
309309
for _, subnet := range s.OCIClusterAccessor.GetNetworkSpec().Vcn.Subnets {
310-
if subnet.Role == infrastructurev1beta2.ControlPlaneEndpointRole && subnet.Type == infrastructurev1beta2.Private {
310+
if subnet != nil && subnet.Role == infrastructurev1beta2.ControlPlaneEndpointRole && subnet.Type == infrastructurev1beta2.Private {
311311
return true
312312
}
313313
}
@@ -316,7 +316,7 @@ func (s *ClusterScope) isControlPlaneEndpointSubnetPrivate() bool {
316316

317317
func (s *ClusterScope) GetControlPlaneEndpointSubnetCidr() string {
318318
for _, subnet := range s.GetSubnetsSpec() {
319-
if subnet.Role == infrastructurev1beta2.ControlPlaneEndpointRole {
319+
if subnet != nil && subnet.Role == infrastructurev1beta2.ControlPlaneEndpointRole {
320320
if subnet.CIDR != "" {
321321
return subnet.CIDR
322322
}
@@ -327,7 +327,7 @@ func (s *ClusterScope) GetControlPlaneEndpointSubnetCidr() string {
327327

328328
func (s *ClusterScope) GetServiceLoadBalancerSubnetCidr() string {
329329
for _, subnet := range s.GetSubnetsSpec() {
330-
if subnet.Role == infrastructurev1beta2.ServiceLoadBalancerRole {
330+
if subnet != nil && subnet.Role == infrastructurev1beta2.ServiceLoadBalancerRole {
331331
if subnet.CIDR != "" {
332332
return subnet.CIDR
333333
}
@@ -340,7 +340,7 @@ func (s *ClusterScope) NodeSubnetCidr() []string {
340340
subnets := s.GetNodeSubnet()
341341
var nodeCIDR []string
342342
for _, subnet := range subnets {
343-
if subnet.CIDR != "" {
343+
if subnet != nil && subnet.CIDR != "" {
344344
nodeCIDR = append(nodeCIDR, subnet.CIDR)
345345
}
346346
nodeCIDR = append(nodeCIDR, WorkerSubnetDefaultCIDR)
@@ -376,7 +376,7 @@ func (s *ClusterScope) IsAllSubnetsPrivate() bool {
376376
// IsAllSubnetsPublic determines if all the ClusterScope's subnets are public
377377
func (s *ClusterScope) IsAllSubnetsPublic() bool {
378378
for _, subnet := range s.GetSubnetsSpec() {
379-
if subnet.Type == infrastructurev1beta2.Private {
379+
if subnet != nil && subnet.Type == infrastructurev1beta2.Private {
380380
return false
381381
}
382382
}

0 commit comments

Comments
 (0)