Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run scorecard tests in helm e2e tests #3768

Merged
merged 2 commits into from
Aug 20, 2020
Merged
Changes from 1 commit
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
48 changes: 48 additions & 0 deletions test/e2e-helm/e2e_helm_olm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
package e2e_helm_test

import (
"encoding/json"
"fmt"
"os/exec"
"path"
"path/filepath"
"strings"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/operator-framework/api/pkg/apis/scorecard/v1alpha3"

testutils "github.com/operator-framework/operator-sdk/test/internal"
)
Expand All @@ -30,6 +33,14 @@ var _ = Describe("Integrating Helm Projects with OLM", func() {
Context("with operator-sdk", func() {
const operatorVersion = "0.0.1"

const (
OLMBundleValidationTest = "olm-bundle-validation"
OLMCRDsHaveValidationTest = "olm-crds-have-validation"
OLMCRDsHaveResourcesTest = "olm-crds-have-resources"
OLMSpecDescriptorsTest = "olm-spec-descriptors"
OLMStatusDescriptorsTest = "olm-status-descriptors"
)

BeforeEach(func() {
By("turning off interactive prompts for all generation tasks.")
replace := "operator-sdk generate kustomize manifests"
Expand Down Expand Up @@ -63,6 +74,19 @@ var _ = Describe("Integrating Helm Projects with OLM", func() {
err = tc.Make("packagemanifests", "IMG="+tc.ImageName)
Expect(err).NotTo(HaveOccurred())

By("running basic scorecard tests")
var scorecardOutput v1alpha3.TestList
runScorecardCmd := exec.Command(tc.BinaryName, "scorecard", "bundle",
"--selector=suite=basic",
camilamacedo86 marked this conversation as resolved.
Show resolved Hide resolved
"--output=json",
"--wait-time=40s")
scorecardOutputBytes, err := tc.Run(runScorecardCmd)
Expect(err).NotTo(HaveOccurred())
err = json.Unmarshal(scorecardOutputBytes, &scorecardOutput)
Expect(err).NotTo(HaveOccurred())
Expect(len(scorecardOutput.Items)).To(Equal(1))
Expect(scorecardOutput.Items[0].Status.Results[0].State).To(Equal(v1alpha3.PassState))

By("running the package")
runPkgManCmd := exec.Command(tc.BinaryName, "run", "packagemanifests",
"--install-mode", "AllNamespaces",
Expand All @@ -76,6 +100,30 @@ var _ = Describe("Integrating Helm Projects with OLM", func() {
"--timeout", "4m")
_, err = tc.Run(cleanupPkgManCmd)
Expect(err).NotTo(HaveOccurred())

By("running olm scorecard tests")
runOLMScorecardCmd := exec.Command(tc.BinaryName, "scorecard", "bundle",
"--selector=suite=olm",
"--output=json",
"--wait-time=40s")
scorecardOutputBytes, err = tc.Run(runOLMScorecardCmd)
Expect(err).To(HaveOccurred())
err = json.Unmarshal(scorecardOutputBytes, &scorecardOutput)

expected := make(map[string]v1alpha3.State)
expected[OLMBundleValidationTest] = v1alpha3.PassState
expected[OLMCRDsHaveResourcesTest] = v1alpha3.FailState
expected[OLMCRDsHaveValidationTest] = v1alpha3.FailState
Copy link
Contributor

@camilamacedo86 camilamacedo86 Aug 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the OLMCRDsHaveValidationTest should fail? Why this test is not returning a passing state? IMO we have a bug here in the scorecard for Helm/Ansible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was noticed before we cut 1.0. I wasn't in the meeting that discussed it, but if we do want to make a change here, it is in the scaffolding, so out of scope for this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference using helm operator-sdk-sample:
$ cd ~/devel/operator-sdk-samples/helm/memcached-operator
$ operator-sdk scorecard ./bundle --selector=suite=olm

SNIP...
--------------------------------------------------------------------------------
Image:      quay.io/operator-framework/scorecard-test:master
Entrypoint: [scorecard-test olm-crds-have-validation]
Labels:
	"suite":"olm"
	"test":"olm-crds-have-validation-test"
Results:
	Name: olm-crds-have-validation
	State: fail

	Suggestions:
		Add CRD validation for spec field `metrics` in Memcached/v1alpha1
		Add CRD validation for spec field `podAnnotations` in Memcached/v1alpha1
		Add CRD validation for spec field `updateStrategy` in Memcached/v1alpha1
		Add CRD validation for spec field `extraContainers` in Memcached/v1alpha1
		Add CRD validation for spec field `image` in Memcached/v1alpha1
		Add CRD validation for spec field `kind` in Memcached/v1alpha1
		Add CRD validation for spec field `pdbMinAvailable` in Memcached/v1alpha1
		Add CRD validation for spec field `replicaCount` in Memcached/v1alpha1
		Add CRD validation for spec field `securityContext` in Memcached/v1alpha1
		Add CRD validation for spec field `tolerations` in Memcached/v1alpha1
		Add CRD validation for spec field `affinity` in Memcached/v1alpha1
		Add CRD validation for spec field `memcached` in Memcached/v1alpha1
		Add CRD validation for spec field `resources` in Memcached/v1alpha1
		Add CRD validation for spec field `serviceAnnotations` in Memcached/v1alpha1
		Add CRD validation for spec field `AntiAffinity` in Memcached/v1alpha1
		Add CRD validation for spec field `nodeSelector` in Memcached/v1alpha1
		Add CRD validation for spec field `extraVolumes` in Memcached/v1alpha1
	Log:
		Loaded 1 Custom Resources from alm-examples
		Loaded CustomresourceDefinitions: [&CustomResourceDefinition{ObjectMeta:{memcacheds.cache.example.com      0 0001-01-01 00:00:00 +0000 UTC <nil> <nil> map[] map[] [] []  []},Spec:CustomResourceDefinitionSpec{Group:cache.example.com,Names:CustomResourceDefinitionNames{Plural:memcacheds,Singular:memcached,ShortNames:[],Kind:Memcached,ListKind:MemcachedList,Categories:[],},Scope:Namespaced,Versions:[]CustomResourceDefinitionVersion{CustomResourceDefinitionVersion{Name:v1alpha1,Served:true,Storage:true,Schema:&CustomResourceValidation{OpenAPIV3Schema:&JSONSchemaProps{ID:,Schema:,Ref:nil,Description:Memcached is the Schema for the memcacheds API,Type:object,Format:,Title:,Default:nil,Maximum:nil,ExclusiveMaximum:false,Minimum:nil,ExclusiveMinimum:false,MaxLength:nil,MinLength:nil,Pattern:,MaxItems:nil,MinItems:nil,UniqueItems:false,MultipleOf:nil,Enum:[]JSON{},MaxProperties:nil,MinProperties:nil,Required:[],Items:nil,AllOf:[]JSONSchemaProps{},OneOf:[]JSONSchemaProps{},AnyOf:[]JSONSchemaProps{},Not:nil,Properties:map[string]JSONSchemaProps{apiVersion: {  <nil> APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources string   nil <nil> false <nil> false <nil> <nil>  <nil> <nil> false <nil> [] <nil> <nil> [] nil [] [] [] nil map[] nil map[] map[] nil map[] nil nil false <nil> false false [] <nil> <nil>},kind: {  <nil> Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds string   nil <nil> false <nil> false <nil> <nil>  <nil> <nil> false <nil> [] <nil> <nil> [] nil [] [] [] nil map[] nil map[] map[] nil map[] nil nil false <nil> false false [] <nil> <nil>},metadata: {  <nil>  object   nil <nil> false <nil> false <nil> <nil>  <nil> <nil> false <nil> [] <nil> <nil> [] nil [] [] [] nil map[] nil map[] map[] nil map[] nil nil false <nil> false false [] <nil> <nil>},spec: {  <nil> Spec defines the desired state of Memcached object   nil <nil> false <nil> false <nil> <nil>  <nil> <nil> false <nil> [] <nil> <nil> [] nil [] [] [] nil map[] nil map[] map[] nil map[] nil nil false 0xc0004c8778 false false [] <nil> <nil>},status: {  <nil> Status defines the observed state of Memcached object   nil <nil> false <nil> false <nil> <nil>  <nil> <nil> false <nil> [] <nil> <nil> [] nil [] [] [] nil map[] nil map[] map[] nil map[] nil nil false 0xc0004c8779 false false [] <nil> <nil>},},AdditionalProperties:nil,PatternProperties:map[string]JSONSchemaProps{},Dependencies:JSONSchemaDependencies{},AdditionalItems:nil,Definitions:JSONSchemaDefinitions{},ExternalDocs:nil,Example:nil,Nullable:false,XPreserveUnknownFields:nil,XEmbeddedResource:false,XIntOrString:false,XListMapKeys:[],XListType:nil,XMapType:nil,},},Subresources:&CustomResourceSubresources{Status:&CustomResourceSubresourceStatus{},Scale:nil,},AdditionalPrinterColumns:[]CustomResourceColumnDefinition{},},},Conversion:nil,PreserveUnknownFields:false,},Status:CustomResourceDefinitionStatus{Conditions:[]CustomResourceDefinitionCondition{},AcceptedNames:CustomResourceDefinitionNames{Plural:,Singular:,ShortNames:[],Kind:,ListKind:,Categories:[],},StoredVersions:[],},}]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @asmacdo,

It is true: since in tHelm/Ansible we have not the go types definition and we do not all the make manifests (controller-gen) the CRD has not the CR specs and their validations.

Copy link
Contributor

@camilamacedo86 camilamacedo86 Aug 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I raised : #3770 let's see what others think as well.

expected[OLMSpecDescriptorsTest] = v1alpha3.FailState
expected[OLMStatusDescriptorsTest] = v1alpha3.FailState

Expect(len(scorecardOutput.Items)).To(Equal(len(expected)))
for a := 0; a < len(scorecardOutput.Items); a++ {
fmt.Println(" - Name: ", scorecardOutput.Items[a].Status.Results[0].Name)
fmt.Println(" Expected: ", expected[scorecardOutput.Items[a].Status.Results[0].Name])
fmt.Println(" Output: ", scorecardOutput.Items[a].Status.Results[0].State)
Expect(scorecardOutput.Items[a].Status.Results[0].State).To(Equal(expected[scorecardOutput.Items[a].Status.Results[0].Name]))
}
})
})
})