Skip to content

Commit

Permalink
add CSV markers to go/v3 testdata (operator-framework#5641)
Browse files Browse the repository at this point in the history
  • Loading branch information
everettraven authored Apr 8, 2022
1 parent 8b3d756 commit c5b5f62
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
12 changes: 12 additions & 0 deletions hack/generate/samples/internal/go/v3/memcached_with_webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ func (mh *Memcached) implementingAPI() {
`
// Size defines the number of Memcached instances
// +operator-sdk:csv:customresourcedefinitions:type=spec
Size int32 `+"`"+`json:"size,omitempty"`+"`"+`
`)
pkg.CheckError("inserting spec Status", err)
Expand All @@ -285,10 +286,21 @@ func (mh *Memcached) implementingAPI() {
`
// Nodes store the name of the pods which are running Memcached instances
// +operator-sdk:csv:customresourcedefinitions:type=status
Nodes []string `+"`"+`json:"nodes,omitempty"`+"`"+`
`)
pkg.CheckError("inserting Node Status", err)

// Add CSV marker that shows CRD owned resources
err = kbutil.InsertCode(
filepath.Join(mh.ctx.Dir, "api", mh.ctx.Version, fmt.Sprintf("%s_types.go", strings.ToLower(mh.ctx.Kind))),
`//+kubebuilder:subresource:status`,
`
// +operator-sdk:csv:customresourcedefinitions:resources={{Deployment,v1,memcached-deployment}}
`)

pkg.CheckError("inserting CRD owned resources CSV marker", err)

sampleFile := filepath.Join("config", "samples",
fmt.Sprintf("%s_%s_%s.yaml", mh.ctx.Group, mh.ctx.Version, strings.ToLower(mh.ctx.Kind)))

Expand Down
10 changes: 9 additions & 1 deletion test/common/scorecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ func ScorecardSpec(tc *testutils.TestContext, operatorType string) func() {
"--wait-time", "4m")
outputBytes, err = tc.Run(cmd)
// Some tests are expected to fail, which results in scorecard exiting 1.
Expect(err).To(HaveOccurred())
// Go tests no longer expect to fail
if strings.ToLower(operatorType) != "go" {
Expect(err).To(HaveOccurred())
}
Expect(json.Unmarshal(outputBytes, &output)).To(Succeed())

expected := map[string]v1alpha3.State{
Expand All @@ -75,6 +78,11 @@ func ScorecardSpec(tc *testutils.TestContext, operatorType string) func() {
if strings.ToLower(operatorType) == "go" {
// Go projects have generated CRD validation.
expected["olm-crds-have-validation"] = v1alpha3.PassState
// Go generated test operator now has CSV markers
// that allows these validations to pass
expected["olm-crds-have-resources"] = v1alpha3.PassState
expected["olm-spec-descriptors"] = v1alpha3.PassState
expected["olm-status-descriptors"] = v1alpha3.PassState
// The Go sample project tests a custom suite.
expected["customtest1"] = v1alpha3.PassState
expected["customtest2"] = v1alpha3.PassState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type MemcachedSpec struct {
// Important: Run "make" to regenerate code after modifying this file

// Size defines the number of Memcached instances
// +operator-sdk:csv:customresourcedefinitions:type=spec
Size int32 `json:"size,omitempty"`

// Foo is an example field of Memcached. Edit memcached_types.go to remove/update
Expand All @@ -41,11 +42,13 @@ type MemcachedStatus struct {
// Important: Run "make" to regenerate code after modifying this file

// Nodes store the name of the pods which are running Memcached instances
// +operator-sdk:csv:customresourcedefinitions:type=status
Nodes []string `json:"nodes,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +operator-sdk:csv:customresourcedefinitions:resources={{Deployment,v1,memcached-deployment}}

// Memcached is the Schema for the memcacheds API
type Memcached struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ spec:
displayName: Memcached
kind: Memcached
name: memcacheds.cache.example.com
resources:
- kind: Deployment
name: memcached-deployment
version: v1
specDescriptors:
- description: Size defines the number of Memcached instances
displayName: Size
path: size
statusDescriptors:
- description: Nodes store the name of the pods which are running Memcached
instances
displayName: Nodes
path: nodes
version: v1alpha1
description: Memcached Operator description. TODO.
displayName: Memcached Operator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ spec:
displayName: Memcached
kind: Memcached
name: memcacheds.cache.example.com
resources:
- kind: Deployment
name: memcached-deployment
version: v1
specDescriptors:
- description: Size defines the number of Memcached instances
displayName: Size
path: size
statusDescriptors:
- description: Nodes store the name of the pods which are running Memcached
instances
displayName: Nodes
path: nodes
version: v1alpha1
description: Memcached Operator description. TODO.
displayName: Memcached Operator
Expand Down

0 comments on commit c5b5f62

Please sign in to comment.