Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEP-0142] Support default resolver for Ref to remote StepAction #7345

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/stepactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,5 @@ spec:
- name: pathInRepo
value: remote_step.yaml
```

The default resolver type can be configured by the `default-resolver-type` field in the `config-defaults` ConfigMap (`alpha` feature). See [additional-configs.md](./additional-configs.md) for details.
7 changes: 7 additions & 0 deletions pkg/apis/pipeline/v1/task_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1
import (
"context"

"github.com/tektoncd/pipeline/pkg/apis/config"
"knative.dev/pkg/apis"
)

Expand All @@ -31,6 +32,12 @@ func (t *Task) SetDefaults(ctx context.Context) {

// SetDefaults set any defaults for the task spec
func (ts *TaskSpec) SetDefaults(ctx context.Context) {
cfg := config.FromContextOrDefaults(ctx)
for _, s := range ts.Steps {
if s.Ref != nil && s.Ref.Name == "" && s.Ref.Resolver == "" {
s.Ref.Resolver = ResolverName(cfg.Defaults.DefaultResolverType)
}
}
for i := range ts.Params {
ts.Params[i].SetDefaults(ctx)
}
Expand Down
100 changes: 100 additions & 0 deletions pkg/apis/pipeline/v1/task_defaults_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
Copyright 2023 The Tekton Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1_test

import (
"context"
"testing"

"github.com/google/go-cmp/cmp"
cfgtesting "github.com/tektoncd/pipeline/pkg/apis/config/testing"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"github.com/tektoncd/pipeline/test/diff"
)

func TestTask_SetDefaults(t *testing.T) {
tests := []struct {
name string
in *v1.Task
want *v1.Task
}{{
name: "remote Ref uses default resolver",
in: &v1.Task{
Spec: v1.TaskSpec{
Steps: []v1.Step{{
Name: "foo",
Ref: &v1.Ref{},
}},
},
},
want: &v1.Task{
Spec: v1.TaskSpec{
Steps: []v1.Step{{
Name: "foo",
Ref: &v1.Ref{ResolverRef: v1.ResolverRef{Resolver: "git"}},
}},
},
},
}, {
name: "remote Ref has resolver not overwritten by default resolver",
in: &v1.Task{
Spec: v1.TaskSpec{
Steps: []v1.Step{{
Name: "foo",
Ref: &v1.Ref{ResolverRef: v1.ResolverRef{Resolver: "bundle"}},
}},
},
},
want: &v1.Task{
Spec: v1.TaskSpec{
Steps: []v1.Step{{
Name: "foo",
Ref: &v1.Ref{ResolverRef: v1.ResolverRef{Resolver: "bundle"}},
}},
},
},
}, {
name: "local Ref not adding default resolver",
in: &v1.Task{
Spec: v1.TaskSpec{
Steps: []v1.Step{{
Name: "foo",
Ref: &v1.Ref{Name: "local"},
}},
},
},
want: &v1.Task{
Spec: v1.TaskSpec{
Steps: []v1.Step{{
Name: "foo",
Ref: &v1.Ref{Name: "local"},
}},
},
},
}}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
ctx := cfgtesting.SetDefaults(context.Background(), t, map[string]string{
"default-resolver-type": "git",
})
got := tc.in
got.SetDefaults(ctx)
if d := cmp.Diff(tc.want, got); d != "" {
t.Errorf("SetDefaults %s", diff.PrintWantGot(d))
}
})
}
}
Loading