Skip to content

Commit a574769

Browse files
camilamacedo86perdasilva
authored andcommitted
🌱 good practices validator nit clean up (openshift#240)
Upstream-repository: api Upstream-commit: 8d4b21341834007272aba7809945348594bf703f
1 parent bb036e1 commit a574769

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
//
2222
// - The channel names seems are not following the convention https://olm.operatorframework.io/docs/best-practices/channel-naming/
2323
//
24+
// - CRDs defined in the bundle have empty descriptions
2425
var GoodPracticesValidator interfaces.Validator = interfaces.ValidatorFunc(goodPracticesValidator)
2526

2627
func goodPracticesValidator(objs ...interface{}) (results []errors.ManifestResult) {
@@ -48,20 +49,20 @@ func validateGoodPracticesFrom(bundle *manifests.Bundle) errors.ManifestResult {
4849
}
4950

5051
errs, warns := validateResourceRequests(bundle.CSV)
52+
warns = append(warns, validateCrdDescriptions(bundle.CSV.Spec.CustomResourceDefinitions)...)
53+
warns = append(warns, validateHubChannels(bundle))
54+
5155
for _, err := range errs {
52-
result.Add(errors.ErrFailedValidation(err.Error(), bundle.CSV.GetName()))
56+
if err != nil {
57+
result.Add(errors.ErrFailedValidation(err.Error(), bundle.CSV.GetName()))
58+
}
5359
}
5460
for _, warn := range warns {
55-
result.Add(errors.WarnFailedValidation(warn.Error(), bundle.CSV.GetName()))
56-
}
57-
for _, warn := range validateCrdDescriptions(bundle.CSV.Spec.CustomResourceDefinitions) {
58-
result.Add(errors.WarnFailedValidation(warn.Error(), bundle.CSV.GetName()))
61+
if warn != nil {
62+
result.Add(errors.WarnFailedValidation(warn.Error(), bundle.CSV.GetName()))
63+
}
5964
}
6065

61-
channels := append(bundle.Channels, bundle.DefaultChannel)
62-
if warn := validateHubChannels(channels); warn != nil {
63-
result.Add(errors.WarnFailedValidation(warn.Error(), bundle.CSV.GetName()))
64-
}
6566
return result
6667
}
6768

@@ -90,7 +91,8 @@ func validateResourceRequests(csv *operatorsv1alpha1.ClusterServiceVersion) (err
9091
// validateHubChannels will check the channels. The motivation for the following check is to ensure that operators
9192
// authors knows if their operator bundles are or not respecting the Naming Convention Rules.
9293
// However, the operator authors still able to choose the names as please them.
93-
func validateHubChannels(channels []string) error {
94+
func validateHubChannels(bundle *manifests.Bundle) error {
95+
channels := append(bundle.Channels, bundle.DefaultChannel)
9496
const candidate = "candidate"
9597
const stable = "stable"
9698
const fast = "fast"
@@ -130,7 +132,7 @@ func getUniqueValues(array []string) []string {
130132
return result
131133
}
132134

133-
// validateCrdDescrptions ensures that all CRDs defined in the bundle have non-empty descriptions.
135+
// validateCrdDescriptions ensures that all CRDs defined in the bundle have non-empty descriptions.
134136
func validateCrdDescriptions(crds operatorsv1alpha1.CustomResourceDefinitions) []error {
135137
f := func(crds []operatorsv1alpha1.CRDDescription, relation string) []error {
136138
errors := make([]error, 0, len(crds))

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ func TestValidateHubChannels(t *testing.T) {
149149
}
150150
for _, tt := range tests {
151151
t.Run(tt.name, func(t *testing.T) {
152-
err := validateHubChannels(tt.args.channels)
152+
bundle, err := manifests.GetBundleFromDir("./testdata/valid_bundle")
153+
require.NoError(t, err)
154+
bundle.Channels = tt.args.channels
155+
err = validateHubChannels(bundle)
153156
if (err != nil) != tt.wantWarn {
154157
t.Errorf("validateHubChannels() error = %v, wantWarn %v", err, tt.wantWarn)
155158
}

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

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

0 commit comments

Comments
 (0)