Skip to content

Commit

Permalink
Fix converted legacy bundle->remote resolver syntax to be case-insens…
Browse files Browse the repository at this point in the history
…itive for kind

fixes #6058

When we finished deprecating the legacy bundle resolution syntax, we recommended users change from:
```
      taskRef:
        name: git-batch-merge
        bundle: gcr.io/tekton-releases/catalog/upstream/git-batch-merge:0.2
```
to
```
      taskRef:
        resolver: bundles
        params:
          - name: bundle
            value: gcr.io/tekton-releases/catalog/upstream/git-batch-merge:0.2
          - name: name
            value: git-batch-merge
          - name: kind
            value: Task
```

But that created a problem - we have been comparing the `kind` parameter to the `dev.tekton.image.kind` annotation value in the bundle, which is generally all lower-case. Since we generally use `Task`, `Pipeline`, etc for `kind` values in our syntax, we've created a situation where the "normal" way to specify a `kind`, i.e., capitalized, is not going to work for most, if not all, bundles.

To fix this, we're changing the check in the remote bundles resolver to do a case-insensitive comparison.

Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
  • Loading branch information
abayer committed Jan 27, 2023
1 parent b44d9a3 commit 659fb04
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/resolution/resolver/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func GetEntry(ctx context.Context, keychain authn.Keychain, opts RequestOptions)
lKind := l.Annotations[BundleAnnotationKind]
lName := l.Annotations[BundleAnnotationName]

if opts.Kind == lKind && opts.EntryName == lName {
if strings.ToLower(opts.Kind) == strings.ToLower(lKind) && opts.EntryName == lName {
obj, err := readTarLayer(layerMap[l.Digest.String()])
if err != nil {
// This could still be a raw layer so try to read it as that instead.
Expand Down
18 changes: 16 additions & 2 deletions pkg/resolution/resolver/bundle/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ type params struct {
bundle string
name string
kind string
expectedKind string
}

func TestResolve(t *testing.T) {
Expand Down Expand Up @@ -295,6 +296,16 @@ func TestResolve(t *testing.T) {
},
imageName: "single-task",
expectedStatus: internal.CreateResolutionRequestStatusWithData(taskAsYAML),
}, {
name: "single task: kind is capitalized",
args: &params{
bundle: fmt.Sprintf("%s@%s:%s", testImages["single-task"].uri, testImages["single-task"].algo, testImages["single-task"].hex),
name: "example-task",
kind: "Task",
expectedKind: "task",
},
imageName: "single-task",
expectedStatus: internal.CreateResolutionRequestStatusWithData(taskAsYAML),
}, {
name: "single task: tag is included in the bundle parameter",
args: &params{
Expand Down Expand Up @@ -419,9 +430,12 @@ func TestResolve(t *testing.T) {
expectedStatus.Annotations = make(map[string]string)
}

if tc.args.kind != "" {
switch {
case tc.args.expectedKind != "":
expectedStatus.Annotations[ResolverAnnotationKind] = tc.args.expectedKind
case tc.args.kind != "":
expectedStatus.Annotations[ResolverAnnotationKind] = tc.args.kind
} else {
default:
expectedStatus.Annotations[ResolverAnnotationKind] = "task"
}

Expand Down

0 comments on commit 659fb04

Please sign in to comment.