Skip to content
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
59 changes: 33 additions & 26 deletions pkg/validation/internal/community.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func communityValidator(objs ...interface{}) (results []errors.ManifestResult) {
type CommunityOperatorChecks struct {
bundle manifests.Bundle
indexImagePath string
indexImage string
errs []error
warns []error
}
Expand Down Expand Up @@ -108,12 +107,11 @@ func checkMaxOpenShiftVersion(checks CommunityOperatorChecks, v1beta1MsgForResou
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 %s which are no "+
"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,
k8sApiDeprecatedInfo,
ocpVerV1beta1Unsupported,
v1beta1MsgForResourcesFound))
return checks
Expand Down Expand Up @@ -141,11 +139,10 @@ func checkMaxOpenShiftVersion(checks CommunityOperatorChecks, v1beta1MsgForResou
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 %s. Migrate the API(s) for %s or use the annotation",
"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,
k8sApiDeprecatedInfo,
v1beta1MsgForResourcesFound))
return checks
}
Expand All @@ -160,14 +157,13 @@ func checkMaxOpenShiftVersion(checks CommunityOperatorChecks, v1beta1MsgForResou

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 %s. "+
"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,
k8sApiDeprecatedInfo,
v1beta1MsgForResourcesFound,
ocpVerV1beta1Unsupported))
return checks
Expand All @@ -179,15 +175,14 @@ func checkMaxOpenShiftVersion(checks CommunityOperatorChecks, v1beta1MsgForResou
// 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 && len(checks.indexImage) == 0 {
if len(checks.indexImagePath) == 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleanup - not used.

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 %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,
k8sApiDeprecatedInfo))
IndexImagePathKey))
return checks
}

Expand Down Expand Up @@ -229,11 +224,8 @@ func validateImageFile(checks CommunityOperatorChecks, deprecatedAPImsg string)
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) on the LABEL %s. Migrate the API(s) "+
"for %s or use the OCP labels. (e.g. LABEL %s='4.6-4.8')",
checks.errs = append(checks.errs, fmt.Errorf("invalid syntax (%s) for (%s)",
line[i],
deprecatedAPImsg,
ocpLabelindex,
ocpLabelindex))
return checks
}
Expand All @@ -256,23 +248,32 @@ func validateImageFile(checks CommunityOperatorChecks, deprecatedAPImsg string)
}

if verParsed.GE(semVerOCPV1beta1Unsupported) {
checks.errs = append(checks.errs, fmt.Errorf("this bundle is %s. Migrate the API(s) "+
"for %s or use the OCP labels for compatible version(s). (e.g. LABEL %s='=v4.8')",
k8sApiDeprecatedInfo,
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
}
} else {
// 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 %s. "+
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 comatible version(s) via the labels. (e.g. LABEL %s='4.6-4.8')",
deprecatedAPImsg,
"%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
}
Expand All @@ -286,10 +287,15 @@ func validateImageFile(checks CommunityOperatorChecks, deprecatedAPImsg string)
}

if verParsed.GE(semVerOCPV1beta1Unsupported) {
checks.errs = append(checks.errs, fmt.Errorf("this bundle is %s. Upgrade the APIs from "+
"(v1beta1) to (v1) for %s or provide com[atible version(s) via the labels. (e.g. LABEL %s='4.6-4.8')",
k8sApiDeprecatedInfo,
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
}
Expand All @@ -304,9 +310,10 @@ func validateImageFile(checks CommunityOperatorChecks, deprecatedAPImsg string)
}
}
} else {
checks.errs = append(checks.errs, fmt.Errorf("this bundle is %s. Migrate the APIs "+
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')",
k8sApiDeprecatedInfo,
deprecatedAPImsg,
ocpLabelindex))
return checks
Expand Down
5 changes: 3 additions & 2 deletions pkg/validation/internal/operatorhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,11 @@ func validateHubDeprecatedAPIS(bundle *manifests.Bundle, versionProvided string)
semverMinKube.GE(semVerK8sVerV1betav1Unsupported)
// We only raise an error when the version >= 1.22 was informed via
// the k8s key/value option or is specifically defined in the CSV
msg := 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", deprecatedAPIsMessage)
if isUnsupported {
errs = append(errs, fmt.Errorf("this bundle is %s. Migrate the API(s) for %s", k8sApiDeprecatedInfo, deprecatedAPIsMessage))
errs = append(errs, msg)
} else {
warns = append(warns, fmt.Errorf("this bundle is %s. Migrate the API(s) for %s", k8sApiDeprecatedInfo, deprecatedAPIsMessage))
warns = append(warns, msg)
}
}
}
Expand Down
18 changes: 14 additions & 4 deletions pkg/validation/internal/operatorhub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,10 @@ func TestValidateHubDeprecatedAPIS(t *testing.T) {
directory: "./testdata/valid_bundle_v1beta1",
},
wantWarning: true,
warnStrings: []string{"this bundle is " + k8sApiDeprecatedInfo + ". Migrate the API(s) for CRD: ([\"etcdbackups.etcd.database.coreos.com\" \"etcdclusters.etcd.database.coreos.com\" \"etcdrestores.etcd.database.coreos.com\"])"},
warnStrings: []string{"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\"])"},
},
{
name: "should not return a warning or error when has minKubeVersion but the k8sVersion informed is <= 1.15",
Expand All @@ -395,7 +398,10 @@ func TestValidateHubDeprecatedAPIS(t *testing.T) {
directory: "./testdata/valid_bundle_v1beta1",
},
wantError: true,
errStrings: []string{"this bundle is " + k8sApiDeprecatedInfo + ". Migrate the API(s) for CRD: ([\"etcdbackups.etcd.database.coreos.com\" \"etcdclusters.etcd.database.coreos.com\" \"etcdrestores.etcd.database.coreos.com\"])"},
errStrings: []string{"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\"])"},
wantWarning: true,
warnStrings: []string{"checking APIs against Kubernetes version : 1.22"},
},
Expand All @@ -417,8 +423,12 @@ func TestValidateHubDeprecatedAPIS(t *testing.T) {
},
wantError: true,
wantWarning: true,
errStrings: []string{"unable to use csv.Spec.MinKubeVersion to verify the CRD/Webhook apis because it has an invalid value: invalid"},
warnStrings: []string{"this bundle is " + k8sApiDeprecatedInfo + ". Migrate the API(s) for CRD: ([\"etcdbackups.etcd.database.coreos.com\" \"etcdclusters.etcd.database.coreos.com\" \"etcdrestores.etcd.database.coreos.com\"])"},
errStrings: []string{"unable to use csv.Spec.MinKubeVersion to verify the CRD/Webhook apis because it " +
"has an invalid value: invalid"},
warnStrings: []string{"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\"])"},
},
}
for _, tt := range tests {
Expand Down
3 changes: 0 additions & 3 deletions pkg/validation/internal/removed_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

// k8sApiDeprecatedInfo define the message which will appears by default when is possible to identify that the project has deprecated API(s)
const k8sApiDeprecatedInfo = "using APIs which were deprecated and removed in v1.22. More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22"

// OCP version where the apis v1beta1 is no longer supported
const ocpVerV1beta1Unsupported = "4.9"

Expand Down