Skip to content

Commit

Permalink
updated code and made state as pass and throw suggestion instead of e…
Browse files Browse the repository at this point in the history
…rror for missing spec in CR. (#6245)

* updated code and made state as pass and thrown suggestions for the same

Signed-off-by: laxmikantbpandhare <laxmikantpandhare@gmail.com>

* updated code and made state as pass and thrown suggestions for the same

Signed-off-by: laxmikantbpandhare <laxmikantpandhare@gmail.com>

* updated test cases

Signed-off-by: laxmikantbpandhare <laxmikantpandhare@gmail.com>

* updated according to suggestions

Signed-off-by: laxmikantbpandhare <laxmikantpandhare@gmail.com>

* updated according to suggestions

Signed-off-by: laxmikantbpandhare <laxmikantpandhare@gmail.com>

Signed-off-by: laxmikantbpandhare <laxmikantpandhare@gmail.com>
  • Loading branch information
laxmikantbpandhare committed Jan 11, 2023
1 parent 346012f commit a5d933b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
17 changes: 17 additions & 0 deletions changelog/fragments/spec-scoreacrd-fix.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions internal/scorecard/tests/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/scorecard/tests/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit a5d933b

Please sign in to comment.