Skip to content

Commit

Permalink
Update from Tekton v1beta1 to v1
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsauter committed Oct 5, 2023
1 parent 5bd4f73 commit 88bb3ad
Show file tree
Hide file tree
Showing 24 changed files with 63 additions and 60 deletions.
2 changes: 1 addition & 1 deletion deploy/chart/templates/task-finish.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: tekton.dev/v1beta1
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: ods-pipeline-finish
Expand Down
2 changes: 1 addition & 1 deletion deploy/chart/templates/task-start.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: tekton.dev/v1beta1
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: ods-pipeline-start
Expand Down
6 changes: 3 additions & 3 deletions docs/authoring-tasks.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The simplest YAML definition of a task looks like this:

[source]
----
apiVersion: tekton.dev/v1beta1
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: hello-world
Expand Down Expand Up @@ -118,7 +118,7 @@ For this example, we will consider a very basic application like this link:https

[source,yaml]
----
apiVersion: tekton.dev/v1beta1
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: build-ruby
Expand Down Expand Up @@ -161,7 +161,7 @@ As a first step, copy the YAML from link:https://github.com/opendevstack/ods-pip

[source,yaml]
----
apiVersion: tekton.dev/v1beta1
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: build-go
Expand Down
28 changes: 14 additions & 14 deletions internal/manager/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

tektonClient "github.com/opendevstack/ods-pipeline/internal/tekton"
"github.com/opendevstack/ods-pipeline/pkg/config"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand All @@ -26,7 +26,7 @@ const (
// Label specifying the Git ref (e.g. branch) related to the pipeline.
gitRefLabel = labelPrefix + "git-ref"
// tektonAPIVersion specifies the Tekton API version in use
tektonAPIVersion = "tekton.dev/v1beta1"
tektonAPIVersion = "tekton.dev/v1"
// sharedWorkspaceName is the name of the workspace shared by all tasks
sharedWorkspaceName = "shared-workspace"
)
Expand Down Expand Up @@ -55,12 +55,10 @@ func createPipelineRun(
Kind: "PipelineRun",
},
Spec: tekton.PipelineRunSpec{
PipelineSpec: assemblePipelineSpec(cfg),
Params: extractPipelineParams(cfg.Params),
ServiceAccountName: "pipeline", // TODO
PodTemplate: cfg.PipelineSpec.PodTemplate,
TaskRunSpecs: cfg.PipelineSpec.TaskRunSpecs,
Timeouts: cfg.PipelineSpec.Timeouts,
PipelineSpec: assemblePipelineSpec(cfg),
Params: extractPipelineParams(cfg.Params),
TaskRunSpecs: cfg.PipelineSpec.TaskRunSpecs,
Timeouts: cfg.PipelineSpec.Timeouts,
Workspaces: []tekton.WorkspaceBinding{
{
Name: sharedWorkspaceName,
Expand Down Expand Up @@ -188,17 +186,19 @@ func pipelineRunIsProgressing(pr tekton.PipelineRun) bool {

// tektonStringParam returns a Tekton task parameter.
func tektonStringParam(name, val string) tekton.Param {
return tekton.Param{Name: name, Value: tekton.ArrayOrString{Type: "string", StringVal: val}}
return tekton.Param{
Name: name,
Value: tekton.ParamValue{Type: tekton.ParamTypeString, StringVal: val},
}
}

// tektonStringParam returns a Tekton task parameter spec.
func tektonStringParamSpec(name, defaultVal string) tekton.ParamSpec {
return tekton.ParamSpec{
Name: name,
Type: "string",
Default: &tekton.ArrayOrString{
Type: tekton.ParamTypeString, StringVal: defaultVal,
}}
Name: name,
Type: tekton.ParamTypeString,
Default: &tekton.ParamValue{Type: tekton.ParamTypeString, StringVal: defaultVal},
}
}

// tektonDefaultWorkspaceBindings returns the default workspace bindings for a task.
Expand Down
6 changes: 3 additions & 3 deletions internal/manager/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/google/go-cmp/cmp"
tektonClient "github.com/opendevstack/ods-pipeline/internal/tekton"
"github.com/opendevstack/ods-pipeline/pkg/config"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
)

func TestShortenString(t *testing.T) {
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestCreatePipelineRun(t *testing.T) {
if err != nil {
t.Fatal(err)
}
wantParams := []tekton.Param{
wantParams := tekton.Params{
{Name: "hello", Value: tekton.ParamValue{Type: "string", StringVal: "world"}},
}
if diff := cmp.Diff(wantParams, pr.Spec.Params); diff != "" {
Expand Down Expand Up @@ -370,7 +370,7 @@ func TestAppendTriggerBasedParams(t *testing.T) {
},
})
got := mergeTriggerBasedParams(tasks, params)
want := []tekton.Param{
want := tekton.Params{
tektonStringParam("zero", "0"),
tektonStringParam("two", "b"),
tektonStringParam("four", "d"),
Expand Down
2 changes: 1 addition & 1 deletion internal/manager/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

tektonClient "github.com/opendevstack/ods-pipeline/internal/tekton"
"github.com/opendevstack/ods-pipeline/pkg/logging"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/manager/prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/google/go-cmp/cmp"
tektonClient "github.com/opendevstack/ods-pipeline/internal/tekton"
"github.com/opendevstack/ods-pipeline/pkg/logging"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down
8 changes: 4 additions & 4 deletions internal/manager/receive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/opendevstack/ods-pipeline/pkg/bitbucket"
"github.com/opendevstack/ods-pipeline/pkg/config"
"github.com/opendevstack/ods-pipeline/pkg/logging"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
)

func TestIsCiSkipInCommitMessage(t *testing.T) {
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestFetchODSConfig(t *testing.T) {
"ods.yml": []byte("pipelines: [{tasks: [{name: yml}]}]"),
},
wantErr: "",
wantODS: &config.ODS{Pipelines: []config.Pipeline{{Tasks: []v1beta1.PipelineTask{{Name: "yaml"}}}}},
wantODS: &config.ODS{Pipelines: []config.Pipeline{{Tasks: []tekton.PipelineTask{{Name: "yaml"}}}}},
},
}

Expand Down Expand Up @@ -728,11 +728,11 @@ func verifyMatchingPipelineInfo(pInfo *PipelineInfo, odsConfig *config.ODS, want
// Annotate wanted pipeline/trigger so that
// we can check later if it was selected.
// no matching pipeline, as wanted by the test case.
odsConfig.Pipelines[wantPipelineIndex].Tasks = []v1beta1.PipelineTask{
odsConfig.Pipelines[wantPipelineIndex].Tasks = []tekton.PipelineTask{
{Name: "match this"},
}
if wantTriggerIndex > -1 {
odsConfig.Pipelines[wantPipelineIndex].Triggers[wantTriggerIndex].Params = []v1beta1.Param{
odsConfig.Pipelines[wantPipelineIndex].Triggers[wantTriggerIndex].Params = []tekton.Param{
tektonStringParam("match", "this"),
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/manager/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
kubernetesClient "github.com/opendevstack/ods-pipeline/internal/kubernetes"
tektonClient "github.com/opendevstack/ods-pipeline/internal/tekton"
"github.com/opendevstack/ods-pipeline/pkg/logging"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
)

type StorageConfig struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/manager/schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
kubernetesClient "github.com/opendevstack/ods-pipeline/internal/kubernetes"
tektonClient "github.com/opendevstack/ods-pipeline/internal/tekton"
"github.com/opendevstack/ods-pipeline/pkg/logging"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/manager/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

tektonClient "github.com/opendevstack/ods-pipeline/internal/tekton"
"github.com/opendevstack/ods-pipeline/pkg/logging"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down
6 changes: 4 additions & 2 deletions internal/manager/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

tektonClient "github.com/opendevstack/ods-pipeline/internal/tekton"
"github.com/opendevstack/ods-pipeline/pkg/logging"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/clock"
)
Expand Down Expand Up @@ -145,7 +145,9 @@ func timedOutPipelineRun(t *testing.T, name string, creationTime time.Time) *tek
CreationTimestamp: metav1.Time{Time: creationTime},
},
Spec: tekton.PipelineRunSpec{
Timeout: &metav1.Duration{Duration: time.Second},
Timeouts: &tekton.TimeoutFields{
Pipeline: &metav1.Duration{Duration: time.Second},
},
},
Status: tekton.PipelineRunStatus{
PipelineRunStatusFields: tekton.PipelineRunStatusFields{
Expand Down
10 changes: 5 additions & 5 deletions internal/tekton/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/opendevstack/ods-pipeline/pkg/logging"
tektonClient "github.com/tektoncd/pipeline/pkg/client/clientset/versioned"
v1beta1 "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/typed/pipeline/v1beta1"
tektonv1 "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/typed/pipeline/v1"
"k8s.io/client-go/rest"
)

Expand Down Expand Up @@ -72,10 +72,10 @@ func (c *Client) namespace() string {
return c.clientConfig.Namespace
}

func (c *Client) tektonV1beta1Client() v1beta1.TektonV1beta1Interface {
return c.clientConfig.TektonClient.TektonV1beta1()
func (c *Client) tektonV1Client() tektonv1.TektonV1Interface {
return c.clientConfig.TektonClient.TektonV1()
}

func (c *Client) pipelineRunsClient() v1beta1.PipelineRunInterface {
return c.tektonV1beta1Client().PipelineRuns(c.namespace())
func (c *Client) pipelineRunsClient() tektonv1.PipelineRunInterface {
return c.tektonV1Client().PipelineRuns(c.namespace())
}
4 changes: 2 additions & 2 deletions internal/tekton/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"net/url"

tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -49,7 +49,7 @@ func PipelineRunURL(consoleURL, namespace, name string) (string, error) {
return "", fmt.Errorf("parse base URL: %w", err)
}
cPath := fmt.Sprintf(
"/k8s/ns/%s/tekton.dev~v1beta1~PipelineRun/%s/",
"/k8s/ns/%s/tekton.dev~v1~PipelineRun/%s/",
namespace,
name,
)
Expand Down
2 changes: 1 addition & 1 deletion internal/tekton/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestPipelineRunURL(t *testing.T) {
if err != nil {
t.Fatal(err)
}
want := "https://console.example.com/k8s/ns/foo/tekton.dev~v1beta1~PipelineRun/bar-ab12c/"
want := "https://console.example.com/k8s/ns/foo/tekton.dev~v1~PipelineRun/bar-ab12c/"
if u != want {
t.Fatalf("want: %s, got: %s", want, u)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/tekton/test_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"fmt"

tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down
4 changes: 1 addition & 3 deletions pkg/config/ods.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"path/filepath"
"strings"

"github.com/tektoncd/pipeline/pkg/apis/pipeline/pod"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"sigs.k8s.io/yaml"
)

Expand Down Expand Up @@ -55,7 +54,6 @@ type Pipeline struct {
Tasks []tekton.PipelineTask `json:"tasks,omitempty"`
Finally []tekton.PipelineTask `json:"finally,omitempty"`
Timeouts *tekton.TimeoutFields `json:"timeouts,omitempty"`
PodTemplate *pod.PodTemplate `json:"podTemplate,omitempty"`
TaskRunSpecs []tekton.PipelineTaskRunSpec `json:"taskRunSpecs,omitempty"`
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/taskdoc/taskdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io"
"text/template"

tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"sigs.k8s.io/yaml"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/tektontaskrun/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

k "github.com/opendevstack/ods-pipeline/internal/kubernetes"
"github.com/opendevstack/ods-pipeline/pkg/taskmanifest"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"
)
Expand All @@ -30,7 +30,7 @@ func installTask(path, namespace string, data map[string]string) (*tekton.Task,
}
clients := k.NewClients()
tc := clients.TektonClientSet
it, err := tc.TektonV1beta1().Tasks(namespace).Create(context.TODO(), &t, metav1.CreateOptions{})
it, err := tc.TektonV1().Tasks(namespace).Create(context.TODO(), &t, metav1.CreateOptions{})
if err != nil {
return nil, fmt.Errorf("create task: %w", err)
}
Expand Down
11 changes: 7 additions & 4 deletions pkg/tektontaskrun/taskrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

k "github.com/opendevstack/ods-pipeline/internal/kubernetes"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
pipelineclientset "github.com/tektoncd/pipeline/pkg/client/clientset/versioned"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -71,7 +71,7 @@ func createTaskRunWithParams(tknClient *pipelineclientset.Clientset, tc *TaskRun
})
}

tr, err := tknClient.TektonV1beta1().TaskRuns(tc.Namespace).Create(context.TODO(),
tr, err := tknClient.TektonV1().TaskRuns(tc.Namespace).Create(context.TODO(),
&tekton.TaskRun{
ObjectMeta: metav1.ObjectMeta{
Name: makeRandomTaskrunName(tc.Name),
Expand Down Expand Up @@ -103,7 +103,7 @@ func waitForTaskRunDone(
timeout := time.Until(deadline)
log.Printf("Waiting up to %v seconds for task %s in namespace %s to be done...\n", timeout.Round(time.Second).Seconds(), name, ns)

w, err := c.TektonV1beta1().TaskRuns(ns).Watch(ctx, metav1.SingleObject(metav1.ObjectMeta{
w, err := c.TektonV1().TaskRuns(ns).Watch(ctx, metav1.SingleObject(metav1.ObjectMeta{
Name: name,
Namespace: ns,
}))
Expand Down Expand Up @@ -143,7 +143,7 @@ func waitForTaskRunPod(

var taskRunPod *corev1.Pod

podsInformer.AddEventHandler(
_, err := podsInformer.AddEventHandler(
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
// when a new task is created, watch its events
Expand All @@ -156,6 +156,9 @@ func waitForTaskRunPod(

},
})
if err != nil {
log.Printf("Unable to install the event handler: %s", err)
}

defer close(stop)
kubeInformerFactory.Start(stop)
Expand Down
2 changes: 1 addition & 1 deletion pkg/tektontaskrun/taskrun_opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/opendevstack/ods-pipeline/internal/directory"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
tekton "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
)

const (
Expand Down
Loading

0 comments on commit 88bb3ad

Please sign in to comment.