Skip to content

Commit 333d064

Browse files
author
Eric Stroczynski
authored
Merge pull request #55 from estroz/feature/scorecard-apis
This commit moves `pkg/apis/scorecard/v1alpha3` from operator-sdk this repo.
2 parents 6c81a47 + 7bc9d3c commit 333d064

File tree

6 files changed

+376
-0
lines changed

6 files changed

+376
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package v1alpha3
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
)
6+
7+
// ConfigurationKind is the default scorecard componentconfig kind.
8+
const ConfigurationKind = "Configuration"
9+
10+
// Configuration represents the set of test configurations which scorecard would run.
11+
type Configuration struct {
12+
metav1.TypeMeta `json:",inline" yaml:",inline"`
13+
14+
// Do not use metav1.ObjectMeta because this "object" should not be treated as an actual object.
15+
Metadata struct {
16+
// Name is a required field for kustomize-able manifests, and is not used on-cluster (nor is the config itself).
17+
Name string `json:"name,omitempty" yaml:"name,omitempty"`
18+
} `json:"metadata,omitempty" yaml:"metadata,omitempty"`
19+
20+
// Stages is a set of test stages to run. Once a stage is finished, the next stage in the slice will be run.
21+
Stages []StageConfiguration `json:"stages" yaml:"stages"`
22+
}
23+
24+
// StageConfiguration configures a set of tests to be run.
25+
type StageConfiguration struct {
26+
// Parallel, if true, will run each test in tests in parallel.
27+
// The default is to wait until a test finishes to run the next.
28+
Parallel bool `json:"parallel,omitempty" yaml:"parallel,omitempty"`
29+
// Tests are a list of tests to run.
30+
Tests []TestConfiguration `json:"tests" yaml:"tests"`
31+
}
32+
33+
// TestConfiguration configures a specific scorecard test, identified by entrypoint.
34+
type TestConfiguration struct {
35+
// Image is the name of the test image.
36+
Image string `json:"image" yaml:"image"`
37+
// Entrypoint is a list of commands and arguments passed to the test image.
38+
Entrypoint []string `json:"entrypoint,omitempty" yaml:"entrypoint,omitempty"`
39+
// Labels further describe the test and enable selection.
40+
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
41+
}

pkg/apis/scorecard/v1alpha3/doc.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// +k8s:deepcopy-gen=package,register
2+
// +groupName=scorecard.operatorframework.io
3+
4+
// Package v1alpha3 contains resources types for version v1alpha3 of the scorecard.operatorframework.com API group.
5+
package v1alpha3
+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package v1alpha3
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"strings"
7+
)
8+
9+
func (s Test) MarshalText() string {
10+
var sb strings.Builder
11+
12+
sb.WriteString(fmt.Sprintf("%s\n", strings.Repeat("-", 80)))
13+
sb.WriteString(fmt.Sprintf("Image: %s\n", s.Spec.Image))
14+
15+
if len(s.Spec.Entrypoint) > 0 {
16+
sb.WriteString(fmt.Sprintf("Entrypoint: %s\n", s.Spec.Entrypoint))
17+
}
18+
19+
if len(s.Spec.Labels) > 0 {
20+
sb.WriteString("Labels:\n")
21+
for labelKey, labelValue := range s.Spec.Labels {
22+
sb.WriteString(fmt.Sprintf("\t%q:%q\n", labelKey, labelValue))
23+
}
24+
}
25+
if len(s.Status.Results) > 0 {
26+
sb.WriteString("Results:\n")
27+
for _, result := range s.Status.Results {
28+
if len(result.Name) > 0 {
29+
sb.WriteString(fmt.Sprintf("\tName: %s\n", result.Name))
30+
}
31+
sb.WriteString("\tState: ")
32+
switch result.State {
33+
case PassState, FailState, ErrorState:
34+
sb.WriteString(string(result.State))
35+
sb.WriteString("\n")
36+
default:
37+
sb.WriteString("unknown")
38+
}
39+
sb.WriteString("\n")
40+
41+
if len(result.Suggestions) > 0 {
42+
sb.WriteString("\tSuggestions:\n")
43+
for _, suggestion := range result.Suggestions {
44+
sb.WriteString(fmt.Sprintf("\t\t%s\n", suggestion))
45+
}
46+
}
47+
48+
if len(result.Errors) > 0 {
49+
sb.WriteString("\tErrors:\n")
50+
for _, err := range result.Errors {
51+
sb.WriteString(fmt.Sprintf("\t\t%s\n", err))
52+
}
53+
}
54+
55+
if result.Log != "" {
56+
sb.WriteString("\tLog:\n")
57+
scanner := bufio.NewScanner(strings.NewReader(result.Log))
58+
for scanner.Scan() {
59+
sb.WriteString(fmt.Sprintf("\t\t%s\n", scanner.Text()))
60+
}
61+
}
62+
sb.WriteString("\n")
63+
}
64+
}
65+
return sb.String()
66+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package v1alpha3
2+
3+
import (
4+
"k8s.io/apimachinery/pkg/runtime/schema"
5+
)
6+
7+
var (
8+
// GroupVersion is the group and version of this package. Used for parsing purposes only.
9+
GroupVersion = schema.GroupVersion{Group: "scorecard.operatorframework.io", Version: "v1alpha3"}
10+
)
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package v1alpha3
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
)
6+
7+
// State is a type used to indicate the result state of a Test.
8+
type State string
9+
10+
const (
11+
// PassState occurs when a Test's ExpectedPoints == MaximumPoints.
12+
PassState State = "pass"
13+
// FailState occurs when a Test's ExpectedPoints == 0.
14+
FailState State = "fail"
15+
// ErrorState occurs when a Test encounters a fatal error and the reported points should not be considered.
16+
ErrorState State = "error"
17+
)
18+
19+
// TestResult contains the results of an individual scorecard test
20+
type TestResult struct {
21+
// Name is the name of the test
22+
Name string `json:"name,omitempty"`
23+
// Log holds a log produced from the test (if applicable)
24+
Log string `json:"log,omitempty"`
25+
// State is the final state of the test
26+
State State `json:"state"`
27+
// Errors is a list of the errors that occurred during the test (this can include both fatal and non-fatal errors)
28+
Errors []string `json:"errors,omitempty"`
29+
// Suggestions is a list of suggestions for the user to improve their score (if applicable)
30+
Suggestions []string `json:"suggestions,omitempty"`
31+
}
32+
33+
// TestStatus contains collection of testResults.
34+
type TestStatus struct {
35+
Results []TestResult `json:"results,omitempty"`
36+
}
37+
38+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
39+
40+
// Test specifies a single test run.
41+
type Test struct {
42+
metav1.TypeMeta `json:",inline"`
43+
Spec TestConfiguration `json:"spec,omitempty"`
44+
Status TestStatus `json:"status,omitempty"`
45+
}
46+
47+
// TestList is a list of tests.
48+
type TestList struct {
49+
metav1.TypeMeta `json:",inline"`
50+
Items []Test `json:"items"`
51+
}
52+
53+
func NewTest() Test {
54+
return Test{
55+
TypeMeta: metav1.TypeMeta{
56+
APIVersion: GroupVersion.String(),
57+
Kind: "Test",
58+
},
59+
}
60+
}
61+
62+
func NewTestList() TestList {
63+
return TestList{
64+
TypeMeta: metav1.TypeMeta{
65+
APIVersion: GroupVersion.String(),
66+
Kind: "TestList",
67+
},
68+
}
69+
}

pkg/apis/scorecard/v1alpha3/zz_generated.deepcopy.go

+185
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)