Skip to content

Commit aeb7d91

Browse files
committedSep 23, 2020
The default channel info/annotation is optional & not required
The default channel annotation is no longer required as default channel information is now optional. Users may provide default channel if they intend to update default channel information in the index/DB. The default channel may still be infered if package.yaml is present. If the default channel cannot be infered, then the default channel will be omitted. Bundle validation will no longer error out if default channel annotation is missing. Signed-off-by: Vu Dinh <[email protected]>
1 parent 0e50c92 commit aeb7d91

File tree

5 files changed

+24
-28
lines changed

5 files changed

+24
-28
lines changed
 

‎docs/design/operator-bundle.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ We use the following labels to annotate the operator bundle image.
4545
* The value `metadata.v1` implies that this bundle has operator metadata.
4646
* The label `operators.operatorframework.io.bundle.package.v1` reflects the package name of the bundle.
4747
* The label `operators.operatorframework.io.bundle.channels.v1` reflects the list of channels the bundle is subscribing to when added into an operator registry
48-
* The label `operators.operatorframework.io.bundle.channel.default.v1` reflects the default channel an operator should be subscribed to when installed from a registry
48+
* The label `operators.operatorframework.io.bundle.channel.default.v1` reflects the default channel an operator should be subscribed to when installed from a registry. This label is optional if the default channel has been set by previous bundles and the default channel is unchanged for this bundle.
4949

5050
The labels will also be put inside a YAML file, as shown below.
5151

@@ -240,7 +240,7 @@ $ ./opm alpha bundle build --directory /test/0.1.0/ --tag quay.io/coreos/test-op
240240
--image-builder podman --package test-operator --channels stable,beta --default stable
241241
```
242242

243-
The `--package` or `-p` is the name of package for the operator such as `etcd` which maps `channels` to a particular application definition. `channels` allow package authors to write different upgrade paths for different users (e.g. `beta` vs. `stable`). The `channels` list is provided via `--channels` or `-c` flag. Multiple `channels` are separated by a comma (`,`). The default channel is provided optionally via `--default` or `-e` flag. If the default channel is not provided, the first channel in channel list is selected as default.
243+
The `--package` or `-p` is the name of package for the operator such as `etcd` which maps `channels` to a particular application definition. `channels` allow package authors to write different upgrade paths for different users (e.g. `beta` vs. `stable`). The `channels` list is provided via `--channels` or `-c` flag. Multiple `channels` are separated by a comma (`,`). The default channel is provided optionally via `--default` or `-e` flag.
244244

245245
*Notes:*
246246
* If there is `Dockerfile` existing in the directory, it will be overwritten.

‎pkg/lib/bundle/generate.go

+15-12
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ func GenerateFunc(directory, outputDir, packageName, channels, channelDefault st
112112

113113
if channelDefault == "" {
114114
channelDefault = i.GetDefaultChannel()
115-
if !containsString(strings.Split(channels, ","), channelDefault) {
116-
channelDefault = ""
117-
}
118115
log.Infof("Inferred default channel: %s", channelDefault)
119116
}
120117
}
@@ -299,16 +296,18 @@ func ValidateAnnotations(existing, expected []byte) error {
299296
func GenerateAnnotations(mediaType, manifests, metadata, packageName, channels, channelDefault string) ([]byte, error) {
300297
annotations := &AnnotationMetadata{
301298
Annotations: map[string]string{
302-
MediatypeLabel: mediaType,
303-
ManifestsLabel: manifests,
304-
MetadataLabel: metadata,
305-
PackageLabel: packageName,
306-
ChannelsLabel: channels,
307-
ChannelDefaultLabel: channelDefault,
299+
MediatypeLabel: mediaType,
300+
ManifestsLabel: manifests,
301+
MetadataLabel: metadata,
302+
PackageLabel: packageName,
303+
ChannelsLabel: channels,
308304
},
309305
}
310306

311-
annotations.Annotations[ChannelDefaultLabel] = channelDefault
307+
// Only add defaultChannel annotation if present
308+
if channelDefault != "" {
309+
annotations.Annotations[ChannelDefaultLabel] = channelDefault
310+
}
312311

313312
afile, err := yaml.Marshal(annotations)
314313
if err != nil {
@@ -343,7 +342,11 @@ func GenerateDockerfile(mediaType, manifests, metadata, copyManifestDir, copyMet
343342
fileContent += fmt.Sprintf("LABEL %s=%s\n", MetadataLabel, metadata)
344343
fileContent += fmt.Sprintf("LABEL %s=%s\n", PackageLabel, packageName)
345344
fileContent += fmt.Sprintf("LABEL %s=%s\n", ChannelsLabel, channels)
346-
fileContent += fmt.Sprintf("LABEL %s=%s\n\n", ChannelDefaultLabel, channelDefault)
345+
346+
// Only add defaultChannel annotation if present
347+
if channelDefault != "" {
348+
fileContent += fmt.Sprintf("LABEL %s=%s\n\n", ChannelDefaultLabel, channelDefault)
349+
}
347350

348351
// CONTENT
349352
fileContent += fmt.Sprintf("COPY %s %s\n", relativeManifestDirectory, "/manifests/")
@@ -352,7 +355,7 @@ func GenerateDockerfile(mediaType, manifests, metadata, copyManifestDir, copyMet
352355
return []byte(fileContent), nil
353356
}
354357

355-
// Write `fileName` file with `content` into a `directory`
358+
// WriteFile writes `fileName` file with `content` into a `directory`
356359
// Note: Will overwrite the existing `fileName` file if it exists
357360
func WriteFile(fileName, directory string, content []byte) error {
358361
if _, err := os.Stat(directory); os.IsNotExist(err) {

‎pkg/lib/bundle/generate_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ func TestGenerateDockerfileFunc(t *testing.T) {
170170
"LABEL operators.operatorframework.io.bundle.metadata.v1=%s\n"+
171171
"LABEL operators.operatorframework.io.bundle.package.v1=test4\n"+
172172
"LABEL operators.operatorframework.io.bundle.channels.v1=test5\n"+
173-
"LABEL operators.operatorframework.io.bundle.channel.default.v1=\n\n"+
174173
"COPY test2 /manifests/\n"+
175174
"COPY metadata /metadata/\n", MetadataDir)
176175

@@ -255,7 +254,7 @@ func TestGenerateFunc(t *testing.T) {
255254
os.Remove(filepath.Join("./", DockerFile))
256255

257256
output := fmt.Sprintf("annotations:\n" +
258-
" operators.operatorframework.io.bundle.channel.default.v1: \"\"\n" +
257+
" operators.operatorframework.io.bundle.channel.default.v1: alpha\n" +
259258
" operators.operatorframework.io.bundle.channels.v1: beta\n" +
260259
" operators.operatorframework.io.bundle.manifests.v1: manifests/\n" +
261260
" operators.operatorframework.io.bundle.mediatype.v1: registry+v1\n" +

‎pkg/lib/bundle/validate.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func validateAnnotations(mediaType string, fileAnnotations *AnnotationMetadata)
180180

181181
for label, item := range annotations {
182182
val, ok := fileAnnotations.Annotations[label]
183-
if !ok {
183+
if !ok && label != ChannelDefaultLabel {
184184
aErr := fmt.Errorf("Missing annotation %q", label)
185185
validationErrors = append(validationErrors, aErr)
186186
}
@@ -205,11 +205,12 @@ func validateAnnotations(mediaType string, fileAnnotations *AnnotationMetadata)
205205
if val == "" {
206206
aErr := fmt.Errorf("Expecting annotation %q to have non-empty value", label)
207207
validationErrors = append(validationErrors, aErr)
208-
} else {
209-
annotations[label] = val
210208
}
211209
case ChannelDefaultLabel:
212-
annotations[label] = val
210+
if val == "" {
211+
aErr := fmt.Errorf("Expecting annotation %q to have non-empty value", label)
212+
validationErrors = append(validationErrors, aErr)
213+
}
213214
}
214215
}
215216

‎pkg/registry/types.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,5 @@ func (a *AnnotationsFile) GetChannels() []string {
333333

334334
// GetDefaultChannelName returns the name of the default channel
335335
func (a *AnnotationsFile) GetDefaultChannelName() string {
336-
if a.Annotations.DefaultChannelName != "" {
337-
return a.Annotations.DefaultChannelName
338-
}
339-
channels := a.GetChannels()
340-
if len(channels) == 1 {
341-
return channels[0]
342-
}
343-
return ""
336+
return a.Annotations.DefaultChannelName
344337
}

0 commit comments

Comments
 (0)
Please sign in to comment.