From 83308e16a0de98e22fc1037afe73f4cf59541e9b Mon Sep 17 00:00:00 2001 From: Dan Bryant Date: Sat, 27 Apr 2024 17:54:45 +0100 Subject: [PATCH] fix: warn and fix invalid namespace --- pkg/judge/rego.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/judge/rego.go b/pkg/judge/rego.go index 438721f1..7baa52eb 100644 --- a/pkg/judge/rego.go +++ b/pkg/judge/rego.go @@ -2,6 +2,7 @@ package judge import ( "context" + "github.com/doitintl/kube-no-trouble/pkg/rules" "github.com/open-policy-agent/opa/rego" "github.com/rs/zerolog/log" @@ -56,6 +57,12 @@ func (j *RegoJudge) Eval(input []map[string]interface{}) ([]Result, error) { log.Debug().Msgf("Failed to parse version: %s", err) } + // shouldn't really happen - but if it does fix up and move on + if m["Namespace"] == nil { + log.Warn().Msgf("Object has invalid namespace: %s/%s %s", m["ApiVersion"].(string), m["Kind"].(string), m["Name"].(string)) + m["Namespace"] = "" + } + results = append(results, Result{ Name: m["Name"].(string), Namespace: m["Namespace"].(string),