From 83fa808c8677ada20a37ed020949205de47a9eb7 Mon Sep 17 00:00:00 2001 From: Camila Macedo Date: Wed, 24 Nov 2021 19:53:43 +0000 Subject: [PATCH] remove community validator --- pkg/validation/internal/community.go | 340 ------------------ pkg/validation/internal/community_test.go | 242 ------------- .../bundle_without_label.Dockerfile | 17 - .../invalid_bundle_equals_upper.Dockerfile | 18 - .../invalid_bundle_range_upper.Dockerfile | 18 - ...invalid_bundle_range_upper_coma.Dockerfile | 18 - .../dockerfile/valid_bundle.Dockerfile | 18 - .../dockerfile/valid_bundle_4_8.Dockerfile | 18 - pkg/validation/validation.go | 5 - 9 files changed, 694 deletions(-) delete mode 100644 pkg/validation/internal/community.go delete mode 100644 pkg/validation/internal/community_test.go delete mode 100644 pkg/validation/internal/testdata/dockerfile/bundle_without_label.Dockerfile delete mode 100644 pkg/validation/internal/testdata/dockerfile/invalid_bundle_equals_upper.Dockerfile delete mode 100644 pkg/validation/internal/testdata/dockerfile/invalid_bundle_range_upper.Dockerfile delete mode 100644 pkg/validation/internal/testdata/dockerfile/invalid_bundle_range_upper_coma.Dockerfile delete mode 100644 pkg/validation/internal/testdata/dockerfile/valid_bundle.Dockerfile delete mode 100644 pkg/validation/internal/testdata/dockerfile/valid_bundle_4_8.Dockerfile diff --git a/pkg/validation/internal/community.go b/pkg/validation/internal/community.go deleted file mode 100644 index 3a42d7ec2..000000000 --- a/pkg/validation/internal/community.go +++ /dev/null @@ -1,340 +0,0 @@ -package internal - -import ( - "encoding/json" - "fmt" - "github.com/blang/semver" - "io/ioutil" - "os" - "strings" - - "github.com/operator-framework/api/pkg/manifests" - "github.com/operator-framework/api/pkg/validation/errors" - interfaces "github.com/operator-framework/api/pkg/validation/interfaces" -) - -// IndexImagePathKey defines the key which can be used by its consumers -// to inform where their index image path is to be checked -const IndexImagePathKey = "index-path" - -// ocpLabelindex defines the OCP label which allow configure the OCP versions -// where the bundle will be distributed -const ocpLabelindex = "com.redhat.openshift.versions" - -// OCP version where the apis v1beta1 is no longer supported -const ocpVerV1beta1Unsupported = "4.9" - -// CommunityOperatorValidator validates the bundle manifests against the required criteria to publish -// the projects on the community operators -// -// Note that this validator allows to receive a List of optional values as key=values. Currently, only the -// `index-path` key is allowed. If informed, it will check the labels on the image index according to its criteria. -var CommunityOperatorValidator interfaces.Validator = interfaces.ValidatorFunc(communityValidator) - -func communityValidator(objs ...interface{}) (results []errors.ManifestResult) { - - // Obtain the k8s version if informed via the objects an optional - var indexImagePath = "" - for _, obj := range objs { - switch obj.(type) { - case map[string]string: - indexImagePath = obj.(map[string]string)[IndexImagePathKey] - if len(indexImagePath) > 0 { - break - } - } - } - - for _, obj := range objs { - switch v := obj.(type) { - case *manifests.Bundle: - results = append(results, validateCommunityBundle(v, indexImagePath)) - } - } - - return results -} - -type CommunityOperatorChecks struct { - bundle manifests.Bundle - indexImagePath string - errs []error - warns []error -} - -// validateCommunityBundle will check the bundle against the community-operator criterias -func validateCommunityBundle(bundle *manifests.Bundle, indexImagePath string) errors.ManifestResult { - result := errors.ManifestResult{Name: bundle.Name} - if bundle == nil { - result.Add(errors.ErrInvalidBundle("Bundle is nil", nil)) - return result - } - - if bundle.CSV == nil { - result.Add(errors.ErrInvalidBundle("Bundle csv is nil", bundle.Name)) - return result - } - - checks := CommunityOperatorChecks{bundle: *bundle, indexImagePath: indexImagePath, errs: []error{}, warns: []error{}} - - deprecatedAPIs := getRemovedAPIsOn1_22From(bundle) - // Check if has deprecated apis then, check the olm.maxOpenShiftVersion property - if len(deprecatedAPIs) > 0 { - deprecatedAPIsMessage := generateMessageWithDeprecatedAPIs(deprecatedAPIs) - checks = checkMaxOpenShiftVersion(checks, deprecatedAPIsMessage) - checks = checkOCPLabelsWithHasDeprecatedAPIs(checks, deprecatedAPIsMessage) - for _, err := range checks.errs { - result.Add(errors.ErrInvalidCSV(err.Error(), bundle.CSV.GetName())) - } - for _, warn := range checks.warns { - result.Add(errors.WarnInvalidCSV(warn.Error(), bundle.CSV.GetName())) - } - } - - return result -} - -type propertiesAnnotation struct { - Type string - Value string -} - -// checkMaxOpenShiftVersion will verify if the OpenShiftVersion property was informed -func checkMaxOpenShiftVersion(checks CommunityOperatorChecks, v1beta1MsgForResourcesFound string) CommunityOperatorChecks { - // Ensure that has the OCPMaxAnnotation - const olmproperties = "olm.properties" - const olmmaxOpenShiftVersion = "olm.maxOpenShiftVersion" - semVerOCPV1beta1Unsupported, _ := semver.ParseTolerant(ocpVerV1beta1Unsupported) - - properties := checks.bundle.CSV.Annotations[olmproperties] - if len(properties) == 0 { - checks.errs = append(checks.errs, fmt.Errorf("csv.Annotations not specified %s for an "+ - "OCP version < %s. This annotation is required to prevent the user from upgrading their OCP cluster "+ - "before they have installed a version of their operator which is compatible with %s. This bundle is using APIs which were deprecated and removed in v1.22. More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22 which are no "+ - "longer supported on %s. Migrate the API(s) for %s or use the annotation", - olmmaxOpenShiftVersion, - ocpVerV1beta1Unsupported, - ocpVerV1beta1Unsupported, - ocpVerV1beta1Unsupported, - v1beta1MsgForResourcesFound)) - return checks - } - - var properList []propertiesAnnotation - if err := json.Unmarshal([]byte(properties), &properList); err != nil { - checks.errs = append(checks.errs, fmt.Errorf("csv.Annotations has an invalid value specified for %s. "+ - "Please, check the value (%s) and ensure that it is an array such as: "+ - "\"olm.properties\": '[{\"type\": \"key name\", \"value\": \"key value\"}]'", - olmproperties, properties)) - return checks - } - - hasOlmMaxOpenShiftVersion := false - olmMaxOpenShiftVersionValue := "" - for _, v := range properList { - if v.Type == olmmaxOpenShiftVersion { - hasOlmMaxOpenShiftVersion = true - olmMaxOpenShiftVersionValue = v.Value - break - } - } - - if !hasOlmMaxOpenShiftVersion { - checks.errs = append(checks.errs, fmt.Errorf("csv.Annotations.%s with the "+ - "key `%s` and a value with an OCP version which is < %s is required for any operator "+ - "bundle that is using APIs which were deprecated and removed in v1.22. More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. Migrate the API(s) for %s or use the annotation", - olmproperties, - olmmaxOpenShiftVersion, - ocpVerV1beta1Unsupported, - v1beta1MsgForResourcesFound)) - return checks - } - - semVerVersionMaxOcp, err := semver.ParseTolerant(olmMaxOpenShiftVersionValue) - if err != nil { - checks.errs = append(checks.errs, fmt.Errorf("csv.Annotations.%s has an invalid value. "+ - "Unable to parse (%s) using semver : %s", - olmproperties, olmMaxOpenShiftVersionValue, err)) - return checks - } - - truncatedMaxOcp := semver.Version{Major: semVerVersionMaxOcp.Major, Minor: semVerVersionMaxOcp.Minor} - if !semVerVersionMaxOcp.EQ(truncatedMaxOcp) { - checks.warns = append(checks.warns, fmt.Errorf("csv.Annotations.%s has an invalid value. "+ - "%s must specify only major.minor versions, %s will be truncated to %s", - olmproperties, olmmaxOpenShiftVersion, semVerVersionMaxOcp, truncatedMaxOcp)) - return checks - } - - if semVerVersionMaxOcp.GE(semVerOCPV1beta1Unsupported) { - checks.errs = append(checks.errs, fmt.Errorf("csv.Annotations.%s with the "+ - "key and value for %s has the OCP version value %s which is >= of %s. This bundle is using APIs which were deprecated and removed in v1.22. More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. "+ - "Migrate the API(s) for %s "+ - "or inform in this property an OCP version which is < %s", - olmproperties, - olmmaxOpenShiftVersion, - olmMaxOpenShiftVersionValue, - ocpVerV1beta1Unsupported, - v1beta1MsgForResourcesFound, - ocpVerV1beta1Unsupported)) - return checks - } - - return checks -} - -// checkOCPLabels will ensure that OCP labels are set and with a ocp target < 4.9 -func checkOCPLabelsWithHasDeprecatedAPIs(checks CommunityOperatorChecks, deprecatedAPImsg string) CommunityOperatorChecks { - // Note that we cannot make mandatory because the package format still valid - if len(checks.indexImagePath) == 0 { - checks.warns = append(checks.errs, fmt.Errorf("please, inform the path of "+ - "its index image file via the the optional key values and the key %s to allow this validator check the labels "+ - "configuration or migrate the API(s) for %s. "+ - "(e.g. %s=./mypath/bundle.Dockerfile). This bundle is using APIs which were deprecated and removed in v1.22. More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22 ", - IndexImagePathKey, - deprecatedAPImsg, - IndexImagePathKey)) - return checks - } - - return validateImageFile(checks, deprecatedAPImsg) -} - -func validateImageFile(checks CommunityOperatorChecks, deprecatedAPImsg string) CommunityOperatorChecks { - if len(checks.indexImagePath) == 0 { - return checks - } - - info, err := os.Stat(checks.indexImagePath) - if err != nil { - checks.errs = append(checks.errs, fmt.Errorf("the index image in the path "+ - "(%s) was not found. Please, inform the path of the bundle operator index image via the the optional key values and the key %s. "+ - "(e.g. %s=./mypath/bundle.Dockerfile). Error : %s", checks.indexImagePath, IndexImagePathKey, IndexImagePathKey, err)) - return checks - } - if info.IsDir() { - checks.errs = append(checks.errs, fmt.Errorf("the index image in the path "+ - "(%s) is not file. Please, inform the path of its index image via the the optional key values and the key %s. "+ - "(e.g. %s=./mypath/bundle.Dockerfile). The value informed is a diretory and not a file", checks.indexImagePath, IndexImagePathKey, IndexImagePathKey)) - return checks - } - - b, err := ioutil.ReadFile(checks.indexImagePath) - if err != nil { - checks.errs = append(checks.errs, fmt.Errorf("unable to read the index image in the path "+ - "(%s). Error : %s", checks.indexImagePath, err)) - return checks - } - - indexPathContent := string(b) - hasOCPLabel := strings.Contains(indexPathContent, ocpLabelindex) - if hasOCPLabel { - semVerOCPV1beta1Unsupported, _ := semver.ParseTolerant(ocpVerV1beta1Unsupported) - // the OCP range informed cannot allow carry on to OCP 4.9+ - line := strings.Split(indexPathContent, "\n") - for i := 0; i < len(line); i++ { - if strings.Contains(line[i], ocpLabelindex) { - if !strings.Contains(line[i], "=") { - checks.errs = append(checks.errs, fmt.Errorf("invalid syntax (%s) for (%s)", - line[i], - ocpLabelindex)) - return checks - } - - value := strings.Split(line[i], "=") - // It means that the OCP label is =OCP version - if len(value) > 2 && len(value[2]) > 0 { - version := cleanStringToGetTheVersionToParse(value[2]) - verParsed, err := semver.ParseTolerant(version) - if err != nil { - checks.errs = append(checks.errs, fmt.Errorf("unable to parse the value (%s) on (%s)", - version, ocpLabelindex)) - return checks - } - - if verParsed.GE(semVerOCPV1beta1Unsupported) { - checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were "+ - "deprecated and removed in v1.22. "+ - "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. "+ - "Migrate the API(s) for "+ - "%s or provide compatible version(s) by using the %s annotation in "+ - "`metadata/annotations.yaml` to ensure that the index image will be geneared "+ - "with its label. (e.g. LABEL %s='4.6-4.8')", - deprecatedAPImsg, - ocpLabelindex, - ocpLabelindex)) - return checks - } - return checks - } - indexRange := cleanStringToGetTheVersionToParse(value[1]) - if len(indexRange) > 1 { - // if has the = then, the value needs to be < 4.9 - // if not has not the = then the value needs contains - value less < 4.9 - if !strings.Contains(indexRange, "-") { - checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were "+ - "deprecated and removed in v1.22. "+ - "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22 "+ - "The %s allows to distribute it on >= %s. Migrate the API(s) for "+ - "%s or provide compatible version(s) by using the %s annotation in "+ - "`metadata/annotations.yaml` to ensure that the index image will be generated "+ - "with its label. (e.g. LABEL %s='4.6-4.8')", - indexRange, - ocpVerV1beta1Unsupported, - deprecatedAPImsg, - ocpLabelindex, - ocpLabelindex)) - return checks - } - - version := strings.Split(indexRange, "-")[1] - verParsed, err := semver.ParseTolerant(version) - if err != nil { - checks.errs = append(checks.errs, fmt.Errorf("unable to parse the value (%s) on (%s)", - version, ocpLabelindex)) - return checks - } - - if verParsed.GE(semVerOCPV1beta1Unsupported) { - checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were "+ - "deprecated and removed in v1.22. "+ - "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. "+ - "Upgrade the APIs from "+ - "for %s or provide compatible distribution version(s) by using the %s "+ - "annotation in `metadata/annotations.yaml` to ensure that the index image will "+ - "be generated with its label. (e.g. LABEL %s='4.6-4.8')", - deprecatedAPImsg, - ocpLabelindex, - ocpLabelindex)) - return checks - } - } else { - checks.errs = append(checks.errs, fmt.Errorf("unable to get the range informed on %s", - ocpLabelindex)) - return checks - } - break - } - } - } else { - checks.errs = append(checks.errs, fmt.Errorf("this bundle is using APIs which were deprecated and "+ - "removed in v1.22. More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. "+ - "Migrate the APIs "+ - "for %s or provide compatible version(s) via the labels. (e.g. LABEL %s='4.6-4.8')", - deprecatedAPImsg, - ocpLabelindex)) - return checks - } - return checks -} - -// cleanStringToGetTheVersionToParse will remove the expected characters for -// we are able to parse the version informed. -func cleanStringToGetTheVersionToParse(value string) string { - doubleQuote := "\"" - singleQuote := "'" - value = strings.ReplaceAll(value, singleQuote, "") - value = strings.ReplaceAll(value, doubleQuote, "") - value = strings.ReplaceAll(value, "v", "") - return value -} diff --git a/pkg/validation/internal/community_test.go b/pkg/validation/internal/community_test.go deleted file mode 100644 index 0f91e8934..000000000 --- a/pkg/validation/internal/community_test.go +++ /dev/null @@ -1,242 +0,0 @@ -package internal - -import ( - "fmt" - "github.com/operator-framework/api/pkg/manifests" - "github.com/stretchr/testify/require" - "testing" -) - -func Test_communityValidator(t *testing.T) { - type args struct { - annotations map[string]string - bundleDir string - imageIndexPath string - } - tests := []struct { - name string - args args - wantError bool - wantWarning bool - errStrings []string - warnStrings []string - }{ - { - name: "should work successfully when no deprecated apis are found and has not the annotations or ocp index labels", - wantError: false, - args: args{ - bundleDir: "./testdata/valid_bundle_v1", - }, - }, - { - name: "should pass when the olm annotation and index label are set with a " + - "value < 4.9 and has deprecated apis", - wantError: false, - args: args{ - bundleDir: "./testdata/valid_bundle_v1beta1", - imageIndexPath: "./testdata/dockerfile/valid_bundle.Dockerfile", - annotations: map[string]string{ - "olm.properties": fmt.Sprintf(`[{"type": "olm.maxOpenShiftVersion", "value": "4.8"}]`), - }, - }, - }, - { - name: "should fail because is missing the olm.annotation and has deprecated apis", - wantError: true, - args: args{ - bundleDir: "./testdata/valid_bundle_v1beta1", - imageIndexPath: "./testdata/dockerfile/valid_bundle.Dockerfile", - }, - errStrings: []string{"Error: Value : (etcdoperator.v0.9.4) csv.Annotations not specified " + - "olm.maxOpenShiftVersion for an OCP version < 4.9. This annotation is required to " + - "prevent the user from upgrading their OCP cluster before they have installed a " + - "version of their operator which is compatible with 4.9. " + - "This bundle is using APIs which were deprecated and removed in v1.22. " + - "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22 which are no " + - "longer supported on 4.9. Migrate the API(s) for CRD: ([\"etcdbackups.etcd.database.coreos.com\" \"etcdclusters.etcd.database.coreos.com\" \"etcdrestores.etcd.database.coreos.com\"]) or use the annotation"}, - }, - { - name: "should fail when the olm annotation is set without the properties for max ocp version and has " + - "deprecated apis", - wantError: true, - args: args{ - bundleDir: "./testdata/valid_bundle_v1beta1", - imageIndexPath: "./testdata/dockerfile/valid_bundle.Dockerfile", - annotations: map[string]string{ - "olm.properties": fmt.Sprintf(`[{"type": "olm.invalid", "value": "4.9"}]`), - }, - }, - errStrings: []string{"Error: Value : (etcdoperator.v0.9.4) csv.Annotations.olm.properties with the key " + - "`olm.maxOpenShiftVersion` and a value with an OCP version which is < 4.9 is required for any operator " + - "bundle that is using APIs which were deprecated and removed in v1.22. More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. " + - "Migrate the API(s) for CRD: ([\"etcdbackups.etcd.database.coreos.com\" \"etcdclusters.etcd.database.coreos.com\" \"etcdrestores.etcd.database.coreos.com\"]) " + - "or use the annotation"}, - }, - { - name: "should fail when the olm annotation is set with a value >= 4.9 and has deprecated apis", - wantError: true, - args: args{ - bundleDir: "./testdata/valid_bundle_v1beta1", - imageIndexPath: "./testdata/dockerfile/valid_bundle.Dockerfile", - annotations: map[string]string{ - "olm.properties": fmt.Sprintf(`[{"type": "olm.maxOpenShiftVersion", "value": "4.9"}]`), - }, - }, - errStrings: []string{"Error: Value : (etcdoperator.v0.9.4) csv.Annotations.olm.properties with the key " + - "and value for olm.maxOpenShiftVersion has the OCP version value 4.9 which is >= of 4.9. " + - "This bundle is using APIs which were deprecated and removed in v1.22. More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22." + - " Migrate the API(s) for CRD: ([\"etcdbackups.etcd.database.coreos.com\" \"etcdclusters.etcd.database.coreos.com\" \"etcdrestores.etcd.database.coreos.com\"]) or inform in this property an OCP version which is < 4.9"}, - }, - { - name: "should warning because is missing the index-path and has deprecated apis", - wantWarning: true, - args: args{ - bundleDir: "./testdata/valid_bundle_v1beta1", - annotations: map[string]string{ - "olm.properties": fmt.Sprintf(`[{"type": "olm.maxOpenShiftVersion", "value": "4.8"}]`), - }, - }, - warnStrings: []string{"Warning: Value : (etcdoperator.v0.9.4) please, inform the path of its index image " + - "file via the the optional key values and the key index-path to allow this validator check the labels " + - "configuration or migrate the API(s) for CRD: " + - "([\"etcdbackups.etcd.database.coreos.com\" \"etcdclusters.etcd.database.coreos.com\" " + - "\"etcdrestores.etcd.database.coreos.com\"]). (e.g. index-path=./mypath/bundle.Dockerfile). " + - "This bundle is using APIs which were deprecated and removed in v1.22. " + - "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22 "}, - }, - { - name: "should warn on patch version in maxOpenShiftVersion", - wantWarning: true, - args: args{ - bundleDir: "./testdata/valid_bundle_v1beta1", - imageIndexPath: "./testdata/dockerfile/valid_bundle.Dockerfile", - annotations: map[string]string{ - "olm.properties": fmt.Sprintf(`[{"type": "olm.maxOpenShiftVersion", "value": "4.8.1"}]`), - }, - }, - warnStrings: []string{ - "Warning: Value : (etcdoperator.v0.9.4) csv.Annotations.olm.properties has an invalid value. olm.maxOpenShiftVersion must specify only major.minor versions, 4.8.1 will be truncated to 4.8.0", - }, - }, - { - name: "should pass when the maxOpenShiftVersion is semantically equivalent to ..0", - wantError: false, - args: args{ - bundleDir: "./testdata/valid_bundle_v1beta1", - imageIndexPath: "./testdata/dockerfile/valid_bundle.Dockerfile", - annotations: map[string]string{ - "olm.properties": fmt.Sprintf(`[{"type": "olm.maxOpenShiftVersion", "value": "4.8.0+build"}]`), - }, - }, - }, - { - name: "should pass when the olm annotation and index label are set with a " + - "value =v4.8 and has deprecated apis", - wantError: false, - args: args{ - bundleDir: "./testdata/valid_bundle_v1beta1", - imageIndexPath: "./testdata/dockerfile/valid_bundle_4_8.Dockerfile", - annotations: map[string]string{ - "olm.properties": fmt.Sprintf(`[{"type": "olm.maxOpenShiftVersion", "value": "4.8"}]`), - }, - }, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - - // Validate the bundle object - bundle, err := manifests.GetBundleFromDir(tt.args.bundleDir) - require.NoError(t, err) - - if len(tt.args.annotations) > 0 { - bundle.CSV.Annotations = tt.args.annotations - } - - results := validateCommunityBundle(bundle, tt.args.imageIndexPath) - require.Equal(t, tt.wantWarning, len(results.Warnings) > 0) - if tt.wantWarning { - require.Equal(t, len(tt.warnStrings), len(results.Warnings)) - for _, w := range results.Warnings { - wString := w.Error() - require.Contains(t, tt.warnStrings, wString) - } - } - - require.Equal(t, tt.wantError, len(results.Errors) > 0) - if tt.wantError { - require.Equal(t, len(tt.errStrings), len(results.Errors)) - for _, err := range results.Errors { - errString := err.Error() - require.Contains(t, tt.errStrings, errString) - } - } - }) - } -} - -func Test_checkOCPLabelsWithHasDeprecatedAPIs(t *testing.T) { - type args struct { - checks CSVChecks - indexPath string - } - tests := []struct { - name string - args args - wantError bool - wantWarning bool - }{ - { - name: "should pass when has a valid value for the OCP labels", - args: args{ - indexPath: "./testdata/dockerfile/valid_bundle.Dockerfile", - }, - }, - { - name: "should fail when the OCP label is not found", - wantError: true, - args: args{ - indexPath: "./testdata/dockerfile/bundle_without_label.Dockerfile", - }, - }, - { - name: "should fail when the the index path is an invalid path", - wantError: true, - args: args{ - indexPath: "./testdata/dockerfile/invalid", - }, - }, - { - name: "should fail when the OCP label index is => 4.9", - wantError: true, - args: args{ - indexPath: "./testdata/dockerfile/invalid_bundle_equals_upper.Dockerfile", - }, - }, - { - name: "should fail when the OCP label index range is => 4.9", - wantError: true, - args: args{ - indexPath: "./testdata/dockerfile/invalid_bundle_range_upper.Dockerfile", - }, - }, - { - name: "should fail when the OCP label index range is => 4.9 with coma e.g. v4.5,4.6", - wantError: true, - args: args{ - indexPath: "./testdata/dockerfile/invalid_bundle_range_upper.Dockerfile", - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - checks := CommunityOperatorChecks{bundle: manifests.Bundle{}, indexImagePath: tt.args.indexPath, errs: []error{}, warns: []error{}} - - checks = checkOCPLabelsWithHasDeprecatedAPIs(checks, "CRD: ([\"etcdbackups.etcd.database.coreos.com\" \"etcdclusters.etcd.database.coreos.com\" \"etcdrestores.etcd.database.coreos.com\"])") - - require.Equal(t, tt.wantWarning, len(checks.warns) > 0) - require.Equal(t, tt.wantError, len(checks.errs) > 0) - }) - } -} diff --git a/pkg/validation/internal/testdata/dockerfile/bundle_without_label.Dockerfile b/pkg/validation/internal/testdata/dockerfile/bundle_without_label.Dockerfile deleted file mode 100644 index 432577b95..000000000 --- a/pkg/validation/internal/testdata/dockerfile/bundle_without_label.Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM scratch - -# Core bundle labels. -LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1 -LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/ -LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ -LABEL operators.operatorframework.io.bundle.package.v1=memcached-operator -LABEL operators.operatorframework.io.bundle.channels.v1=alpha - -# Labels for testing. -LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1 -LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/ - -# Copy files to locations specified by labels. -COPY bundle/manifests /manifests/ -COPY bundle/metadata /metadata/ -COPY bundle/tests/scorecard /tests/scorecard/ diff --git a/pkg/validation/internal/testdata/dockerfile/invalid_bundle_equals_upper.Dockerfile b/pkg/validation/internal/testdata/dockerfile/invalid_bundle_equals_upper.Dockerfile deleted file mode 100644 index 46cf02769..000000000 --- a/pkg/validation/internal/testdata/dockerfile/invalid_bundle_equals_upper.Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM scratch - -# Core bundle labels. -LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1 -LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/ -LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ -LABEL operators.operatorframework.io.bundle.package.v1=memcached-operator -LABEL operators.operatorframework.io.bundle.channels.v1=alpha -LABEL com.redhat.openshift.versions="=v4.9" - -# Labels for testing. -LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1 -LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/ - -# Copy files to locations specified by labels. -COPY bundle/manifests /manifests/ -COPY bundle/metadata /metadata/ -COPY bundle/tests/scorecard /tests/scorecard/ diff --git a/pkg/validation/internal/testdata/dockerfile/invalid_bundle_range_upper.Dockerfile b/pkg/validation/internal/testdata/dockerfile/invalid_bundle_range_upper.Dockerfile deleted file mode 100644 index 470d5cee3..000000000 --- a/pkg/validation/internal/testdata/dockerfile/invalid_bundle_range_upper.Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM scratch - -# Core bundle labels. -LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1 -LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/ -LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ -LABEL operators.operatorframework.io.bundle.package.v1=memcached-operator -LABEL operators.operatorframework.io.bundle.channels.v1=alpha -LABEL com.redhat.openshift.versions="v4.6-v4.9" - -# Labels for testing. -LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1 -LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/ - -# Copy files to locations specified by labels. -COPY bundle/manifests /manifests/ -COPY bundle/metadata /metadata/ -COPY bundle/tests/scorecard /tests/scorecard/ diff --git a/pkg/validation/internal/testdata/dockerfile/invalid_bundle_range_upper_coma.Dockerfile b/pkg/validation/internal/testdata/dockerfile/invalid_bundle_range_upper_coma.Dockerfile deleted file mode 100644 index 5c98da76a..000000000 --- a/pkg/validation/internal/testdata/dockerfile/invalid_bundle_range_upper_coma.Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM scratch - -# Core bundle labels. -LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1 -LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/ -LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ -LABEL operators.operatorframework.io.bundle.package.v1=memcached-operator -LABEL operators.operatorframework.io.bundle.channels.v1=alpha -LABEL com.redhat.openshift.versions="v4.6,v4.7" - -# Labels for testing. -LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1 -LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/ - -# Copy files to locations specified by labels. -COPY bundle/manifests /manifests/ -COPY bundle/metadata /metadata/ -COPY bundle/tests/scorecard /tests/scorecard/ diff --git a/pkg/validation/internal/testdata/dockerfile/valid_bundle.Dockerfile b/pkg/validation/internal/testdata/dockerfile/valid_bundle.Dockerfile deleted file mode 100644 index 03d1ef427..000000000 --- a/pkg/validation/internal/testdata/dockerfile/valid_bundle.Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM scratch - -# Core bundle labels. -LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1 -LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/ -LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ -LABEL operators.operatorframework.io.bundle.package.v1=memcached-operator -LABEL operators.operatorframework.io.bundle.channels.v1=alpha -LABEL com.redhat.openshift.versions="v4.6-v4.8" - -# Labels for testing. -LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1 -LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/ - -# Copy files to locations specified by labels. -COPY bundle/manifests /manifests/ -COPY bundle/metadata /metadata/ -COPY bundle/tests/scorecard /tests/scorecard/ diff --git a/pkg/validation/internal/testdata/dockerfile/valid_bundle_4_8.Dockerfile b/pkg/validation/internal/testdata/dockerfile/valid_bundle_4_8.Dockerfile deleted file mode 100644 index 9f96edfb6..000000000 --- a/pkg/validation/internal/testdata/dockerfile/valid_bundle_4_8.Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM scratch - -# Core bundle labels. -LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1 -LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/ -LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ -LABEL operators.operatorframework.io.bundle.package.v1=memcached-operator -LABEL operators.operatorframework.io.bundle.channels.v1=alpha -LABEL com.redhat.openshift.versions="=v4.8" - -# Labels for testing. -LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1 -LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/ - -# Copy files to locations specified by labels. -COPY bundle/manifests /manifests/ -COPY bundle/metadata /metadata/ -COPY bundle/tests/scorecard /tests/scorecard/ diff --git a/pkg/validation/validation.go b/pkg/validation/validation.go index 3c35db4b1..f68ccb174 100644 --- a/pkg/validation/validation.go +++ b/pkg/validation/validation.go @@ -38,10 +38,6 @@ var ObjectValidator = internal.ObjectValidator // OperatorGroupValidator implements Validator to validate OperatorGroup manifests var OperatorGroupValidator = internal.OperatorGroupValidator -// CommunityOperatorValidator implements Validator to validate bundle objects -// for the Community Operator requirements. -var CommunityOperatorValidator = internal.CommunityOperatorValidator - // AlphaDeprecatedAPIsValidator implements Validator to validate bundle objects // for API deprecation requirements. var AlphaDeprecatedAPIsValidator = internal.AlphaDeprecatedAPIsValidator @@ -55,7 +51,6 @@ var AllValidators = interfaces.Validators{ OperatorHubValidator, ObjectValidator, OperatorGroupValidator, - CommunityOperatorValidator, AlphaDeprecatedAPIsValidator, }