/
scorecard_olm_suite.go
77 lines (64 loc) · 2.64 KB
/
scorecard_olm_suite.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package operator
import (
"context"
"fmt"
"github.com/redhat-openshift-ecosystem/openshift-preflight/internal/check"
"github.com/redhat-openshift-ecosystem/openshift-preflight/internal/image"
"github.com/redhat-openshift-ecosystem/openshift-preflight/internal/log"
"github.com/go-logr/logr"
)
var _ check.Check = &ScorecardOlmSuiteCheck{}
// ScorecardOlmSuiteCheck evaluates the image to ensure it passes the operator-sdk
// scorecard check with the olm suite selected.
type ScorecardOlmSuiteCheck struct {
scorecardCheck
fatalError bool
}
const scorecardOlmSuiteResult string = "operator_bundle_scorecard_OlmSuiteCheck.json"
func NewScorecardOlmSuiteCheck(operatorSdk operatorSdk, ns, sa string, kubeconfig []byte, waittime string) *ScorecardOlmSuiteCheck {
return &ScorecardOlmSuiteCheck{
scorecardCheck: scorecardCheck{
OperatorSdk: operatorSdk,
namespace: ns,
serviceAccount: sa,
kubeconfig: kubeconfig,
waitTime: waittime,
},
fatalError: false,
}
}
func (p *ScorecardOlmSuiteCheck) Validate(ctx context.Context, bundleRef image.ImageReference) (bool, error) {
logger := logr.FromContextOrDiscard(ctx)
logger.V(log.TRC).Info("running operator-sdk scorecard check", "image", bundleRef.ImageURI)
selector := []string{"suite=olm"}
scorecardReport, err := p.getDataToValidate(ctx, bundleRef.ImageFSPath, selector, scorecardOlmSuiteResult)
if err != nil {
p.fatalError = true
return false, fmt.Errorf("%v", err)
}
return p.validate(ctx, scorecardReport.Items)
}
func (p *ScorecardOlmSuiteCheck) Name() string {
return "ScorecardOlmSuiteCheck"
}
func (p *ScorecardOlmSuiteCheck) Metadata() check.Metadata {
return check.Metadata{
Description: "Operator-sdk scorecard OLM Test Suite Check",
Level: "best",
KnowledgeBaseURL: "https://sdk.operatorframework.io/docs/testing-operators/scorecard/#overview",
CheckURL: "https://sdk.operatorframework.io/docs/testing-operators/scorecard/#olm-test-suite",
}
}
func (p *ScorecardOlmSuiteCheck) Help() check.HelpText {
if p.fatalError {
return check.HelpText{
Message: "There was a fatal error while running operator-sdk scorecard tests. " +
"Please see the preflight log for details. If necessary, set logging to be more verbose.",
Suggestion: "If the logs are showing a context timeout, try setting wait time to a higher value.",
}
}
return check.HelpText{
Message: "Check ScorecardOlmSuiteCheck encountered an error. Please review the " + scorecardOlmSuiteResult + " file in your execution artifacts for more information.",
Suggestion: "See scorecard output for details, artifacts/operator_bundle_scorecard_OlmSuiteCheck.json",
}
}