From 5bb47a6e50f4463c9411955bf4f53ad9e3ee2ab0 Mon Sep 17 00:00:00 2001 From: Sascha Schwarze Date: Mon, 20 Nov 2023 21:57:30 +0100 Subject: [PATCH] Use Tekton V1 API when working with TaskRuns --- pkg/config/config.go | 37 ++++-- pkg/config/config_test.go | 17 ++- pkg/controller/controller.go | 4 +- pkg/reconciler/buildrun/buildrun.go | 16 +-- pkg/reconciler/buildrun/buildrun_test.go | 32 ++--- pkg/reconciler/buildrun/controller.go | 12 +- .../buildrun/resources/conditions.go | 18 +-- .../buildrun/resources/conditions_test.go | 4 +- .../buildrun/resources/failure_details.go | 19 +-- .../resources/failure_details_test.go | 47 +++---- .../buildrun/resources/image_processing.go | 30 +++-- .../resources/image_processing_test.go | 20 +-- pkg/reconciler/buildrun/resources/params.go | 18 +-- .../buildrun/resources/params_test.go | 56 ++++---- pkg/reconciler/buildrun/resources/results.go | 10 +- .../buildrun/resources/results_test.go | 74 +++++------ pkg/reconciler/buildrun/resources/sources.go | 6 +- .../buildrun/resources/sources/bundle.go | 32 +++-- .../buildrun/resources/sources/git.go | 58 +++++---- .../buildrun/resources/sources/git_test.go | 10 +- .../buildrun/resources/sources/http.go | 8 +- .../buildrun/resources/sources/http_test.go | 18 +-- .../buildrun/resources/sources/local_copy.go | 21 ++- .../resources/sources/local_copy_test.go | 6 +- .../buildrun/resources/sources/utils.go | 6 +- .../buildrun/resources/sources/utils_test.go | 10 +- .../resources/steps/security_context.go | 4 +- .../resources/steps/security_context_test.go | 8 +- pkg/reconciler/buildrun/resources/taskrun.go | 121 +++++++++--------- .../buildrun/resources/taskrun_test.go | 19 +-- pkg/reconciler/buildrun/resources/volumes.go | 4 +- test/e2e/v1alpha1/validators_test.go | 4 +- test/e2e/v1beta1/validators_test.go | 4 +- .../integration/buildruns_to_taskruns_test.go | 4 +- .../buildstrategy_to_taskruns_test.go | 28 ++-- test/utils/v1alpha1/lookup.go | 14 +- test/utils/v1alpha1/taskruns.go | 14 +- test/utils/v1beta1/lookup.go | 14 +- test/utils/v1beta1/taskruns.go | 14 +- test/v1alpha1_samples/catalog.go | 62 ++++----- test/v1beta1_samples/catalog.go | 62 ++++----- 41 files changed, 500 insertions(+), 465 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index fde2657eaf..e98e265a75 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -12,7 +12,6 @@ import ( "time" "github.com/prometheus/client_golang/prometheus" - pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" ) @@ -93,10 +92,10 @@ var ( // can be set to use on the Build controllers type Config struct { CtxTimeOut time.Duration - GitContainerTemplate pipeline.Step - ImageProcessingContainerTemplate pipeline.Step - BundleContainerTemplate pipeline.Step - WaiterContainerTemplate pipeline.Step + GitContainerTemplate Step + ImageProcessingContainerTemplate Step + BundleContainerTemplate Step + WaiterContainerTemplate Step RemoteArtifactsContainerImage string TerminationLogPath string Prometheus PrometheusConfig @@ -141,6 +140,17 @@ type KubeAPIOptions struct { Burst int } +type Step struct { + Args []string `json:"args,omitempty"` + Command []string `json:"command,omitempty"` + Env []corev1.EnvVar `json:"env,omitempty"` + Image string `json:"image,omitempty"` + ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"` + Resources corev1.ResourceRequirements `json:"resources,omitempty"` + SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"` + WorkingDir string `json:"workingDir,omitempty"` +} + // NewDefaultConfig returns a new Config, with context timeout and default Kaniko image. func NewDefaultConfig() *Config { return &Config{ @@ -149,7 +159,7 @@ func NewDefaultConfig() *Config { TerminationLogPath: terminationLogPathDefault, GitRewriteRule: false, - GitContainerTemplate: pipeline.Step{ + GitContainerTemplate: Step{ Image: gitDefaultImage, Command: []string{ "/ko-app/git", @@ -173,7 +183,7 @@ func NewDefaultConfig() *Config { }, }, - BundleContainerTemplate: pipeline.Step{ + BundleContainerTemplate: Step{ Image: bundleDefaultImage, Command: []string{ "/ko-app/bundle", @@ -196,7 +206,8 @@ func NewDefaultConfig() *Config { RunAsGroup: nonRoot, }, }, - ImageProcessingContainerTemplate: pipeline.Step{ + + ImageProcessingContainerTemplate: Step{ Image: imageProcessingDefaultImage, Command: []string{ "/ko-app/image-processing", @@ -228,7 +239,7 @@ func NewDefaultConfig() *Config { }, }, - WaiterContainerTemplate: pipeline.Step{ + WaiterContainerTemplate: Step{ Image: waiterDefaultImage, Command: []string{ "/ko-app/waiter", @@ -298,7 +309,7 @@ func (c *Config) SetConfigFromEnv() error { } if gitContainerTemplate := os.Getenv(gitContainerTemplateEnvVar); gitContainerTemplate != "" { - c.GitContainerTemplate = pipeline.Step{} + c.GitContainerTemplate = Step{} if err := json.Unmarshal([]byte(gitContainerTemplate), &c.GitContainerTemplate); err != nil { return err } @@ -313,7 +324,7 @@ func (c *Config) SetConfigFromEnv() error { } if imageProcessingContainerTemplate := os.Getenv(imageProcessingContainerTemplateEnvVar); imageProcessingContainerTemplate != "" { - c.ImageProcessingContainerTemplate = pipeline.Step{} + c.ImageProcessingContainerTemplate = Step{} if err := json.Unmarshal([]byte(imageProcessingContainerTemplate), &c.ImageProcessingContainerTemplate); err != nil { return err } @@ -334,7 +345,7 @@ func (c *Config) SetConfigFromEnv() error { } if bundleContainerTemplate := os.Getenv(bundleContainerTemplateEnvVar); bundleContainerTemplate != "" { - c.BundleContainerTemplate = pipeline.Step{} + c.BundleContainerTemplate = Step{} if err := json.Unmarshal([]byte(bundleContainerTemplate), &c.BundleContainerTemplate); err != nil { return err } @@ -349,7 +360,7 @@ func (c *Config) SetConfigFromEnv() error { } if waiterContainerTemplate := os.Getenv(waiterContainerTemplateEnvVar); waiterContainerTemplate != "" { - c.WaiterContainerTemplate = pipeline.Step{} + c.WaiterContainerTemplate = Step{} if err := json.Unmarshal([]byte(waiterContainerTemplate), &c.WaiterContainerTemplate); err != nil { return err } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 9520c87c3b..0eaa7d0db3 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -10,7 +10,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" "k8s.io/utils/pointer" @@ -108,7 +107,7 @@ var _ = Describe("Config", func() { } configWithEnvVariableOverrides(overrides, func(config *Config) { - Expect(config.GitContainerTemplate).To(Equal(pipeline.Step{ + Expect(config.GitContainerTemplate).To(Equal(Step{ Image: "myregistry/custom/git-image", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ @@ -127,7 +126,7 @@ var _ = Describe("Config", func() { configWithEnvVariableOverrides(overrides, func(config *Config) { nonRoot := pointer.Int64(1000) - Expect(config.GitContainerTemplate).To(Equal(pipeline.Step{ + Expect(config.GitContainerTemplate).To(Equal(Step{ Image: "myregistry/custom/git-image", Command: []string{ "/ko-app/git", @@ -154,7 +153,7 @@ var _ = Describe("Config", func() { } configWithEnvVariableOverrides(overrides, func(config *Config) { - Expect(config.GitContainerTemplate).To(Equal(pipeline.Step{ + Expect(config.GitContainerTemplate).To(Equal(Step{ Image: "myregistry/custom/git-image:override", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ @@ -172,7 +171,7 @@ var _ = Describe("Config", func() { } configWithEnvVariableOverrides(overrides, func(config *Config) { - Expect(config.ImageProcessingContainerTemplate).To(Equal(pipeline.Step{ + Expect(config.ImageProcessingContainerTemplate).To(Equal(Step{ Image: "myregistry/custom/image-processing", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ @@ -190,7 +189,7 @@ var _ = Describe("Config", func() { } configWithEnvVariableOverrides(overrides, func(config *Config) { - Expect(config.WaiterContainerTemplate).To(Equal(pipeline.Step{ + Expect(config.WaiterContainerTemplate).To(Equal(Step{ Image: "myregistry/custom/image", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ @@ -209,7 +208,7 @@ var _ = Describe("Config", func() { } configWithEnvVariableOverrides(overrides, func(config *Config) { - Expect(config.ImageProcessingContainerTemplate).To(Equal(pipeline.Step{ + Expect(config.ImageProcessingContainerTemplate).To(Equal(Step{ Image: "myregistry/custom/image-processing:override", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ @@ -229,7 +228,7 @@ var _ = Describe("Config", func() { configWithEnvVariableOverrides(overrides, func(config *Config) { nonRoot := pointer.Int64(1000) - Expect(config.WaiterContainerTemplate).To(Equal(pipeline.Step{ + Expect(config.WaiterContainerTemplate).To(Equal(Step{ Image: "myregistry/custom/image", Command: []string{"/ko-app/waiter"}, Args: []string{"start"}, @@ -255,7 +254,7 @@ var _ = Describe("Config", func() { } configWithEnvVariableOverrides(overrides, func(config *Config) { - Expect(config.WaiterContainerTemplate).To(Equal(pipeline.Step{ + Expect(config.WaiterContainerTemplate).To(Equal(Step{ Image: "myregistry/custom/image:override", Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 656f134b01..c427c524e0 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -7,7 +7,7 @@ package controller import ( "context" - pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "k8s.io/client-go/rest" "sigs.k8s.io/controller-runtime/pkg/manager" @@ -39,7 +39,7 @@ func NewManager(ctx context.Context, config *config.Config, cfg *rest.Config, op ctxlog.Info(ctx, "Registering Components.") - if err := pipelinev1beta1.AddToScheme(mgr.GetScheme()); err != nil { + if err := pipelineapi.AddToScheme(mgr.GetScheme()); err != nil { return nil, err } diff --git a/pkg/reconciler/buildrun/buildrun.go b/pkg/reconciler/buildrun/buildrun.go index 7c6840d526..eb7ab6ba7f 100644 --- a/pkg/reconciler/buildrun/buildrun.go +++ b/pkg/reconciler/buildrun/buildrun.go @@ -12,7 +12,7 @@ import ( "strconv" "strings" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "knative.dev/pkg/apis" corev1 "k8s.io/api/core/v1" @@ -81,7 +81,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req // so we can no longer assume that a build run event will not come in after the build run has a task run ref in its status buildRun = &buildv1alpha1.BuildRun{} getBuildRunErr := r.GetBuildRunObject(ctx, request.Name, request.Namespace, buildRun) - lastTaskRun := &v1beta1.TaskRun{} + lastTaskRun := &pipelineapi.TaskRun{} getTaskRunErr := r.client.Get(ctx, types.NamespacedName{Name: request.Name, Namespace: request.Namespace}, lastTaskRun) if getBuildRunErr != nil && getTaskRunErr != nil { @@ -372,7 +372,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req ctxlog.Info(ctx, "buildRun marked for cancellation, patching task run", namespace, request.Namespace, name, request.Name) // patch tekton taskrun a la tkn to start tekton's cancelling logic trueParam := true - if err := r.patchTaskRun(ctx, lastTaskRun, "replace", "/spec/status", v1beta1.TaskRunSpecStatusCancelled, metav1.PatchOptions{Force: &trueParam}); err != nil { + if err := r.patchTaskRun(ctx, lastTaskRun, "replace", "/spec/status", pipelineapi.TaskRunSpecStatusCancelled, metav1.PatchOptions{Force: &trueParam}); err != nil { return reconcile.Result{}, err } } @@ -386,9 +386,9 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req return reconcile.Result{}, nil } - if len(lastTaskRun.Status.TaskRunResults) > 0 { + if len(lastTaskRun.Status.Results) > 0 { ctxlog.Info(ctx, "surfacing taskRun results to BuildRun status", namespace, request.Namespace, name, request.Name) - resources.UpdateBuildRunUsingTaskResults(ctx, buildRun, lastTaskRun.Status.TaskRunResults, request) + resources.UpdateBuildRunUsingTaskResults(ctx, buildRun, lastTaskRun.Status.Results, request) } trCondition := lastTaskRun.Status.GetCondition(apis.ConditionSucceeded) @@ -550,9 +550,9 @@ func (r *ReconcileBuildRun) getReferencedStrategy(ctx context.Context, build *bu return strategy, err } -func (r *ReconcileBuildRun) createTaskRun(ctx context.Context, serviceAccount *corev1.ServiceAccount, strategy buildv1alpha1.BuilderStrategy, build *buildv1alpha1.Build, buildRun *buildv1alpha1.BuildRun) (*v1beta1.TaskRun, error) { +func (r *ReconcileBuildRun) createTaskRun(ctx context.Context, serviceAccount *corev1.ServiceAccount, strategy buildv1alpha1.BuilderStrategy, build *buildv1alpha1.Build, buildRun *buildv1alpha1.BuildRun) (*pipelineapi.TaskRun, error) { var ( - generatedTaskRun *v1beta1.TaskRun + generatedTaskRun *pipelineapi.TaskRun ) generatedTaskRun, err := resources.GenerateTaskRun(r.config, build, buildRun, serviceAccount.Name, strategy) @@ -582,7 +582,7 @@ type patchStringValue struct { Value string `json:"value"` } -func (r *ReconcileBuildRun) patchTaskRun(ctx context.Context, tr *v1beta1.TaskRun, op, path, value string, opts metav1.PatchOptions) error { +func (r *ReconcileBuildRun) patchTaskRun(ctx context.Context, tr *pipelineapi.TaskRun, op, path, value string, opts metav1.PatchOptions) error { payload := []patchStringValue{{ Op: op, Path: path, diff --git a/pkg/reconciler/buildrun/buildrun_test.go b/pkg/reconciler/buildrun/buildrun_test.go index ffba2168e0..1f95f07649 100644 --- a/pkg/reconciler/buildrun/buildrun_test.go +++ b/pkg/reconciler/buildrun/buildrun_test.go @@ -13,7 +13,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -46,7 +46,7 @@ var _ = Describe("Reconcile BuildRun", func() { ctl test.Catalog buildSample *build.Build buildRunSample *build.BuildRun - taskRunSample *v1beta1.TaskRun + taskRunSample *pipelineapi.TaskRun statusWriter *fakes.FakeStatusWriter taskRunName, buildRunName, buildName, strategyName, ns string ) @@ -71,7 +71,7 @@ var _ = Describe("Reconcile BuildRun", func() { case *build.BuildRun: buildRunSample.DeepCopyInto(object) return nil - case *v1beta1.TaskRun: + case *pipelineapi.TaskRun: taskRunSample.DeepCopyInto(object) return nil } @@ -378,7 +378,7 @@ var _ = Describe("Reconcile BuildRun", func() { statusWriter.UpdateCalls(stubUpdateCalls) stubPatchCalls := func(_ context.Context, object crc.Object, patch crc.Patch, opts ...crc.PatchOption) error { switch v := object.(type) { - case *v1beta1.TaskRun: + case *pipelineapi.TaskRun: if v.Name == taskRunSample.Name { cancelPatchCalled = true } @@ -394,11 +394,11 @@ var _ = Describe("Reconcile BuildRun", func() { // actually set value the patch would have set (but we overrode above) // for next call - taskRunSample.Spec.Status = v1beta1.TaskRunSpecStatusCancelled + taskRunSample.Spec.Status = pipelineapi.TaskRunSpecStatusCancelled taskRunSample.Status.Conditions = knativev1.Conditions{ { Type: knativeapi.ConditionSucceeded, - Reason: string(v1beta1.TaskRunReasonCancelled), + Reason: string(pipelineapi.TaskRunReasonCancelled), Status: corev1.ConditionFalse, }, } @@ -463,15 +463,15 @@ var _ = Describe("Reconcile BuildRun", func() { It("does not break the reconcile when a failed taskrun has a pod with no failed container", func() { buildRunSample = ctl.BuildRunWithBuildSnapshot(buildRunName, buildName) - taskRunSample = &v1beta1.TaskRun{ + taskRunSample = &pipelineapi.TaskRun{ ObjectMeta: metav1.ObjectMeta{ Name: taskRunName, Namespace: ns, Labels: map[string]string{"buildrun.shipwright.io/name": buildRunName}, }, - Spec: v1beta1.TaskRunSpec{}, - Status: v1beta1.TaskRunStatus{ - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + Spec: pipelineapi.TaskRunSpec{}, + Status: pipelineapi.TaskRunStatus{ + TaskRunStatusFields: pipelineapi.TaskRunStatusFields{ PodName: "foobar", CompletionTime: &metav1.Time{ Time: time.Now(), @@ -484,7 +484,7 @@ var _ = Describe("Reconcile BuildRun", func() { Conditions: knativev1.Conditions{ { Type: knativeapi.ConditionSucceeded, - Reason: string(v1beta1.TaskRunReasonFailed), + Reason: string(pipelineapi.TaskRunReasonFailed), Status: corev1.ConditionFalse, Message: "some message", }, @@ -973,7 +973,7 @@ var _ = Describe("Reconcile BuildRun", func() { // Stub the create calls for a TaskRun client.CreateCalls(func(_ context.Context, object crc.Object, _ ...crc.CreateOption) error { switch object := object.(type) { - case *v1beta1.TaskRun: + case *pipelineapi.TaskRun: ctl.DefaultTaskRunWithStatus(taskRunName, buildRunName, ns, corev1.ConditionTrue, "Succeeded").DeepCopyInto(object) } return nil @@ -1002,7 +1002,7 @@ var _ = Describe("Reconcile BuildRun", func() { // Stub the create calls for a TaskRun client.CreateCalls(func(_ context.Context, object crc.Object, _ ...crc.CreateOption) error { switch object := object.(type) { - case *v1beta1.TaskRun: + case *pipelineapi.TaskRun: ctl.DefaultTaskRunWithStatus(taskRunName, buildRunName, ns, corev1.ConditionTrue, "Succeeded").DeepCopyInto(object) } return nil @@ -1085,7 +1085,7 @@ var _ = Describe("Reconcile BuildRun", func() { // Stub the create calls for a TaskRun client.CreateCalls(func(_ context.Context, object crc.Object, _ ...crc.CreateOption) error { switch object := object.(type) { - case *v1beta1.TaskRun: + case *pipelineapi.TaskRun: ctl.DefaultTaskRunWithStatus(taskRunName, buildRunName, ns, corev1.ConditionTrue, "Succeeded").DeepCopyInto(object) } return nil @@ -1294,7 +1294,7 @@ var _ = Describe("Reconcile BuildRun", func() { var taskRunCreates int client.CreateCalls(func(_ context.Context, o crc.Object, _ ...crc.CreateOption) error { switch o.(type) { - case *v1beta1.TaskRun: + case *pipelineapi.TaskRun: taskRunCreates++ } @@ -1466,7 +1466,7 @@ var _ = Describe("Reconcile BuildRun", func() { var taskRunCreates int client.CreateCalls(func(_ context.Context, o crc.Object, _ ...crc.CreateOption) error { switch taskRun := o.(type) { - case *v1beta1.TaskRun: + case *pipelineapi.TaskRun: taskRunCreates++ Expect(taskRun.Labels).ToNot(HaveKey(build.LabelBuild), "no build name label is suppose to be set") diff --git a/pkg/reconciler/buildrun/controller.go b/pkg/reconciler/buildrun/controller.go index b6341c38cd..034c19906b 100644 --- a/pkg/reconciler/buildrun/controller.go +++ b/pkg/reconciler/buildrun/controller.go @@ -7,7 +7,7 @@ package buildrun import ( "context" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "knative.dev/pkg/apis" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -81,8 +81,8 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in predTaskRun := predicate.Funcs{ UpdateFunc: func(e event.UpdateEvent) bool { - o := e.ObjectOld.(*v1beta1.TaskRun) - n := e.ObjectNew.(*v1beta1.TaskRun) + o := e.ObjectOld.(*pipelineapi.TaskRun) + n := e.ObjectNew.(*pipelineapi.TaskRun) // Process an update event when the old TR resource is not yet started and the new TR resource got a // condition of the type Succeeded @@ -99,7 +99,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in return false }, DeleteFunc: func(e event.DeleteEvent) bool { - o := e.Object.(*v1beta1.TaskRun) + o := e.Object.(*pipelineapi.TaskRun) // If the TaskRun was deleted before completion, then we reconcile to update the BuildRun to a Failed status return o.Status.CompletionTime == nil @@ -113,8 +113,8 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in // enqueue Reconciles requests only for events where a TaskRun already exists and that is related // to a BuildRun - return c.Watch(&source.Kind{Type: &v1beta1.TaskRun{}}, handler.EnqueueRequestsFromMapFunc(func(o client.Object) []reconcile.Request { - taskRun := o.(*v1beta1.TaskRun) + return c.Watch(&source.Kind{Type: &pipelineapi.TaskRun{}}, handler.EnqueueRequestsFromMapFunc(func(o client.Object) []reconcile.Request { + taskRun := o.(*pipelineapi.TaskRun) // check if TaskRun is related to BuildRun if taskRun.GetLabels() == nil || taskRun.GetLabels()[buildv1alpha1.LabelBuildRun] == "" { diff --git a/pkg/reconciler/buildrun/resources/conditions.go b/pkg/reconciler/buildrun/resources/conditions.go index 8ca0bf5a6b..3478096212 100644 --- a/pkg/reconciler/buildrun/resources/conditions.go +++ b/pkg/reconciler/buildrun/resources/conditions.go @@ -8,7 +8,7 @@ import ( "context" "fmt" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "knative.dev/pkg/apis" "sigs.k8s.io/controller-runtime/pkg/client" @@ -47,39 +47,39 @@ const ( ) // UpdateBuildRunUsingTaskRunCondition updates the BuildRun Succeeded Condition -func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Client, buildRun *buildv1alpha1.BuildRun, taskRun *v1beta1.TaskRun, trCondition *apis.Condition) error { +func UpdateBuildRunUsingTaskRunCondition(ctx context.Context, client client.Client, buildRun *buildv1alpha1.BuildRun, taskRun *pipelineapi.TaskRun, trCondition *apis.Condition) error { var reason, message string = trCondition.Reason, trCondition.Message status := trCondition.Status - switch v1beta1.TaskRunReason(reason) { - case v1beta1.TaskRunReasonStarted: + switch pipelineapi.TaskRunReason(reason) { + case pipelineapi.TaskRunReasonStarted: fallthrough - case v1beta1.TaskRunReasonRunning: + case pipelineapi.TaskRunReasonRunning: if buildRun.IsCanceled() { status = corev1.ConditionUnknown // in practice the taskrun status is already unknown in this case, but we are making sure here reason = buildv1alpha1.BuildRunStateCancel message = "The user requested the BuildRun to be canceled. This BuildRun controller has requested the TaskRun be canceled. That request has not been process by Tekton's TaskRun controller yet." } - case v1beta1.TaskRunReasonCancelled: + case pipelineapi.TaskRunReasonCancelled: if buildRun.IsCanceled() { status = corev1.ConditionFalse // in practice the taskrun status is already false in this case, bue we are making sure here reason = buildv1alpha1.BuildRunStateCancel message = "The BuildRun and underlying TaskRun were canceled successfully." } - case v1beta1.TaskRunReasonTimedOut: + case pipelineapi.TaskRunReasonTimedOut: reason = "BuildRunTimeout" message = fmt.Sprintf("BuildRun %s failed to finish within %s", buildRun.Name, taskRun.Spec.Timeout.Duration, ) - case v1beta1.TaskRunReasonSuccessful: + case pipelineapi.TaskRunReasonSuccessful: if buildRun.IsCanceled() { message = "The TaskRun completed before the request to cancel the TaskRun could be processed." } - case v1beta1.TaskRunReasonFailed: + case pipelineapi.TaskRunReasonFailed: if taskRun.Status.CompletionTime != nil { pod, failedContainer, err := extractFailedPodAndContainer(ctx, client, taskRun) if err != nil { diff --git a/pkg/reconciler/buildrun/resources/conditions_test.go b/pkg/reconciler/buildrun/resources/conditions_test.go index d9306fdd30..84661792ad 100644 --- a/pkg/reconciler/buildrun/resources/conditions_test.go +++ b/pkg/reconciler/buildrun/resources/conditions_test.go @@ -13,7 +13,7 @@ import ( "github.com/shipwright-io/build/pkg/controller/fakes" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" test "github.com/shipwright-io/build/test/v1alpha1_samples" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -117,7 +117,7 @@ var _ = Describe("Conditions", func() { client *fakes.FakeClient ctl test.Catalog br *build.BuildRun - tr *v1beta1.TaskRun + tr *pipelineapi.TaskRun ) tr = ctl.TaskRunWithStatus("foo", "bar") diff --git a/pkg/reconciler/buildrun/resources/failure_details.go b/pkg/reconciler/buildrun/resources/failure_details.go index b935d8f8c8..b96451abaf 100644 --- a/pkg/reconciler/buildrun/resources/failure_details.go +++ b/pkg/reconciler/buildrun/resources/failure_details.go @@ -15,7 +15,8 @@ import ( buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" "github.com/shipwright-io/build/pkg/ctxlog" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" + "github.com/tektoncd/pipeline/pkg/result" "knative.dev/pkg/apis" ) @@ -27,23 +28,23 @@ const ( ) // UpdateBuildRunUsingTaskFailures is extracting failures from taskRun steps and adding them to buildRun (mutates) -func UpdateBuildRunUsingTaskFailures(ctx context.Context, client client.Client, buildRun *buildv1alpha1.BuildRun, taskRun *v1beta1.TaskRun) { +func UpdateBuildRunUsingTaskFailures(ctx context.Context, client client.Client, buildRun *buildv1alpha1.BuildRun, taskRun *pipelineapi.TaskRun) { trCondition := taskRun.Status.GetCondition(apis.ConditionSucceeded) // only extract failures when failing condition is present - if trCondition != nil && v1beta1.TaskRunReason(trCondition.Reason) == v1beta1.TaskRunReasonFailed { + if trCondition != nil && pipelineapi.TaskRunReason(trCondition.Reason) == pipelineapi.TaskRunReasonFailed { buildRun.Status.FailureDetails = extractFailureDetails(ctx, client, taskRun) } } -func extractFailureReasonAndMessage(taskRun *v1beta1.TaskRun) (errorReason string, errorMessage string) { +func extractFailureReasonAndMessage(taskRun *pipelineapi.TaskRun) (errorReason string, errorMessage string) { for _, step := range taskRun.Status.Steps { if step.Terminated == nil || step.Terminated.ExitCode == 0 { continue } message := step.Terminated.Message - var taskRunResults []v1beta1.PipelineResourceResult + var taskRunResults []result.RunResult if err := json.Unmarshal([]byte(message), &taskRunResults); err != nil { continue @@ -63,7 +64,7 @@ func extractFailureReasonAndMessage(taskRun *v1beta1.TaskRun) (errorReason strin return errorReason, errorMessage } -func extractFailedPodAndContainer(ctx context.Context, client client.Client, taskRun *v1beta1.TaskRun) (*corev1.Pod, *corev1.Container, error) { +func extractFailedPodAndContainer(ctx context.Context, client client.Client, taskRun *pipelineapi.TaskRun) (*corev1.Pod, *corev1.Container, error) { var pod corev1.Pod if err := client.Get(ctx, types.NamespacedName{Namespace: taskRun.Namespace, Name: taskRun.Status.PodName}, &pod); err != nil { ctxlog.Error(ctx, err, "failed to get pod for failure extraction", namespace, taskRun.Namespace, name, taskRun.Status.PodName) @@ -90,7 +91,7 @@ func extractFailedPodAndContainer(ctx context.Context, client client.Client, tas return &pod, failedContainer, nil } -func extractFailureDetails(ctx context.Context, client client.Client, taskRun *v1beta1.TaskRun) (failure *buildv1alpha1.FailureDetails) { +func extractFailureDetails(ctx context.Context, client client.Client, taskRun *pipelineapi.TaskRun) (failure *buildv1alpha1.FailureDetails) { failure = &buildv1alpha1.FailureDetails{} failure.Reason, failure.Message = extractFailureReasonAndMessage(taskRun) @@ -106,8 +107,8 @@ func extractFailureDetails(ctx context.Context, client client.Client, taskRun *v return failure } -func getFailureDetailsTaskSpecResults() []v1beta1.TaskResult { - return []v1beta1.TaskResult{ +func getFailureDetailsTaskSpecResults() []pipelineapi.TaskResult { + return []pipelineapi.TaskResult{ { Name: fmt.Sprintf("%s-%s", prefixParamsResultsVolumes, resultErrorMessage), Description: "The error description of the task run", diff --git a/pkg/reconciler/buildrun/resources/failure_details_test.go b/pkg/reconciler/buildrun/resources/failure_details_test.go index 07cbd7cfea..dbae3cc308 100644 --- a/pkg/reconciler/buildrun/resources/failure_details_test.go +++ b/pkg/reconciler/buildrun/resources/failure_details_test.go @@ -11,7 +11,8 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" + "github.com/tektoncd/pipeline/pkg/result" corev1 "k8s.io/api/core/v1" "knative.dev/pkg/apis" @@ -25,24 +26,24 @@ var _ = Describe("Surfacing errors", func() { client := &buildfakes.FakeClient{} It("surfaces errors to BuildRun in failed TaskRun", func() { - redTaskRun := pipelinev1beta1.TaskRun{} + redTaskRun := pipelineapi.TaskRun{} redTaskRun.Status.Conditions = append(redTaskRun.Status.Conditions, - apis.Condition{Type: apis.ConditionSucceeded, Reason: pipelinev1beta1.TaskRunReasonFailed.String()}) - failedStep := pipelinev1beta1.StepState{} + apis.Condition{Type: apis.ConditionSucceeded, Reason: pipelineapi.TaskRunReasonFailed.String()}) + failedStep := pipelineapi.StepState{} errorReasonValue := "PullBaseImageFailed" errorMessageValue := "Failed to pull the base image." errorReasonKey := fmt.Sprintf("%s-%s", prefixParamsResultsVolumes, resultErrorReason) errorMessageKey := fmt.Sprintf("%s-%s", prefixParamsResultsVolumes, resultErrorMessage) - errorReason := pipelinev1beta1.PipelineResourceResult{Key: errorReasonKey, Value: errorReasonValue} - errorMessage := pipelinev1beta1.PipelineResourceResult{Key: errorMessageKey, Value: errorMessageValue} - unrelated := pipelinev1beta1.PipelineResourceResult{Key: "unrelated-resource-key", Value: "Unrelated resource value"} + errorReason := result.RunResult{Key: errorReasonKey, Value: errorReasonValue} + errorMessage := result.RunResult{Key: errorMessageKey, Value: errorMessageValue} + unrelated := result.RunResult{Key: "unrelated-resource-key", Value: "Unrelated resource value"} - message, _ := json.Marshal([]pipelinev1beta1.PipelineResourceResult{errorReason, errorMessage, unrelated}) + message, _ := json.Marshal([]result.RunResult{errorReason, errorMessage, unrelated}) failedStep.Terminated = &corev1.ContainerStateTerminated{Message: string(message), ExitCode: 1} - followUpStep := pipelinev1beta1.StepState{} + followUpStep := pipelineapi.StepState{} redTaskRun.Status.Steps = append(redTaskRun.Status.Steps, failedStep, followUpStep) redBuild := buildv1alpha1.BuildRun{} @@ -54,14 +55,14 @@ var _ = Describe("Surfacing errors", func() { }) It("does not surface unrelated Tekton resources if the TaskRun fails", func() { - redTaskRun := pipelinev1beta1.TaskRun{} + redTaskRun := pipelineapi.TaskRun{} redTaskRun.Status.Conditions = append(redTaskRun.Status.Conditions, - apis.Condition{Type: apis.ConditionSucceeded, Reason: pipelinev1beta1.TaskRunReasonFailed.String()}) - failedStep := pipelinev1beta1.StepState{} + apis.Condition{Type: apis.ConditionSucceeded, Reason: pipelineapi.TaskRunReasonFailed.String()}) + failedStep := pipelineapi.StepState{} - unrelated := pipelinev1beta1.PipelineResourceResult{Key: "unrelated", Value: "unrelated"} + unrelated := result.RunResult{Key: "unrelated", Value: "unrelated"} - message, _ := json.Marshal([]pipelinev1beta1.PipelineResourceResult{unrelated}) + message, _ := json.Marshal([]result.RunResult{unrelated}) failedStep.Terminated = &corev1.ContainerStateTerminated{Message: string(message)} @@ -75,19 +76,19 @@ var _ = Describe("Surfacing errors", func() { }) It("does not surface error results if the container terminated without failure", func() { - greenTaskRun := pipelinev1beta1.TaskRun{} + greenTaskRun := pipelineapi.TaskRun{} greenTaskRun.Status.Conditions = append(greenTaskRun.Status.Conditions, - apis.Condition{Type: apis.ConditionSucceeded, Reason: pipelinev1beta1.TaskRunReasonSuccessful.String()}) - failedStep := pipelinev1beta1.StepState{} + apis.Condition{Type: apis.ConditionSucceeded, Reason: pipelineapi.TaskRunReasonSuccessful.String()}) + failedStep := pipelineapi.StepState{} errorReasonValue := "PullBaseImageFailed" errorMessageValue := "Failed to pull the base image." errorReasonKey := fmt.Sprintf("%s-%s", prefixParamsResultsVolumes, resultErrorReason) errorMessageKey := fmt.Sprintf("%s-%s", prefixParamsResultsVolumes, resultErrorMessage) - errorReason := pipelinev1beta1.PipelineResourceResult{Key: errorReasonKey, Value: errorReasonValue} - errorMessage := pipelinev1beta1.PipelineResourceResult{Key: errorMessageKey, Value: errorMessageValue} - message, _ := json.Marshal([]pipelinev1beta1.PipelineResourceResult{errorReason, errorMessage}) + errorReason := result.RunResult{Key: errorReasonKey, Value: errorReasonValue} + errorMessage := result.RunResult{Key: errorMessageKey, Value: errorMessageValue} + message, _ := json.Marshal([]result.RunResult{errorReason, errorMessage}) failedStep.Terminated = &corev1.ContainerStateTerminated{Message: string(message)} @@ -100,7 +101,7 @@ var _ = Describe("Surfacing errors", func() { }) It("should not surface errors for a successful TaskRun", func() { - greenTaskRun := pipelinev1beta1.TaskRun{} + greenTaskRun := pipelineapi.TaskRun{} greenTaskRun.Status.Conditions = append(greenTaskRun.Status.Conditions, apis.Condition{Type: apis.ConditionSucceeded}) greenBuildRun := buildv1alpha1.BuildRun{} @@ -110,7 +111,7 @@ var _ = Describe("Surfacing errors", func() { }) It("should not surface errors if the TaskRun does not have a Succeeded condition", func() { - unfinishedTaskRun := pipelinev1beta1.TaskRun{} + unfinishedTaskRun := pipelineapi.TaskRun{} unfinishedTaskRun.Status.Conditions = append(unfinishedTaskRun.Status.Conditions, apis.Condition{Type: apis.ConditionReady}) unfinishedBuildRun := buildv1alpha1.BuildRun{} @@ -119,7 +120,7 @@ var _ = Describe("Surfacing errors", func() { }) It("should not surface errors if the TaskRun is in progress", func() { - unknownTaskRun := pipelinev1beta1.TaskRun{} + unknownTaskRun := pipelineapi.TaskRun{} unknownTaskRun.Status.Conditions = append(unknownTaskRun.Status.Conditions, apis.Condition{Type: apis.ConditionSucceeded, Reason: "random"}) unknownBuildRun := buildv1alpha1.BuildRun{} diff --git a/pkg/reconciler/buildrun/resources/image_processing.go b/pkg/reconciler/buildrun/resources/image_processing.go index ae4becab8a..349ed6af63 100644 --- a/pkg/reconciler/buildrun/resources/image_processing.go +++ b/pkg/reconciler/buildrun/resources/image_processing.go @@ -10,7 +10,7 @@ import ( build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/sources" - pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" core "k8s.io/api/core/v1" ) @@ -21,7 +21,7 @@ const ( ) // SetupImageProcessing appends the image-processing step to a TaskRun if desired -func SetupImageProcessing(taskRun *pipeline.TaskRun, cfg *config.Config, buildOutput, buildRunOutput build.Image) { +func SetupImageProcessing(taskRun *pipelineapi.TaskRun, cfg *config.Config, buildOutput, buildRunOutput build.Image) { stepArgs := []string{} // Check if any build step references the output-directory system parameter. If that is the case, @@ -44,17 +44,17 @@ func SetupImageProcessing(taskRun *pipeline.TaskRun, cfg *config.Config, buildOu }) // add the parameter definition - taskRun.Spec.TaskSpec.Params = append(taskRun.Spec.TaskSpec.Params, pipeline.ParamSpec{ + taskRun.Spec.TaskSpec.Params = append(taskRun.Spec.TaskSpec.Params, pipelineapi.ParamSpec{ Name: prefixedOutputDirectory, - Type: pipeline.ParamTypeString, + Type: pipelineapi.ParamTypeString, }) // add the parameter value - taskRun.Spec.Params = append(taskRun.Spec.Params, pipeline.Param{ + taskRun.Spec.Params = append(taskRun.Spec.Params, pipelineapi.Param{ Name: prefixedOutputDirectory, - Value: pipeline.ParamValue{ + Value: pipelineapi.ParamValue{ StringVal: outputDirectoryMountPath, - Type: pipeline.ParamTypeString, + Type: pipelineapi.ParamTypeString, }, }) @@ -95,11 +95,19 @@ func SetupImageProcessing(taskRun *pipeline.TaskRun, cfg *config.Config, buildOu stepArgs = append(stepArgs, "--result-file-image-size", fmt.Sprintf("$(results.%s-%s.path)", prefixParamsResultsVolumes, imageSizeResult)) // add the push step - // initialize the step from the template - imageProcessingStep := *cfg.ImageProcessingContainerTemplate.DeepCopy() - imageProcessingStep.Name = containerNameImageProcessing - imageProcessingStep.Args = stepArgs + // initialize the step from the template and the build-specific arguments + imageProcessingStep := pipelineapi.Step{ + Name: containerNameImageProcessing, + Image: cfg.ImageProcessingContainerTemplate.Image, + ImagePullPolicy: cfg.ImageProcessingContainerTemplate.ImagePullPolicy, + Command: cfg.ImageProcessingContainerTemplate.Command, + Args: stepArgs, + Env: cfg.ImageProcessingContainerTemplate.Env, + ComputeResources: cfg.ImageProcessingContainerTemplate.Resources, + SecurityContext: cfg.ImageProcessingContainerTemplate.SecurityContext, + WorkingDir: cfg.ImageProcessingContainerTemplate.WorkingDir, + } if volumeAdded { imageProcessingStep.VolumeMounts = append(imageProcessingStep.VolumeMounts, core.VolumeMount{ diff --git a/pkg/reconciler/buildrun/resources/image_processing_test.go b/pkg/reconciler/buildrun/resources/image_processing_test.go index ebaaa0d741..0e7853a854 100644 --- a/pkg/reconciler/buildrun/resources/image_processing_test.go +++ b/pkg/reconciler/buildrun/resources/image_processing_test.go @@ -14,19 +14,19 @@ import ( "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" utils "github.com/shipwright-io/build/test/utils/v1alpha1" - pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" ) var _ = Describe("Image Processing overrides", func() { config := config.NewDefaultConfig() - var processedTaskRun *pipeline.TaskRun + var processedTaskRun *pipelineapi.TaskRun Context("for a TaskRun that does not reference the output directory", func() { - taskRun := &pipeline.TaskRun{ - Spec: pipeline.TaskRunSpec{ - TaskSpec: &pipeline.TaskSpec{ - Steps: []pipeline.Step{ + taskRun := &pipelineapi.TaskRun{ + Spec: pipelineapi.TaskRunSpec{ + TaskSpec: &pipelineapi.TaskSpec{ + Steps: []pipelineapi.Step{ { Name: "test-step", }, @@ -83,10 +83,10 @@ var _ = Describe("Image Processing overrides", func() { Context("for a TaskRun that references the output directory", func() { - taskRun := &pipeline.TaskRun{ - Spec: pipeline.TaskRunSpec{ - TaskSpec: &pipeline.TaskSpec{ - Steps: []pipeline.Step{ + taskRun := &pipelineapi.TaskRun{ + Spec: pipelineapi.TaskRunSpec{ + TaskSpec: &pipelineapi.TaskSpec{ + Steps: []pipelineapi.Step{ { Name: "test-step", Args: []string{ diff --git a/pkg/reconciler/buildrun/resources/params.go b/pkg/reconciler/buildrun/resources/params.go index 00f62198d9..3e5b9f8205 100644 --- a/pkg/reconciler/buildrun/resources/params.go +++ b/pkg/reconciler/buildrun/resources/params.go @@ -13,7 +13,7 @@ import ( corev1 "k8s.io/api/core/v1" buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" ) const ( @@ -90,17 +90,17 @@ func FindParamValueByName(paramValues []buildv1alpha1.ParamValue, name string) * } // HandleTaskRunParam makes the necessary changes to a TaskRun for a parameter -func HandleTaskRunParam(taskRun *pipeline.TaskRun, parameterDefinition *buildv1alpha1.Parameter, paramValue buildv1alpha1.ParamValue) error { - taskRunParam := pipeline.Param{ +func HandleTaskRunParam(taskRun *pipelineapi.TaskRun, parameterDefinition *buildv1alpha1.Parameter, paramValue buildv1alpha1.ParamValue) error { + taskRunParam := pipelineapi.Param{ Name: paramValue.Name, - Value: pipeline.ParamValue{}, + Value: pipelineapi.ParamValue{}, } switch parameterDefinition.Type { case "": // string is default fallthrough case buildv1alpha1.ParameterTypeString: - taskRunParam.Value.Type = pipeline.ParamTypeString + taskRunParam.Value.Type = pipelineapi.ParamTypeString switch { case paramValue.SingleValue == nil && parameterDefinition.Default == nil: @@ -146,7 +146,7 @@ func HandleTaskRunParam(taskRun *pipeline.TaskRun, parameterDefinition *buildv1a } case buildv1alpha1.ParameterTypeArray: - taskRunParam.Value.Type = pipeline.ParamTypeArray + taskRunParam.Value.Type = pipelineapi.ParamTypeArray switch { case paramValue.Values == nil && parameterDefinition.Defaults == nil: @@ -225,7 +225,7 @@ func generateEnvVarName(prefix string) (string, error) { // addConfigMapEnvVar modifies all steps which are referencing a parameter name in their command, args, or environment variable values, // to contain a mapped environment variable for the ConfigMap key. It returns the name of the environment variable name. -func addConfigMapEnvVar(taskRun *pipeline.TaskRun, paramName string, configMapName string, configMapKey string) (string, error) { +func addConfigMapEnvVar(taskRun *pipelineapi.TaskRun, paramName string, configMapName string, configMapKey string) (string, error) { envVarName := "" // In this first loop, we check whether any step already references the same ConfigMap key. This can @@ -287,7 +287,7 @@ stepModifyLoop: // addSecretEnvVar modifies all steps which are referencing a parameter name in their command, args, or environment variable values, // to contain a mapped environment variable for the Secret key. It returns the name of the environment variable name. -func addSecretEnvVar(taskRun *pipeline.TaskRun, paramName string, secretName string, secretKey string) (string, error) { +func addSecretEnvVar(taskRun *pipelineapi.TaskRun, paramName string, secretName string, secretKey string) (string, error) { envVarName := "" // In this first loop, we check whether any step already references the same Secret key. This can @@ -348,7 +348,7 @@ stepModifyLoop: } // isStepReferencingParameter checks if a step is referencing a parameter in its command, args, or environment variable values -func isStepReferencingParameter(step *pipeline.Step, paramName string) bool { +func isStepReferencingParameter(step *pipelineapi.Step, paramName string) bool { searchStrings := []string{ // the trailing ) is intentionally omitted because of arrays // Tekton reference: https://github.com/tektoncd/pipeline/blob/main/docs/tasks.md#using-variable-substitution diff --git a/pkg/reconciler/buildrun/resources/params_test.go b/pkg/reconciler/buildrun/resources/params_test.go index ad61c6183a..b42bc50606 100644 --- a/pkg/reconciler/buildrun/resources/params_test.go +++ b/pkg/reconciler/buildrun/resources/params_test.go @@ -15,7 +15,7 @@ import ( "k8s.io/utils/pointer" buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" ) var _ = Describe("Params overrides", func() { @@ -308,7 +308,7 @@ var _ = Describe("isStepReferencingParameter", func() { Context("for a Step referencing parameters in different ways", func() { - step := &pipeline.Step{ + step := &pipelineapi.Step{ Command: []string{ "some-command", "$(params.first-param)", @@ -347,13 +347,13 @@ var _ = Describe("isStepReferencingParameter", func() { var _ = Describe("HandleTaskRunParam", func() { - var taskRun *pipeline.TaskRun + var taskRun *pipelineapi.TaskRun BeforeEach(func() { - taskRun = &pipeline.TaskRun{ - Spec: pipeline.TaskRunSpec{ - TaskSpec: &pipeline.TaskSpec{ - Steps: []pipeline.Step{ + taskRun = &pipelineapi.TaskRun{ + Spec: pipelineapi.TaskRunSpec{ + TaskSpec: &pipelineapi.TaskSpec{ + Steps: []pipelineapi.Step{ { Name: "first-container", Args: []string{ @@ -388,11 +388,11 @@ var _ = Describe("HandleTaskRunParam", func() { }) Expect(err).ToNot(HaveOccurred()) - Expect(taskRun.Spec.Params).To(BeEquivalentTo([]pipeline.Param{ + Expect(taskRun.Spec.Params).To(BeEquivalentTo([]pipelineapi.Param{ { Name: "string-parameter", - Value: pipeline.ParamValue{ - Type: pipeline.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: "My value", }, }, @@ -431,11 +431,11 @@ var _ = Describe("HandleTaskRunParam", func() { Expect(len(taskRun.Spec.TaskSpec.Steps[1].Env)).To(Equal(0)) // Verify the parameters - Expect(taskRun.Spec.Params).To(BeEquivalentTo([]pipeline.Param{ + Expect(taskRun.Spec.Params).To(BeEquivalentTo([]pipelineapi.Param{ { Name: "string-parameter", - Value: pipeline.ParamValue{ - Type: pipeline.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: fmt.Sprintf("$(%s)", envVarName), }, }, @@ -475,11 +475,11 @@ var _ = Describe("HandleTaskRunParam", func() { Expect(len(taskRun.Spec.TaskSpec.Steps[1].Env)).To(Equal(0)) // Verify the parameters - Expect(taskRun.Spec.Params).To(BeEquivalentTo([]pipeline.Param{ + Expect(taskRun.Spec.Params).To(BeEquivalentTo([]pipelineapi.Param{ { Name: "string-parameter", - Value: pipeline.ParamValue{ - Type: pipeline.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: fmt.Sprintf("The value from the config map is '$(%s)'.", envVarName), }, }, @@ -518,11 +518,11 @@ var _ = Describe("HandleTaskRunParam", func() { Expect(len(taskRun.Spec.TaskSpec.Steps[1].Env)).To(Equal(0)) // Verify the parameters - Expect(taskRun.Spec.Params).To(BeEquivalentTo([]pipeline.Param{ + Expect(taskRun.Spec.Params).To(BeEquivalentTo([]pipelineapi.Param{ { Name: "string-parameter", - Value: pipeline.ParamValue{ - Type: pipeline.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: fmt.Sprintf("$(%s)", envVarName), }, }, @@ -562,11 +562,11 @@ var _ = Describe("HandleTaskRunParam", func() { Expect(len(taskRun.Spec.TaskSpec.Steps[1].Env)).To(Equal(0)) // Verify the parameters - Expect(taskRun.Spec.Params).To(BeEquivalentTo([]pipeline.Param{ + Expect(taskRun.Spec.Params).To(BeEquivalentTo([]pipelineapi.Param{ { Name: "string-parameter", - Value: pipeline.ParamValue{ - Type: pipeline.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: fmt.Sprintf("secret-value: $(%s)", envVarName), }, }, @@ -601,11 +601,11 @@ var _ = Describe("HandleTaskRunParam", func() { Expect(len(taskRun.Spec.TaskSpec.Steps[1].Env)).To(Equal(0)) // Verify the parameters - Expect(taskRun.Spec.Params).To(BeEquivalentTo([]pipeline.Param{ + Expect(taskRun.Spec.Params).To(BeEquivalentTo([]pipelineapi.Param{ { Name: "array-parameter", - Value: pipeline.ParamValue{ - Type: pipeline.ParamTypeArray, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeArray, ArrayVal: []string{ "first entry", "", @@ -660,11 +660,11 @@ var _ = Describe("HandleTaskRunParam", func() { })) // Verify the parameters - Expect(taskRun.Spec.Params).To(BeEquivalentTo([]pipeline.Param{ + Expect(taskRun.Spec.Params).To(BeEquivalentTo([]pipelineapi.Param{ { Name: "array-parameter", - Value: pipeline.ParamValue{ - Type: pipeline.ParamTypeArray, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeArray, ArrayVal: []string{ "first entry", fmt.Sprintf("$(%s)", envVarName), diff --git a/pkg/reconciler/buildrun/resources/results.go b/pkg/reconciler/buildrun/resources/results.go index 4eb12de686..61b31a9d3c 100644 --- a/pkg/reconciler/buildrun/resources/results.go +++ b/pkg/reconciler/buildrun/resources/results.go @@ -12,7 +12,7 @@ import ( build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" "github.com/shipwright-io/build/pkg/ctxlog" - pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "sigs.k8s.io/controller-runtime/pkg/reconcile" ) @@ -26,7 +26,7 @@ const ( func UpdateBuildRunUsingTaskResults( ctx context.Context, buildRun *build.BuildRun, - taskRunResult []pipeline.TaskRunResult, + taskRunResult []pipelineapi.TaskRunResult, request reconcile.Request, ) { // Set source results @@ -39,7 +39,7 @@ func UpdateBuildRunUsingTaskResults( updateBuildRunStatusWithOutputResult(ctx, buildRun, taskRunResult, request) } -func updateBuildRunStatusWithOutputResult(ctx context.Context, buildRun *build.BuildRun, taskRunResult []pipeline.TaskRunResult, request reconcile.Request) { +func updateBuildRunStatusWithOutputResult(ctx context.Context, buildRun *build.BuildRun, taskRunResult []pipelineapi.TaskRunResult, request reconcile.Request) { for _, result := range taskRunResult { switch result.Name { case generateOutputResultName(imageDigestResult): @@ -59,8 +59,8 @@ func generateOutputResultName(resultName string) string { return fmt.Sprintf("%s-%s", prefixParamsResultsVolumes, resultName) } -func getTaskSpecResults() []pipeline.TaskResult { - return []pipeline.TaskResult{ +func getTaskSpecResults() []pipelineapi.TaskResult { + return []pipelineapi.TaskResult{ { Name: fmt.Sprintf("%s-%s", prefixParamsResultsVolumes, imageDigestResult), Description: "The digest of the image", diff --git a/pkg/reconciler/buildrun/resources/results_test.go b/pkg/reconciler/buildrun/resources/results_test.go index 13966611c2..5196d8da4b 100644 --- a/pkg/reconciler/buildrun/resources/results_test.go +++ b/pkg/reconciler/buildrun/resources/results_test.go @@ -14,7 +14,7 @@ import ( "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" test "github.com/shipwright-io/build/test/v1alpha1_samples" - pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -27,7 +27,7 @@ var _ = Describe("TaskRun results to BuildRun", func() { var ( taskRunRequest reconcile.Request br *build.BuildRun - tr *pipelinev1beta1.TaskRun + tr *pipelineapi.TaskRun ) ctx := context.Background() @@ -52,23 +52,23 @@ var _ = Describe("TaskRun results to BuildRun", func() { commitSha := "0e0583421a5e4bf562ffe33f3651e16ba0c78591" br.Status.BuildSpec.Source.URL = pointer.String("https://github.com/shipwright-io/sample-go") - tr.Status.TaskRunResults = append(tr.Status.TaskRunResults, - pipelinev1beta1.TaskRunResult{ + tr.Status.Results = append(tr.Status.Results, + pipelineapi.TaskRunResult{ Name: "shp-source-default-commit-sha", - Value: pipelinev1beta1.ParamValue{ - Type: pipelinev1beta1.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: commitSha, }, }, - pipelinev1beta1.TaskRunResult{ + pipelineapi.TaskRunResult{ Name: "shp-source-default-commit-author", - Value: pipelinev1beta1.ParamValue{ - Type: pipelinev1beta1.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: "foo bar", }, }) - resources.UpdateBuildRunUsingTaskResults(ctx, br, tr.Status.TaskRunResults, taskRunRequest) + resources.UpdateBuildRunUsingTaskResults(ctx, br, tr.Status.Results, taskRunRequest) Expect(len(br.Status.Sources)).To(Equal(1)) Expect(br.Status.Sources[0].Git.CommitSha).To(Equal(commitSha)) @@ -81,16 +81,16 @@ var _ = Describe("TaskRun results to BuildRun", func() { Image: "ghcr.io/shipwright-io/sample-go/source-bundle:latest", } - tr.Status.TaskRunResults = append(tr.Status.TaskRunResults, - pipelinev1beta1.TaskRunResult{ + tr.Status.Results = append(tr.Status.Results, + pipelineapi.TaskRunResult{ Name: "shp-source-default-image-digest", - Value: pipelinev1beta1.ParamValue{ - Type: pipelinev1beta1.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: bundleImageDigest, }, }) - resources.UpdateBuildRunUsingTaskResults(ctx, br, tr.Status.TaskRunResults, taskRunRequest) + resources.UpdateBuildRunUsingTaskResults(ctx, br, tr.Status.Results, taskRunRequest) Expect(len(br.Status.Sources)).To(Equal(1)) Expect(br.Status.Sources[0].Bundle.Digest).To(Equal(bundleImageDigest)) @@ -99,23 +99,23 @@ var _ = Describe("TaskRun results to BuildRun", func() { It("should surface the TaskRun results emitting from output step", func() { imageDigest := "sha256:fe1b73cd25ac3f11dec752755e2" - tr.Status.TaskRunResults = append(tr.Status.TaskRunResults, - pipelinev1beta1.TaskRunResult{ + tr.Status.Results = append(tr.Status.Results, + pipelineapi.TaskRunResult{ Name: "shp-image-digest", - Value: pipelinev1beta1.ParamValue{ - Type: pipelinev1beta1.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: imageDigest, }, }, - pipelinev1beta1.TaskRunResult{ + pipelineapi.TaskRunResult{ Name: "shp-image-size", - Value: pipelinev1beta1.ParamValue{ - Type: pipelinev1beta1.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: "230", }, }) - resources.UpdateBuildRunUsingTaskResults(ctx, br, tr.Status.TaskRunResults, taskRunRequest) + resources.UpdateBuildRunUsingTaskResults(ctx, br, tr.Status.Results, taskRunRequest) Expect(br.Status.Output.Digest).To(Equal(imageDigest)) Expect(br.Status.Output.Size).To(Equal(int64(230))) @@ -126,37 +126,37 @@ var _ = Describe("TaskRun results to BuildRun", func() { imageDigest := "sha256:fe1b73cd25ac3f11dec752755e2" br.Status.BuildSpec.Source.URL = pointer.String("https://github.com/shipwright-io/sample-go") - tr.Status.TaskRunResults = append(tr.Status.TaskRunResults, - pipelinev1beta1.TaskRunResult{ + tr.Status.Results = append(tr.Status.Results, + pipelineapi.TaskRunResult{ Name: "shp-source-default-commit-sha", - Value: pipelinev1beta1.ParamValue{ - Type: pipelinev1beta1.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: commitSha, }, }, - pipelinev1beta1.TaskRunResult{ + pipelineapi.TaskRunResult{ Name: "shp-source-default-commit-author", - Value: pipelinev1beta1.ParamValue{ - Type: pipelinev1beta1.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: "foo bar", }, }, - pipelinev1beta1.TaskRunResult{ + pipelineapi.TaskRunResult{ Name: "shp-image-digest", - Value: pipelinev1beta1.ParamValue{ - Type: pipelinev1beta1.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: imageDigest, }, }, - pipelinev1beta1.TaskRunResult{ + pipelineapi.TaskRunResult{ Name: "shp-image-size", - Value: pipelinev1beta1.ParamValue{ - Type: pipelinev1beta1.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: "230", }, }) - resources.UpdateBuildRunUsingTaskResults(ctx, br, tr.Status.TaskRunResults, taskRunRequest) + resources.UpdateBuildRunUsingTaskResults(ctx, br, tr.Status.Results, taskRunRequest) Expect(len(br.Status.Sources)).To(Equal(1)) Expect(br.Status.Sources[0].Git.CommitSha).To(Equal(commitSha)) diff --git a/pkg/reconciler/buildrun/resources/sources.go b/pkg/reconciler/buildrun/resources/sources.go index 0d80a6c809..37e94a7c60 100644 --- a/pkg/reconciler/buildrun/resources/sources.go +++ b/pkg/reconciler/buildrun/resources/sources.go @@ -9,7 +9,7 @@ import ( "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/sources" - pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" ) const defaultSourceName = "default" @@ -37,7 +37,7 @@ func isLocalCopyBuildSource( // alternatively, configures the Task steps to use bundle and "git clone". func AmendTaskSpecWithSources( cfg *config.Config, - taskSpec *pipeline.TaskSpec, + taskSpec *pipelineapi.TaskSpec, build *buildv1alpha1.Build, buildRun *buildv1alpha1.BuildRun, ) { @@ -62,7 +62,7 @@ func AmendTaskSpecWithSources( } } -func updateBuildRunStatusWithSourceResult(buildrun *buildv1alpha1.BuildRun, results []pipeline.TaskRunResult) { +func updateBuildRunStatusWithSourceResult(buildrun *buildv1alpha1.BuildRun, results []pipelineapi.TaskRunResult) { buildSpec := buildrun.Status.BuildSpec switch { diff --git a/pkg/reconciler/buildrun/resources/sources/bundle.go b/pkg/reconciler/buildrun/resources/sources/bundle.go index 5903573bff..8b7eda6402 100644 --- a/pkg/reconciler/buildrun/resources/sources/bundle.go +++ b/pkg/reconciler/buildrun/resources/sources/bundle.go @@ -13,31 +13,37 @@ import ( build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" "github.com/shipwright-io/build/pkg/config" - pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" ) // AppendBundleStep appends the bundle step to the TaskSpec func AppendBundleStep( cfg *config.Config, - taskSpec *pipeline.TaskSpec, + taskSpec *pipelineapi.TaskSpec, source build.Source, name string, ) { // append the result - taskSpec.Results = append(taskSpec.Results, pipeline.TaskResult{ + taskSpec.Results = append(taskSpec.Results, pipelineapi.TaskResult{ Name: fmt.Sprintf("%s-source-%s-image-digest", prefixParamsResultsVolumes, name), Description: "The digest of the bundle image.", }) - // initialize the step from the template - bundleStep := *cfg.BundleContainerTemplate.DeepCopy() - - // add the build-specific details - bundleStep.Name = fmt.Sprintf("source-%s", name) - bundleStep.Args = []string{ - "--image", source.BundleContainer.Image, - "--target", fmt.Sprintf("$(params.%s-%s)", prefixParamsResultsVolumes, paramSourceRoot), - "--result-file-image-digest", fmt.Sprintf("$(results.%s-source-%s-image-digest.path)", prefixParamsResultsVolumes, name), + // initialize the step from the template and the build-specific arguments + bundleStep := pipelineapi.Step{ + Name: fmt.Sprintf("source-%s", name), + Image: cfg.BundleContainerTemplate.Image, + ImagePullPolicy: cfg.BundleContainerTemplate.ImagePullPolicy, + Command: cfg.BundleContainerTemplate.Command, + Args: []string{ + "--image", source.BundleContainer.Image, + "--target", fmt.Sprintf("$(params.%s-%s)", prefixParamsResultsVolumes, paramSourceRoot), + "--result-file-image-digest", fmt.Sprintf("$(results.%s-source-%s-image-digest.path)", prefixParamsResultsVolumes, name), + }, + Env: cfg.BundleContainerTemplate.Env, + ComputeResources: cfg.BundleContainerTemplate.Resources, + SecurityContext: cfg.BundleContainerTemplate.SecurityContext, + WorkingDir: cfg.BundleContainerTemplate.WorkingDir, } // add credentials mount, if provided @@ -68,7 +74,7 @@ func AppendBundleStep( } // AppendBundleResult append bundle source result to build run -func AppendBundleResult(buildRun *build.BuildRun, name string, results []pipeline.TaskRunResult) { +func AppendBundleResult(buildRun *build.BuildRun, name string, results []pipelineapi.TaskRunResult) { imageDigest := findResultValue(results, fmt.Sprintf("%s-source-%s-image-digest", prefixParamsResultsVolumes, name)) if strings.TrimSpace(imageDigest) != "" { diff --git a/pkg/reconciler/buildrun/resources/sources/git.go b/pkg/reconciler/buildrun/resources/sources/git.go index 7b19a96d1f..640e2c7af2 100644 --- a/pkg/reconciler/buildrun/resources/sources/git.go +++ b/pkg/reconciler/buildrun/resources/sources/git.go @@ -10,7 +10,7 @@ import ( buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" "github.com/shipwright-io/build/pkg/config" - tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" ) @@ -23,42 +23,48 @@ const ( // AppendGitStep appends the Git step and results and volume if needed to the TaskSpec func AppendGitStep( cfg *config.Config, - taskSpec *tektonv1beta1.TaskSpec, + taskSpec *pipelineapi.TaskSpec, source buildv1alpha1.Source, name string, ) { // append the result - taskSpec.Results = append(taskSpec.Results, tektonv1beta1.TaskResult{ + taskSpec.Results = append(taskSpec.Results, pipelineapi.TaskResult{ Name: fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, commitSHAResult), Description: "The commit SHA of the cloned source.", - }, tektonv1beta1.TaskResult{ + }, pipelineapi.TaskResult{ Name: fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, commitAuthorResult), Description: "The author of the last commit of the cloned source.", - }, tektonv1beta1.TaskResult{ + }, pipelineapi.TaskResult{ Name: fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, branchName), Description: "The name of the branch used of the cloned source.", }) - // initialize the step from the template - gitStep := *cfg.GitContainerTemplate.DeepCopy() - - // add the build-specific details - gitStep.Name = fmt.Sprintf("source-%s", name) - gitStep.Args = []string{ - "--url", - *source.URL, - "--target", - fmt.Sprintf("$(params.%s-%s)", prefixParamsResultsVolumes, paramSourceRoot), - "--result-file-commit-sha", - fmt.Sprintf("$(results.%s-source-%s-%s.path)", prefixParamsResultsVolumes, name, commitSHAResult), - "--result-file-commit-author", - fmt.Sprintf("$(results.%s-source-%s-%s.path)", prefixParamsResultsVolumes, name, commitAuthorResult), - "--result-file-branch-name", - fmt.Sprintf("$(results.%s-source-%s-%s.path)", prefixParamsResultsVolumes, name, branchName), - "--result-file-error-message", - fmt.Sprintf("$(results.%s-error-message.path)", prefixParamsResultsVolumes), - "--result-file-error-reason", - fmt.Sprintf("$(results.%s-error-reason.path)", prefixParamsResultsVolumes), + // initialize the step from the template and the build-specific arguments + gitStep := pipelineapi.Step{ + Name: fmt.Sprintf("source-%s", name), + Image: cfg.GitContainerTemplate.Image, + ImagePullPolicy: cfg.GitContainerTemplate.ImagePullPolicy, + Command: cfg.GitContainerTemplate.Command, + Args: []string{ + "--url", + *source.URL, + "--target", + fmt.Sprintf("$(params.%s-%s)", prefixParamsResultsVolumes, paramSourceRoot), + "--result-file-commit-sha", + fmt.Sprintf("$(results.%s-source-%s-%s.path)", prefixParamsResultsVolumes, name, commitSHAResult), + "--result-file-commit-author", + fmt.Sprintf("$(results.%s-source-%s-%s.path)", prefixParamsResultsVolumes, name, commitAuthorResult), + "--result-file-branch-name", + fmt.Sprintf("$(results.%s-source-%s-%s.path)", prefixParamsResultsVolumes, name, branchName), + "--result-file-error-message", + fmt.Sprintf("$(results.%s-error-message.path)", prefixParamsResultsVolumes), + "--result-file-error-reason", + fmt.Sprintf("$(results.%s-error-reason.path)", prefixParamsResultsVolumes), + }, + Env: cfg.GitContainerTemplate.Env, + ComputeResources: cfg.GitContainerTemplate.Resources, + SecurityContext: cfg.GitContainerTemplate.SecurityContext, + WorkingDir: cfg.GitContainerTemplate.WorkingDir, } // Check if a revision is defined @@ -102,7 +108,7 @@ func AppendGitStep( } // AppendGitResult append git source result to build run -func AppendGitResult(buildRun *buildv1alpha1.BuildRun, name string, results []tektonv1beta1.TaskRunResult) { +func AppendGitResult(buildRun *buildv1alpha1.BuildRun, name string, results []pipelineapi.TaskRunResult) { commitAuthor := findResultValue(results, fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, commitAuthorResult)) commitSha := findResultValue(results, fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, commitSHAResult)) branchName := findResultValue(results, fmt.Sprintf("%s-source-%s-%s", prefixParamsResultsVolumes, name, branchName)) diff --git a/pkg/reconciler/buildrun/resources/sources/git_test.go b/pkg/reconciler/buildrun/resources/sources/git_test.go index 19df2a68d1..2f97e64b57 100644 --- a/pkg/reconciler/buildrun/resources/sources/git_test.go +++ b/pkg/reconciler/buildrun/resources/sources/git_test.go @@ -12,7 +12,7 @@ import ( "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/sources" - tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" ) @@ -23,10 +23,10 @@ var _ = Describe("Git", func() { Context("when adding a public Git source", func() { - var taskSpec *tektonv1beta1.TaskSpec + var taskSpec *pipelineapi.TaskSpec BeforeEach(func() { - taskSpec = &tektonv1beta1.TaskSpec{} + taskSpec = &pipelineapi.TaskSpec{} }) JustBeforeEach(func() { @@ -67,10 +67,10 @@ var _ = Describe("Git", func() { Context("when adding a private Git source", func() { - var taskSpec *tektonv1beta1.TaskSpec + var taskSpec *pipelineapi.TaskSpec BeforeEach(func() { - taskSpec = &tektonv1beta1.TaskSpec{} + taskSpec = &pipelineapi.TaskSpec{} }) JustBeforeEach(func() { diff --git a/pkg/reconciler/buildrun/resources/sources/http.go b/pkg/reconciler/buildrun/resources/sources/http.go index 301f97996f..28bbf1805e 100644 --- a/pkg/reconciler/buildrun/resources/sources/http.go +++ b/pkg/reconciler/buildrun/resources/sources/http.go @@ -9,7 +9,7 @@ import ( buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" "github.com/shipwright-io/build/pkg/config" - tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" ) // RemoteArtifactsContainerName name for the container dealing with remote artifacts download. @@ -18,7 +18,7 @@ const RemoteArtifactsContainerName = "sources-http" // AppendHTTPStep appends the step for a HTTP source to the TaskSpec func AppendHTTPStep( cfg *config.Config, - taskSpec *tektonv1beta1.TaskSpec, + taskSpec *pipelineapi.TaskSpec, source buildv1alpha1.BuildSource, ) { // HTTP is done currently all in a single step, see if there is already one @@ -26,7 +26,7 @@ func AppendHTTPStep( if httpStep != nil { httpStep.Args[3] = fmt.Sprintf("%s ; wget %q", httpStep.Args[3], source.URL) } else { - httpStep := tektonv1beta1.Step{ + httpStep := pipelineapi.Step{ Name: RemoteArtifactsContainerName, Image: cfg.RemoteArtifactsContainerImage, WorkingDir: fmt.Sprintf("$(params.%s-%s)", prefixParamsResultsVolumes, paramSourceRoot), @@ -46,7 +46,7 @@ func AppendHTTPStep( } } -func findExistingHTTPSourcesStep(taskSpec *tektonv1beta1.TaskSpec) *tektonv1beta1.Step { +func findExistingHTTPSourcesStep(taskSpec *pipelineapi.TaskSpec) *pipelineapi.Step { for _, candidateStep := range taskSpec.Steps { if candidateStep.Name == RemoteArtifactsContainerName { return &candidateStep diff --git a/pkg/reconciler/buildrun/resources/sources/http_test.go b/pkg/reconciler/buildrun/resources/sources/http_test.go index 2cf1bc3fe6..b2f8083be9 100644 --- a/pkg/reconciler/buildrun/resources/sources/http_test.go +++ b/pkg/reconciler/buildrun/resources/sources/http_test.go @@ -12,7 +12,7 @@ import ( "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/sources" - tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" ) var _ = Describe("HTTP", func() { @@ -20,10 +20,10 @@ var _ = Describe("HTTP", func() { cfg := config.NewDefaultConfig() Context("when a TaskSpec does not contain an step", func() { - var taskSpec *tektonv1beta1.TaskSpec + var taskSpec *pipelineapi.TaskSpec BeforeEach(func() { - taskSpec = &tektonv1beta1.TaskSpec{} + taskSpec = &pipelineapi.TaskSpec{} }) It("adds the first step", func() { @@ -41,11 +41,11 @@ var _ = Describe("HTTP", func() { }) Context("when a TaskSpec already contains the http step", func() { - var taskSpec *tektonv1beta1.TaskSpec + var taskSpec *pipelineapi.TaskSpec BeforeEach(func() { - taskSpec = &tektonv1beta1.TaskSpec{ - Steps: []tektonv1beta1.Step{ + taskSpec = &pipelineapi.TaskSpec{ + Steps: []pipelineapi.Step{ { Name: sources.RemoteArtifactsContainerName, Image: cfg.RemoteArtifactsContainerImage, @@ -79,11 +79,11 @@ var _ = Describe("HTTP", func() { }) Context("when a TaskSpec already another source step step", func() { - var taskSpec *tektonv1beta1.TaskSpec + var taskSpec *pipelineapi.TaskSpec BeforeEach(func() { - taskSpec = &tektonv1beta1.TaskSpec{ - Steps: []tektonv1beta1.Step{ + taskSpec = &pipelineapi.TaskSpec{ + Steps: []pipelineapi.Step{ { Name: "source-something", }, diff --git a/pkg/reconciler/buildrun/resources/sources/local_copy.go b/pkg/reconciler/buildrun/resources/sources/local_copy.go index 0013dc325d..17670fa220 100644 --- a/pkg/reconciler/buildrun/resources/sources/local_copy.go +++ b/pkg/reconciler/buildrun/resources/sources/local_copy.go @@ -9,7 +9,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/shipwright-io/build/pkg/config" - tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" ) // WaiterContainerName name given to the container watier container. @@ -17,11 +17,20 @@ const WaiterContainerName = "source-local" // AppendLocalCopyStep defines and append a new task based on the waiter container template, passed // by the configuration instance. -func AppendLocalCopyStep(cfg *config.Config, taskSpec *tektonv1beta1.TaskSpec, timeout *metav1.Duration) { - step := *cfg.WaiterContainerTemplate.DeepCopy() - // the data upload mechanism targets a specific POD, and in this POD it aims for a specific - // container name, and having a static name, makes this process straight forward. - step.Name = WaiterContainerName +func AppendLocalCopyStep(cfg *config.Config, taskSpec *pipelineapi.TaskSpec, timeout *metav1.Duration) { + step := pipelineapi.Step{ + // the data upload mechanism targets a specific POD, and in this POD it aims for a specific + // container name, and having a static name, makes this process straight forward. + Name: WaiterContainerName, + Image: cfg.WaiterContainerTemplate.Image, + ImagePullPolicy: cfg.WaiterContainerTemplate.ImagePullPolicy, + Command: cfg.WaiterContainerTemplate.Command, + Args: cfg.WaiterContainerTemplate.Args, + Env: cfg.WaiterContainerTemplate.Env, + ComputeResources: cfg.WaiterContainerTemplate.Resources, + SecurityContext: cfg.WaiterContainerTemplate.SecurityContext, + WorkingDir: cfg.WaiterContainerTemplate.WorkingDir, + } if timeout != nil { step.Args = append(step.Args, fmt.Sprintf("--timeout=%s", timeout.Duration.String())) diff --git a/pkg/reconciler/buildrun/resources/sources/local_copy_test.go b/pkg/reconciler/buildrun/resources/sources/local_copy_test.go index c2aa55ee90..5962f38458 100644 --- a/pkg/reconciler/buildrun/resources/sources/local_copy_test.go +++ b/pkg/reconciler/buildrun/resources/sources/local_copy_test.go @@ -10,7 +10,7 @@ import ( . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "github.com/shipwright-io/build/pkg/config" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/sources" @@ -20,10 +20,10 @@ var _ = Describe("LocalCopy", func() { cfg := config.NewDefaultConfig() Context("when LocalCopy source type is informed", func() { - var taskSpec *tektonv1beta1.TaskSpec + var taskSpec *pipelineapi.TaskSpec BeforeEach(func() { - taskSpec = &tektonv1beta1.TaskSpec{} + taskSpec = &pipelineapi.TaskSpec{} sources.AppendLocalCopyStep(cfg, taskSpec, &metav1.Duration{Duration: time.Minute}) }) diff --git a/pkg/reconciler/buildrun/resources/sources/utils.go b/pkg/reconciler/buildrun/resources/sources/utils.go index 72d837fe6f..b6b600d97a 100644 --- a/pkg/reconciler/buildrun/resources/sources/utils.go +++ b/pkg/reconciler/buildrun/resources/sources/utils.go @@ -9,7 +9,7 @@ import ( "regexp" "strings" - tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" ) @@ -29,7 +29,7 @@ var ( // AppendSecretVolume checks if a volume for a secret already exists, if not it appends it to the TaskSpec func AppendSecretVolume( - taskSpec *tektonv1beta1.TaskSpec, + taskSpec *pipelineapi.TaskSpec, secretName string, ) { volumeName := SanitizeVolumeNameForSecretName(secretName) @@ -69,7 +69,7 @@ func SanitizeVolumeNameForSecretName(secretName string) string { return sanitizedName } -func findResultValue(results []tektonv1beta1.TaskRunResult, name string) string { +func findResultValue(results []pipelineapi.TaskRunResult, name string) string { for _, result := range results { if result.Name == name { return result.Value.StringVal diff --git a/pkg/reconciler/buildrun/resources/sources/utils_test.go b/pkg/reconciler/buildrun/resources/sources/utils_test.go index 8521521c6c..5651b1de54 100644 --- a/pkg/reconciler/buildrun/resources/sources/utils_test.go +++ b/pkg/reconciler/buildrun/resources/sources/utils_test.go @@ -9,7 +9,7 @@ import ( . "github.com/onsi/gomega" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/sources" - tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" ) @@ -34,10 +34,10 @@ var _ = Describe("Utils", func() { }) Context("when a TaskSpec does not contain any volume", func() { - var taskSpec *tektonv1beta1.TaskSpec + var taskSpec *pipelineapi.TaskSpec BeforeEach(func() { - taskSpec = &tektonv1beta1.TaskSpec{} + taskSpec = &pipelineapi.TaskSpec{} }) It("adds the first volume", func() { @@ -51,10 +51,10 @@ var _ = Describe("Utils", func() { }) Context("when a TaskSpec already contains a volume secret", func() { - var taskSpec *tektonv1beta1.TaskSpec + var taskSpec *pipelineapi.TaskSpec BeforeEach(func() { - taskSpec = &tektonv1beta1.TaskSpec{ + taskSpec = &pipelineapi.TaskSpec{ Volumes: []corev1.Volume{ { Name: "shp-a-secret", diff --git a/pkg/reconciler/buildrun/resources/steps/security_context.go b/pkg/reconciler/buildrun/resources/steps/security_context.go index 4a866e16cf..4cc0af4302 100644 --- a/pkg/reconciler/buildrun/resources/steps/security_context.go +++ b/pkg/reconciler/buildrun/resources/steps/security_context.go @@ -8,7 +8,7 @@ import ( "fmt" buildapi "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - tektonapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" "k8s.io/utils/strings/slices" @@ -28,7 +28,7 @@ const ( // UpdateSecurityContext updates the security context of a step based on the build strategy steps. If all build strategy steps run as the same user and group, // then the step is configured to also run as this user and group. This ensures that the supporting steps run as the same user as the build strategy and file // permissions created by source steps match the user that runs the build strategy steps. -func UpdateSecurityContext(taskSpec *tektonapi.TaskSpec, taskRunAnnotations map[string]string, buildStrategySteps []buildapi.BuildStep, buildStrategySecurityContext *buildapi.BuildStrategySecurityContext) { +func UpdateSecurityContext(taskSpec *pipelineapi.TaskSpec, taskRunAnnotations map[string]string, buildStrategySteps []buildapi.BuildStep, buildStrategySecurityContext *buildapi.BuildStrategySecurityContext) { if buildStrategySecurityContext == nil { return } diff --git a/pkg/reconciler/buildrun/resources/steps/security_context_test.go b/pkg/reconciler/buildrun/resources/steps/security_context_test.go index 64eda83c56..a3de510633 100644 --- a/pkg/reconciler/buildrun/resources/steps/security_context_test.go +++ b/pkg/reconciler/buildrun/resources/steps/security_context_test.go @@ -10,7 +10,7 @@ import ( "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/steps" buildapi "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" - tektonapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" @@ -22,7 +22,7 @@ var _ = Describe("UpdateSecurityContext", func() { var buildStrategySecurityContext *buildapi.BuildStrategySecurityContext var buildStrategySteps []buildapi.BuildStep - var taskRunSpec *tektonapi.TaskSpec + var taskRunSpec *pipelineapi.TaskSpec var taskRunAnnotations map[string]string BeforeEach(func() { @@ -47,8 +47,8 @@ var _ = Describe("UpdateSecurityContext", func() { }, }} - taskRunSpec = &tektonapi.TaskSpec{ - Steps: []tektonapi.Step{{ + taskRunSpec = &pipelineapi.TaskSpec{ + Steps: []pipelineapi.Step{{ Name: "shp-source-default", SecurityContext: &corev1.SecurityContext{ RunAsUser: pointer.Int64(1000), diff --git a/pkg/reconciler/buildrun/resources/taskrun.go b/pkg/reconciler/buildrun/resources/taskrun.go index 99077e6b7d..cf91c0a606 100644 --- a/pkg/reconciler/buildrun/resources/taskrun.go +++ b/pkg/reconciler/buildrun/resources/taskrun.go @@ -10,8 +10,6 @@ import ( "strconv" "strings" - v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -20,6 +18,7 @@ import ( "github.com/shipwright-io/build/pkg/env" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources/steps" "github.com/shipwright-io/build/pkg/volumes" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" ) const ( @@ -68,14 +67,14 @@ func GenerateTaskSpec( buildSteps []buildv1alpha1.BuildStep, parameterDefinitions []buildv1alpha1.Parameter, buildStrategyVolumes []buildv1alpha1.BuildStrategyVolume, -) (*v1beta1.TaskSpec, error) { - generatedTaskSpec := v1beta1.TaskSpec{ - Params: []v1beta1.ParamSpec{ +) (*pipelineapi.TaskSpec, error) { + generatedTaskSpec := pipelineapi.TaskSpec{ + Params: []pipelineapi.ParamSpec{ { Description: "Path to the Dockerfile", Name: inputParamDockerfile, - Default: &v1beta1.ParamValue{ - Type: v1beta1.ParamTypeString, + Default: &pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: "Dockerfile", }, }, @@ -84,33 +83,33 @@ func GenerateTaskSpec( // in the Build object Description: "The root of the code", Name: inputParamContextDir, - Default: &v1beta1.ParamValue{ - Type: v1beta1.ParamTypeString, + Default: &pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: ".", }, }, { Name: fmt.Sprintf("%s-%s", prefixParamsResultsVolumes, paramOutputImage), Description: "The URL of the image that the build produces", - Type: v1beta1.ParamTypeString, + Type: pipelineapi.ParamTypeString, }, { Name: fmt.Sprintf("%s-%s", prefixParamsResultsVolumes, paramOutputInsecure), Description: "A flag indicating that the output image is on an insecure container registry", - Type: v1beta1.ParamTypeString, + Type: pipelineapi.ParamTypeString, }, { Name: fmt.Sprintf("%s-%s", prefixParamsResultsVolumes, paramSourceContext), Description: "The context directory inside the source directory", - Type: v1beta1.ParamTypeString, + Type: pipelineapi.ParamTypeString, }, { Name: fmt.Sprintf("%s-%s", prefixParamsResultsVolumes, paramSourceRoot), Description: "The source directory", - Type: v1beta1.ParamTypeString, + Type: pipelineapi.ParamTypeString, }, }, - Workspaces: []v1beta1.WorkspaceDeclaration{ + Workspaces: []pipelineapi.WorkspaceDeclaration{ // workspace for the source files { Name: workspaceSource, @@ -121,11 +120,11 @@ func GenerateTaskSpec( generatedTaskSpec.Results = append(getTaskSpecResults(), getFailureDetailsTaskSpecResults()...) if build.Spec.Builder != nil { - InputBuilder := v1beta1.ParamSpec{ + InputBuilder := pipelineapi.ParamSpec{ Description: "Image containing the build tools/logic", Name: inputParamBuilder, - Default: &v1beta1.ParamValue{ - Type: v1beta1.ParamTypeString, + Default: &pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: build.Spec.Builder.Image, }, } @@ -138,7 +137,7 @@ func GenerateTaskSpec( // Add the strategy defined parameters into the Task spec for _, parameterDefinition := range parameterDefinitions { - param := v1beta1.ParamSpec{ + param := pipelineapi.ParamSpec{ Name: parameterDefinition.Name, Description: parameterDefinition.Description, } @@ -147,19 +146,19 @@ func GenerateTaskSpec( case "": // string is default fallthrough case buildv1alpha1.ParameterTypeString: - param.Type = v1beta1.ParamTypeString + param.Type = pipelineapi.ParamTypeString if parameterDefinition.Default != nil { - param.Default = &v1beta1.ParamValue{ - Type: v1beta1.ParamTypeString, + param.Default = &pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: *parameterDefinition.Default, } } case buildv1alpha1.ParameterTypeArray: - param.Type = v1beta1.ParamTypeArray + param.Type = pipelineapi.ParamTypeArray if parameterDefinition.Defaults != nil { - param.Default = &v1beta1.ParamValue{ - Type: v1beta1.ParamTypeArray, + param.Default = &pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeArray, ArrayVal: *parameterDefinition.Defaults, } } @@ -202,17 +201,17 @@ func GenerateTaskSpec( return &generatedTaskSpec, fmt.Errorf("error(s) occurred merging environment variables into BuildStrategy %q steps: %s", build.Spec.StrategyName(), err.Error()) } - step := v1beta1.Step{ - Image: taskImage, - ImagePullPolicy: containerValue.ImagePullPolicy, - Name: containerValue.Name, - VolumeMounts: containerValue.VolumeMounts, - Command: taskCommand, - Args: taskArgs, - SecurityContext: containerValue.SecurityContext, - WorkingDir: containerValue.WorkingDir, - Resources: containerValue.Resources, - Env: stepEnv, + step := pipelineapi.Step{ + Image: taskImage, + ImagePullPolicy: containerValue.ImagePullPolicy, + Name: containerValue.Name, + VolumeMounts: containerValue.VolumeMounts, + Command: taskCommand, + Args: taskArgs, + SecurityContext: containerValue.SecurityContext, + WorkingDir: containerValue.WorkingDir, + ComputeResources: containerValue.Resources, + Env: stepEnv, } generatedTaskSpec.Steps = append(generatedTaskSpec.Steps, step) @@ -244,7 +243,7 @@ func GenerateTaskRun( buildRun *buildv1alpha1.BuildRun, serviceAccountName string, strategy buildv1alpha1.BuilderStrategy, -) (*v1beta1.TaskRun, error) { +) (*pipelineapi.TaskRun, error) { // retrieve expected imageURL form build or buildRun var image string @@ -285,16 +284,16 @@ func GenerateTaskRun( taskRunLabels[buildv1alpha1.LabelBuildGeneration] = strconv.FormatInt(build.Generation, 10) } - expectedTaskRun := &v1beta1.TaskRun{ + expectedTaskRun := &pipelineapi.TaskRun{ ObjectMeta: metav1.ObjectMeta{ GenerateName: buildRun.Name + "-", Namespace: buildRun.Namespace, Labels: taskRunLabels, }, - Spec: v1beta1.TaskRunSpec{ + Spec: pipelineapi.TaskRunSpec{ ServiceAccountName: serviceAccountName, TaskSpec: taskSpec, - Workspaces: []v1beta1.WorkspaceBinding{ + Workspaces: []pipelineapi.WorkspaceBinding{ // workspace for the source files { Name: workspaceSource, @@ -325,69 +324,69 @@ func GenerateTaskRun( expectedTaskRun.Spec.Timeout = effectiveTimeout(build, buildRun) - params := []v1beta1.Param{ + params := []pipelineapi.Param{ { // shp-output-image Name: fmt.Sprintf("%s-%s", prefixParamsResultsVolumes, paramOutputImage), - Value: v1beta1.ParamValue{ - Type: v1beta1.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: image, }, }, { // shp-output-insecure Name: fmt.Sprintf("%s-%s", prefixParamsResultsVolumes, paramOutputInsecure), - Value: v1beta1.ParamValue{ - Type: v1beta1.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: strconv.FormatBool(insecure), }, }, { Name: fmt.Sprintf("%s-%s", prefixParamsResultsVolumes, paramSourceRoot), - Value: v1beta1.ParamValue{ - Type: v1beta1.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: "/workspace/source", }, }, } if build.Spec.Builder != nil { - params = append(params, v1beta1.Param{ + params = append(params, pipelineapi.Param{ Name: inputParamBuilder, - Value: v1beta1.ParamValue{ - Type: v1beta1.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: build.Spec.Builder.Image, }, }) } if build.Spec.Dockerfile != nil && *build.Spec.Dockerfile != "" { - params = append(params, v1beta1.Param{ + params = append(params, pipelineapi.Param{ Name: inputParamDockerfile, - Value: v1beta1.ParamValue{ - Type: v1beta1.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: *build.Spec.Dockerfile, }, }) } if build.Spec.Source.ContextDir != nil { - params = append(params, v1beta1.Param{ + params = append(params, pipelineapi.Param{ Name: inputParamContextDir, - Value: v1beta1.ParamValue{ - Type: v1beta1.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: *build.Spec.Source.ContextDir, }, }) - params = append(params, v1beta1.Param{ + params = append(params, pipelineapi.Param{ Name: fmt.Sprintf("%s-%s", prefixParamsResultsVolumes, paramSourceContext), - Value: v1beta1.ParamValue{ - Type: v1beta1.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: path.Join("/workspace/source", *build.Spec.Source.ContextDir), }, }) } else { - params = append(params, v1beta1.Param{ + params = append(params, pipelineapi.Param{ Name: fmt.Sprintf("%s-%s", prefixParamsResultsVolumes, paramSourceContext), - Value: v1beta1.ParamValue{ - Type: v1beta1.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: "/workspace/source", }, }) diff --git a/pkg/reconciler/buildrun/resources/taskrun_test.go b/pkg/reconciler/buildrun/resources/taskrun_test.go index 521d3f046c..c7f2e23655 100644 --- a/pkg/reconciler/buildrun/resources/taskrun_test.go +++ b/pkg/reconciler/buildrun/resources/taskrun_test.go @@ -12,7 +12,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -48,7 +48,7 @@ var _ = Describe("GenerateTaskrun", func() { Describe("Generate the TaskSpec", func() { var ( expectedCommandOrArg []string - got *v1beta1.TaskSpec + got *pipelineapi.TaskSpec err error ) BeforeEach(func() { @@ -123,11 +123,11 @@ var _ = Describe("GenerateTaskrun", func() { }) It("should ensure resource replacements happen for the first step", func() { - Expect(got.Steps[1].Resources).To(Equal(ctl.LoadCustomResources("500m", "1Gi"))) + Expect(got.Steps[1].ComputeResources).To(Equal(ctl.LoadCustomResources("500m", "1Gi"))) }) It("should ensure resource replacements happen for the second step", func() { - Expect(got.Steps[2].Resources).To(Equal(ctl.LoadCustomResources("100m", "65Mi"))) + Expect(got.Steps[2].ComputeResources).To(Equal(ctl.LoadCustomResources("100m", "65Mi"))) }) It("should ensure arg replacements happen when needed", func() { @@ -403,7 +403,7 @@ var _ = Describe("GenerateTaskrun", func() { k8sDuration30s *metav1.Duration k8sDuration1m *metav1.Duration namespace, contextDir, outputPath, outputPathBuildRun, serviceAccountName string - got *v1beta1.TaskRun + got *pipelineapi.TaskRun err error ) BeforeEach(func() { @@ -462,11 +462,6 @@ var _ = Describe("GenerateTaskrun", func() { Expect(got.Annotations["kubernetes.io/ingress-bandwidth"]).To(Equal("1M")) }) - It("should ensure generated TaskRun has no resources", func() { - //lint:ignore SA1019 we want to verify that we do not set something that is not used - Expect(got.Spec.Resources).To(BeNil()) // nolint:staticcheck - }) - It("should ensure resource replacements happen when needed", func() { expectedResourceOrArg := corev1.ResourceRequirements{ Limits: corev1.ResourceList{ @@ -478,7 +473,7 @@ var _ = Describe("GenerateTaskrun", func() { corev1.ResourceMemory: resource.MustParse("2Gi"), }, } - Expect(got.Spec.TaskSpec.Steps[1].Resources).To(Equal(expectedResourceOrArg)) + Expect(got.Spec.TaskSpec.Steps[1].ComputeResources).To(Equal(expectedResourceOrArg)) }) It("should have no timeout set", func() { @@ -580,7 +575,7 @@ var _ = Describe("GenerateTaskrun", func() { corev1.ResourceMemory: resource.MustParse("2Gi"), }, } - Expect(got.Spec.TaskSpec.Steps[1].Resources).To(Equal(expectedResourceOrArg)) + Expect(got.Spec.TaskSpec.Steps[1].ComputeResources).To(Equal(expectedResourceOrArg)) }) It("should have the timeout set correctly", func() { diff --git a/pkg/reconciler/buildrun/resources/volumes.go b/pkg/reconciler/buildrun/resources/volumes.go index 2012bdf1b8..0c2b609fe5 100644 --- a/pkg/reconciler/buildrun/resources/volumes.go +++ b/pkg/reconciler/buildrun/resources/volumes.go @@ -7,7 +7,7 @@ package resources import ( "context" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" @@ -23,7 +23,7 @@ func namespacedName(name, namespace string) types.NamespacedName { // CheckTaskRunVolumesExist tries to find some of the volumes referenced by the BuildRun with all the // overrides. If some secret or configmap does not exist in the namespace, function returns error // describing the missing resource -func CheckTaskRunVolumesExist(ctx context.Context, client client.Client, taskRun *v1beta1.TaskRun) error { +func CheckTaskRunVolumesExist(ctx context.Context, client client.Client, taskRun *pipelineapi.TaskRun) error { for _, volume := range taskRun.Spec.TaskSpec.Volumes { var ( err error diff --git a/test/e2e/v1alpha1/validators_test.go b/test/e2e/v1alpha1/validators_test.go index a2d3c677b6..d85acc33d7 100644 --- a/test/e2e/v1alpha1/validators_test.go +++ b/test/e2e/v1alpha1/validators_test.go @@ -165,7 +165,7 @@ func validateBuildRunResultsFromGitSource(testBuildRun *buildv1alpha1.BuildRun) tr, err := testBuild.GetTaskRunFromBuildRun(testBuildRun.Name) Expect(err).ToNot(HaveOccurred()) - for _, result := range tr.Status.TaskRunResults { + for _, result := range tr.Status.Results { switch result.Name { case "shp-source-default-commit-sha": Expect(result.Value.StringVal).To(Equal(testBuildRun.Status.Sources[0].Git.CommitSha)) @@ -195,7 +195,7 @@ func validateBuildRunResultsFromBundleSource(testBuildRun *buildv1alpha1.BuildRu tr, err := testBuild.GetTaskRunFromBuildRun(testBuildRun.Name) Expect(err).ToNot(HaveOccurred()) - for _, result := range tr.Status.TaskRunResults { + for _, result := range tr.Status.Results { switch result.Name { case "shp-source-default-image-digest": Expect(result.Value.StringVal).To(Equal(testBuildRun.Status.Sources[0].Bundle.Digest)) diff --git a/test/e2e/v1beta1/validators_test.go b/test/e2e/v1beta1/validators_test.go index 05d1bcb2fb..135df35096 100644 --- a/test/e2e/v1beta1/validators_test.go +++ b/test/e2e/v1beta1/validators_test.go @@ -164,7 +164,7 @@ func validateBuildRunResultsFromGitSource(testBuildRun *buildv1beta1.BuildRun) { tr, err := testBuild.GetTaskRunFromBuildRun(testBuildRun.Name) Expect(err).ToNot(HaveOccurred()) - for _, result := range tr.Status.TaskRunResults { + for _, result := range tr.Status.Results { switch result.Name { case "shp-source-default-commit-sha": Expect(result.Value.StringVal).To(Equal(testBuildRun.Status.Source.Git.CommitSha)) @@ -194,7 +194,7 @@ func validateBuildRunResultsFromBundleSource(testBuildRun *buildv1beta1.BuildRun tr, err := testBuild.GetTaskRunFromBuildRun(testBuildRun.Name) Expect(err).ToNot(HaveOccurred()) - for _, result := range tr.Status.TaskRunResults { + for _, result := range tr.Status.Results { switch result.Name { case "shp-source-default-image-digest": Expect(result.Value.StringVal).To(Equal(testBuildRun.Status.Source.OciArtifact.Digest)) diff --git a/test/integration/buildruns_to_taskruns_test.go b/test/integration/buildruns_to_taskruns_test.go index 5c80107f8e..8d75f6ec49 100644 --- a/test/integration/buildruns_to_taskruns_test.go +++ b/test/integration/buildruns_to_taskruns_test.go @@ -12,7 +12,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" "github.com/shipwright-io/build/pkg/reconciler/buildrun/resources" @@ -337,7 +337,7 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { tr.Spec.Status = "TaskRunCancelled" - _, err = tb.UpdateTaskRun(tr.Name, func(tr *v1beta1.TaskRun) { + _, err = tb.UpdateTaskRun(tr.Name, func(tr *pipelineapi.TaskRun) { tr.Spec.Status = "TaskRunCancelled" }) Expect(err).To(BeNil()) diff --git a/test/integration/buildstrategy_to_taskruns_test.go b/test/integration/buildstrategy_to_taskruns_test.go index 162bf1d4a4..adc6064812 100644 --- a/test/integration/buildstrategy_to_taskruns_test.go +++ b/test/integration/buildstrategy_to_taskruns_test.go @@ -13,7 +13,7 @@ import ( "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" utils "github.com/shipwright-io/build/test/utils/v1alpha1" test "github.com/shipwright-io/build/test/v1alpha1_samples" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" ) @@ -124,21 +124,21 @@ var _ = Describe("Integration tests BuildStrategies and TaskRuns", func() { Expect(err).To(BeNil()) }) - var constructStringParam = func(paramName string, val string) v1beta1.Param { - return v1beta1.Param{ + var constructStringParam = func(paramName string, val string) pipelineapi.Param { + return pipelineapi.Param{ Name: paramName, - Value: v1beta1.ParamValue{ - Type: v1beta1.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: val, }, } } - var constructArrayParam = func(paramName string, values ...string) v1beta1.Param { - return v1beta1.Param{ + var constructArrayParam = func(paramName string, values ...string) pipelineapi.Param { + return pipelineapi.Param{ Name: paramName, - Value: v1beta1.ParamValue{ - Type: v1beta1.ParamTypeArray, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeArray, ArrayVal: values, }, } @@ -425,18 +425,18 @@ var _ = Describe("Integration tests BuildStrategies and TaskRuns", func() { Expect(err).To(BeNil()) // Validate that the TaskSpec parameter have no default value - Expect(taskRun.Spec.TaskSpec.Params).To(ContainElement(v1beta1.ParamSpec{ + Expect(taskRun.Spec.TaskSpec.Params).To(ContainElement(pipelineapi.ParamSpec{ Name: "sleep-time", - Type: v1beta1.ParamTypeString, + Type: pipelineapi.ParamTypeString, Description: "time in seconds for sleeping", Default: nil, })) // Validate that the TaskRun param have an empty string as the value - Expect(taskRun.Spec.Params).To(ContainElement(v1beta1.Param{ + Expect(taskRun.Spec.Params).To(ContainElement(pipelineapi.Param{ Name: "sleep-time", - Value: v1beta1.ParamValue{ - Type: v1beta1.ParamTypeString, + Value: pipelineapi.ParamValue{ + Type: pipelineapi.ParamTypeString, StringVal: "", }, })) diff --git a/test/utils/v1alpha1/lookup.go b/test/utils/v1alpha1/lookup.go index a0220b7bed..4797303901 100644 --- a/test/utils/v1alpha1/lookup.go +++ b/test/utils/v1alpha1/lookup.go @@ -9,7 +9,7 @@ import ( "strings" "time" - pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -61,18 +61,18 @@ func (t *TestBuild) LookupBuildRun(entity types.NamespacedName) (*buildv1alpha1. return result.(*buildv1alpha1.BuildRun), err } -func (t *TestBuild) LookupTaskRun(entity types.NamespacedName) (*pipelinev1beta1.TaskRun, error) { +func (t *TestBuild) LookupTaskRun(entity types.NamespacedName) (*pipelineapi.TaskRun, error) { result, err := lookupRuntimeObject(func() (runtime.Object, error) { return t.PipelineClientSet. - TektonV1beta1(). + TektonV1(). TaskRuns(entity.Namespace). Get(t.Context, entity.Name, metav1.GetOptions{}) }) - return result.(*pipelinev1beta1.TaskRun), err + return result.(*pipelineapi.TaskRun), err } -func (t *TestBuild) LookupTaskRunUsingBuildRun(buildRun *buildv1alpha1.BuildRun) (*pipelinev1beta1.TaskRun, error) { +func (t *TestBuild) LookupTaskRunUsingBuildRun(buildRun *buildv1alpha1.BuildRun) (*pipelineapi.TaskRun, error) { if buildRun == nil { return nil, fmt.Errorf("no BuildRun specified to lookup TaskRun") } @@ -83,7 +83,7 @@ func (t *TestBuild) LookupTaskRunUsingBuildRun(buildRun *buildv1alpha1.BuildRun) tmp, err := lookupRuntimeObject(func() (runtime.Object, error) { return t.PipelineClientSet. - TektonV1beta1(). + TektonV1(). TaskRuns(buildRun.Namespace). List(t.Context, metav1.ListOptions{ LabelSelector: labels.SelectorFromSet( @@ -97,7 +97,7 @@ func (t *TestBuild) LookupTaskRunUsingBuildRun(buildRun *buildv1alpha1.BuildRun) return nil, err } - var taskRunList = tmp.(*pipelinev1beta1.TaskRunList) + var taskRunList = tmp.(*pipelineapi.TaskRunList) switch len(taskRunList.Items) { case 0: return nil, fmt.Errorf("no TaskRun found for BuildRun %s/%s", buildRun.Namespace, buildRun.Name) diff --git a/test/utils/v1alpha1/taskruns.go b/test/utils/v1alpha1/taskruns.go index aef9a53919..c8ae31121b 100644 --- a/test/utils/v1alpha1/taskruns.go +++ b/test/utils/v1alpha1/taskruns.go @@ -9,7 +9,7 @@ import ( "errors" "fmt" - v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "knative.dev/pkg/apis" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -21,10 +21,10 @@ import ( // This class is intended to host all CRUD calls for testing TaskRuns CRDs resources // GetTaskRunFromBuildRun retrieves an owned TaskRun based on the BuildRunName -func (t *TestBuild) GetTaskRunFromBuildRun(buildRunName string) (*v1beta1.TaskRun, error) { +func (t *TestBuild) GetTaskRunFromBuildRun(buildRunName string) (*pipelineapi.TaskRun, error) { taskRunLabelSelector := fmt.Sprintf("buildrun.shipwright.io/name=%s", buildRunName) - trInterface := t.PipelineClientSet.TektonV1beta1().TaskRuns(t.Namespace) + trInterface := t.PipelineClientSet.TektonV1().TaskRuns(t.Namespace) trList, err := trInterface.List(context.TODO(), metav1.ListOptions{ LabelSelector: taskRunLabelSelector, @@ -41,8 +41,8 @@ func (t *TestBuild) GetTaskRunFromBuildRun(buildRunName string) (*v1beta1.TaskRu } // UpdateTaskRun applies changes to a TaskRun object -func (t *TestBuild) UpdateTaskRun(name string, apply func(tr *v1beta1.TaskRun)) (*v1beta1.TaskRun, error) { - var tr *v1beta1.TaskRun +func (t *TestBuild) UpdateTaskRun(name string, apply func(tr *pipelineapi.TaskRun)) (*pipelineapi.TaskRun, error) { + var tr *pipelineapi.TaskRun var err error for i := 0; i < 5; i++ { tr, err = t.LookupTaskRun(types.NamespacedName{ @@ -55,7 +55,7 @@ func (t *TestBuild) UpdateTaskRun(name string, apply func(tr *v1beta1.TaskRun)) apply(tr) - tr, err = t.PipelineClientSet.TektonV1beta1().TaskRuns(t.Namespace).Update(context.TODO(), tr, metav1.UpdateOptions{}) + tr, err = t.PipelineClientSet.TektonV1().TaskRuns(t.Namespace).Update(context.TODO(), tr, metav1.UpdateOptions{}) if err == nil { return tr, nil } @@ -105,7 +105,7 @@ func (t *TestBuild) GetTRTillDesiredReason(buildRunName string, reason string) ( // DeleteTR deletes a TaskRun from a desired namespace func (t *TestBuild) DeleteTR(name string) error { - trInterface := t.PipelineClientSet.TektonV1beta1().TaskRuns(t.Namespace) + trInterface := t.PipelineClientSet.TektonV1().TaskRuns(t.Namespace) if err := trInterface.Delete(context.TODO(), name, metav1.DeleteOptions{}); err != nil { return err diff --git a/test/utils/v1beta1/lookup.go b/test/utils/v1beta1/lookup.go index 595c9a6e5b..4c0ccf32d1 100644 --- a/test/utils/v1beta1/lookup.go +++ b/test/utils/v1beta1/lookup.go @@ -9,7 +9,7 @@ import ( "strings" "time" - pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -61,18 +61,18 @@ func (t *TestBuild) LookupBuildRun(entity types.NamespacedName) (*buildv1beta1.B return result.(*buildv1beta1.BuildRun), err } -func (t *TestBuild) LookupTaskRun(entity types.NamespacedName) (*pipelinev1beta1.TaskRun, error) { +func (t *TestBuild) LookupTaskRun(entity types.NamespacedName) (*pipelineapi.TaskRun, error) { result, err := lookupRuntimeObject(func() (runtime.Object, error) { return t.PipelineClientSet. - TektonV1beta1(). + TektonV1(). TaskRuns(entity.Namespace). Get(t.Context, entity.Name, metav1.GetOptions{}) }) - return result.(*pipelinev1beta1.TaskRun), err + return result.(*pipelineapi.TaskRun), err } -func (t *TestBuild) LookupTaskRunUsingBuildRun(buildRun *buildv1beta1.BuildRun) (*pipelinev1beta1.TaskRun, error) { +func (t *TestBuild) LookupTaskRunUsingBuildRun(buildRun *buildv1beta1.BuildRun) (*pipelineapi.TaskRun, error) { if buildRun == nil { return nil, fmt.Errorf("no BuildRun specified to lookup TaskRun") } @@ -83,7 +83,7 @@ func (t *TestBuild) LookupTaskRunUsingBuildRun(buildRun *buildv1beta1.BuildRun) tmp, err := lookupRuntimeObject(func() (runtime.Object, error) { return t.PipelineClientSet. - TektonV1beta1(). + TektonV1(). TaskRuns(buildRun.Namespace). List(t.Context, metav1.ListOptions{ LabelSelector: labels.SelectorFromSet( @@ -97,7 +97,7 @@ func (t *TestBuild) LookupTaskRunUsingBuildRun(buildRun *buildv1beta1.BuildRun) return nil, err } - var taskRunList = tmp.(*pipelinev1beta1.TaskRunList) + var taskRunList = tmp.(*pipelineapi.TaskRunList) switch len(taskRunList.Items) { case 0: return nil, fmt.Errorf("no TaskRun found for BuildRun %s/%s", buildRun.Namespace, buildRun.Name) diff --git a/test/utils/v1beta1/taskruns.go b/test/utils/v1beta1/taskruns.go index aef9a53919..c8ae31121b 100644 --- a/test/utils/v1beta1/taskruns.go +++ b/test/utils/v1beta1/taskruns.go @@ -9,7 +9,7 @@ import ( "errors" "fmt" - v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "knative.dev/pkg/apis" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -21,10 +21,10 @@ import ( // This class is intended to host all CRUD calls for testing TaskRuns CRDs resources // GetTaskRunFromBuildRun retrieves an owned TaskRun based on the BuildRunName -func (t *TestBuild) GetTaskRunFromBuildRun(buildRunName string) (*v1beta1.TaskRun, error) { +func (t *TestBuild) GetTaskRunFromBuildRun(buildRunName string) (*pipelineapi.TaskRun, error) { taskRunLabelSelector := fmt.Sprintf("buildrun.shipwright.io/name=%s", buildRunName) - trInterface := t.PipelineClientSet.TektonV1beta1().TaskRuns(t.Namespace) + trInterface := t.PipelineClientSet.TektonV1().TaskRuns(t.Namespace) trList, err := trInterface.List(context.TODO(), metav1.ListOptions{ LabelSelector: taskRunLabelSelector, @@ -41,8 +41,8 @@ func (t *TestBuild) GetTaskRunFromBuildRun(buildRunName string) (*v1beta1.TaskRu } // UpdateTaskRun applies changes to a TaskRun object -func (t *TestBuild) UpdateTaskRun(name string, apply func(tr *v1beta1.TaskRun)) (*v1beta1.TaskRun, error) { - var tr *v1beta1.TaskRun +func (t *TestBuild) UpdateTaskRun(name string, apply func(tr *pipelineapi.TaskRun)) (*pipelineapi.TaskRun, error) { + var tr *pipelineapi.TaskRun var err error for i := 0; i < 5; i++ { tr, err = t.LookupTaskRun(types.NamespacedName{ @@ -55,7 +55,7 @@ func (t *TestBuild) UpdateTaskRun(name string, apply func(tr *v1beta1.TaskRun)) apply(tr) - tr, err = t.PipelineClientSet.TektonV1beta1().TaskRuns(t.Namespace).Update(context.TODO(), tr, metav1.UpdateOptions{}) + tr, err = t.PipelineClientSet.TektonV1().TaskRuns(t.Namespace).Update(context.TODO(), tr, metav1.UpdateOptions{}) if err == nil { return tr, nil } @@ -105,7 +105,7 @@ func (t *TestBuild) GetTRTillDesiredReason(buildRunName string, reason string) ( // DeleteTR deletes a TaskRun from a desired namespace func (t *TestBuild) DeleteTR(name string) error { - trInterface := t.PipelineClientSet.TektonV1beta1().TaskRuns(t.Namespace) + trInterface := t.PipelineClientSet.TektonV1().TaskRuns(t.Namespace) if err := trInterface.Delete(context.TODO(), name, metav1.DeleteOptions{}); err != nil { return err diff --git a/test/v1alpha1_samples/catalog.go b/test/v1alpha1_samples/catalog.go index beab9e3567..15a64b0ed5 100644 --- a/test/v1alpha1_samples/catalog.go +++ b/test/v1alpha1_samples/catalog.go @@ -11,7 +11,7 @@ import ( "time" . "github.com/onsi/gomega" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "knative.dev/pkg/apis" knativev1 "knative.dev/pkg/apis/duck/v1" @@ -286,14 +286,14 @@ func (c *Catalog) StubBuildRun( // and a TaskRun when there is a client GET on this two objects func (c *Catalog) StubBuildRunAndTaskRun( b *build.BuildRun, - tr *v1beta1.TaskRun, + tr *pipelineapi.TaskRun, ) func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { return func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { switch object := object.(type) { case *build.BuildRun: b.DeepCopyInto(object) return nil - case *v1beta1.TaskRun: + case *pipelineapi.TaskRun: tr.DeepCopyInto(object) return nil } @@ -305,14 +305,14 @@ func (c *Catalog) StubBuildRunAndTaskRun( // and a TaskRun when there is a client GET on this two objects func (c *Catalog) StubBuildAndTaskRun( b *build.Build, - tr *v1beta1.TaskRun, + tr *pipelineapi.TaskRun, ) func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { return func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { switch object := object.(type) { case *build.Build: b.DeepCopyInto(object) return nil - case *v1beta1.TaskRun: + case *pipelineapi.TaskRun: tr.DeepCopyInto(object) return nil } @@ -390,7 +390,7 @@ func (c *Catalog) StubBuildRunGetWithoutSA( func (c *Catalog) StubBuildRunGetWithTaskRunAndSA( b *build.Build, br *build.BuildRun, - tr *v1beta1.TaskRun, + tr *pipelineapi.TaskRun, sa *corev1.ServiceAccount, ) func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { return func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { @@ -401,7 +401,7 @@ func (c *Catalog) StubBuildRunGetWithTaskRunAndSA( case *build.BuildRun: br.DeepCopyInto(object) return nil - case *v1beta1.TaskRun: + case *pipelineapi.TaskRun: tr.DeepCopyInto(object) return nil case *corev1.ServiceAccount: @@ -513,7 +513,7 @@ func (c *Catalog) StubBuildCRDsPodAndTaskRun( sa *corev1.ServiceAccount, cb *build.ClusterBuildStrategy, bs *build.BuildStrategy, - tr *v1beta1.TaskRun, + tr *pipelineapi.TaskRun, pod *corev1.Pod, ) func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { return func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { @@ -533,7 +533,7 @@ func (c *Catalog) StubBuildCRDsPodAndTaskRun( case *build.BuildStrategy: bs.DeepCopyInto(object) return nil - case *v1beta1.TaskRun: + case *pipelineapi.TaskRun: tr.DeepCopyInto(object) return nil case *corev1.Pod: @@ -545,18 +545,18 @@ func (c *Catalog) StubBuildCRDsPodAndTaskRun( } // TaskRunWithStatus returns a minimal tekton TaskRun with an Status -func (c *Catalog) TaskRunWithStatus(trName string, ns string) *v1beta1.TaskRun { - return &v1beta1.TaskRun{ +func (c *Catalog) TaskRunWithStatus(trName string, ns string) *pipelineapi.TaskRun { + return &pipelineapi.TaskRun{ ObjectMeta: metav1.ObjectMeta{ Name: trName, Namespace: ns, }, - Spec: v1beta1.TaskRunSpec{ + Spec: pipelineapi.TaskRunSpec{ Timeout: &metav1.Duration{ Duration: time.Minute * 2, }, }, - Status: v1beta1.TaskRunStatus{ + Status: pipelineapi.TaskRunStatus{ Status: knativev1.Status{ Conditions: knativev1.Conditions{ { @@ -566,7 +566,7 @@ func (c *Catalog) TaskRunWithStatus(trName string, ns string) *v1beta1.TaskRun { }, }, }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + TaskRunStatusFields: pipelineapi.TaskRunStatusFields{ PodName: "foobar-pod", StartTime: &metav1.Time{ Time: time.Now(), @@ -580,15 +580,15 @@ func (c *Catalog) TaskRunWithStatus(trName string, ns string) *v1beta1.TaskRun { } // DefaultTaskRunWithStatus returns a minimal tekton TaskRun with an Status -func (c *Catalog) DefaultTaskRunWithStatus(trName string, buildRunName string, ns string, status corev1.ConditionStatus, reason string) *v1beta1.TaskRun { - return &v1beta1.TaskRun{ +func (c *Catalog) DefaultTaskRunWithStatus(trName string, buildRunName string, ns string, status corev1.ConditionStatus, reason string) *pipelineapi.TaskRun { + return &pipelineapi.TaskRun{ ObjectMeta: metav1.ObjectMeta{ Name: trName, Namespace: ns, Labels: map[string]string{"buildrun.shipwright.io/name": buildRunName}, }, - Spec: v1beta1.TaskRunSpec{}, - Status: v1beta1.TaskRunStatus{ + Spec: pipelineapi.TaskRunSpec{}, + Status: pipelineapi.TaskRunStatus{ Status: knativev1.Status{ Conditions: knativev1.Conditions{ { @@ -598,7 +598,7 @@ func (c *Catalog) DefaultTaskRunWithStatus(trName string, buildRunName string, n }, }, }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + TaskRunStatusFields: pipelineapi.TaskRunStatusFields{ StartTime: &metav1.Time{ Time: time.Now(), }, @@ -609,16 +609,16 @@ func (c *Catalog) DefaultTaskRunWithStatus(trName string, buildRunName string, n // TaskRunWithCompletionAndStartTime provides a TaskRun object with a // Completion and StartTime -func (c *Catalog) TaskRunWithCompletionAndStartTime(trName string, buildRunName string, ns string) *v1beta1.TaskRun { - return &v1beta1.TaskRun{ +func (c *Catalog) TaskRunWithCompletionAndStartTime(trName string, buildRunName string, ns string) *pipelineapi.TaskRun { + return &pipelineapi.TaskRun{ ObjectMeta: metav1.ObjectMeta{ Name: trName, Namespace: ns, Labels: map[string]string{"buildrun.shipwright.io/name": buildRunName}, }, - Spec: v1beta1.TaskRunSpec{}, - Status: v1beta1.TaskRunStatus{ - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + Spec: pipelineapi.TaskRunSpec{}, + Status: pipelineapi.TaskRunStatus{ + TaskRunStatusFields: pipelineapi.TaskRunStatusFields{ CompletionTime: &metav1.Time{ Time: time.Now(), }, @@ -642,15 +642,15 @@ func (c *Catalog) TaskRunWithCompletionAndStartTime(trName string, buildRunName } // DefaultTaskRunWithFalseStatus returns a minimal tektont TaskRun with a FALSE status -func (c *Catalog) DefaultTaskRunWithFalseStatus(trName string, buildRunName string, ns string) *v1beta1.TaskRun { - return &v1beta1.TaskRun{ +func (c *Catalog) DefaultTaskRunWithFalseStatus(trName string, buildRunName string, ns string) *pipelineapi.TaskRun { + return &pipelineapi.TaskRun{ ObjectMeta: metav1.ObjectMeta{ Name: trName, Namespace: ns, Labels: map[string]string{"buildrun.shipwright.io/name": buildRunName}, }, - Spec: v1beta1.TaskRunSpec{}, - Status: v1beta1.TaskRunStatus{ + Spec: pipelineapi.TaskRunSpec{}, + Status: pipelineapi.TaskRunStatus{ Status: knativev1.Status{ Conditions: knativev1.Conditions{ { @@ -661,7 +661,7 @@ func (c *Catalog) DefaultTaskRunWithFalseStatus(trName string, buildRunName stri }, }, }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + TaskRunStatusFields: pipelineapi.TaskRunStatusFields{ StartTime: &metav1.Time{ Time: time.Now(), }, @@ -867,8 +867,8 @@ func (c *Catalog) BuildRunWithFakeNamespace(buildRunName string, buildName strin } // DefaultTaskRun returns a minimal TaskRun object -func (c *Catalog) DefaultTaskRun(taskRunName string, ns string) *v1beta1.TaskRun { - return &v1beta1.TaskRun{ +func (c *Catalog) DefaultTaskRun(taskRunName string, ns string) *pipelineapi.TaskRun { + return &pipelineapi.TaskRun{ ObjectMeta: metav1.ObjectMeta{ Name: taskRunName, Namespace: ns, diff --git a/test/v1beta1_samples/catalog.go b/test/v1beta1_samples/catalog.go index 177291b746..338c8cf71f 100644 --- a/test/v1beta1_samples/catalog.go +++ b/test/v1beta1_samples/catalog.go @@ -11,7 +11,7 @@ import ( "time" . "github.com/onsi/gomega" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "knative.dev/pkg/apis" knativev1 "knative.dev/pkg/apis/duck/v1" @@ -293,14 +293,14 @@ func (c *Catalog) StubBuildRun( // and a TaskRun when there is a client GET on this two objects func (c *Catalog) StubBuildRunAndTaskRun( b *build.BuildRun, - tr *v1beta1.TaskRun, + tr *pipelineapi.TaskRun, ) func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { return func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { switch object := object.(type) { case *build.BuildRun: b.DeepCopyInto(object) return nil - case *v1beta1.TaskRun: + case *pipelineapi.TaskRun: tr.DeepCopyInto(object) return nil } @@ -312,14 +312,14 @@ func (c *Catalog) StubBuildRunAndTaskRun( // and a TaskRun when there is a client GET on this two objects func (c *Catalog) StubBuildAndTaskRun( b *build.Build, - tr *v1beta1.TaskRun, + tr *pipelineapi.TaskRun, ) func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { return func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { switch object := object.(type) { case *build.Build: b.DeepCopyInto(object) return nil - case *v1beta1.TaskRun: + case *pipelineapi.TaskRun: tr.DeepCopyInto(object) return nil } @@ -397,7 +397,7 @@ func (c *Catalog) StubBuildRunGetWithoutSA( func (c *Catalog) StubBuildRunGetWithTaskRunAndSA( b *build.Build, br *build.BuildRun, - tr *v1beta1.TaskRun, + tr *pipelineapi.TaskRun, sa *corev1.ServiceAccount, ) func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { return func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { @@ -408,7 +408,7 @@ func (c *Catalog) StubBuildRunGetWithTaskRunAndSA( case *build.BuildRun: br.DeepCopyInto(object) return nil - case *v1beta1.TaskRun: + case *pipelineapi.TaskRun: tr.DeepCopyInto(object) return nil case *corev1.ServiceAccount: @@ -520,7 +520,7 @@ func (c *Catalog) StubBuildCRDsPodAndTaskRun( sa *corev1.ServiceAccount, cb *build.ClusterBuildStrategy, bs *build.BuildStrategy, - tr *v1beta1.TaskRun, + tr *pipelineapi.TaskRun, pod *corev1.Pod, ) func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { return func(context context.Context, nn types.NamespacedName, object client.Object, getOptions ...client.GetOption) error { @@ -540,7 +540,7 @@ func (c *Catalog) StubBuildCRDsPodAndTaskRun( case *build.BuildStrategy: bs.DeepCopyInto(object) return nil - case *v1beta1.TaskRun: + case *pipelineapi.TaskRun: tr.DeepCopyInto(object) return nil case *corev1.Pod: @@ -552,18 +552,18 @@ func (c *Catalog) StubBuildCRDsPodAndTaskRun( } // TaskRunWithStatus returns a minimal tekton TaskRun with an Status -func (c *Catalog) TaskRunWithStatus(trName string, ns string) *v1beta1.TaskRun { - return &v1beta1.TaskRun{ +func (c *Catalog) TaskRunWithStatus(trName string, ns string) *pipelineapi.TaskRun { + return &pipelineapi.TaskRun{ ObjectMeta: metav1.ObjectMeta{ Name: trName, Namespace: ns, }, - Spec: v1beta1.TaskRunSpec{ + Spec: pipelineapi.TaskRunSpec{ Timeout: &metav1.Duration{ Duration: time.Minute * 2, }, }, - Status: v1beta1.TaskRunStatus{ + Status: pipelineapi.TaskRunStatus{ Status: knativev1.Status{ Conditions: knativev1.Conditions{ { @@ -573,7 +573,7 @@ func (c *Catalog) TaskRunWithStatus(trName string, ns string) *v1beta1.TaskRun { }, }, }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + TaskRunStatusFields: pipelineapi.TaskRunStatusFields{ PodName: "foobar-pod", StartTime: &metav1.Time{ Time: time.Now(), @@ -587,15 +587,15 @@ func (c *Catalog) TaskRunWithStatus(trName string, ns string) *v1beta1.TaskRun { } // DefaultTaskRunWithStatus returns a minimal tekton TaskRun with an Status -func (c *Catalog) DefaultTaskRunWithStatus(trName string, buildRunName string, ns string, status corev1.ConditionStatus, reason string) *v1beta1.TaskRun { - return &v1beta1.TaskRun{ +func (c *Catalog) DefaultTaskRunWithStatus(trName string, buildRunName string, ns string, status corev1.ConditionStatus, reason string) *pipelineapi.TaskRun { + return &pipelineapi.TaskRun{ ObjectMeta: metav1.ObjectMeta{ Name: trName, Namespace: ns, Labels: map[string]string{"buildrun.shipwright.io/name": buildRunName}, }, - Spec: v1beta1.TaskRunSpec{}, - Status: v1beta1.TaskRunStatus{ + Spec: pipelineapi.TaskRunSpec{}, + Status: pipelineapi.TaskRunStatus{ Status: knativev1.Status{ Conditions: knativev1.Conditions{ { @@ -605,7 +605,7 @@ func (c *Catalog) DefaultTaskRunWithStatus(trName string, buildRunName string, n }, }, }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + TaskRunStatusFields: pipelineapi.TaskRunStatusFields{ StartTime: &metav1.Time{ Time: time.Now(), }, @@ -616,16 +616,16 @@ func (c *Catalog) DefaultTaskRunWithStatus(trName string, buildRunName string, n // TaskRunWithCompletionAndStartTime provides a TaskRun object with a // Completion and StartTime -func (c *Catalog) TaskRunWithCompletionAndStartTime(trName string, buildRunName string, ns string) *v1beta1.TaskRun { - return &v1beta1.TaskRun{ +func (c *Catalog) TaskRunWithCompletionAndStartTime(trName string, buildRunName string, ns string) *pipelineapi.TaskRun { + return &pipelineapi.TaskRun{ ObjectMeta: metav1.ObjectMeta{ Name: trName, Namespace: ns, Labels: map[string]string{"buildrun.shipwright.io/name": buildRunName}, }, - Spec: v1beta1.TaskRunSpec{}, - Status: v1beta1.TaskRunStatus{ - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + Spec: pipelineapi.TaskRunSpec{}, + Status: pipelineapi.TaskRunStatus{ + TaskRunStatusFields: pipelineapi.TaskRunStatusFields{ CompletionTime: &metav1.Time{ Time: time.Now(), }, @@ -649,15 +649,15 @@ func (c *Catalog) TaskRunWithCompletionAndStartTime(trName string, buildRunName } // DefaultTaskRunWithFalseStatus returns a minimal tektont TaskRun with a FALSE status -func (c *Catalog) DefaultTaskRunWithFalseStatus(trName string, buildRunName string, ns string) *v1beta1.TaskRun { - return &v1beta1.TaskRun{ +func (c *Catalog) DefaultTaskRunWithFalseStatus(trName string, buildRunName string, ns string) *pipelineapi.TaskRun { + return &pipelineapi.TaskRun{ ObjectMeta: metav1.ObjectMeta{ Name: trName, Namespace: ns, Labels: map[string]string{"buildrun.shipwright.io/name": buildRunName}, }, - Spec: v1beta1.TaskRunSpec{}, - Status: v1beta1.TaskRunStatus{ + Spec: pipelineapi.TaskRunSpec{}, + Status: pipelineapi.TaskRunStatus{ Status: knativev1.Status{ Conditions: knativev1.Conditions{ { @@ -668,7 +668,7 @@ func (c *Catalog) DefaultTaskRunWithFalseStatus(trName string, buildRunName stri }, }, }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + TaskRunStatusFields: pipelineapi.TaskRunStatusFields{ StartTime: &metav1.Time{ Time: time.Now(), }, @@ -878,8 +878,8 @@ func (c *Catalog) BuildRunWithFakeNamespace(buildRunName string, buildName strin } // DefaultTaskRun returns a minimal TaskRun object -func (c *Catalog) DefaultTaskRun(taskRunName string, ns string) *v1beta1.TaskRun { - return &v1beta1.TaskRun{ +func (c *Catalog) DefaultTaskRun(taskRunName string, ns string) *pipelineapi.TaskRun { + return &pipelineapi.TaskRun{ ObjectMeta: metav1.ObjectMeta{ Name: taskRunName, Namespace: ns,