From 3277b2ad4b27ade9bd7da07f5fc8d8f074355177 Mon Sep 17 00:00:00 2001 From: Alex Jones Date: Sun, 17 Sep 2023 12:12:28 +0100 Subject: [PATCH] fix: pdb panic error guard (#664) Signed-off-by: Alex Jones Co-authored-by: Aris Boutselis --- pkg/analyzer/pdb.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/pkg/analyzer/pdb.go b/pkg/analyzer/pdb.go index 9a5e3b2aa2..9c9eb1f579 100644 --- a/pkg/analyzer/pdb.go +++ b/pkg/analyzer/pdb.go @@ -58,21 +58,23 @@ func (PdbAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) { if pdb.Spec.MinAvailable != nil { doc = apiDoc.GetApiDocV2("spec.minAvailable") } - for k, v := range pdb.Spec.Selector.MatchLabels { - failures = append(failures, common.Failure{ - Text: fmt.Sprintf("%s, expected pdb pod label %s=%s", pdb.Status.Conditions[0].Reason, k, v), - KubernetesDoc: doc, - Sensitive: []common.Sensitive{ - { - Unmasked: k, - Masked: util.MaskString(k), + if pdb.Spec.Selector != nil && pdb.Spec.Selector.MatchLabels != nil { + for k, v := range pdb.Spec.Selector.MatchLabels { + failures = append(failures, common.Failure{ + Text: fmt.Sprintf("%s, expected pdb pod label %s=%s", pdb.Status.Conditions[0].Reason, k, v), + KubernetesDoc: doc, + Sensitive: []common.Sensitive{ + { + Unmasked: k, + Masked: util.MaskString(k), + }, + { + Unmasked: v, + Masked: util.MaskString(v), + }, }, - { - Unmasked: v, - Masked: util.MaskString(v), - }, - }, - }) + }) + } } }