Skip to content

Commit f5469b4

Browse files
tylerslatonawgreene
authored andcommitted
feat: add warning for olm.properties being defined when validating csv (openshift#217)
Signed-off-by: Tyler Slaton <[email protected]> Upstream-repository: api Upstream-commit: 82aa2d40a842d73d317298585c2fcca1e45b3553
1 parent adb5f3a commit f5469b4

File tree

8 files changed

+122
-7
lines changed

8 files changed

+122
-7
lines changed

staging/api/pkg/validation/errors/error.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ const (
101101
ErrorInvalidBundle ErrorType = "BundleNotValid"
102102
ErrorInvalidPackageManifest ErrorType = "PackageManifestNotValid"
103103
ErrorObjectFailedValidation ErrorType = "ObjectFailedValidation"
104+
ErrorPropertiesAnnotationUsed ErrorType = "PropertiesAnnotationUsed"
104105
)
105106

106107
func NewError(t ErrorType, detail, field string, v interface{}) Error {
@@ -243,3 +244,7 @@ func invalidObject(lvl Level, detail string, value interface{}) Error {
243244
func WarnInvalidObject(detail string, value interface{}) Error {
244245
return failedValidation(LevelWarn, detail, value)
245246
}
247+
248+
func WarnPropertiesAnnotationUsed(detail string) Error {
249+
return Error{ErrorPropertiesAnnotationUsed, LevelWarn, "", "", detail}
250+
}

staging/api/pkg/validation/internal/annotations.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/operator-framework/api/pkg/validation/errors"
1010
)
1111

12+
const olmpropertiesAnnotation = "olm.properties"
13+
1214
// CaseSensitiveAnnotationKeySet is a set of annotation keys that are case sensitive
1315
// and can be used for validation purposes. The key is always lowercase and the value
1416
// contains the expected case sensitive string. This may not be an exhaustive list.
@@ -24,8 +26,9 @@ var CaseSensitiveAnnotationKeySet = map[string]string{
2426
/*
2527
ValidateAnnotationNames will check annotation keys to ensure they are using
2628
proper case. Uses CaseSensitiveAnnotationKeySet as a source for keys
27-
which are known to be case sensitive. This function can be used anywhere
28-
annotations need to be checked for case sensitivity.
29+
which are known to be case sensitive. It also checks to see if the olm.properties
30+
annotation is defined in order to add a warning if present. This function can be
31+
used anywhere annotations need to be checked for case sensitivity.
2932
3033
Arguments
3134
@@ -48,6 +51,16 @@ func ValidateAnnotationNames(annotations map[string]string, value interface{}) (
4851
errs = append(errs, errors.ErrFailedValidation(fmt.Sprintf("provided annotation %s uses wrong case and should be %s instead", annotationKey, knownCaseSensitiveKey), value))
4952
}
5053
}
54+
55+
if annotationKey == olmpropertiesAnnotation {
56+
errs = append(
57+
errs,
58+
errors.WarnPropertiesAnnotationUsed(
59+
fmt.Sprintf(
60+
"found %s annotation, please define these properties in metadata/properties.yaml instead",
61+
annotationKey,
62+
)))
63+
}
5164
}
5265
return errs
5366
}

staging/api/pkg/validation/internal/community.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package internal
33
import (
44
"encoding/json"
55
"fmt"
6-
"github.com/blang/semver"
76
"io/ioutil"
87
"os"
98
"strings"
109

10+
"github.com/blang/semver"
11+
1112
"github.com/operator-framework/api/pkg/manifests"
1213
"github.com/operator-framework/api/pkg/validation/errors"
1314
interfaces "github.com/operator-framework/api/pkg/validation/interfaces"

staging/api/pkg/validation/internal/csv_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package internal
22

33
import (
4+
"fmt"
45
"io/ioutil"
5-
"k8s.io/apimachinery/pkg/runtime/schema"
66
"path/filepath"
77
"testing"
88

99
"github.com/ghodss/yaml"
1010
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
1111
"github.com/operator-framework/api/pkg/validation/errors"
12+
"k8s.io/apimachinery/pkg/runtime/schema"
1213
)
1314

1415
func TestValidateCSV(t *testing.T) {
@@ -91,7 +92,23 @@ func TestValidateCSV(t *testing.T) {
9192
},
9293
filepath.Join("testdata", "correct.csv.empty.example.yaml"),
9394
},
95+
{
96+
validatorFuncTest{
97+
description: "should warn when olm.properties are defined in the annotations",
98+
wantWarn: true,
99+
errors: []errors.Error{
100+
errors.WarnPropertiesAnnotationUsed(
101+
fmt.Sprintf(
102+
"found %s annotation, please define these properties in metadata/properties.yaml instead",
103+
olmpropertiesAnnotation,
104+
),
105+
),
106+
},
107+
},
108+
filepath.Join("testdata", "correct.csv.olm.properties.annotation.yaml"),
109+
},
94110
}
111+
95112
for _, c := range cases {
96113
b, err := ioutil.ReadFile(c.csvPath)
97114
if err != nil {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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: '[{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdCluster","metadata":{"name":"example","namespace":"default"},"spec":{"size":3,"version":"3.2.13"}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdRestore","metadata":{"name":"example-etcd-cluster"},"spec":{"etcdCluster":{"name":"example-etcd-cluster"},"backupStorageType":"S3","s3":{"path":"<full-s3-path>","awsSecret":"<aws-secret>"}}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdBackup","metadata":{"name":"example-etcd-cluster-backup"},"spec":{"etcdEndpoints":["<etcd-cluster-endpoints>"],"storageType":"S3","s3":{"path":"<full-s3-path>","awsSecret":"<aws-secret>"}}}]'
10+
olm.properties: '[{"type": "foo", "value": "bar"}]'
11+
spec:
12+
version: 0.9.0
13+
installModes:
14+
- type: AllNamespaces
15+
supported: true
16+
install:
17+
strategy: deployment
18+
spec:
19+
permissions:
20+
- serviceAccountName: etcd-operator
21+
rules:
22+
- apiGroups:
23+
- etcd.database.coreos.com
24+
resources:
25+
- etcdclusters
26+
- etcdbackups
27+
- etcdrestores
28+
verbs:
29+
- "*"
30+
deployments:
31+
- name: etcd-operator
32+
spec:
33+
replicas: 1
34+
template:
35+
metadata:
36+
name: etcd-operator-alm-owned
37+
labels:
38+
name: etcd-operator-alm-owned
39+
spec:
40+
serviceAccountName: etcd-operator
41+
containers:
42+
- name: etcd-operator
43+
command:
44+
- etcd-operator
45+
- --create-crd=false
46+
image: quay.io/coreos/etcd-operator@sha256:db563baa8194fcfe39d1df744ed70024b0f1f9e9b55b5923c2f3a413c44dc6b8
47+
env:
48+
- name: MY_POD_NAMESPACE
49+
valueFrom:
50+
fieldRef:
51+
fieldPath: metadata.namespace
52+
- name: MY_POD_NAME
53+
valueFrom:
54+
fieldRef:
55+
fieldPath: metadata.name
56+
customresourcedefinitions:
57+
owned:
58+
- name: etcdclusters.etcd.database.coreos.com
59+
version: v1beta2
60+
kind: EtcdCluster

vendor/github.com/operator-framework/api/pkg/validation/errors/error.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/operator-framework/api/pkg/validation/internal/annotations.go

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/operator-framework/api/pkg/validation/internal/community.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)