Skip to content

Commit

Permalink
fix: do not set default kind when taskRef resolver is present
Browse files Browse the repository at this point in the history
fix #7762

Do not set default kind when taskRef resolver is present,
keep the original configuration of the user.
  • Loading branch information
l-qing committed Mar 19, 2024
1 parent da12202 commit a4ac435
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 22 deletions.
6 changes: 3 additions & 3 deletions pkg/apis/pipeline/v1/pipeline_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ func (ps *PipelineSpec) SetDefaults(ctx context.Context) {
func (pt *PipelineTask) SetDefaults(ctx context.Context) {
cfg := config.FromContextOrDefaults(ctx)
if pt.TaskRef != nil {
if pt.TaskRef.Kind == "" {
pt.TaskRef.Kind = NamespacedTaskKind
}
if pt.TaskRef.Name == "" && pt.TaskRef.Resolver == "" {
pt.TaskRef.Resolver = ResolverName(cfg.Defaults.DefaultResolverType)
}
if pt.TaskRef.Kind == "" && pt.TaskRef.Resolver == "" {
pt.TaskRef.Kind = NamespacedTaskKind
}
}
if pt.TaskSpec != nil {
pt.TaskSpec.SetDefaults(ctx)
Expand Down
2 changes: 0 additions & 2 deletions pkg/apis/pipeline/v1/pipeline_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ func TestPipelineTask_SetDefaults(t *testing.T) {
want: &v1.PipelineTask{
Name: "foo",
TaskRef: &v1.TaskRef{
Kind: v1.NamespacedTaskKind,
ResolverRef: v1.ResolverRef{
Resolver: "git",
},
Expand All @@ -229,7 +228,6 @@ func TestPipelineTask_SetDefaults(t *testing.T) {
want: &v1.PipelineTask{
Name: "foo",
TaskRef: &v1.TaskRef{
Kind: v1.NamespacedTaskKind,
ResolverRef: v1.ResolverRef{
Resolver: "custom resolver",
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/pipeline/v1/taskrun_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ func (tr *TaskRun) SetDefaults(ctx context.Context) {
func (trs *TaskRunSpec) SetDefaults(ctx context.Context) {
cfg := config.FromContextOrDefaults(ctx)
if trs.TaskRef != nil {
if trs.TaskRef.Kind == "" {
trs.TaskRef.Kind = NamespacedTaskKind
}
if trs.TaskRef.Name == "" && trs.TaskRef.Resolver == "" {
trs.TaskRef.Resolver = ResolverName(cfg.Defaults.DefaultResolverType)
}
if trs.TaskRef.Kind == "" && trs.TaskRef.Resolver == "" {
trs.TaskRef.Kind = NamespacedTaskKind
}
}

if trs.Timeout == nil {
Expand Down
2 changes: 0 additions & 2 deletions pkg/apis/pipeline/v1/taskrun_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ func TestTaskRunDefaulting(t *testing.T) {
},
Spec: v1.TaskRunSpec{
TaskRef: &v1.TaskRef{
Kind: "Task",
ResolverRef: v1.ResolverRef{
Resolver: "git",
},
Expand Down Expand Up @@ -378,7 +377,6 @@ func TestTaskRunDefaulting(t *testing.T) {
},
Spec: v1.TaskRunSpec{
TaskRef: &v1.TaskRef{
Kind: "Task",
ResolverRef: v1.ResolverRef{
Resolver: "custom resolver",
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/pipeline/v1beta1/pipeline_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ func (ps *PipelineSpec) SetDefaults(ctx context.Context) {
func (pt *PipelineTask) SetDefaults(ctx context.Context) {
cfg := config.FromContextOrDefaults(ctx)
if pt.TaskRef != nil {
if pt.TaskRef.Kind == "" {
pt.TaskRef.Kind = NamespacedTaskKind
}
if pt.TaskRef.Name == "" && pt.TaskRef.Resolver == "" {
pt.TaskRef.Resolver = ResolverName(cfg.Defaults.DefaultResolverType)
}
if pt.TaskRef.Kind == "" && pt.TaskRef.Resolver == "" {
pt.TaskRef.Kind = NamespacedTaskKind
}
}
if pt.TaskSpec != nil {
pt.TaskSpec.SetDefaults(ctx)
Expand Down
2 changes: 0 additions & 2 deletions pkg/apis/pipeline/v1beta1/pipeline_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ func TestPipelineTask_SetDefaults(t *testing.T) {
want: &v1beta1.PipelineTask{
Name: "foo",
TaskRef: &v1beta1.TaskRef{
Kind: v1beta1.NamespacedTaskKind,
ResolverRef: v1beta1.ResolverRef{
Resolver: "git",
},
Expand All @@ -229,7 +228,6 @@ func TestPipelineTask_SetDefaults(t *testing.T) {
want: &v1beta1.PipelineTask{
Name: "foo",
TaskRef: &v1beta1.TaskRef{
Kind: v1beta1.NamespacedTaskKind,
ResolverRef: v1beta1.ResolverRef{
Resolver: "custom resolver",
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/pipeline/v1beta1/taskrun_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ func (tr *TaskRun) SetDefaults(ctx context.Context) {
func (trs *TaskRunSpec) SetDefaults(ctx context.Context) {
cfg := config.FromContextOrDefaults(ctx)
if trs.TaskRef != nil {
if trs.TaskRef.Kind == "" {
trs.TaskRef.Kind = NamespacedTaskKind
}
if trs.TaskRef.Name == "" && trs.TaskRef.Resolver == "" {
trs.TaskRef.Resolver = ResolverName(cfg.Defaults.DefaultResolverType)
}
if trs.TaskRef.Kind == "" && trs.TaskRef.Resolver == "" {
trs.TaskRef.Kind = NamespacedTaskKind
}
}

if trs.Timeout == nil {
Expand Down
2 changes: 0 additions & 2 deletions pkg/apis/pipeline/v1beta1/taskrun_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ func TestTaskRunDefaulting(t *testing.T) {
},
Spec: v1beta1.TaskRunSpec{
TaskRef: &v1beta1.TaskRef{
Kind: "Task",
ResolverRef: v1beta1.ResolverRef{
Resolver: "git",
},
Expand Down Expand Up @@ -388,7 +387,6 @@ func TestTaskRunDefaulting(t *testing.T) {
},
Spec: v1beta1.TaskRunSpec{
TaskRef: &v1beta1.TaskRef{
Kind: "Task",
ResolverRef: v1beta1.ResolverRef{
Resolver: "custom resolver",
},
Expand Down
1 change: 0 additions & 1 deletion pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8382,7 +8382,6 @@ metadata:
spec:
serviceAccountName: test-sa
taskRef:
kind: Task
resolver: bar
`)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ func TestGetPipelineData_ResolutionSuccess(t *testing.T) {
Tasks: []v1.PipelineTask{{
Name: "pt1",
TaskRef: &v1.TaskRef{
Kind: "Task",
ResolverRef: v1.ResolverRef{
Resolver: "foo",
},
Expand Down

0 comments on commit a4ac435

Please sign in to comment.