From e5d868c5ef7cbdb501f80ee472dbc87f9ebb738c Mon Sep 17 00:00:00 2001 From: Scot Wells Date: Fri, 13 Dec 2024 23:57:31 +0000 Subject: [PATCH] bugfix: add nil check on label selectors --- .../app/internal/webhook/webhook.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cmd/datum-authorization-webhook/app/internal/webhook/webhook.go b/cmd/datum-authorization-webhook/app/internal/webhook/webhook.go index d653f7e..b0ab7d4 100644 --- a/cmd/datum-authorization-webhook/app/internal/webhook/webhook.go +++ b/cmd/datum-authorization-webhook/app/internal/webhook/webhook.go @@ -35,13 +35,15 @@ func NewAuthorizerWebhook(authzer authorizer.Authorizer) *Webhook { attrs.Subresource = resourceAttrs.Subresource attrs.Name = resourceAttrs.Name attrs.ResourceRequest = true - for _, requirement := range r.Spec.ResourceAttributes.LabelSelector.Requirements { - req, _ := labels.NewRequirement( - requirement.Key, - selection.Operator(requirement.Operator), - requirement.Values, - ) - attrs.LabelSelectorRequirements = append(attrs.LabelSelectorRequirements, *req) + if resourceAttrs.LabelSelector != nil { + for _, requirement := range resourceAttrs.LabelSelector.Requirements { + req, _ := labels.NewRequirement( + requirement.Key, + selection.Operator(requirement.Operator), + requirement.Values, + ) + attrs.LabelSelectorRequirements = append(attrs.LabelSelectorRequirements, *req) + } } }