From 659fb04e54b7ec9acc8e11818ed40f55e9585387 Mon Sep 17 00:00:00 2001 From: Andrew Bayer Date: Fri, 27 Jan 2023 08:35:45 -0500 Subject: [PATCH] Fix converted legacy bundle->remote resolver syntax to be case-insensitive 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 --- pkg/resolution/resolver/bundle/bundle.go | 2 +- .../resolver/bundle/resolver_test.go | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pkg/resolution/resolver/bundle/bundle.go b/pkg/resolution/resolver/bundle/bundle.go index 6a956bf2f8f..961b5201dda 100644 --- a/pkg/resolution/resolver/bundle/bundle.go +++ b/pkg/resolution/resolver/bundle/bundle.go @@ -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. diff --git a/pkg/resolution/resolver/bundle/resolver_test.go b/pkg/resolution/resolver/bundle/resolver_test.go index b8b0cbc34f0..f898c68d767 100644 --- a/pkg/resolution/resolver/bundle/resolver_test.go +++ b/pkg/resolution/resolver/bundle/resolver_test.go @@ -191,6 +191,7 @@ type params struct { bundle string name string kind string + expectedKind string } func TestResolve(t *testing.T) { @@ -295,6 +296,16 @@ func TestResolve(t *testing.T) { }, imageName: "single-task", expectedStatus: internal.CreateResolutionRequestStatusWithData(taskAsYAML), + }, { + name: "single task: kind is capitalized", + args: ¶ms{ + 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: ¶ms{ @@ -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" }