Skip to content

Commit 9228b2b

Browse files
committed
fix(validation): Remove default channel validation from bundle lib
It is not possible to determine if the default channel value is valid or not given we can "infer" default channel by using an emptry string. Also, author can add a default channel that is not listed in the channel list in some cases. As a result, the default channel is subjective and there is no methodology to validate it. Therefore, removing this validation will avoid any false positve. Signed-off-by: Vu Dinh <[email protected]>
1 parent b2ceacc commit 9228b2b

File tree

3 files changed

+5
-80
lines changed

3 files changed

+5
-80
lines changed

pkg/lib/bundle/generate.go

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -293,32 +293,6 @@ func ValidateAnnotations(existing, expected []byte) error {
293293
return utilerrors.NewAggregate(errs)
294294
}
295295

296-
// ValidateChannelDefault validates provided default channel to ensure it exists in
297-
// provided channel list.
298-
func ValidateChannelDefault(channels, channelDefault string) (string, error) {
299-
var chanDefault string
300-
var chanErr error
301-
channelList := strings.Split(channels, ",")
302-
303-
if containsString(channelList, "") {
304-
return chanDefault, fmt.Errorf("invalid channels are provided: %s", channels)
305-
}
306-
307-
if channelDefault != "" {
308-
for _, channel := range channelList {
309-
if channel == channelDefault {
310-
chanDefault = channelDefault
311-
break
312-
}
313-
}
314-
if chanDefault == "" {
315-
chanDefault = channelList[0]
316-
chanErr = fmt.Errorf(`The channel list "%s" doesn't contain channelDefault "%s"`, channels, channelDefault)
317-
}
318-
}
319-
return chanDefault, chanErr
320-
}
321-
322296
// GenerateAnnotations builds annotations.yaml with mediatype, manifests &
323297
// metadata directories in bundle image, package name, channels and default
324298
// channels information.
@@ -334,12 +308,7 @@ func GenerateAnnotations(mediaType, manifests, metadata, packageName, channels,
334308
},
335309
}
336310

337-
chanDefault, err := ValidateChannelDefault(channels, channelDefault)
338-
if err != nil {
339-
return nil, err
340-
}
341-
342-
annotations.Annotations[ChannelDefaultLabel] = chanDefault
311+
annotations.Annotations[ChannelDefaultLabel] = channelDefault
343312

344313
afile, err := yaml.Marshal(annotations)
345314
if err != nil {
@@ -355,11 +324,6 @@ func GenerateAnnotations(mediaType, manifests, metadata, packageName, channels,
355324
func GenerateDockerfile(mediaType, manifests, metadata, copyManifestDir, copyMetadataDir, workingDir, packageName, channels, channelDefault string) ([]byte, error) {
356325
var fileContent string
357326

358-
chanDefault, err := ValidateChannelDefault(channels, channelDefault)
359-
if err != nil {
360-
return nil, err
361-
}
362-
363327
relativeManifestDirectory, err := filepath.Rel(workingDir, copyManifestDir)
364328
if err != nil {
365329
return nil, err
@@ -379,7 +343,7 @@ func GenerateDockerfile(mediaType, manifests, metadata, copyManifestDir, copyMet
379343
fileContent += fmt.Sprintf("LABEL %s=%s\n", MetadataLabel, metadata)
380344
fileContent += fmt.Sprintf("LABEL %s=%s\n", PackageLabel, packageName)
381345
fileContent += fmt.Sprintf("LABEL %s=%s\n", ChannelsLabel, channels)
382-
fileContent += fmt.Sprintf("LABEL %s=%s\n\n", ChannelDefaultLabel, chanDefault)
346+
fileContent += fmt.Sprintf("LABEL %s=%s\n\n", ChannelDefaultLabel, channelDefault)
383347

384348
// CONTENT
385349
fileContent += fmt.Sprintf("COPY %s %s\n", relativeManifestDirectory, "/manifests/")

pkg/lib/bundle/generate_test.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -49,43 +49,6 @@ func TestGetMediaType(t *testing.T) {
4949
}
5050
}
5151

52-
func TestValidateChannelDefault(t *testing.T) {
53-
tests := []struct {
54-
channels string
55-
channelDefault string
56-
result string
57-
errorMsg string
58-
}{
59-
{
60-
"test5,test6",
61-
"",
62-
"",
63-
"",
64-
},
65-
{
66-
"test5,test6",
67-
"test7",
68-
"test5",
69-
`The channel list "test5,test6" doesn't contain channelDefault "test7"`,
70-
},
71-
{
72-
",",
73-
"",
74-
"",
75-
`invalid channels are provided: ,`,
76-
},
77-
}
78-
79-
for _, item := range tests {
80-
output, err := ValidateChannelDefault(item.channels, item.channelDefault)
81-
if item.errorMsg == "" {
82-
require.Equal(t, item.result, output)
83-
} else {
84-
require.Equal(t, item.errorMsg, err.Error())
85-
}
86-
}
87-
}
88-
8952
func TestValidateAnnotations(t *testing.T) {
9053
tests := []struct {
9154
existing []byte

pkg/lib/bundle/validate.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,18 @@ func validateAnnotations(mediaType string, fileAnnotations *AnnotationMetadata)
201201
aErr := fmt.Errorf("Expecting annotation %q to have value %q instead of %q", label, MetadataDir, val)
202202
validationErrors = append(validationErrors, aErr)
203203
}
204-
case ChannelsLabel, ChannelDefaultLabel:
204+
case ChannelsLabel:
205205
if val == "" {
206206
aErr := fmt.Errorf("Expecting annotation %q to have non-empty value", label)
207207
validationErrors = append(validationErrors, aErr)
208208
} else {
209209
annotations[label] = val
210210
}
211+
case ChannelDefaultLabel:
212+
annotations[label] = val
211213
}
212214
}
213215

214-
_, err := ValidateChannelDefault(annotations[ChannelsLabel], annotations[ChannelDefaultLabel])
215-
if err != nil {
216-
validationErrors = append(validationErrors, err)
217-
}
218216
return validationErrors
219217
}
220218

0 commit comments

Comments
 (0)