Skip to content

Commit c5b5f62

Browse files
authored
add CSV markers to go/v3 testdata (#5641)
1 parent 8b3d756 commit c5b5f62

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

hack/generate/samples/internal/go/v3/memcached_with_webhooks.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ func (mh *Memcached) implementingAPI() {
274274
`
275275
276276
// Size defines the number of Memcached instances
277+
// +operator-sdk:csv:customresourcedefinitions:type=spec
277278
Size int32 `+"`"+`json:"size,omitempty"`+"`"+`
278279
`)
279280
pkg.CheckError("inserting spec Status", err)
@@ -285,10 +286,21 @@ func (mh *Memcached) implementingAPI() {
285286
`
286287
287288
// Nodes store the name of the pods which are running Memcached instances
289+
// +operator-sdk:csv:customresourcedefinitions:type=status
288290
Nodes []string `+"`"+`json:"nodes,omitempty"`+"`"+`
289291
`)
290292
pkg.CheckError("inserting Node Status", err)
291293

294+
// Add CSV marker that shows CRD owned resources
295+
err = kbutil.InsertCode(
296+
filepath.Join(mh.ctx.Dir, "api", mh.ctx.Version, fmt.Sprintf("%s_types.go", strings.ToLower(mh.ctx.Kind))),
297+
`//+kubebuilder:subresource:status`,
298+
`
299+
// +operator-sdk:csv:customresourcedefinitions:resources={{Deployment,v1,memcached-deployment}}
300+
`)
301+
302+
pkg.CheckError("inserting CRD owned resources CSV marker", err)
303+
292304
sampleFile := filepath.Join("config", "samples",
293305
fmt.Sprintf("%s_%s_%s.yaml", mh.ctx.Group, mh.ctx.Version, strings.ToLower(mh.ctx.Kind)))
294306

test/common/scorecard.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ func ScorecardSpec(tc *testutils.TestContext, operatorType string) func() {
5959
"--wait-time", "4m")
6060
outputBytes, err = tc.Run(cmd)
6161
// Some tests are expected to fail, which results in scorecard exiting 1.
62-
Expect(err).To(HaveOccurred())
62+
// Go tests no longer expect to fail
63+
if strings.ToLower(operatorType) != "go" {
64+
Expect(err).To(HaveOccurred())
65+
}
6366
Expect(json.Unmarshal(outputBytes, &output)).To(Succeed())
6467

6568
expected := map[string]v1alpha3.State{
@@ -75,6 +78,11 @@ func ScorecardSpec(tc *testutils.TestContext, operatorType string) func() {
7578
if strings.ToLower(operatorType) == "go" {
7679
// Go projects have generated CRD validation.
7780
expected["olm-crds-have-validation"] = v1alpha3.PassState
81+
// Go generated test operator now has CSV markers
82+
// that allows these validations to pass
83+
expected["olm-crds-have-resources"] = v1alpha3.PassState
84+
expected["olm-spec-descriptors"] = v1alpha3.PassState
85+
expected["olm-status-descriptors"] = v1alpha3.PassState
7886
// The Go sample project tests a custom suite.
7987
expected["customtest1"] = v1alpha3.PassState
8088
expected["customtest2"] = v1alpha3.PassState

testdata/go/v3/memcached-operator/api/v1alpha1/memcached_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type MemcachedSpec struct {
2929
// Important: Run "make" to regenerate code after modifying this file
3030

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

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

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

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

5053
// Memcached is the Schema for the memcacheds API
5154
type Memcached struct {

testdata/go/v3/memcached-operator/bundle/manifests/memcached-operator.clusterserviceversion.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ spec:
2626
displayName: Memcached
2727
kind: Memcached
2828
name: memcacheds.cache.example.com
29+
resources:
30+
- kind: Deployment
31+
name: memcached-deployment
32+
version: v1
33+
specDescriptors:
34+
- description: Size defines the number of Memcached instances
35+
displayName: Size
36+
path: size
37+
statusDescriptors:
38+
- description: Nodes store the name of the pods which are running Memcached
39+
instances
40+
displayName: Nodes
41+
path: nodes
2942
version: v1alpha1
3043
description: Memcached Operator description. TODO.
3144
displayName: Memcached Operator

testdata/go/v3/memcached-operator/config/manifests/bases/memcached-operator.clusterserviceversion.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ spec:
1414
displayName: Memcached
1515
kind: Memcached
1616
name: memcacheds.cache.example.com
17+
resources:
18+
- kind: Deployment
19+
name: memcached-deployment
20+
version: v1
21+
specDescriptors:
22+
- description: Size defines the number of Memcached instances
23+
displayName: Size
24+
path: size
25+
statusDescriptors:
26+
- description: Nodes store the name of the pods which are running Memcached
27+
instances
28+
displayName: Nodes
29+
path: nodes
1730
version: v1alpha1
1831
description: Memcached Operator description. TODO.
1932
displayName: Memcached Operator

0 commit comments

Comments
 (0)