From f7c89e683fdc51c5335b422a6231b38c356bb78d Mon Sep 17 00:00:00 2001 From: odubajDT Date: Thu, 16 Nov 2023 15:06:43 +0100 Subject: [PATCH] check if assignment is ok Signed-off-by: odubajDT --- webhooks/common.go | 5 ++++- webhooks/common_test.go | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/webhooks/common.go b/webhooks/common.go index 1423fb991..138087ebb 100644 --- a/webhooks/common.go +++ b/webhooks/common.go @@ -11,7 +11,10 @@ import ( ) func OpenFeatureEnabledAnnotationIndex(o client.Object) []string { - pod := o.(*corev1.Pod) + pod, ok := o.(*corev1.Pod) + if !ok { + return []string{"false"} + } if pod.ObjectMeta.Annotations == nil { return []string{ "false", diff --git a/webhooks/common_test.go b/webhooks/common_test.go index 2b46446ae..5fe8bcac9 100644 --- a/webhooks/common_test.go +++ b/webhooks/common_test.go @@ -21,6 +21,10 @@ func TestOpenFeatureEnabledAnnotationIndex(t *testing.T) { want []string }{ { + name: "not a pod", + o: &corev1.ConfigMap{}, + want: []string{"false"}, + }, { name: "no annotations", o: &corev1.Pod{}, want: []string{"false"},