diff --git a/internal/queryer/queryer.go b/internal/queryer/queryer.go index db8ed0b1e6..541079ead7 100644 --- a/internal/queryer/queryer.go +++ b/internal/queryer/queryer.go @@ -740,18 +740,23 @@ func (osq *ObjectStoreQueryer) ConfigMapsForPod(ctx context.Context, pod *corev1 return nil, errors.Wrap(err, "copying object metadata") } - for _, c := range pod.Spec.Containers { + for ci := range pod.Spec.Containers { + c := &pod.Spec.Containers[ci] for _, e := range c.Env { - ref := e.ValueFrom.ConfigMapKeyRef - if ref.Name == configMap.Name { - configMaps = append(configMaps, configMap) + if e.ValueFrom != nil && e.ValueFrom.ConfigMapKeyRef != nil { + ref := e.ValueFrom.ConfigMapKeyRef + if ref.Name == configMap.Name { + configMaps = append(configMaps, configMap) + } } } for _, e := range c.EnvFrom { - ref := e.ConfigMapRef - if ref.Name == configMap.Name { - configMaps = append(configMaps, configMap) + if e.ConfigMapRef != nil { + ref := e.ConfigMapRef + if ref.Name == configMap.Name { + configMaps = append(configMaps, configMap) + } } } } diff --git a/internal/queryer/queryer_test.go b/internal/queryer/queryer_test.go index 66cd89b05e..2263e092a8 100644 --- a/internal/queryer/queryer_test.go +++ b/internal/queryer/queryer_test.go @@ -910,6 +910,10 @@ func TestObjectStoreQueryer_ConfigMapsForPod(t *testing.T) { }, }, Env: []corev1.EnvVar{ + { + Name: "configmap3", + Value: "configmap3_value", + }, { ValueFrom: &corev1.EnvVarSource{ ConfigMapKeyRef: &corev1.ConfigMapKeySelector{