Skip to content

Commit 5ef6813

Browse files
nil pointer dereference and index simplification
Signed-off-by: James Milligan <[email protected]>
1 parent b093881 commit 5ef6813

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

webhooks/pod_webhook.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -417,19 +417,25 @@ func setSecurityContext() *corev1.SecurityContext {
417417
}
418418

419419
func OpenFeatureEnabledAnnotationIndex(o client.Object) []string {
420-
val, ok := o.(*corev1.Pod).ObjectMeta.Annotations["openfeature.dev/enabled"]
421-
if !ok || val != "true" {
422-
val, ok := o.(*corev1.Pod).ObjectMeta.Annotations["openfeature.dev"]
423-
if ok && val == "enabled" {
424-
return []string{
425-
"true",
426-
}
427-
}
420+
pod := o.(*corev1.Pod)
421+
if pod.ObjectMeta.Annotations == nil {
428422
return []string{
429423
"false",
430424
}
431425
}
426+
val, ok := pod.ObjectMeta.Annotations["openfeature.dev/enabled"]
427+
if ok && val == "true" {
428+
return []string{
429+
"true",
430+
}
431+
}
432+
val, ok = pod.ObjectMeta.Annotations["openfeature.dev"]
433+
if ok && val == "enabled" {
434+
return []string{
435+
"true",
436+
}
437+
}
432438
return []string{
433-
"true",
439+
"false",
434440
}
435441
}

0 commit comments

Comments
 (0)