From a5d933b5e8d729c9c3f9f1790f61053cf37dfafd Mon Sep 17 00:00:00 2001 From: Laxmikant Bhaskar Pandhare <47066536+laxmikantbpandhare@users.noreply.github.com> Date: Wed, 11 Jan 2023 12:59:17 -0800 Subject: [PATCH] updated code and made state as pass and throw suggestion instead of error for missing spec in CR. (#6245) * updated code and made state as pass and thrown suggestions for the same Signed-off-by: laxmikantbpandhare * updated code and made state as pass and thrown suggestions for the same Signed-off-by: laxmikantbpandhare * updated test cases Signed-off-by: laxmikantbpandhare * updated according to suggestions Signed-off-by: laxmikantbpandhare * updated according to suggestions Signed-off-by: laxmikantbpandhare Signed-off-by: laxmikantbpandhare --- changelog/fragments/spec-scoreacrd-fix.yaml | 17 +++++++++++++++++ internal/scorecard/tests/basic.go | 3 +-- internal/scorecard/tests/bundle_test.go | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 changelog/fragments/spec-scoreacrd-fix.yaml diff --git a/changelog/fragments/spec-scoreacrd-fix.yaml b/changelog/fragments/spec-scoreacrd-fix.yaml new file mode 100644 index 00000000000..31d05939f69 --- /dev/null +++ b/changelog/fragments/spec-scoreacrd-fix.yaml @@ -0,0 +1,17 @@ +# entries is a list of entries to include in +# release notes and/or the migration guide +entries: + - description: > + (scorecard): Fixes a bug where an error would be thrown if a Custom Resource did not have a `.spec` field, which is a perfectly valid scenario. Instead of throwing an error scorecard will now issue a suggestion. + + # kind is one of: + # - addition + # - change + # - deprecation + # - removal + # - bugfix + kind: "bugfix" + + # Is this a breaking change? + breaking: false + diff --git a/internal/scorecard/tests/basic.go b/internal/scorecard/tests/basic.go index 382e406eb30..587b854b733 100644 --- a/internal/scorecard/tests/basic.go +++ b/internal/scorecard/tests/basic.go @@ -50,8 +50,7 @@ func checkSpec(crSet []unstructured.Unstructured, res scapiv1alpha3.TestResult) scapiv1alpha3.TestResult { for _, cr := range crSet { if cr.Object["spec"] == nil { - res.Errors = append(res.Errors, fmt.Sprintf("error spec does not exist for the custom resource %s", cr.GetName())) - res.State = scapiv1alpha3.FailState + res.State = scapiv1alpha3.PassState res.Suggestions = append(res.Suggestions, fmt.Sprintf("spec missing from [%+v]", cr.GetName())) return res } diff --git a/internal/scorecard/tests/bundle_test.go b/internal/scorecard/tests/bundle_test.go index fbdba46df7d..49f45757a2e 100644 --- a/internal/scorecard/tests/bundle_test.go +++ b/internal/scorecard/tests/bundle_test.go @@ -283,7 +283,7 @@ var _ = Describe("Basic and OLM tests", func() { }, } result = checkSpec(cr, result) - Expect(result.State).To(Equal(scapiv1alpha3.FailState)) + Expect(result.State).To(Equal(scapiv1alpha3.PassState)) }) It("should pass when CRs do have spec field specified", func() { cr := []unstructured.Unstructured{