Skip to content

feat: add warning for olm.properties being defined when validating csv #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/validation/errors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const (
ErrorInvalidBundle ErrorType = "BundleNotValid"
ErrorInvalidPackageManifest ErrorType = "PackageManifestNotValid"
ErrorObjectFailedValidation ErrorType = "ObjectFailedValidation"
ErrorPropertiesAnnotationUsed ErrorType = "PropertiesAnnotationUsed"
)

func NewError(t ErrorType, detail, field string, v interface{}) Error {
Expand Down Expand Up @@ -243,3 +244,7 @@ func invalidObject(lvl Level, detail string, value interface{}) Error {
func WarnInvalidObject(detail string, value interface{}) Error {
return failedValidation(LevelWarn, detail, value)
}

func WarnPropertiesAnnotationUsed(detail string) Error {
return Error{ErrorPropertiesAnnotationUsed, LevelWarn, "", "", detail}
}
17 changes: 15 additions & 2 deletions pkg/validation/internal/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/operator-framework/api/pkg/validation/errors"
)

const olmpropertiesAnnotation = "olm.properties"

// CaseSensitiveAnnotationKeySet is a set of annotation keys that are case sensitive
// and can be used for validation purposes. The key is always lowercase and the value
// contains the expected case sensitive string. This may not be an exhaustive list.
Expand All @@ -24,8 +26,9 @@ var CaseSensitiveAnnotationKeySet = map[string]string{
/*
ValidateAnnotationNames will check annotation keys to ensure they are using
proper case. Uses CaseSensitiveAnnotationKeySet as a source for keys
which are known to be case sensitive. This function can be used anywhere
annotations need to be checked for case sensitivity.
which are known to be case sensitive. It also checks to see if the olm.properties
annotation is defined in order to add a warning if present. This function can be
used anywhere annotations need to be checked for case sensitivity.

Arguments

Expand All @@ -48,6 +51,16 @@ func ValidateAnnotationNames(annotations map[string]string, value interface{}) (
errs = append(errs, errors.ErrFailedValidation(fmt.Sprintf("provided annotation %s uses wrong case and should be %s instead", annotationKey, knownCaseSensitiveKey), value))
}
}

if annotationKey == olmpropertiesAnnotation {
errs = append(
errs,
errors.WarnPropertiesAnnotationUsed(
fmt.Sprintf(
"found %s annotation, please define these properties in metadata/properties.yaml instead",
annotationKey,
)))
}
}
return errs
}
3 changes: 2 additions & 1 deletion pkg/validation/internal/community.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package internal
import (
"encoding/json"
"fmt"
"github.com/blang/semver"
"io/ioutil"
"os"
"strings"

"github.com/blang/semver"

"github.com/operator-framework/api/pkg/manifests"
"github.com/operator-framework/api/pkg/validation/errors"
interfaces "github.com/operator-framework/api/pkg/validation/interfaces"
Expand Down
19 changes: 18 additions & 1 deletion pkg/validation/internal/csv_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package internal

import (
"fmt"
"io/ioutil"
"k8s.io/apimachinery/pkg/runtime/schema"
"path/filepath"
"testing"

"github.com/ghodss/yaml"
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/operator-framework/api/pkg/validation/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
)

func TestValidateCSV(t *testing.T) {
Expand Down Expand Up @@ -91,7 +92,23 @@ func TestValidateCSV(t *testing.T) {
},
filepath.Join("testdata", "correct.csv.empty.example.yaml"),
},
{
validatorFuncTest{
description: "should warn when olm.properties are defined in the annotations",
wantWarn: true,
errors: []errors.Error{
errors.WarnPropertiesAnnotationUsed(
fmt.Sprintf(
"found %s annotation, please define these properties in metadata/properties.yaml instead",
olmpropertiesAnnotation,
),
),
},
},
filepath.Join("testdata", "correct.csv.olm.properties.annotation.yaml"),
},
}

for _, c := range cases {
b, err := ioutil.ReadFile(c.csvPath)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#! 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: '[{"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>"}}}]'
olm.properties: '[{"type": "foo", "value": "bar"}]'
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