Skip to content

Commit

Permalink
Update cluster resolver to fetch v1 tasks and pipelines
Browse files Browse the repository at this point in the history
The cluster resolver used the v1beta1 pipeline client to fetch tasks and
pipelines. This meant that it always fetched the v1beta1 versions of the
resources. Since we are moving to using the reconcilers to use v1 versions of
the API, we should update the resolvers to return the v1 representations of the
tasks and pipelines from the cluster.

Note that the resolution framework itself relies on the pipeline v1beta1 API
for certain fields (Params, ConfigSource,RefSource). Migrating those is out of
scope of this commit.

Signed-off-by: Dibyo Mukherjee <dibyo@google.com>
  • Loading branch information
dibyom committed May 3, 2023
1 parent d214516 commit 027f273
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
7 changes: 4 additions & 3 deletions pkg/resolution/resolver/cluster/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

resolverconfig "github.com/tektoncd/pipeline/pkg/apis/config/resolver"
pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
clientset "github.com/tektoncd/pipeline/pkg/client/clientset/versioned"
pipelineclient "github.com/tektoncd/pipeline/pkg/client/injection/client"
resolutioncommon "github.com/tektoncd/pipeline/pkg/resolution/common"
Expand Down Expand Up @@ -105,11 +106,11 @@ func (r *Resolver) Resolve(ctx context.Context, origParams []pipelinev1beta1.Par
var data []byte
var spec []byte
var uid string
groupVersion := pipelinev1beta1.SchemeGroupVersion.String()
groupVersion := pipelinev1.SchemeGroupVersion.String()

switch params[KindParam] {
case "task":
task, err := r.pipelineClientSet.TektonV1beta1().Tasks(params[NamespaceParam]).Get(ctx, params[NameParam], metav1.GetOptions{})
task, err := r.pipelineClientSet.TektonV1().Tasks(params[NamespaceParam]).Get(ctx, params[NameParam], metav1.GetOptions{})
if err != nil {
logger.Infof("failed to load task %s from namespace %s: %v", params[NameParam], params[NamespaceParam], err)
return nil, err
Expand All @@ -129,7 +130,7 @@ func (r *Resolver) Resolve(ctx context.Context, origParams []pipelinev1beta1.Par
return nil, err
}
case "pipeline":
pipeline, err := r.pipelineClientSet.TektonV1beta1().Pipelines(params[NamespaceParam]).Get(ctx, params[NameParam], metav1.GetOptions{})
pipeline, err := r.pipelineClientSet.TektonV1().Pipelines(params[NamespaceParam]).Get(ctx, params[NameParam], metav1.GetOptions{})
if err != nil {
logger.Infof("failed to load pipeline %s from namespace %s: %v", params[NameParam], params[NamespaceParam], err)
return nil, err
Expand Down
50 changes: 20 additions & 30 deletions pkg/resolution/resolver/cluster/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func TestValidateParamsFailure(t *testing.T) {
func TestResolve(t *testing.T) {
defaultNS := "pipeline-ns"

exampleTask := &pipelinev1beta1.Task{
exampleTask := &pipelinev1.Task{
ObjectMeta: metav1.ObjectMeta{
Name: "example-task",
Namespace: "task-ns",
Expand All @@ -201,10 +201,10 @@ func TestResolve(t *testing.T) {
},
TypeMeta: metav1.TypeMeta{
Kind: string(pipelinev1beta1.NamespacedTaskKind),
APIVersion: "tekton.dev/v1beta1",
APIVersion: "tekton.dev/v1",
},
Spec: pipelinev1beta1.TaskSpec{
Steps: []pipelinev1beta1.Step{{
Spec: pipelinev1.TaskSpec{
Steps: []pipelinev1.Step{{
Name: "some-step",
Image: "some-image",
Command: []string{"something"},
Expand All @@ -220,7 +220,7 @@ func TestResolve(t *testing.T) {
t.Fatalf("couldn't marshal task spec: %v", err)
}

examplePipeline := &pipelinev1beta1.Pipeline{
examplePipeline := &pipelinev1.Pipeline{
ObjectMeta: metav1.ObjectMeta{
Name: "example-pipeline",
Namespace: defaultNS,
Expand All @@ -229,14 +229,14 @@ func TestResolve(t *testing.T) {
},
TypeMeta: metav1.TypeMeta{
Kind: "Pipeline",
APIVersion: "tekton.dev/v1beta1",
APIVersion: "tekton.dev/v1",
},
Spec: pipelinev1beta1.PipelineSpec{
Tasks: []pipelinev1beta1.PipelineTask{{
Spec: pipelinev1.PipelineSpec{
Tasks: []pipelinev1.PipelineTask{{
Name: "some-pipeline-task",
TaskRef: &pipelinev1beta1.TaskRef{
TaskRef: &pipelinev1.TaskRef{
Name: "some-task",
Kind: pipelinev1beta1.NamespacedTaskKind,
Kind: pipelinev1.NamespacedTaskKind,
},
}},
},
Expand Down Expand Up @@ -270,13 +270,13 @@ func TestResolve(t *testing.T) {
ResolutionRequestStatusFields: v1beta1.ResolutionRequestStatusFields{
Data: base64.StdEncoding.Strict().EncodeToString(taskAsYAML),
RefSource: &pipelinev1beta1.RefSource{
URI: "/apis/tekton.dev/v1beta1/namespaces/task-ns/task/example-task@a123",
URI: "/apis/tekton.dev/v1/namespaces/task-ns/task/example-task@a123",
Digest: map[string]string{
"sha256": sha256CheckSum(taskSpec),
},
},
Source: &pipelinev1beta1.ConfigSource{
URI: "/apis/tekton.dev/v1beta1/namespaces/task-ns/task/example-task@a123",
URI: "/apis/tekton.dev/v1/namespaces/task-ns/task/example-task@a123",
Digest: map[string]string{
"sha256": sha256CheckSum(taskSpec),
},
Expand All @@ -293,13 +293,13 @@ func TestResolve(t *testing.T) {
ResolutionRequestStatusFields: v1beta1.ResolutionRequestStatusFields{
Data: base64.StdEncoding.Strict().EncodeToString(pipelineAsYAML),
RefSource: &pipelinev1beta1.RefSource{
URI: "/apis/tekton.dev/v1beta1/namespaces/pipeline-ns/pipeline/example-pipeline@b123",
URI: "/apis/tekton.dev/v1/namespaces/pipeline-ns/pipeline/example-pipeline@b123",
Digest: map[string]string{
"sha256": sha256CheckSum(pipelineSpec),
},
},
Source: &pipelinev1beta1.ConfigSource{
URI: "/apis/tekton.dev/v1beta1/namespaces/pipeline-ns/pipeline/example-pipeline@b123",
URI: "/apis/tekton.dev/v1/namespaces/pipeline-ns/pipeline/example-pipeline@b123",
Digest: map[string]string{
"sha256": sha256CheckSum(pipelineSpec),
},
Expand All @@ -315,13 +315,13 @@ func TestResolve(t *testing.T) {
ResolutionRequestStatusFields: v1beta1.ResolutionRequestStatusFields{
Data: base64.StdEncoding.Strict().EncodeToString(pipelineAsYAML),
RefSource: &pipelinev1beta1.RefSource{
URI: "/apis/tekton.dev/v1beta1/namespaces/pipeline-ns/pipeline/example-pipeline@b123",
URI: "/apis/tekton.dev/v1/namespaces/pipeline-ns/pipeline/example-pipeline@b123",
Digest: map[string]string{
"sha256": sha256CheckSum(pipelineSpec),
},
},
Source: &pipelinev1beta1.ConfigSource{
URI: "/apis/tekton.dev/v1beta1/namespaces/pipeline-ns/pipeline/example-pipeline@b123",
URI: "/apis/tekton.dev/v1/namespaces/pipeline-ns/pipeline/example-pipeline@b123",
Digest: map[string]string{
"sha256": sha256CheckSum(pipelineSpec),
},
Expand All @@ -337,13 +337,13 @@ func TestResolve(t *testing.T) {
ResolutionRequestStatusFields: v1beta1.ResolutionRequestStatusFields{
Data: base64.StdEncoding.Strict().EncodeToString(taskAsYAML),
RefSource: &pipelinev1beta1.RefSource{
URI: "/apis/tekton.dev/v1beta1/namespaces/task-ns/task/example-task@a123",
URI: "/apis/tekton.dev/v1/namespaces/task-ns/task/example-task@a123",
Digest: map[string]string{
"sha256": sha256CheckSum(taskSpec),
},
},
Source: &pipelinev1beta1.ConfigSource{
URI: "/apis/tekton.dev/v1beta1/namespaces/task-ns/task/example-task@a123",
URI: "/apis/tekton.dev/v1/namespaces/task-ns/task/example-task@a123",
Digest: map[string]string{
"sha256": sha256CheckSum(taskSpec),
},
Expand Down Expand Up @@ -403,16 +403,6 @@ func TestResolve(t *testing.T) {
confMap[cluster.BlockedNamespacesKey] = tc.blockedNamespaces
}

v1ExamplePipeline := &pipelinev1.Pipeline{}
if err := examplePipeline.ConvertTo(ctx, v1ExamplePipeline); err != nil {
t.Errorf("Error converting examplePipeline %s", err)
}

v1ExampleTask := &pipelinev1.Task{}
if err := exampleTask.ConvertTo(ctx, v1ExampleTask); err != nil {
t.Errorf("Error converting exampleTask %s", err)
}

d := test.Data{
ConfigMaps: []*corev1.ConfigMap{{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -429,9 +419,9 @@ func TestResolve(t *testing.T) {
"enable-cluster-resolver": "true",
},
}},
Pipelines: []*pipelinev1.Pipeline{v1ExamplePipeline},
Pipelines: []*pipelinev1.Pipeline{examplePipeline},
ResolutionRequests: []*v1beta1.ResolutionRequest{request},
Tasks: []*pipelinev1.Task{v1ExampleTask},
Tasks: []*pipelinev1.Task{exampleTask},
}

resolver := &cluster.Resolver{}
Expand Down

0 comments on commit 027f273

Please sign in to comment.