Skip to content

Commit 2204786

Browse files
AverageMarcustekton-robot
authored andcommitted
Fix StepAction support in Cluster resolver
Signed-off-by: Marcus Noble <[email protected]>
1 parent 7056a41 commit 2204786

File tree

3 files changed

+75
-7
lines changed

3 files changed

+75
-7
lines changed

docs/cluster-resolver.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ This Resolver responds to type `cluster`.
1313

1414
## Parameters
1515

16-
| Param Name | Description | Example Value |
17-
|-------------|-------------------------------------------------------|------------------------------|
18-
| `kind` | The kind of resource to fetch. | `task`, `pipeline` |
19-
| `name` | The name of the resource to fetch. | `some-pipeline`, `some-task` |
20-
| `namespace` | The namespace in the cluster containing the resource. | `default`, `other-namespace` |
16+
| Param Name | Description | Example Value |
17+
|-------------|-------------------------------------------------------|----------------------------------|
18+
| `kind` | The kind of resource to fetch. | `task`, `pipeline`, `stepaction` |
19+
| `name` | The name of the resource to fetch. | `some-pipeline`, `some-task` |
20+
| `namespace` | The namespace in the cluster containing the resource. | `default`, `other-namespace` |
2121

2222
## Requirements
2323

@@ -37,7 +37,7 @@ for the name, namespace and defaults that the resolver ships with.
3737

3838
| Option Name | Description | Example Values |
3939
|----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|
40-
| `default-kind` | The default resource kind to fetch if not specified in parameters. | `task`, `pipeline` |
40+
| `default-kind` | The default resource kind to fetch if not specified in parameters. | `task`, `pipeline`, `stepaction` |
4141
| `default-namespace` | The default namespace to fetch resources from if not specified in parameters. | `default`, `some-namespace` |
4242
| `allowed-namespaces` | An optional comma-separated list of namespaces which the resolver is allowed to access. Defaults to empty, meaning all namespaces are allowed. | `default,some-namespace`, (empty) |
4343
| `blocked-namespaces` | An optional comma-separated list of namespaces which the resolver is blocked from accessing. If the value is a `*` all namespaces will be disallowed and allowed namespace will need to be explicitely listed in `allowed-namespaces`. Defaults to empty, meaning all namespaces are allowed. | `default,other-namespace`, `*`, (empty) |
@@ -63,6 +63,27 @@ spec:
6363
value: namespace-containing-task
6464
```
6565
66+
### StepAction Resolution
67+
68+
```yaml
69+
apiVersion: tekton.dev/v1beta1
70+
kind: Task
71+
metadata:
72+
name: remote-stepaction-reference
73+
spec:
74+
steps:
75+
- name: step-action-example
76+
ref
77+
resolver: cluster
78+
params:
79+
- name: kind
80+
value: stepaction
81+
- name: name
82+
value: some-stepaction
83+
- name: namespace
84+
value: namespace-containing-stepaction
85+
```
86+
6687
### Pipeline resolution
6788
6889
```yaml

pkg/resolution/resolver/cluster/resolver.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"encoding/hex"
2222
"errors"
2323
"fmt"
24+
"slices"
2425
"strings"
2526

2627
resolverconfig "github.com/tektoncd/pipeline/pkg/apis/config/resolver"
@@ -51,6 +52,8 @@ const (
5152

5253
var _ framework.Resolver = &Resolver{}
5354

55+
var supportedKinds = []string{"task", "pipeline", "stepaction"}
56+
5457
// Resolver implements a framework.Resolver that can fetch resources from other namespaces.
5558
//
5659
// Deprecated: Use [github.com/tektoncd/pipeline/pkg/remoteresolution/resolver/cluster.Resolver] instead.
@@ -229,7 +232,7 @@ func populateParamsWithDefaults(ctx context.Context, origParams []pipelinev1.Par
229232
} else {
230233
params[KindParam] = pKind.StringVal
231234
}
232-
if kindVal, ok := params[KindParam]; ok && kindVal != "task" && kindVal != "pipeline" {
235+
if kindVal, ok := params[KindParam]; ok && !isSupportedKind(kindVal) {
233236
return nil, fmt.Errorf("unknown or unsupported resource kind '%s'", kindVal)
234237
}
235238

@@ -364,3 +367,7 @@ func fetchPipeline(ctx context.Context, groupVersion string, pipeline *pipelinev
364367
}
365368
return uid, data, sha256Checksum, spec, nil
366369
}
370+
371+
func isSupportedKind(kindValue string) bool {
372+
return slices.Contains[[]string, string](supportedKinds, kindValue)
373+
}

pkg/resolution/resolver/cluster/resolver_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,28 @@ func TestResolve(t *testing.T) {
279279
t.Fatalf("couldn't marshal pipeline: %v", err)
280280
}
281281

282+
exampleStepAction := &pipelinev1beta1.StepAction{
283+
ObjectMeta: metav1.ObjectMeta{
284+
Name: "example-stepaction",
285+
Namespace: "stepaction-ns",
286+
ResourceVersion: "00003",
287+
UID: "c123",
288+
},
289+
TypeMeta: metav1.TypeMeta{
290+
Kind: "StepAction",
291+
APIVersion: "tekton.dev/v1beta1",
292+
},
293+
Spec: pipelinev1beta1.StepActionSpec{},
294+
}
295+
stepActionChecksum, err := exampleStepAction.Checksum()
296+
if err != nil {
297+
t.Fatalf("couldn't checksum stepaction: %v", err)
298+
}
299+
stepActionAsYAML, err := yaml.Marshal(exampleStepAction)
300+
if err != nil {
301+
t.Fatalf("couldn't marshal stepaction: %v", err)
302+
}
303+
282304
testCases := []struct {
283305
name string
284306
kind string
@@ -323,6 +345,23 @@ func TestResolve(t *testing.T) {
323345
},
324346
},
325347
},
348+
}, {
349+
name: "successful stepaction",
350+
kind: "stepaction",
351+
resourceName: exampleStepAction.Name,
352+
namespace: exampleStepAction.Namespace,
353+
expectedStatus: &v1beta1.ResolutionRequestStatus{
354+
Status: duckv1.Status{},
355+
ResolutionRequestStatusFields: v1beta1.ResolutionRequestStatusFields{
356+
Data: base64.StdEncoding.Strict().EncodeToString(stepActionAsYAML),
357+
RefSource: &pipelinev1.RefSource{
358+
URI: "/apis/tekton.dev/v1/namespaces/stepaction-ns/stepaction/example-stepaction@c123",
359+
Digest: map[string]string{
360+
"sha256": hex.EncodeToString(stepActionChecksum),
361+
},
362+
},
363+
},
364+
},
326365
}, {
327366
name: "default namespace",
328367
kind: "pipeline",
@@ -427,6 +466,7 @@ func TestResolve(t *testing.T) {
427466
Pipelines: []*pipelinev1.Pipeline{examplePipeline},
428467
ResolutionRequests: []*v1beta1.ResolutionRequest{request},
429468
Tasks: []*pipelinev1.Task{exampleTask},
469+
StepActions: []*pipelinev1beta1.StepAction{exampleStepAction},
430470
}
431471

432472
resolver := &cluster.Resolver{}

0 commit comments

Comments
 (0)