Skip to content
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

Add CRD description check validation #234

Merged
merged 1 commit into from
Apr 5, 2022
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
18 changes: 18 additions & 0 deletions pkg/validation/internal/good_practices.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func validateGoodPracticesFrom(bundle *manifests.Bundle) errors.ManifestResult {
for _, warn := range warns {
result.Add(errors.WarnFailedValidation(warn.Error(), bundle.CSV.GetName()))
}
for _, warn := range validateCrdDescriptions(bundle.CSV.Spec.CustomResourceDefinitions) {
result.Add(errors.WarnFailedValidation(warn.Error(), bundle.CSV.GetName()))
}

channels := append(bundle.Channels, bundle.DefaultChannel)
if warn := validateHubChannels(channels); warn != nil {
Expand Down Expand Up @@ -126,3 +129,18 @@ func getUniqueValues(array []string) []string {
}
return result
}

// validateCrdDescrptions ensures that all CRDs defined in the bundle have non-empty descriptions.
func validateCrdDescriptions(crds operatorsv1alpha1.CustomResourceDefinitions) []error {
f := func(crds []operatorsv1alpha1.CRDDescription, relation string) []error {
errors := make([]error, 0, len(crds))
for _, crd := range crds {
if crd.Description == "" {
errors = append(errors, fmt.Errorf("%s CRD %q has an empty description", relation, crd.Name))
}
}
return errors
}

return append(f(crds.Owned, "owned"), f(crds.Required, "required")...)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

@camilamacedo86 camilamacedo86 Apr 4, 2022

Choose a reason for hiding this comment

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

feel free to close sorted out. :-)

14 changes: 13 additions & 1 deletion pkg/validation/internal/good_practices_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package internal

import (
"testing"

"github.com/operator-framework/api/pkg/manifests"
"github.com/stretchr/testify/require"
"testing"
)

func Test_ValidateGoodPractices(t *testing.T) {
bundleWithDeploymentSpecEmpty, _ := manifests.GetBundleFromDir("./testdata/valid_bundle")
bundleWithDeploymentSpecEmpty.CSV.Spec.InstallStrategy.StrategySpec.DeploymentSpecs = nil

bundleWithMissingCrdDescription, _ := manifests.GetBundleFromDir("./testdata/valid_bundle")
bundleWithMissingCrdDescription.CSV.Spec.CustomResourceDefinitions.Owned[0].Description = ""

type args struct {
bundleDir string
bundle *manifests.Bundle
Expand Down Expand Up @@ -70,6 +74,14 @@ func Test_ValidateGoodPractices(t *testing.T) {
},
warnStrings: []string{"Warning: Value memcached-operator.v0.0.1: channel(s) [\"alpha\"] are not following the recommended naming convention: https://olm.operatorframework.io/docs/best-practices/channel-naming"},
},
{
name: "should raise a warn when a CRD does not have a description",
wantWarning: true,
args: args{
bundle: bundleWithMissingCrdDescription,
},
warnStrings: []string{"Warning: Value etcdoperator.v0.9.4: owned CRD \"etcdclusters.etcd.database.coreos.com\" has an empty description"},
},
}

for _, tt := range tests {
Expand Down