Skip to content

Commit 77b3984

Browse files
fix: alm-example parse check should not fail when the annotation if empty (#215)
* fix: alm-example parse check should not fail when the annotation if empty * applying review
1 parent 12a70c0 commit 77b3984

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

pkg/validation/internal/csv.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ func validateExamplesAnnotations(csv *v1alpha1.ClusterServiceVersion) (errs []er
124124

125125
func validateJSON(value string) error {
126126
var js json.RawMessage
127+
128+
if len(value) == 0 {
129+
return nil
130+
}
131+
127132
byteValue := []byte(value)
128133
if err := json.Unmarshal(byteValue, &js); err != nil {
129134
switch t := err.(type) {

pkg/validation/internal/csv_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package internal
22

33
import (
44
"io/ioutil"
5+
"k8s.io/apimachinery/pkg/runtime/schema"
56
"path/filepath"
67
"testing"
78

@@ -80,6 +81,16 @@ func TestValidateCSV(t *testing.T) {
8081
},
8182
filepath.Join("testdata", "invalid.alm-examples.csv.yaml"),
8283
},
84+
{
85+
validatorFuncTest{
86+
description: "should not fail when alm-examples is not informed",
87+
wantWarn: true,
88+
errors: []errors.Error{
89+
errors.WarnInvalidOperation("provided API should have an example annotation", schema.GroupVersionKind{Group: "etcd.database.coreos.com", Version: "v1beta2", Kind: "EtcdCluster"}),
90+
},
91+
},
92+
filepath.Join("testdata", "correct.csv.empty.example.yaml"),
93+
},
8394
}
8495
for _, c := range cases {
8596
b, err := ioutil.ReadFile(c.csvPath)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#! validate-crd: deploy/chart/templates/0000_30_02-clusterserviceversion.crd.yaml
2+
#! parse-kind: ClusterServiceVersion
3+
apiVersion: operators.coreos.com/v1alpha1
4+
kind: ClusterServiceVersion
5+
metadata:
6+
name: etcdoperator.v0.9.0
7+
namespace: placeholder
8+
annotations:
9+
"alm-examples": ""
10+
spec:
11+
version: 0.9.0
12+
installModes:
13+
- type: AllNamespaces
14+
supported: true
15+
install:
16+
strategy: deployment
17+
spec:
18+
permissions:
19+
- serviceAccountName: etcd-operator
20+
rules:
21+
- apiGroups:
22+
- etcd.database.coreos.com
23+
resources:
24+
- etcdclusters
25+
- etcdbackups
26+
- etcdrestores
27+
verbs:
28+
- "*"
29+
deployments:
30+
- name: etcd-operator
31+
spec:
32+
replicas: 1
33+
template:
34+
metadata:
35+
name: etcd-operator-alm-owned
36+
labels:
37+
name: etcd-operator-alm-owned
38+
spec:
39+
serviceAccountName: etcd-operator
40+
containers:
41+
- name: etcd-operator
42+
command:
43+
- etcd-operator
44+
- --create-crd=false
45+
image: quay.io/coreos/etcd-operator@sha256:db563baa8194fcfe39d1df744ed70024b0f1f9e9b55b5923c2f3a413c44dc6b8
46+
env:
47+
- name: MY_POD_NAMESPACE
48+
valueFrom:
49+
fieldRef:
50+
fieldPath: metadata.namespace
51+
- name: MY_POD_NAME
52+
valueFrom:
53+
fieldRef:
54+
fieldPath: metadata.name
55+
customresourcedefinitions:
56+
owned:
57+
- name: etcdclusters.etcd.database.coreos.com
58+
version: v1beta2
59+
kind: EtcdCluster
60+
61+

0 commit comments

Comments
 (0)