From a09aec96dc90b7516ab0b0027d841fed0f67350d Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Mon, 11 Nov 2024 06:12:33 -0700 Subject: [PATCH] Fix StepAction support in Cluster resolver Signed-off-by: Marcus Noble --- pkg/resolution/resolver/cluster/resolver.go | 2 +- .../resolver/cluster/resolver_test.go | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/pkg/resolution/resolver/cluster/resolver.go b/pkg/resolution/resolver/cluster/resolver.go index bc53d51ab8d..a6a601d6dda 100644 --- a/pkg/resolution/resolver/cluster/resolver.go +++ b/pkg/resolution/resolver/cluster/resolver.go @@ -229,7 +229,7 @@ func populateParamsWithDefaults(ctx context.Context, origParams []pipelinev1.Par } else { params[KindParam] = pKind.StringVal } - if kindVal, ok := params[KindParam]; ok && kindVal != "task" && kindVal != "pipeline" { + if kindVal, ok := params[KindParam]; ok && kindVal != "task" && kindVal != "pipeline" && kindVal != "stepaction" { return nil, fmt.Errorf("unknown or unsupported resource kind '%s'", kindVal) } diff --git a/pkg/resolution/resolver/cluster/resolver_test.go b/pkg/resolution/resolver/cluster/resolver_test.go index 6cfdf36ac70..dd24ae7846b 100644 --- a/pkg/resolution/resolver/cluster/resolver_test.go +++ b/pkg/resolution/resolver/cluster/resolver_test.go @@ -279,6 +279,28 @@ func TestResolve(t *testing.T) { t.Fatalf("couldn't marshal pipeline: %v", err) } + exampleStepAction := &pipelinev1beta1.StepAction{ + ObjectMeta: metav1.ObjectMeta{ + Name: "example-stepaction", + Namespace: "stepaction-ns", + ResourceVersion: "00003", + UID: "c123", + }, + TypeMeta: metav1.TypeMeta{ + Kind: "StepAction", + APIVersion: "tekton.dev/v1beta1", + }, + Spec: pipelinev1beta1.StepActionSpec{}, + } + stepActionChecksum, err := exampleStepAction.Checksum() + if err != nil { + t.Fatalf("couldn't checksum stepaction: %v", err) + } + stepActionAsYAML, err := yaml.Marshal(exampleStepAction) + if err != nil { + t.Fatalf("couldn't marshal stepaction: %v", err) + } + testCases := []struct { name string kind string @@ -323,6 +345,23 @@ func TestResolve(t *testing.T) { }, }, }, + }, { + name: "successful stepaction", + kind: "stepaction", + resourceName: exampleStepAction.Name, + namespace: exampleStepAction.Namespace, + expectedStatus: &v1beta1.ResolutionRequestStatus{ + Status: duckv1.Status{}, + ResolutionRequestStatusFields: v1beta1.ResolutionRequestStatusFields{ + Data: base64.StdEncoding.Strict().EncodeToString(stepActionAsYAML), + RefSource: &pipelinev1.RefSource{ + URI: "/apis/tekton.dev/v1/namespaces/stepaction-ns/stepaction/example-stepaction@c123", + Digest: map[string]string{ + "sha256": hex.EncodeToString(stepActionChecksum), + }, + }, + }, + }, }, { name: "default namespace", kind: "pipeline", @@ -427,6 +466,7 @@ func TestResolve(t *testing.T) { Pipelines: []*pipelinev1.Pipeline{examplePipeline}, ResolutionRequests: []*v1beta1.ResolutionRequest{request}, Tasks: []*pipelinev1.Task{exampleTask}, + StepActions: []*pipelinev1beta1.StepAction{exampleStepAction}, } resolver := &cluster.Resolver{}