Skip to content

Commit f8c87b6

Browse files
Merge pull request #95 from gallettilance/operatorhub-icon-fix
fix error on missing icon
2 parents 3a93b21 + 37e0a56 commit f8c87b6

7 files changed

+401
-10
lines changed

pkg/validation/errors/error.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,3 @@ func invalidObject(lvl Level, detail string, value interface{}) Error {
243243
func WarnInvalidObject(detail string, value interface{}) Error {
244244
return failedValidation(LevelWarn, detail, value)
245245
}
246-
247-
func WarnMissingIcon(detail string) Error {
248-
return failedValidation(LevelWarn, detail, "")
249-
}

pkg/validation/internal/operatorhub.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,19 @@ func validateBundleOperatorHub(bundle *manifests.Bundle) errors.ManifestResult {
7474
return result
7575
}
7676

77-
errs := validateHubCSVSpec(*bundle.CSV)
77+
errs, warns := validateHubCSVSpec(*bundle.CSV)
7878
for _, err := range errs {
7979
result.Add(errors.ErrInvalidCSV(err.Error(), bundle.CSV.GetName()))
8080
}
81-
81+
for _, warn := range warns {
82+
result.Add(errors.WarnInvalidCSV(warn.Error(), bundle.CSV.GetName()))
83+
}
8284
return result
8385
}
8486

85-
func validateHubCSVSpec(csv v1alpha1.ClusterServiceVersion) []error {
87+
func validateHubCSVSpec(csv v1alpha1.ClusterServiceVersion) ([]error, []error) {
8688
var errs []error
89+
var warns []error
8790

8891
if csv.Spec.Provider.Name == "" {
8992
errs = append(errs, fmt.Errorf("csv.Spec.Provider.Name not specified"))
@@ -146,7 +149,7 @@ func validateHubCSVSpec(csv v1alpha1.ClusterServiceVersion) []error {
146149
}
147150
}
148151
} else {
149-
errs = append(errs, errors.WarnMissingIcon("csv.Spec.Icon not specified"))
152+
warns = append(warns, fmt.Errorf("csv.Spec.Icon not specified"))
150153
}
151154

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

178-
return errs
181+
return errs, warns
179182
}
180183

181184
type categories struct {

pkg/validation/internal/operatorhub_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,47 @@ func TestExtractCategories(t *testing.T) {
128128
}
129129
}
130130
}
131+
132+
func TestWarnNoIcon(t *testing.T) {
133+
var table = []struct {
134+
description string
135+
directory string
136+
hasError bool
137+
errStrings []string
138+
warnStrings []string
139+
}{
140+
{
141+
description: "valid bundle no icon",
142+
directory: "./testdata/valid_bundle_no_icon",
143+
hasError: false,
144+
errStrings: []string{},
145+
warnStrings: []string{"Warning: Value : (etcdoperator.v0.9.4) csv.Spec.Icon not specified"},
146+
},
147+
}
148+
149+
for _, tt := range table {
150+
// Validate the bundle object
151+
bundle, err := manifests.GetBundleFromDir(tt.directory)
152+
require.NoError(t, err)
153+
154+
results := OperatorHubValidator.Validate(bundle)
155+
156+
if len(results) > 0 {
157+
require.Equal(t, tt.hasError, results[0].HasError())
158+
if results[0].HasError() {
159+
require.Equal(t, len(tt.errStrings), len(results[0].Errors))
160+
for _, err := range results[0].Errors {
161+
errString := err.Error()
162+
require.Contains(t, tt.errStrings, errString)
163+
}
164+
}
165+
if results[0].HasWarn() {
166+
require.Equal(t, len(tt.warnStrings), len(results[0].Warnings))
167+
for _, warn := range results[0].Warnings {
168+
warnString := warn.Error()
169+
require.Contains(t, tt.warnStrings, warnString)
170+
}
171+
}
172+
}
173+
}
174+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: etcdbackups.etcd.database.coreos.com
5+
spec:
6+
group: etcd.database.coreos.com
7+
names:
8+
kind: EtcdBackup
9+
listKind: EtcdBackupList
10+
plural: etcdbackups
11+
singular: etcdbackup
12+
scope: Namespaced
13+
version: v1beta2
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: etcdclusters.etcd.database.coreos.com
5+
spec:
6+
group: etcd.database.coreos.com
7+
names:
8+
kind: EtcdCluster
9+
listKind: EtcdClusterList
10+
plural: etcdclusters
11+
shortNames:
12+
- etcdclus
13+
- etcd
14+
singular: etcdcluster
15+
scope: Namespaced
16+
version: v1beta2

0 commit comments

Comments
 (0)