diff --git a/pkg/validation/internal/csv.go b/pkg/validation/internal/csv.go index 74576b05e..b5b7683c0 100644 --- a/pkg/validation/internal/csv.go +++ b/pkg/validation/internal/csv.go @@ -124,6 +124,11 @@ func validateExamplesAnnotations(csv *v1alpha1.ClusterServiceVersion) (errs []er func validateJSON(value string) error { var js json.RawMessage + + if len(value) == 0 { + return nil + } + byteValue := []byte(value) if err := json.Unmarshal(byteValue, &js); err != nil { switch t := err.(type) { diff --git a/pkg/validation/internal/csv_test.go b/pkg/validation/internal/csv_test.go index f3b2a83e4..239122907 100644 --- a/pkg/validation/internal/csv_test.go +++ b/pkg/validation/internal/csv_test.go @@ -2,6 +2,7 @@ package internal import ( "io/ioutil" + "k8s.io/apimachinery/pkg/runtime/schema" "path/filepath" "testing" @@ -80,6 +81,16 @@ func TestValidateCSV(t *testing.T) { }, filepath.Join("testdata", "invalid.alm-examples.csv.yaml"), }, + { + validatorFuncTest{ + description: "should not fail when alm-examples is not informed", + wantWarn: true, + errors: []errors.Error{ + errors.WarnInvalidOperation("provided API should have an example annotation", schema.GroupVersionKind{Group: "etcd.database.coreos.com", Version: "v1beta2", Kind: "EtcdCluster"}), + }, + }, + filepath.Join("testdata", "correct.csv.empty.example.yaml"), + }, } for _, c := range cases { b, err := ioutil.ReadFile(c.csvPath) diff --git a/pkg/validation/internal/testdata/correct.csv.empty.example.yaml b/pkg/validation/internal/testdata/correct.csv.empty.example.yaml new file mode 100644 index 000000000..2aa19870d --- /dev/null +++ b/pkg/validation/internal/testdata/correct.csv.empty.example.yaml @@ -0,0 +1,61 @@ +#! validate-crd: deploy/chart/templates/0000_30_02-clusterserviceversion.crd.yaml +#! parse-kind: ClusterServiceVersion +apiVersion: operators.coreos.com/v1alpha1 +kind: ClusterServiceVersion +metadata: + name: etcdoperator.v0.9.0 + namespace: placeholder + annotations: + "alm-examples": "" +spec: + version: 0.9.0 + installModes: + - type: AllNamespaces + supported: true + install: + strategy: deployment + spec: + permissions: + - serviceAccountName: etcd-operator + rules: + - apiGroups: + - etcd.database.coreos.com + resources: + - etcdclusters + - etcdbackups + - etcdrestores + verbs: + - "*" + deployments: + - name: etcd-operator + spec: + replicas: 1 + template: + metadata: + name: etcd-operator-alm-owned + labels: + name: etcd-operator-alm-owned + spec: + serviceAccountName: etcd-operator + containers: + - name: etcd-operator + command: + - etcd-operator + - --create-crd=false + image: quay.io/coreos/etcd-operator@sha256:db563baa8194fcfe39d1df744ed70024b0f1f9e9b55b5923c2f3a413c44dc6b8 + env: + - name: MY_POD_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: MY_POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + customresourcedefinitions: + owned: + - name: etcdclusters.etcd.database.coreos.com + version: v1beta2 + kind: EtcdCluster + +