Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions pkg/apis/scorecard/v1alpha3/configuration_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package v1alpha3

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ConfigurationKind is the default scorecard componentconfig kind.
const ConfigurationKind = "Configuration"

// Configuration represents the set of test configurations which scorecard would run.
type Configuration struct {
metav1.TypeMeta `json:",inline" yaml:",inline"`

// Do not use metav1.ObjectMeta because this "object" should not be treated as an actual object.
Metadata struct {
// Name is a required field for kustomize-able manifests, and is not used on-cluster (nor is the config itself).
Name string `json:"name,omitempty" yaml:"name,omitempty"`
} `json:"metadata,omitempty" yaml:"metadata,omitempty"`

// Stages is a set of test stages to run. Once a stage is finished, the next stage in the slice will be run.
Stages []StageConfiguration `json:"stages" yaml:"stages"`
}

// StageConfiguration configures a set of tests to be run.
type StageConfiguration struct {
// Parallel, if true, will run each test in tests in parallel.
// The default is to wait until a test finishes to run the next.
Parallel bool `json:"parallel,omitempty" yaml:"parallel,omitempty"`
// Tests are a list of tests to run.
Tests []TestConfiguration `json:"tests" yaml:"tests"`
}

// TestConfiguration configures a specific scorecard test, identified by entrypoint.
type TestConfiguration struct {
// Image is the name of the test image.
Image string `json:"image" yaml:"image"`
// Entrypoint is a list of commands and arguments passed to the test image.
Entrypoint []string `json:"entrypoint,omitempty" yaml:"entrypoint,omitempty"`
// Labels further describe the test and enable selection.
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
}
5 changes: 5 additions & 0 deletions pkg/apis/scorecard/v1alpha3/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +k8s:deepcopy-gen=package,register
// +groupName=scorecard.operatorframework.io

// Package v1alpha3 contains resources types for version v1alpha3 of the scorecard.operatorframework.com API group.
package v1alpha3
66 changes: 66 additions & 0 deletions pkg/apis/scorecard/v1alpha3/formatter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package v1alpha3

import (
"bufio"
"fmt"
"strings"
)

func (s Test) MarshalText() string {
var sb strings.Builder

sb.WriteString(fmt.Sprintf("%s\n", strings.Repeat("-", 80)))
sb.WriteString(fmt.Sprintf("Image: %s\n", s.Spec.Image))

if len(s.Spec.Entrypoint) > 0 {
sb.WriteString(fmt.Sprintf("Entrypoint: %s\n", s.Spec.Entrypoint))
}

if len(s.Spec.Labels) > 0 {
sb.WriteString("Labels:\n")
for labelKey, labelValue := range s.Spec.Labels {
sb.WriteString(fmt.Sprintf("\t%q:%q\n", labelKey, labelValue))
}
}
if len(s.Status.Results) > 0 {
sb.WriteString("Results:\n")
for _, result := range s.Status.Results {
if len(result.Name) > 0 {
sb.WriteString(fmt.Sprintf("\tName: %s\n", result.Name))
}
sb.WriteString("\tState: ")
switch result.State {
case PassState, FailState, ErrorState:
sb.WriteString(string(result.State))
sb.WriteString("\n")
default:
sb.WriteString("unknown")
}
sb.WriteString("\n")

if len(result.Suggestions) > 0 {
sb.WriteString("\tSuggestions:\n")
for _, suggestion := range result.Suggestions {
sb.WriteString(fmt.Sprintf("\t\t%s\n", suggestion))
}
}

if len(result.Errors) > 0 {
sb.WriteString("\tErrors:\n")
for _, err := range result.Errors {
sb.WriteString(fmt.Sprintf("\t\t%s\n", err))
}
}

if result.Log != "" {
sb.WriteString("\tLog:\n")
scanner := bufio.NewScanner(strings.NewReader(result.Log))
for scanner.Scan() {
sb.WriteString(fmt.Sprintf("\t\t%s\n", scanner.Text()))
}
}
sb.WriteString("\n")
}
}
return sb.String()
}
10 changes: 10 additions & 0 deletions pkg/apis/scorecard/v1alpha3/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package v1alpha3

import (
"k8s.io/apimachinery/pkg/runtime/schema"
)

var (
// GroupVersion is the group and version of this package. Used for parsing purposes only.
GroupVersion = schema.GroupVersion{Group: "scorecard.operatorframework.io", Version: "v1alpha3"}
)
69 changes: 69 additions & 0 deletions pkg/apis/scorecard/v1alpha3/test_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package v1alpha3

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// State is a type used to indicate the result state of a Test.
type State string

const (
// PassState occurs when a Test's ExpectedPoints == MaximumPoints.
PassState State = "pass"
// FailState occurs when a Test's ExpectedPoints == 0.
FailState State = "fail"
// ErrorState occurs when a Test encounters a fatal error and the reported points should not be considered.
ErrorState State = "error"
)

// TestResult contains the results of an individual scorecard test
type TestResult struct {
// Name is the name of the test
Name string `json:"name,omitempty"`
// Log holds a log produced from the test (if applicable)
Log string `json:"log,omitempty"`
// State is the final state of the test
State State `json:"state"`
// Errors is a list of the errors that occurred during the test (this can include both fatal and non-fatal errors)
Errors []string `json:"errors,omitempty"`
// Suggestions is a list of suggestions for the user to improve their score (if applicable)
Suggestions []string `json:"suggestions,omitempty"`
}

// TestStatus contains collection of testResults.
type TestStatus struct {
Results []TestResult `json:"results,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// Test specifies a single test run.
type Test struct {
metav1.TypeMeta `json:",inline"`
Spec TestConfiguration `json:"spec,omitempty"`
Status TestStatus `json:"status,omitempty"`
}

// TestList is a list of tests.
type TestList struct {
metav1.TypeMeta `json:",inline"`
Items []Test `json:"items"`
}

func NewTest() Test {
return Test{
TypeMeta: metav1.TypeMeta{
APIVersion: GroupVersion.String(),
Kind: "Test",
},
}
}

func NewTestList() TestList {
return TestList{
TypeMeta: metav1.TypeMeta{
APIVersion: GroupVersion.String(),
Kind: "TestList",
},
}
}
185 changes: 185 additions & 0 deletions pkg/apis/scorecard/v1alpha3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.