From 8599d56e7c6c975d6584c47e12487e6b002703c0 Mon Sep 17 00:00:00 2001 From: Vishal Choudhary Date: Thu, 8 Feb 2024 01:05:26 +0530 Subject: [PATCH] fix: add nil pointer check for scope in table conversion (#60) --- pkg/api/table.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/pkg/api/table.go b/pkg/api/table.go index 37770d5..d283ab8 100644 --- a/pkg/api/table.go +++ b/pkg/api/table.go @@ -38,8 +38,15 @@ func addPolicyReportToTable(table *metav1beta1.Table, polrs ...v1alpha2.PolicyRe } row := make([]interface{}, 0, len(table.ColumnDefinitions)) row = append(row, polr.Name) - row = append(row, polr.Scope.Kind) - row = append(row, polr.Scope.Name) + + if polr.Scope == nil { + row = append(row, "") + row = append(row, "") + } else { + row = append(row, polr.Scope.Kind) + row = append(row, polr.Scope.Name) + } + row = append(row, polr.Summary.Pass) row = append(row, polr.Summary.Fail) row = append(row, polr.Summary.Warn) @@ -68,8 +75,15 @@ func addClusterPolicyReportToTable(table *metav1beta1.Table, cpolrs ...v1alpha2. } row := make([]interface{}, 0, len(table.ColumnDefinitions)) row = append(row, cpolr.Name) - row = append(row, cpolr.Scope.Kind) - row = append(row, cpolr.Scope.Name) + + if cpolr.Scope == nil { + row = append(row, "") + row = append(row, "") + } else { + row = append(row, cpolr.Scope.Kind) + row = append(row, cpolr.Scope.Name) + } + row = append(row, cpolr.Summary.Pass) row = append(row, cpolr.Summary.Fail) row = append(row, cpolr.Summary.Warn)