From 3e2acc27f03fafb279a32985d3c8b7a8a0b6ca4a Mon Sep 17 00:00:00 2001 From: Lukas Piwowarski Date: Wed, 13 Nov 2024 03:58:30 -0500 Subject: [PATCH] [OSPRH-11191] Remove dereference for nil pointer This patch fixes the issue when ExtraConfigmapsMounts is empty. Dereferencing a nil pointer leads to a panic. We now first check whether the pointer is nil and then move to dereferencing it. --- pkg/ansibletest/volumes.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/ansibletest/volumes.go b/pkg/ansibletest/volumes.go index 5ee0355..ebe5255 100644 --- a/pkg/ansibletest/volumes.go +++ b/pkg/ansibletest/volumes.go @@ -106,7 +106,7 @@ func GetVolumes( volumes = append(volumes, extraVol) } - if len(instance.Spec.Workflow) > 0 && *instance.Spec.Workflow[externalWorkflowCounter].ExtraConfigmapsMounts != nil { + if len(instance.Spec.Workflow) > 0 && instance.Spec.Workflow[externalWorkflowCounter].ExtraConfigmapsMounts != nil { for _, vol := range *instance.Spec.Workflow[externalWorkflowCounter].ExtraConfigmapsMounts { extraWorkflowVol := corev1.Volume{ Name: vol.Name, @@ -204,7 +204,7 @@ func GetVolumeMounts(mountCerts bool, instance *testv1beta1.AnsibleTest, externa volumeMounts = append(volumeMounts, extraConfigmapsMounts) } - if len(instance.Spec.Workflow) > 0 && *instance.Spec.Workflow[externalWorkflowCounter].ExtraConfigmapsMounts != nil { + if len(instance.Spec.Workflow) > 0 && instance.Spec.Workflow[externalWorkflowCounter].ExtraConfigmapsMounts != nil { for _, vol := range *instance.Spec.Workflow[externalWorkflowCounter].ExtraConfigmapsMounts { extraConfigmapsMounts := corev1.VolumeMount{