Skip to content

Commit a3e46bf

Browse files
authored
add nil pointer checks for auto-mode config (#183)
Issue: aws-controllers-k8s/community#2619 Description of changes: - add nil pointer checks to auto-mode config By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 909fb91 commit a3e46bf

File tree

1 file changed

+39
-18
lines changed

1 file changed

+39
-18
lines changed

pkg/resource/cluster/hook.go

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -666,33 +666,54 @@ func (rm *resourceManager) updateComputeConfig(
666666
exit := rlog.Trace("rm.updateComputeConfig")
667667
defer exit(err)
668668

669-
// Convert []*string to []string for NodePools
670-
nodePools := make([]string, 0, len(r.ko.Spec.ComputeConfig.NodePools))
671-
for _, nodePool := range r.ko.Spec.ComputeConfig.NodePools {
672-
if nodePool != nil {
673-
nodePools = append(nodePools, *nodePool)
674-
}
675-
}
676-
677669
input := &svcsdk.UpdateClusterConfigInput{
678670
Name: r.ko.Spec.Name,
679-
ComputeConfig: &svcsdktypes.ComputeConfigRequest{
671+
}
672+
673+
if r.ko.Spec.ComputeConfig != nil {
674+
// Convert []*string to []string for NodePools
675+
nodePools := make([]string, 0, len(r.ko.Spec.ComputeConfig.NodePools))
676+
for _, nodePool := range r.ko.Spec.ComputeConfig.NodePools {
677+
if nodePool != nil {
678+
nodePools = append(nodePools, *nodePool)
679+
}
680+
}
681+
682+
input.ComputeConfig = &svcsdktypes.ComputeConfigRequest{
680683
Enabled: r.ko.Spec.ComputeConfig.Enabled,
681684
NodePools: nodePools, // Use the converted []string slice
682685
NodeRoleArn: r.ko.Spec.ComputeConfig.NodeRoleARN,
683-
},
684-
StorageConfig: &svcsdktypes.StorageConfigRequest{
686+
}
687+
}
688+
689+
// Only set StorageConfig if it's not nil
690+
if r.ko.Spec.StorageConfig != nil && r.ko.Spec.StorageConfig.BlockStorage != nil {
691+
input.StorageConfig = &svcsdktypes.StorageConfigRequest{
685692
BlockStorage: &svcsdktypes.BlockStorage{
686693
Enabled: r.ko.Spec.StorageConfig.BlockStorage.Enabled,
687694
},
688-
},
689-
KubernetesNetworkConfig: &svcsdktypes.KubernetesNetworkConfigRequest{
690-
ElasticLoadBalancing: &svcsdktypes.ElasticLoadBalancing{
695+
}
696+
}
697+
698+
// Only set KubernetesNetworkConfig if it's not nil
699+
if r.ko.Spec.KubernetesNetworkConfig != nil {
700+
kubernetesNetworkConfig := &svcsdktypes.KubernetesNetworkConfigRequest{}
701+
702+
if r.ko.Spec.KubernetesNetworkConfig.ElasticLoadBalancing != nil {
703+
kubernetesNetworkConfig.ElasticLoadBalancing = &svcsdktypes.ElasticLoadBalancing{
691704
Enabled: r.ko.Spec.KubernetesNetworkConfig.ElasticLoadBalancing.Enabled,
692-
},
693-
IpFamily: svcsdktypes.IpFamily(*r.ko.Spec.KubernetesNetworkConfig.IPFamily),
694-
ServiceIpv4Cidr: r.ko.Spec.KubernetesNetworkConfig.ServiceIPv4CIDR,
695-
},
705+
}
706+
}
707+
708+
if r.ko.Spec.KubernetesNetworkConfig.IPFamily != nil {
709+
kubernetesNetworkConfig.IpFamily = svcsdktypes.IpFamily(*r.ko.Spec.KubernetesNetworkConfig.IPFamily)
710+
}
711+
712+
if r.ko.Spec.KubernetesNetworkConfig.ServiceIPv4CIDR != nil {
713+
kubernetesNetworkConfig.ServiceIpv4Cidr = r.ko.Spec.KubernetesNetworkConfig.ServiceIPv4CIDR
714+
}
715+
716+
input.KubernetesNetworkConfig = kubernetesNetworkConfig
696717
}
697718

698719
_, err = rm.sdkapi.UpdateClusterConfig(ctx, input)

0 commit comments

Comments
 (0)