Skip to content

Commit

Permalink
Merge pull request #96 from estroz/bugfix/95-v0.4.x
Browse files Browse the repository at this point in the history
fix error on missing icon
  • Loading branch information
Eric Stroczynski authored Feb 1, 2021
2 parents 640da4e + 57e38d4 commit 775f204
Show file tree
Hide file tree
Showing 7 changed files with 401 additions and 10 deletions.
4 changes: 0 additions & 4 deletions pkg/validation/errors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,3 @@ func invalidObject(lvl Level, detail string, value interface{}) Error {
func WarnInvalidObject(detail string, value interface{}) Error {
return failedValidation(LevelWarn, detail, value)
}

func WarnMissingIcon(detail string) Error {
return failedValidation(LevelWarn, detail, "")
}
15 changes: 9 additions & 6 deletions pkg/validation/internal/operatorhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,19 @@ func validateBundleOperatorHub(bundle *manifests.Bundle) errors.ManifestResult {
return result
}

errs := validateHubCSVSpec(*bundle.CSV)
errs, warns := validateHubCSVSpec(*bundle.CSV)
for _, err := range errs {
result.Add(errors.ErrInvalidCSV(err.Error(), bundle.CSV.GetName()))
}

for _, warn := range warns {
result.Add(errors.WarnInvalidCSV(warn.Error(), bundle.CSV.GetName()))
}
return result
}

func validateHubCSVSpec(csv v1alpha1.ClusterServiceVersion) []error {
func validateHubCSVSpec(csv v1alpha1.ClusterServiceVersion) ([]error, []error) {
var errs []error
var warns []error

if csv.Spec.Provider.Name == "" {
errs = append(errs, fmt.Errorf("csv.Spec.Provider.Name not specified"))
Expand Down Expand Up @@ -146,7 +149,7 @@ func validateHubCSVSpec(csv v1alpha1.ClusterServiceVersion) []error {
}
}
} else {
errs = append(errs, errors.WarnMissingIcon("csv.Spec.Icon not specified"))
warns = append(warns, fmt.Errorf("csv.Spec.Icon not specified"))
}

if categories, ok := csv.ObjectMeta.Annotations["categories"]; ok {
Expand All @@ -158,7 +161,7 @@ func validateHubCSVSpec(csv v1alpha1.ClusterServiceVersion) []error {
customCategories, err := extractCategories(customCategoriesPath)
if err != nil {
errs = append(errs, fmt.Errorf("could not extract custom categories from categories %#v: %s", customCategories, err))
return errs
return errs, warns
}
for _, category := range categorySlice {
if _, ok := customCategories[strings.TrimSpace(category)]; !ok {
Expand All @@ -175,7 +178,7 @@ func validateHubCSVSpec(csv v1alpha1.ClusterServiceVersion) []error {
}
}

return errs
return errs, warns
}

type categories struct {
Expand Down
44 changes: 44 additions & 0 deletions pkg/validation/internal/operatorhub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,47 @@ func TestExtractCategories(t *testing.T) {
}
}
}

func TestWarnNoIcon(t *testing.T) {
var table = []struct {
description string
directory string
hasError bool
errStrings []string
warnStrings []string
}{
{
description: "valid bundle no icon",
directory: "./testdata/valid_bundle_no_icon",
hasError: false,
errStrings: []string{},
warnStrings: []string{"Warning: Value : (etcdoperator.v0.9.4) csv.Spec.Icon not specified"},
},
}

for _, tt := range table {
// Validate the bundle object
bundle, err := manifests.GetBundleFromDir(tt.directory)
require.NoError(t, err)

results := OperatorHubValidator.Validate(bundle)

if len(results) > 0 {
require.Equal(t, tt.hasError, results[0].HasError())
if results[0].HasError() {
require.Equal(t, len(tt.errStrings), len(results[0].Errors))
for _, err := range results[0].Errors {
errString := err.Error()
require.Contains(t, tt.errStrings, errString)
}
}
if results[0].HasWarn() {
require.Equal(t, len(tt.warnStrings), len(results[0].Warnings))
for _, warn := range results[0].Warnings {
warnString := warn.Error()
require.Contains(t, tt.warnStrings, warnString)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: etcdbackups.etcd.database.coreos.com
spec:
group: etcd.database.coreos.com
names:
kind: EtcdBackup
listKind: EtcdBackupList
plural: etcdbackups
singular: etcdbackup
scope: Namespaced
version: v1beta2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: etcdclusters.etcd.database.coreos.com
spec:
group: etcd.database.coreos.com
names:
kind: EtcdCluster
listKind: EtcdClusterList
plural: etcdclusters
shortNames:
- etcdclus
- etcd
singular: etcdcluster
scope: Namespaced
version: v1beta2
Loading

0 comments on commit 775f204

Please sign in to comment.