From 50c3c72120d7238decbb7a0c71be04683f92f481 Mon Sep 17 00:00:00 2001 From: Andrew Bayer Date: Fri, 1 Oct 2021 17:49:00 -0400 Subject: [PATCH] Removing internal/builder/v1alpha1 and all usages Part of #3178. `internal/builder/v1beta1` is still there - I did remove it from some of the files under `pkg/reconciler` where I was removing `internal/builder/v1alpha1` usage while I was there, but there are still plenty of references left, including _1,487_ in `pkg/reconciler/pipelinerun/pipelinerun_test.go`. Yikes! Signed-off-by: Andrew Bayer --- internal/builder/v1alpha1/condition.go | 138 --- internal/builder/v1alpha1/container.go | 71 -- internal/builder/v1alpha1/doc.go | 27 - internal/builder/v1alpha1/owner_reference.go | 36 - internal/builder/v1alpha1/param.go | 37 - internal/builder/v1alpha1/pipeline.go | 627 ------------- internal/builder/v1alpha1/sidecar.go | 67 -- internal/builder/v1alpha1/step.go | 88 -- internal/builder/v1alpha1/task.go | 883 ------------------ .../v1alpha1/pipelinerun_types_test.go | 77 +- .../pipeline/v1alpha1/taskrun_types_test.go | 175 +++- .../v1alpha1/taskrun_validation_test.go | 72 +- .../pipelinerun/pipelinerun_test.go | 106 ++- .../resources/conditionresolution_test.go | 133 ++- .../pipelinerun/resources/pipelineref_test.go | 127 ++- .../resources/pipelinerunresolution_test.go | 19 +- .../taskrun/resources/taskref_test.go | 24 +- test/pipelinerun_test.go | 17 +- test/v1alpha1/artifact_bucket_test.go | 279 ++++-- test/v1alpha1/cluster_resource_test.go | 144 ++- test/v1alpha1/duplicate_test.go | 29 +- test/v1alpha1/embed_test.go | 68 +- test/v1alpha1/kaniko_task_test.go | 152 ++- test/v1alpha1/pipelinerun_test.go | 547 ++++++++--- test/v1alpha1/status_test.go | 69 +- test/v1alpha1/taskrun_test.go | 94 +- test/v1alpha1/timeout_test.go | 189 +++- test/v1alpha1/workingdir_test.go | 70 +- test/v1alpha1/workspace_test.go | 186 +++- 29 files changed, 2014 insertions(+), 2537 deletions(-) delete mode 100644 internal/builder/v1alpha1/condition.go delete mode 100644 internal/builder/v1alpha1/container.go delete mode 100644 internal/builder/v1alpha1/doc.go delete mode 100644 internal/builder/v1alpha1/owner_reference.go delete mode 100644 internal/builder/v1alpha1/param.go delete mode 100644 internal/builder/v1alpha1/pipeline.go delete mode 100644 internal/builder/v1alpha1/sidecar.go delete mode 100644 internal/builder/v1alpha1/step.go delete mode 100644 internal/builder/v1alpha1/task.go diff --git a/internal/builder/v1alpha1/condition.go b/internal/builder/v1alpha1/condition.go deleted file mode 100644 index c5d25f6b398..00000000000 --- a/internal/builder/v1alpha1/condition.go +++ /dev/null @@ -1,138 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// ConditionOp is an operation which modifies a Condition struct. -type ConditionOp func(*v1alpha1.Condition) - -// ConditionSpecOp is an operation which modifies a ConditionSpec struct. -type ConditionSpecOp func(spec *v1alpha1.ConditionSpec) - -// Condition creates a Condition with default values. -// Any number of Condition modifiers can be passed to transform it. -func Condition(name string, ops ...ConditionOp) *v1alpha1.Condition { - condition := &v1alpha1.Condition{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - }, - } - for _, op := range ops { - op(condition) - } - return condition -} - -// ConditionNamespace sets the namespace on the condition -func ConditionNamespace(namespace string) ConditionOp { - return func(t *v1alpha1.Condition) { - t.ObjectMeta.Namespace = namespace - } -} - -// ConditionLabels sets the labels on the condition. -func ConditionLabels(labels map[string]string) ConditionOp { - return func(Condition *v1alpha1.Condition) { - if Condition.ObjectMeta.Labels == nil { - Condition.ObjectMeta.Labels = map[string]string{} - } - for key, value := range labels { - Condition.ObjectMeta.Labels[key] = value - } - } -} - -// ConditionAnnotations sets the annotations on the condition. -func ConditionAnnotations(annotations map[string]string) ConditionOp { - return func(Condition *v1alpha1.Condition) { - if Condition.ObjectMeta.Annotations == nil { - Condition.ObjectMeta.Annotations = map[string]string{} - } - for key, value := range annotations { - Condition.ObjectMeta.Annotations[key] = value - } - } -} - -// ConditionSpec creates a ConditionSpec with default values. -// Any number of ConditionSpec modifiers can be passed to transform it. -func ConditionSpec(ops ...ConditionSpecOp) ConditionOp { - return func(Condition *v1alpha1.Condition) { - ConditionSpec := &Condition.Spec - for _, op := range ops { - op(ConditionSpec) - } - Condition.Spec = *ConditionSpec - } -} - -// ConditionSpecCheck adds a Container, with the specified name and image, to the Condition Spec Check. -// Any number of Container modifiers can be passed to transform it. -func ConditionSpecCheck(name, image string, ops ...ContainerOp) ConditionSpecOp { - return func(spec *v1alpha1.ConditionSpec) { - c := &corev1.Container{ - Name: name, - Image: image, - } - for _, op := range ops { - op(c) - } - spec.Check.Container = *c - } -} - -// ConditionDescription sets the description of the condition -func ConditionDescription(desc string) ConditionSpecOp { - return func(spec *v1alpha1.ConditionSpec) { - spec.Description = desc - } -} - -// ConditionSpecCheckScript adds a script to the Spec. -func ConditionSpecCheckScript(script string) ConditionSpecOp { - return func(spec *v1alpha1.ConditionSpec) { - spec.Check.Script = script - } -} - -// ConditionParamSpec adds a param, with specified name, to the Spec. -// Any number of ParamSpec modifiers can be passed to transform it. -func ConditionParamSpec(name string, pt v1alpha1.ParamType, ops ...ParamSpecOp) ConditionSpecOp { - return func(ps *v1alpha1.ConditionSpec) { - pp := &v1alpha1.ParamSpec{Name: name, Type: pt} - for _, op := range ops { - op(pp) - } - ps.Params = append(ps.Params, *pp) - } -} - -// ConditionResource adds a resource with specified name, and type to the ConditionSpec. -func ConditionResource(name string, resourceType v1alpha1.PipelineResourceType) ConditionSpecOp { - return func(spec *v1alpha1.ConditionSpec) { - r := v1alpha1.ResourceDeclaration{ - Name: name, - Type: resourceType, - } - spec.Resources = append(spec.Resources, r) - } -} diff --git a/internal/builder/v1alpha1/container.go b/internal/builder/v1alpha1/container.go deleted file mode 100644 index ad472af8868..00000000000 --- a/internal/builder/v1alpha1/container.go +++ /dev/null @@ -1,71 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - v1beta1 "github.com/tektoncd/pipeline/internal/builder/v1beta1" -) - -// ContainerOp is an operation which modifies a Container struct. -type ContainerOp = v1beta1.ContainerOp - -// VolumeMountOp is an operation which modifies a VolumeMount struct. -type VolumeMountOp = v1beta1.VolumeMountOp - -// ResourceRequirementsOp is an operation which modifies a ResourceRequirements struct. -type ResourceRequirementsOp = v1beta1.ResourceRequirementsOp - -// ResourceListOp is an operation which modifies a ResourceList struct. -type ResourceListOp = v1beta1.ResourceListOp - -var ( - // Command sets the command to the Container (step in this case). - Command = v1beta1.Command - - // Args sets the command arguments to the Container (step in this case). - Args = v1beta1.Args - - // EnvVar add an environment variable, with specified name and value, to the Container (step). - EnvVar = v1beta1.EnvVar - - // WorkingDir sets the WorkingDir on the Container. - WorkingDir = v1beta1.WorkingDir - - // VolumeMount add a VolumeMount to the Container (step). - VolumeMount = v1beta1.VolumeMount - - // Resources adds ResourceRequirements to the Container (step). - Resources = v1beta1.Resources - - // Limits adds Limits to the ResourceRequirements. - Limits = v1beta1.Limits - - // Requests adds Requests to the ResourceRequirements. - Requests = v1beta1.Requests - - // CPU sets the CPU resource on the ResourceList. - CPU = v1beta1.CPU - - // Memory sets the memory resource on the ResourceList. - Memory = v1beta1.Memory - - // EphemeralStorage sets the ephemeral storage resource on the ResourceList. - EphemeralStorage = v1beta1.EphemeralStorage - - // TerminationMessagePath sets the termination message path. - TerminationMessagePath = v1beta1.TerminationMessagePath -) diff --git a/internal/builder/v1alpha1/doc.go b/internal/builder/v1alpha1/doc.go deleted file mode 100644 index 59e2ba93b80..00000000000 --- a/internal/builder/v1alpha1/doc.go +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -/* -Package builder holds Builder functions that can be used to create -struct in tests with less noise. - -By convention, this package is import with the "tb" as alias. The -examples make that assumption. - -Deprecated: This package is deprecated. See -https://github.com/tektoncd/pipeline/issues/3178 for more information. -*/ -package builder diff --git a/internal/builder/v1alpha1/owner_reference.go b/internal/builder/v1alpha1/owner_reference.go deleted file mode 100644 index 99109204426..00000000000 --- a/internal/builder/v1alpha1/owner_reference.go +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - v1beta1 "github.com/tektoncd/pipeline/internal/builder/v1beta1" -) - -// OwnerReferenceOp is an operation which modifies an OwnerReference struct. -type OwnerReferenceOp = v1beta1.OwnerReferenceOp - -var ( - - // OwnerReferenceAPIVersion sets the APIVersion to the OwnerReference. - OwnerReferenceAPIVersion = v1beta1.OwnerReferenceAPIVersion - - // Controller sets the Controller to the OwnerReference. - Controller = v1beta1.Controller - - // BlockOwnerDeletion sets the BlockOwnerDeletion to the OwnerReference. - BlockOwnerDeletion = v1beta1.BlockOwnerDeletion -) diff --git a/internal/builder/v1alpha1/param.go b/internal/builder/v1alpha1/param.go deleted file mode 100644 index 0b7e745e465..00000000000 --- a/internal/builder/v1alpha1/param.go +++ /dev/null @@ -1,37 +0,0 @@ -/* -Copyright 2019 The Tekton Authors -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" -) - -// ParamSpecOp is an operation which modify a ParamSpec struct. -type ParamSpecOp func(*v1alpha1.ParamSpec) - -// ParamSpecDescription sets the description of a ParamSpec. -func ParamSpecDescription(desc string) ParamSpecOp { - return func(ps *v1alpha1.ParamSpec) { - ps.Description = desc - } -} - -// ParamSpecDefault sets the default value of a ParamSpec. -func ParamSpecDefault(value string, additionalValues ...string) ParamSpecOp { - arrayOrString := v1beta1.NewArrayOrString(value, additionalValues...) - return func(ps *v1alpha1.ParamSpec) { - ps.Default = arrayOrString - } -} diff --git a/internal/builder/v1alpha1/pipeline.go b/internal/builder/v1alpha1/pipeline.go deleted file mode 100644 index b36723dd65d..00000000000 --- a/internal/builder/v1alpha1/pipeline.go +++ /dev/null @@ -1,627 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - "time" - - "github.com/tektoncd/pipeline/pkg/apis/config" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" -) - -// PipelineOp is an operation which modify a Pipeline struct. -type PipelineOp func(*v1alpha1.Pipeline) - -// PipelineSpecOp is an operation which modify a PipelineSpec struct. -type PipelineSpecOp func(*v1alpha1.PipelineSpec) - -// PipelineTaskOp is an operation which modify a PipelineTask struct. -type PipelineTaskOp func(*v1alpha1.PipelineTask) - -// PipelineRunOp is an operation which modify a PipelineRun struct. -type PipelineRunOp func(*v1alpha1.PipelineRun) - -// PipelineRunSpecOp is an operation which modify a PipelineRunSpec struct. -type PipelineRunSpecOp func(*v1alpha1.PipelineRunSpec) - -// PipelineResourceOp is an operation which modify a PipelineResource struct. -type PipelineResourceOp func(*v1alpha1.PipelineResource) - -// PipelineResourceBindingOp is an operation which modify a PipelineResourceBinding struct. -type PipelineResourceBindingOp func(*v1alpha1.PipelineResourceBinding) - -// PipelineResourceSpecOp is an operation which modify a PipelineResourceSpec struct. -type PipelineResourceSpecOp func(*v1alpha1.PipelineResourceSpec) - -// PipelineTaskInputResourceOp is an operation which modifies a PipelineTaskInputResource. -type PipelineTaskInputResourceOp func(*v1alpha1.PipelineTaskInputResource) - -// PipelineRunStatusOp is an operation which modifies a PipelineRunStatus -type PipelineRunStatusOp func(*v1alpha1.PipelineRunStatus) - -// PipelineTaskConditionOp is an operation which modifies a PipelineTaskCondition -type PipelineTaskConditionOp func(condition *v1alpha1.PipelineTaskCondition) - -// Pipeline creates a Pipeline with default values. -// Any number of Pipeline modifier can be passed to transform it. -func Pipeline(name string, ops ...PipelineOp) *v1alpha1.Pipeline { - p := &v1alpha1.Pipeline{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - }, - } - - for _, op := range ops { - op(p) - } - - return p -} - -// PipelineType will add a TypeMeta to the pipeline's definition. -func PipelineType(t *v1alpha1.Pipeline) { - t.TypeMeta = metav1.TypeMeta{ - Kind: "Pipeline", - APIVersion: "tekton.dev/v1alpha1", - } -} - -// PipelineNamespace sets the namespace on the Pipeline -func PipelineNamespace(namespace string) PipelineOp { - return func(t *v1alpha1.Pipeline) { - t.ObjectMeta.Namespace = namespace - } -} - -// PipelineSpec sets the PipelineSpec to the Pipeline. -// Any number of PipelineSpec modifier can be passed to transform it. -func PipelineSpec(ops ...PipelineSpecOp) PipelineOp { - return func(p *v1alpha1.Pipeline) { - ps := &p.Spec - - for _, op := range ops { - op(ps) - } - - p.Spec = *ps - } -} - -// PipelineCreationTimestamp sets the creation time of the pipeline -func PipelineCreationTimestamp(t time.Time) PipelineOp { - return func(p *v1alpha1.Pipeline) { - p.CreationTimestamp = metav1.Time{Time: t} - } -} - -// PipelineDescription sets the description of the pipeline -func PipelineDescription(desc string) PipelineSpecOp { - return func(ps *v1alpha1.PipelineSpec) { - ps.Description = desc - } -} - -// PipelineRunCancelled sets the status to cancel to the TaskRunSpec. -func PipelineRunCancelled(spec *v1alpha1.PipelineRunSpec) { - spec.Status = v1alpha1.PipelineRunSpecStatusCancelled -} - -// PipelineDeclaredResource adds a resource declaration to the Pipeline Spec, -// with the specified name and type. -func PipelineDeclaredResource(name string, t v1alpha1.PipelineResourceType) PipelineSpecOp { - return func(ps *v1alpha1.PipelineSpec) { - r := v1alpha1.PipelineDeclaredResource{ - Name: name, - Type: t, - } - ps.Resources = append(ps.Resources, r) - } -} - -// PipelineParamSpec adds a param, with specified name and type, to the PipelineSpec. -// Any number of PipelineParamSpec modifiers can be passed to transform it. -func PipelineParamSpec(name string, pt v1alpha1.ParamType, ops ...ParamSpecOp) PipelineSpecOp { - return func(ps *v1alpha1.PipelineSpec) { - pp := &v1alpha1.ParamSpec{Name: name, Type: pt} - for _, op := range ops { - op(pp) - } - ps.Params = append(ps.Params, *pp) - } -} - -// PipelineTask adds a PipelineTask, with specified name and task name, to the PipelineSpec. -// Any number of PipelineTask modifier can be passed to transform it. -func PipelineTask(name, taskName string, ops ...PipelineTaskOp) PipelineSpecOp { - return func(ps *v1alpha1.PipelineSpec) { - pTask := &v1alpha1.PipelineTask{ - Name: name, - } - if taskName != "" { - pTask.TaskRef = &v1alpha1.TaskRef{ - Name: taskName, - } - } - for _, op := range ops { - op(pTask) - } - ps.Tasks = append(ps.Tasks, *pTask) - } -} - -// PipelineResult adds a PipelineResult, with specified name, value and description, to the PipelineSpec. -func PipelineResult(name, value, description string) PipelineSpecOp { - return func(ps *v1alpha1.PipelineSpec) { - pResult := &v1beta1.PipelineResult{ - Name: name, - Value: value, - Description: description, - } - ps.Results = append(ps.Results, *pResult) - } -} - -// PipelineRunResult adds a PipelineResultStatus, with specified name, value and description, to the PipelineRunStatusSpec. -func PipelineRunResult(name, value string) PipelineRunStatusOp { - return func(s *v1alpha1.PipelineRunStatus) { - pResult := &v1beta1.PipelineRunResult{ - Name: name, - Value: value, - } - s.PipelineResults = append(s.PipelineResults, *pResult) - } -} - -// PipelineTaskSpec sets the TaskSpec on a PipelineTask. -func PipelineTaskSpec(spec *v1alpha1.TaskSpec) PipelineTaskOp { - return func(pt *v1alpha1.PipelineTask) { - pt.TaskSpec = spec - } -} - -// Retries sets the number of retries on a PipelineTask. -func Retries(retries int) PipelineTaskOp { - return func(pt *v1alpha1.PipelineTask) { - pt.Retries = retries - } -} - -// RunAfter will update the provided Pipeline Task to indicate that it -// should be run after the provided list of Pipeline Task names. -func RunAfter(tasks ...string) PipelineTaskOp { - return func(pt *v1alpha1.PipelineTask) { - pt.RunAfter = tasks - } -} - -// PipelineTaskRefKind sets the TaskKind to the PipelineTaskRef. -func PipelineTaskRefKind(kind v1alpha1.TaskKind) PipelineTaskOp { - return func(pt *v1alpha1.PipelineTask) { - pt.TaskRef.Kind = kind - } -} - -// PipelineTaskParam adds a ResourceParam, with specified name and value, to the PipelineTask. -func PipelineTaskParam(name string, value string, additionalValues ...string) PipelineTaskOp { - return func(pt *v1alpha1.PipelineTask) { - pt.Params = append(pt.Params, v1alpha1.Param{ - Name: name, - Value: *v1beta1.NewArrayOrString(value, additionalValues...), - }) - } -} - -// From will update the provided PipelineTaskInputResource to indicate that it -// should come from tasks. -func From(tasks ...string) PipelineTaskInputResourceOp { - return func(r *v1alpha1.PipelineTaskInputResource) { - r.From = tasks - } -} - -// PipelineTaskInputResource adds an input resource to the PipelineTask with the specified -// name, pointing at the declared resource. -// Any number of PipelineTaskInputResource modifies can be passed to transform it. -func PipelineTaskInputResource(name, resource string, ops ...PipelineTaskInputResourceOp) PipelineTaskOp { - return func(pt *v1alpha1.PipelineTask) { - r := v1alpha1.PipelineTaskInputResource{ - Name: name, - Resource: resource, - } - for _, op := range ops { - op(&r) - } - if pt.Resources == nil { - pt.Resources = &v1alpha1.PipelineTaskResources{} - } - pt.Resources.Inputs = append(pt.Resources.Inputs, r) - } -} - -// PipelineTaskOutputResource adds an output resource to the PipelineTask with the specified -// name, pointing at the declared resource. -func PipelineTaskOutputResource(name, resource string) PipelineTaskOp { - return func(pt *v1alpha1.PipelineTask) { - r := v1alpha1.PipelineTaskOutputResource{ - Name: name, - Resource: resource, - } - if pt.Resources == nil { - pt.Resources = &v1alpha1.PipelineTaskResources{} - } - pt.Resources.Outputs = append(pt.Resources.Outputs, r) - } -} - -// PipelineTaskCondition adds a condition to the PipelineTask with the -// specified conditionRef. Any number of PipelineTaskCondition modifiers can be passed -// to transform it -func PipelineTaskCondition(conditionRef string, ops ...PipelineTaskConditionOp) PipelineTaskOp { - return func(pt *v1alpha1.PipelineTask) { - c := &v1alpha1.PipelineTaskCondition{ - ConditionRef: conditionRef, - } - for _, op := range ops { - op(c) - } - pt.Conditions = append(pt.Conditions, *c) - } -} - -// PipelineTaskConditionParam adds a parameter to a PipelineTaskCondition -func PipelineTaskConditionParam(name, val string) PipelineTaskConditionOp { - return func(condition *v1alpha1.PipelineTaskCondition) { - if condition.Params == nil { - condition.Params = []v1alpha1.Param{} - } - condition.Params = append(condition.Params, v1alpha1.Param{ - Name: name, - Value: *v1beta1.NewArrayOrString(val), - }) - } -} - -// PipelineTaskConditionResource adds a resource to a PipelineTaskCondition -func PipelineTaskConditionResource(name, resource string, from ...string) PipelineTaskConditionOp { - return func(condition *v1alpha1.PipelineTaskCondition) { - if condition.Resources == nil { - condition.Resources = []v1alpha1.PipelineTaskInputResource{} - } - condition.Resources = append(condition.Resources, v1alpha1.PipelineTaskInputResource{ - Name: name, - Resource: resource, - From: from, - }) - } -} - -// PipelineTaskWorkspaceBinding adds a workspace with the specified name, workspace and subpath on a PipelineTask. -func PipelineTaskWorkspaceBinding(name, workspace, subPath string) PipelineTaskOp { - return func(pt *v1alpha1.PipelineTask) { - pt.Workspaces = append(pt.Workspaces, v1alpha1.WorkspacePipelineTaskBinding{ - Name: name, - Workspace: workspace, - SubPath: subPath, - }) - } -} - -// PipelineTaskTimeout sets the timeout for the PipelineTask. -func PipelineTaskTimeout(duration time.Duration) PipelineTaskOp { - return func(pt *v1alpha1.PipelineTask) { - pt.Timeout = &metav1.Duration{Duration: duration} - } -} - -// PipelineRun creates a PipelineRun with default values. -// Any number of PipelineRun modifier can be passed to transform it. -func PipelineRun(name string, ops ...PipelineRunOp) *v1alpha1.PipelineRun { - pr := &v1alpha1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - }, - Spec: v1alpha1.PipelineRunSpec{}, - } - - for _, op := range ops { - op(pr) - } - - return pr -} - -// PipelineRunNamespace sets the namespace on a PipelineRun. -func PipelineRunNamespace(namespace string) PipelineRunOp { - return func(t *v1alpha1.PipelineRun) { - t.ObjectMeta.Namespace = namespace - } -} - -// PipelineRunSpec sets the PipelineRunSpec, references Pipeline with specified name, to the PipelineRun. -// Any number of PipelineRunSpec modifier can be passed to transform it. -func PipelineRunSpec(name string, ops ...PipelineRunSpecOp) PipelineRunOp { - return func(pr *v1alpha1.PipelineRun) { - prs := &pr.Spec - - prs.PipelineRef = &v1alpha1.PipelineRef{ - Name: name, - } - // Set a default timeout - prs.Timeout = &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute} - - for _, op := range ops { - op(prs) - } - - pr.Spec = *prs - } -} - -// PipelineRunLabel adds a label to the PipelineRun. -func PipelineRunLabel(key, value string) PipelineRunOp { - return func(pr *v1alpha1.PipelineRun) { - if pr.ObjectMeta.Labels == nil { - pr.ObjectMeta.Labels = map[string]string{} - } - pr.ObjectMeta.Labels[key] = value - } -} - -// PipelineRunAnnotation adds a annotation to the PipelineRun. -func PipelineRunAnnotation(key, value string) PipelineRunOp { - return func(pr *v1alpha1.PipelineRun) { - if pr.ObjectMeta.Annotations == nil { - pr.ObjectMeta.Annotations = map[string]string{} - } - pr.ObjectMeta.Annotations[key] = value - } -} - -// PipelineRunResourceBinding adds bindings from actual instances to a Pipeline's declared resources. -func PipelineRunResourceBinding(name string, ops ...PipelineResourceBindingOp) PipelineRunSpecOp { - return func(prs *v1alpha1.PipelineRunSpec) { - r := &v1alpha1.PipelineResourceBinding{ - Name: name, - } - for _, op := range ops { - op(r) - } - prs.Resources = append(prs.Resources, *r) - } -} - -// PipelineResourceBindingRef set the ResourceRef name to the Resource called Name. -func PipelineResourceBindingRef(name string) PipelineResourceBindingOp { - return func(b *v1alpha1.PipelineResourceBinding) { - b.ResourceRef = &v1alpha1.PipelineResourceRef{ - Name: name, - } - } -} - -// PipelineResourceBindingResourceSpec set the PipelineResourceResourceSpec to the PipelineResourceBinding. -func PipelineResourceBindingResourceSpec(spec *v1alpha1.PipelineResourceSpec) PipelineResourceBindingOp { - return func(b *v1alpha1.PipelineResourceBinding) { - b.ResourceSpec = spec - } -} - -// PipelineRunServiceAccountName sets the service account to the PipelineRunSpec. -func PipelineRunServiceAccountName(sa string) PipelineRunSpecOp { - return func(prs *v1alpha1.PipelineRunSpec) { - prs.ServiceAccountName = sa - } -} - -// PipelineRunServiceAccountNameTask configures the service account for given Task in PipelineRun. -func PipelineRunServiceAccountNameTask(taskName, sa string) PipelineRunSpecOp { - return func(prs *v1alpha1.PipelineRunSpec) { - prs.ServiceAccountNames = append(prs.ServiceAccountNames, v1alpha1.PipelineRunSpecServiceAccountName{ - TaskName: taskName, - ServiceAccountName: sa, - }) - } -} - -// PipelineRunParam add a param, with specified name and value, to the PipelineRunSpec. -func PipelineRunParam(name string, value string, additionalValues ...string) PipelineRunSpecOp { - return func(prs *v1alpha1.PipelineRunSpec) { - prs.Params = append(prs.Params, v1alpha1.Param{ - Name: name, - Value: *v1beta1.NewArrayOrString(value, additionalValues...), - }) - } -} - -// PipelineRunTimeout sets the timeout to the PipelineRunSpec. -func PipelineRunTimeout(duration time.Duration) PipelineRunSpecOp { - return func(prs *v1alpha1.PipelineRunSpec) { - prs.Timeout = &metav1.Duration{Duration: duration} - } -} - -// PipelineRunNilTimeout sets the timeout to nil on the PipelineRunSpec -func PipelineRunNilTimeout(prs *v1alpha1.PipelineRunSpec) { - prs.Timeout = nil -} - -// PipelineRunNodeSelector sets the Node selector to the PipelineRunSpec. -func PipelineRunNodeSelector(values map[string]string) PipelineRunSpecOp { - return func(prs *v1alpha1.PipelineRunSpec) { - if prs.PodTemplate == nil { - prs.PodTemplate = &v1alpha1.PodTemplate{} - } - prs.PodTemplate.NodeSelector = values - } -} - -// PipelineRunPipelineSpec adds a PipelineSpec to the PipelineRunSpec. -// Any number of PipelineSpec modifiers can be passed to transform it. -func PipelineRunPipelineSpec(ops ...PipelineSpecOp) PipelineRunSpecOp { - return func(prs *v1alpha1.PipelineRunSpec) { - ps := &v1alpha1.PipelineSpec{} - prs.PipelineRef = nil - for _, op := range ops { - op(ps) - } - prs.PipelineSpec = ps - } -} - -// PipelineRunStatus sets the PipelineRunStatus to the PipelineRun. -// Any number of PipelineRunStatus modifier can be passed to transform it. -func PipelineRunStatus(ops ...PipelineRunStatusOp) PipelineRunOp { - return func(pr *v1alpha1.PipelineRun) { - s := &v1alpha1.PipelineRunStatus{} - for _, op := range ops { - op(s) - } - pr.Status = *s - } -} - -// PipelineRunStatusCondition adds a StatusCondition to the TaskRunStatus. -func PipelineRunStatusCondition(condition apis.Condition) PipelineRunStatusOp { - return func(s *v1alpha1.PipelineRunStatus) { - s.Conditions = append(s.Conditions, condition) - } -} - -// PipelineRunStartTime sets the start time to the PipelineRunStatus. -func PipelineRunStartTime(startTime time.Time) PipelineRunStatusOp { - return func(s *v1alpha1.PipelineRunStatus) { - s.StartTime = &metav1.Time{Time: startTime} - } -} - -// PipelineRunCompletionTime sets the completion time to the PipelineRunStatus. -func PipelineRunCompletionTime(t time.Time) PipelineRunStatusOp { - return func(s *v1alpha1.PipelineRunStatus) { - s.CompletionTime = &metav1.Time{Time: t} - } -} - -// PipelineRunTaskRunsStatus sets the status of TaskRun to the PipelineRunStatus. -func PipelineRunTaskRunsStatus(taskRunName string, status *v1alpha1.PipelineRunTaskRunStatus) PipelineRunStatusOp { - return func(s *v1alpha1.PipelineRunStatus) { - if s.TaskRuns == nil { - s.TaskRuns = make(map[string]*v1alpha1.PipelineRunTaskRunStatus) - } - s.TaskRuns[taskRunName] = status - } -} - -// PipelineResource creates a PipelineResource with default values. -// Any number of PipelineResource modifier can be passed to transform it. -func PipelineResource(name string, ops ...PipelineResourceOp) *v1alpha1.PipelineResource { - resource := &v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - }, - } - for _, op := range ops { - op(resource) - } - return resource -} - -// PipelineResourceNamespace sets the namespace on a PipelineResource. -func PipelineResourceNamespace(namespace string) PipelineResourceOp { - return func(t *v1alpha1.PipelineResource) { - t.ObjectMeta.Namespace = namespace - } -} - -// PipelineResourceSpec set the PipelineResourceSpec, with specified type, to the PipelineResource. -// Any number of PipelineResourceSpec modifier can be passed to transform it. -func PipelineResourceSpec(resourceType v1alpha1.PipelineResourceType, ops ...PipelineResourceSpecOp) PipelineResourceOp { - return func(r *v1alpha1.PipelineResource) { - spec := &r.Spec - spec.Type = resourceType - for _, op := range ops { - op(spec) - } - r.Spec = *spec - } -} - -// PipelineResourceDescription sets the description of the pipeline resource -func PipelineResourceDescription(desc string) PipelineResourceSpecOp { - return func(spec *v1alpha1.PipelineResourceSpec) { - spec.Description = desc - } -} - -// PipelineResourceSpecParam adds a ResourceParam, with specified name and value, to the PipelineResourceSpec. -func PipelineResourceSpecParam(name, value string) PipelineResourceSpecOp { - return func(spec *v1alpha1.PipelineResourceSpec) { - spec.Params = append(spec.Params, v1alpha1.ResourceParam{ - Name: name, - Value: value, - }) - } -} - -// PipelineResourceSpecSecretParam adds a SecretParam, with specified fieldname, secretKey and secretName, to the PipelineResourceSpec. -func PipelineResourceSpecSecretParam(fieldname, secretName, secretKey string) PipelineResourceSpecOp { - return func(spec *v1alpha1.PipelineResourceSpec) { - spec.SecretParams = append(spec.SecretParams, v1alpha1.SecretParam{ - FieldName: fieldname, - SecretKey: secretKey, - SecretName: secretName, - }) - } -} - -// PipelineWorkspaceDeclaration adds a Workspace to the workspaces listed in the pipeline spec. -func PipelineWorkspaceDeclaration(names ...string) PipelineSpecOp { - return func(spec *v1alpha1.PipelineSpec) { - for _, name := range names { - spec.Workspaces = append(spec.Workspaces, v1alpha1.PipelineWorkspaceDeclaration{Name: name}) - } - } -} - -// PipelineRunWorkspaceBindingEmptyDir adds an EmptyDir Workspace to the workspaces of a pipelinerun spec. -func PipelineRunWorkspaceBindingEmptyDir(name string) PipelineRunSpecOp { - return func(spec *v1alpha1.PipelineRunSpec) { - spec.Workspaces = append(spec.Workspaces, v1alpha1.WorkspaceBinding{ - Name: name, - EmptyDir: &corev1.EmptyDirVolumeSource{}, - }) - } -} - -// PipelineRunWorkspaceBindingVolumeClaimTemplate adds an VolumeClaimTemplate Workspace to the workspaces of a pipelineRun spec. -func PipelineRunWorkspaceBindingVolumeClaimTemplate(name string, claimName string, subPath string) PipelineRunSpecOp { - return func(spec *v1alpha1.PipelineRunSpec) { - spec.Workspaces = append(spec.Workspaces, v1alpha1.WorkspaceBinding{ - Name: name, - SubPath: subPath, - VolumeClaimTemplate: &corev1.PersistentVolumeClaim{ - ObjectMeta: metav1.ObjectMeta{ - Name: claimName, - }, - Spec: corev1.PersistentVolumeClaimSpec{}, - }, - }) - } -} diff --git a/internal/builder/v1alpha1/sidecar.go b/internal/builder/v1alpha1/sidecar.go deleted file mode 100644 index b91c8242dfe..00000000000 --- a/internal/builder/v1alpha1/sidecar.go +++ /dev/null @@ -1,67 +0,0 @@ -/* -Copyright 2020 The Tekton Authors -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" - corev1 "k8s.io/api/core/v1" -) - -// SidecarStateName sets the name of the Sidecar for the SidecarState. -func SidecarStateName(name string) SidecarStateOp { - return func(s *v1alpha1.SidecarState) { - s.Name = name - } -} - -// SidecarStateImageID sets ImageID of Sidecar for SidecarState. -func SidecarStateImageID(imageID string) SidecarStateOp { - return func(s *v1alpha1.SidecarState) { - s.ImageID = imageID - } -} - -// SidecarStateContainerName sets ContainerName of Sidecar for SidecarState. -func SidecarStateContainerName(containerName string) SidecarStateOp { - return func(s *v1alpha1.SidecarState) { - s.ContainerName = containerName - } -} - -// SetSidecarStateTerminated sets Terminated state of a Sidecar. -func SetSidecarStateTerminated(terminated corev1.ContainerStateTerminated) SidecarStateOp { - return func(s *v1alpha1.SidecarState) { - s.ContainerState = corev1.ContainerState{ - Terminated: &terminated, - } - } -} - -// SetSidecarStateRunning sets Running state of a Sidecar. -func SetSidecarStateRunning(running corev1.ContainerStateRunning) SidecarStateOp { - return func(s *v1alpha1.SidecarState) { - s.ContainerState = corev1.ContainerState{ - Running: &running, - } - } -} - -// SetSidecarStateWaiting sets Waiting state of a Sidecar. -func SetSidecarStateWaiting(waiting corev1.ContainerStateWaiting) SidecarStateOp { - return func(s *v1alpha1.SidecarState) { - s.ContainerState = corev1.ContainerState{ - Waiting: &waiting, - } - } -} diff --git a/internal/builder/v1alpha1/step.go b/internal/builder/v1alpha1/step.go deleted file mode 100644 index 695f4671b8a..00000000000 --- a/internal/builder/v1alpha1/step.go +++ /dev/null @@ -1,88 +0,0 @@ -/* -Copyright 2019 The Tekton Authors -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" - corev1 "k8s.io/api/core/v1" -) - -// StepOp is an operation which modifies a Container struct. -type StepOp func(*v1alpha1.Step) - -// StepName sets the name of the step. -func StepName(name string) StepOp { - return func(step *v1alpha1.Step) { - step.Name = name - } -} - -// StepCommand sets the command to the Container (step in this case). -func StepCommand(args ...string) StepOp { - return func(step *v1alpha1.Step) { - step.Command = args - } -} - -// StepSecurityContext sets the SecurityContext to the Step. -func StepSecurityContext(context *corev1.SecurityContext) StepOp { - return func(step *v1alpha1.Step) { - step.SecurityContext = context - } -} - -// StepArgs sets the command arguments to the Container (step in this case). -func StepArgs(args ...string) StepOp { - return func(step *v1alpha1.Step) { - step.Args = args - } -} - -// StepEnvVar add an environment variable, with specified name and value, to the Container (step). -func StepEnvVar(name, value string) StepOp { - return func(step *v1alpha1.Step) { - step.Env = append(step.Env, corev1.EnvVar{ - Name: name, - Value: value, - }) - } -} - -// StepWorkingDir sets the WorkingDir on the Container. -func StepWorkingDir(workingDir string) StepOp { - return func(step *v1alpha1.Step) { - step.WorkingDir = workingDir - } -} - -// StepVolumeMount add a VolumeMount to the Container (step). -func StepVolumeMount(name, mountPath string, ops ...VolumeMountOp) StepOp { - return func(step *v1alpha1.Step) { - mount := &corev1.VolumeMount{ - Name: name, - MountPath: mountPath, - } - for _, op := range ops { - op(mount) - } - step.VolumeMounts = append(step.VolumeMounts, *mount) - } -} - -// StepScript sets the script to the Step. -func StepScript(script string) StepOp { - return func(step *v1alpha1.Step) { - step.Script = script - } -} diff --git a/internal/builder/v1alpha1/task.go b/internal/builder/v1alpha1/task.go deleted file mode 100644 index d19d311fb8e..00000000000 --- a/internal/builder/v1alpha1/task.go +++ /dev/null @@ -1,883 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package builder - -import ( - "time" - - "github.com/tektoncd/pipeline/pkg/apis/config" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/pkg/apis" -) - -// TaskOp is an operation which modify a Task struct. -type TaskOp func(*v1alpha1.Task) - -// ClusterTaskOp is an operation which modify a ClusterTask struct. -type ClusterTaskOp func(*v1alpha1.ClusterTask) - -// TaskSpecOp is an operation which modify a TaskSpec struct. -type TaskSpecOp func(*v1alpha1.TaskSpec) - -// TaskResourcesOp is an operation which modify a TaskResources struct. -type TaskResourcesOp func(*v1beta1.TaskResources) - -// InputsOp is an operation which modify an Inputs struct. -type InputsOp func(*v1alpha1.Inputs) - -// OutputsOp is an operation which modify an Outputs struct. -type OutputsOp func(*v1alpha1.Outputs) - -// TaskRunOp is an operation which modify a TaskRun struct. -type TaskRunOp func(*v1alpha1.TaskRun) - -// TaskRunSpecOp is an operation which modify a TaskRunSpec struct. -type TaskRunSpecOp func(*v1alpha1.TaskRunSpec) - -// TaskRunResourcesOp is an operation which modify a TaskRunResources struct. -type TaskRunResourcesOp func(*v1beta1.TaskRunResources) - -// TaskResourceOp is an operation which modify a TaskResource struct. -type TaskResourceOp func(*v1alpha1.TaskResource) - -// TaskResourceBindingOp is an operation which modify a TaskResourceBinding struct. -type TaskResourceBindingOp func(*v1alpha1.TaskResourceBinding) - -// TaskRunStatusOp is an operation which modify a TaskRunStatus struct. -type TaskRunStatusOp func(*v1alpha1.TaskRunStatus) - -// TaskRefOp is an operation which modify a TaskRef struct. -type TaskRefOp func(*v1alpha1.TaskRef) - -// TaskResultOp is an operation which modifies there -type TaskResultOp func(result *v1beta1.TaskResult) - -// TaskRunInputsOp is an operation which modify a TaskRunInputs struct. -type TaskRunInputsOp func(*v1alpha1.TaskRunInputs) - -// TaskRunOutputsOp is an operation which modify a TaskRunOutputs struct. -type TaskRunOutputsOp func(*v1alpha1.TaskRunOutputs) - -// StepStateOp is an operation which modifies a StepState struct. -type StepStateOp func(*v1alpha1.StepState) - -// SidecarStateOp is an operation which modifies a SidecarState struct. -type SidecarStateOp func(*v1alpha1.SidecarState) - -// VolumeOp is an operation which modify a Volume struct. -type VolumeOp func(*corev1.Volume) - -// Task creates a Task with default values. -// Any number of Task modifier can be passed to transform it. -func Task(name string, ops ...TaskOp) *v1alpha1.Task { - t := &v1alpha1.Task{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - }, - } - - for _, op := range ops { - op(t) - } - - return t -} - -// TaskType sets the TypeMeta on the Task which is useful for making it serializable/deserializable. -func TaskType(t *v1alpha1.Task) { - t.TypeMeta = metav1.TypeMeta{ - APIVersion: "tekton.dev/v1alpha1", - Kind: "Task", - } -} - -// ClusterTask creates a ClusterTask with default values. -// Any number of ClusterTask modifier can be passed to transform it. -func ClusterTask(name string, ops ...ClusterTaskOp) *v1alpha1.ClusterTask { - t := &v1alpha1.ClusterTask{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - }, - } - - for _, op := range ops { - op(t) - } - - return t -} - -// TaskNamespace sets the namespace to the Task. -func TaskNamespace(namespace string) TaskOp { - return func(t *v1alpha1.Task) { - t.ObjectMeta.Namespace = namespace - } -} - -// ClusterTaskType sets the TypeMeta on the ClusterTask which is useful for making it serializable/deserializable. -func ClusterTaskType(t *v1alpha1.ClusterTask) { - t.TypeMeta = metav1.TypeMeta{ - APIVersion: "tekton.dev/v1alpha1", - Kind: "ClusterTask", - } -} - -// ClusterTaskSpec sets the specified spec of the cluster task. -// Any number of TaskSpec modifier can be passed to create it. -func ClusterTaskSpec(ops ...TaskSpecOp) ClusterTaskOp { - return func(t *v1alpha1.ClusterTask) { - spec := &t.Spec - for _, op := range ops { - op(spec) - } - t.Spec = *spec - } -} - -// TaskSpec sets the specified spec of the task. -// Any number of TaskSpec modifier can be passed to create/modify it. -func TaskSpec(ops ...TaskSpecOp) TaskOp { - return func(t *v1alpha1.Task) { - spec := &t.Spec - for _, op := range ops { - op(spec) - } - t.Spec = *spec - } -} - -// TaskDescription sets the description of the task -func TaskDescription(desc string) TaskSpecOp { - return func(spec *v1alpha1.TaskSpec) { - spec.Description = desc - } -} - -// Step adds a step with the specified name and image to the TaskSpec. -// Any number of Container modifier can be passed to transform it. -func Step(image string, ops ...StepOp) TaskSpecOp { - return func(spec *v1alpha1.TaskSpec) { - if spec.Steps == nil { - spec.Steps = []v1alpha1.Step{} - } - step := v1alpha1.Step{Container: corev1.Container{ - Image: image, - }} - for _, op := range ops { - op(&step) - } - spec.Steps = append(spec.Steps, step) - } -} - -// Sidecar adds a sidecar container with the specified name and image to the TaskSpec. -// Any number of Container modifier can be passed to transform it. -func Sidecar(name, image string, ops ...ContainerOp) TaskSpecOp { - return func(spec *v1alpha1.TaskSpec) { - c := corev1.Container{ - Name: name, - Image: image, - } - for _, op := range ops { - op(&c) - } - spec.Sidecars = append(spec.Sidecars, v1alpha1.Sidecar{Container: c}) - } -} - -// TaskWorkspace adds a workspace declaration. -func TaskWorkspace(name, desc, mountPath string, readOnly bool) TaskSpecOp { - return func(spec *v1alpha1.TaskSpec) { - spec.Workspaces = append(spec.Workspaces, v1alpha1.WorkspaceDeclaration{ - Name: name, - Description: desc, - MountPath: mountPath, - ReadOnly: readOnly, - }) - } -} - -// TaskStepTemplate adds a base container for all steps in the task. -func TaskStepTemplate(ops ...ContainerOp) TaskSpecOp { - return func(spec *v1alpha1.TaskSpec) { - base := &corev1.Container{} - for _, op := range ops { - op(base) - } - spec.StepTemplate = base - } -} - -// TaskVolume adds a volume with specified name to the TaskSpec. -// Any number of Volume modifier can be passed to transform it. -func TaskVolume(name string, ops ...VolumeOp) TaskSpecOp { - return func(spec *v1alpha1.TaskSpec) { - v := &corev1.Volume{Name: name} - for _, op := range ops { - op(v) - } - spec.Volumes = append(spec.Volumes, *v) - } -} - -// VolumeSource sets the VolumeSource to the Volume. -func VolumeSource(s corev1.VolumeSource) VolumeOp { - return func(v *corev1.Volume) { - v.VolumeSource = s - } -} - -// TaskParam sets the Params to the TaskSpec -func TaskParam(name string, pt v1alpha1.ParamType, ops ...ParamSpecOp) TaskSpecOp { - return func(spec *v1alpha1.TaskSpec) { - ps := &v1alpha1.ParamSpec{Name: name, Type: pt} - for _, op := range ops { - op(ps) - } - spec.Params = append(spec.Params, *ps) - } -} - -// TaskResources sets the Resources to the TaskSpec -func TaskResources(ops ...TaskResourcesOp) TaskSpecOp { - return func(spec *v1alpha1.TaskSpec) { - r := &v1beta1.TaskResources{} - for _, op := range ops { - op(r) - } - spec.Resources = r - } -} - -// TaskResults sets the Results to the TaskSpec -func TaskResults(name, desc string) TaskSpecOp { - return func(spec *v1alpha1.TaskSpec) { - r := &v1beta1.TaskResult{ - Name: name, - Description: desc, - } - spec.Results = append(spec.Results, *r) - } -} - -// TaskResourcesInput adds a TaskResource as Inputs to the TaskResources -func TaskResourcesInput(name string, resourceType v1alpha1.PipelineResourceType, ops ...TaskResourceOp) TaskResourcesOp { - return func(r *v1beta1.TaskResources) { - i := &v1beta1.TaskResource{ - ResourceDeclaration: v1alpha1.ResourceDeclaration{ - Name: name, - Type: resourceType, - }, - } - for _, op := range ops { - op(i) - } - r.Inputs = append(r.Inputs, *i) - } -} - -// TaskResourcesOutput adds a TaskResource as Outputs to the TaskResources -func TaskResourcesOutput(name string, resourceType v1alpha1.PipelineResourceType, ops ...TaskResourceOp) TaskResourcesOp { - return func(r *v1beta1.TaskResources) { - o := &v1beta1.TaskResource{ - ResourceDeclaration: v1alpha1.ResourceDeclaration{ - Name: name, - Type: resourceType, - }, - } - for _, op := range ops { - op(o) - } - r.Outputs = append(r.Outputs, *o) - } -} - -// TaskInputs sets inputs to the TaskSpec. -// Any number of Inputs modifier can be passed to transform it. -func TaskInputs(ops ...InputsOp) TaskSpecOp { - return func(spec *v1alpha1.TaskSpec) { - if spec.Inputs == nil { - spec.Inputs = &v1alpha1.Inputs{} - } - for _, op := range ops { - op(spec.Inputs) - } - } -} - -// TaskOutputs sets inputs to the TaskSpec. -// Any number of Outputs modifier can be passed to transform it. -func TaskOutputs(ops ...OutputsOp) TaskSpecOp { - return func(spec *v1alpha1.TaskSpec) { - if spec.Outputs == nil { - spec.Outputs = &v1alpha1.Outputs{} - } - for _, op := range ops { - op(spec.Outputs) - } - } -} - -// InputsResource adds a resource, with specified name and type, to the Inputs. -// Any number of TaskResource modifier can be passed to transform it. -func InputsResource(name string, resourceType v1alpha1.PipelineResourceType, ops ...TaskResourceOp) InputsOp { - return func(i *v1alpha1.Inputs) { - r := &v1alpha1.TaskResource{ - ResourceDeclaration: v1alpha1.ResourceDeclaration{ - Name: name, - Type: resourceType, - }} - for _, op := range ops { - op(r) - } - i.Resources = append(i.Resources, *r) - } -} - -// ResourceOptional marks a TaskResource as optional. -func ResourceOptional(optional bool) TaskResourceOp { - return func(r *v1alpha1.TaskResource) { - r.Optional = optional - } -} - -// ResourceTargetPath sets the target path to a TaskResource. -func ResourceTargetPath(path string) TaskResourceOp { - return func(r *v1alpha1.TaskResource) { - r.TargetPath = path - } -} - -// OutputsResource adds a resource, with specified name and type, to the Outputs. -func OutputsResource(name string, resourceType v1alpha1.PipelineResourceType, ops ...TaskResourceOp) OutputsOp { - return func(o *v1alpha1.Outputs) { - r := &v1alpha1.TaskResource{ - ResourceDeclaration: v1alpha1.ResourceDeclaration{ - Name: name, - Type: resourceType, - }} - for _, op := range ops { - op(r) - } - o.Resources = append(o.Resources, *r) - } -} - -// InputsParamSpec adds a ParamSpec, with specified name and type, to the Inputs. -// Any number of TaskParamSpec modifier can be passed to transform it. -func InputsParamSpec(name string, pt v1alpha1.ParamType, ops ...ParamSpecOp) InputsOp { - return func(i *v1alpha1.Inputs) { - ps := &v1alpha1.ParamSpec{Name: name, Type: pt} - for _, op := range ops { - op(ps) - } - i.Params = append(i.Params, *ps) - } -} - -// TaskRun creates a TaskRun with default values. -// Any number of TaskRun modifier can be passed to transform it. -func TaskRun(name string, ops ...TaskRunOp) *v1alpha1.TaskRun { - tr := &v1alpha1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Annotations: map[string]string{}, - }, - } - - for _, op := range ops { - op(tr) - } - - return tr -} - -// TaskRunNamespace sets the namespace for the TaskRun. -func TaskRunNamespace(namespace string) TaskRunOp { - return func(t *v1alpha1.TaskRun) { - t.ObjectMeta.Namespace = namespace - } -} - -// TaskRunStatus sets the TaskRunStatus to tshe TaskRun -func TaskRunStatus(ops ...TaskRunStatusOp) TaskRunOp { - return func(tr *v1alpha1.TaskRun) { - status := &tr.Status - for _, op := range ops { - op(status) - } - tr.Status = *status - } -} - -// PodName sets the Pod name to the TaskRunStatus. -func PodName(name string) TaskRunStatusOp { - return func(s *v1alpha1.TaskRunStatus) { - s.PodName = name - } -} - -// StatusCondition adds a StatusCondition to the TaskRunStatus. -func StatusCondition(condition apis.Condition) TaskRunStatusOp { - return func(s *v1alpha1.TaskRunStatus) { - s.Conditions = append(s.Conditions, condition) - } -} - -// TaskRunResult adds a result with the specified name and value to the TaskRunStatus. -func TaskRunResult(name, value string) TaskRunStatusOp { - return func(s *v1alpha1.TaskRunStatus) { - s.TaskRunResults = append(s.TaskRunResults, v1beta1.TaskRunResult{ - Name: name, - Value: value, - }) - } -} - -// Retry adds a RetriesStatus (TaskRunStatus) to the TaskRunStatus. -func Retry(retry v1alpha1.TaskRunStatus) TaskRunStatusOp { - return func(s *v1alpha1.TaskRunStatus) { - s.RetriesStatus = append(s.RetriesStatus, retry) - } -} - -// StepState adds a StepState to the TaskRunStatus. -func StepState(ops ...StepStateOp) TaskRunStatusOp { - return func(s *v1alpha1.TaskRunStatus) { - state := &v1alpha1.StepState{} - for _, op := range ops { - op(state) - } - s.Steps = append(s.Steps, *state) - } -} - -// SidecarState adds a SidecarState to the TaskRunStatus. -func SidecarState(ops ...SidecarStateOp) TaskRunStatusOp { - return func(s *v1alpha1.TaskRunStatus) { - state := &v1alpha1.SidecarState{} - for _, op := range ops { - op(state) - } - s.Sidecars = append(s.Sidecars, *state) - } -} - -// TaskRunStartTime sets the start time to the TaskRunStatus. -func TaskRunStartTime(startTime time.Time) TaskRunStatusOp { - return func(s *v1alpha1.TaskRunStatus) { - s.StartTime = &metav1.Time{Time: startTime} - } -} - -// TaskRunCompletionTime sets the start time to the TaskRunStatus. -func TaskRunCompletionTime(completionTime time.Time) TaskRunStatusOp { - return func(s *v1alpha1.TaskRunStatus) { - s.CompletionTime = &metav1.Time{Time: completionTime} - } -} - -// TaskRunCloudEvent adds an event to the TaskRunStatus. -func TaskRunCloudEvent(target, error string, retryCount int32, condition v1alpha1.CloudEventCondition) TaskRunStatusOp { - return func(s *v1alpha1.TaskRunStatus) { - if len(s.CloudEvents) == 0 { - s.CloudEvents = make([]v1alpha1.CloudEventDelivery, 0) - } - cloudEvent := v1alpha1.CloudEventDelivery{ - Target: target, - Status: v1alpha1.CloudEventDeliveryState{ - Condition: condition, - RetryCount: retryCount, - Error: error, - }, - } - s.CloudEvents = append(s.CloudEvents, cloudEvent) - } -} - -// TaskRunTimeout sets the timeout duration to the TaskRunSpec. -func TaskRunTimeout(d time.Duration) TaskRunSpecOp { - return func(spec *v1alpha1.TaskRunSpec) { - spec.Timeout = &metav1.Duration{Duration: d} - } -} - -// TaskRunNilTimeout sets the timeout duration to nil on the TaskRunSpec. -func TaskRunNilTimeout(spec *v1alpha1.TaskRunSpec) { - spec.Timeout = nil -} - -// TaskRunNodeSelector sets the NodeSelector to the TaskRunSpec. -func TaskRunNodeSelector(values map[string]string) TaskRunSpecOp { - return func(spec *v1alpha1.TaskRunSpec) { - if spec.PodTemplate == nil { - spec.PodTemplate = &v1alpha1.PodTemplate{} - } - spec.PodTemplate.NodeSelector = values - } -} - -// StateTerminated sets Terminated to the StepState. -func StateTerminated(exitcode int) StepStateOp { - return func(s *v1alpha1.StepState) { - s.ContainerState = corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{ExitCode: int32(exitcode)}, - } - } -} - -// SetStepStateTerminated sets Terminated state of a step. -func SetStepStateTerminated(terminated corev1.ContainerStateTerminated) StepStateOp { - return func(s *v1alpha1.StepState) { - s.ContainerState = corev1.ContainerState{ - Terminated: &terminated, - } - } -} - -// SetStepStateRunning sets Running state of a step. -func SetStepStateRunning(running corev1.ContainerStateRunning) StepStateOp { - return func(s *v1alpha1.StepState) { - s.ContainerState = corev1.ContainerState{ - Running: &running, - } - } -} - -// SetStepStateWaiting sets Waiting state of a step. -func SetStepStateWaiting(waiting corev1.ContainerStateWaiting) StepStateOp { - return func(s *v1alpha1.StepState) { - s.ContainerState = corev1.ContainerState{ - Waiting: &waiting, - } - } -} - -// TaskRunOwnerReference sets the OwnerReference, with specified kind and name, to the TaskRun. -func TaskRunOwnerReference(kind, name string, ops ...OwnerReferenceOp) TaskRunOp { - return func(tr *v1alpha1.TaskRun) { - o := &metav1.OwnerReference{ - Kind: kind, - Name: name, - } - for _, op := range ops { - op(o) - } - tr.ObjectMeta.OwnerReferences = append(tr.ObjectMeta.OwnerReferences, *o) - } -} - -// TaskRunLabels add the specified labels to the TaskRun. -func TaskRunLabels(labels map[string]string) TaskRunOp { - return func(tr *v1alpha1.TaskRun) { - if tr.ObjectMeta.Labels == nil { - tr.ObjectMeta.Labels = map[string]string{} - } - for key, value := range labels { - tr.ObjectMeta.Labels[key] = value - } - } -} - -// TaskRunLabel adds a label with the specified key and value to the TaskRun. -func TaskRunLabel(key, value string) TaskRunOp { - return func(tr *v1alpha1.TaskRun) { - if tr.ObjectMeta.Labels == nil { - tr.ObjectMeta.Labels = map[string]string{} - } - tr.ObjectMeta.Labels[key] = value - } -} - -// TaskRunAnnotations adds the specified annotations to the TaskRun. -func TaskRunAnnotations(annotations map[string]string) TaskRunOp { - return func(tr *v1alpha1.TaskRun) { - if tr.ObjectMeta.Annotations == nil { - tr.ObjectMeta.Annotations = map[string]string{} - } - for key, value := range annotations { - tr.ObjectMeta.Annotations[key] = value - } - } -} - -// TaskRunAnnotation adds an annotation with the specified key and value to the TaskRun. -func TaskRunAnnotation(key, value string) TaskRunOp { - return func(tr *v1alpha1.TaskRun) { - if tr.ObjectMeta.Annotations == nil { - tr.ObjectMeta.Annotations = map[string]string{} - } - tr.ObjectMeta.Annotations[key] = value - } -} - -// TaskRunSelfLink adds a SelfLink -func TaskRunSelfLink(selflink string) TaskRunOp { - return func(tr *v1alpha1.TaskRun) { - tr.ObjectMeta.SelfLink = selflink - } -} - -// TaskRunSpec sets the specified spec of the TaskRun. -// Any number of TaskRunSpec modifier can be passed to transform it. -func TaskRunSpec(ops ...TaskRunSpecOp) TaskRunOp { - return func(tr *v1alpha1.TaskRun) { - spec := &tr.Spec - spec.Resources = &v1beta1.TaskRunResources{} - // Set a default timeout - spec.Timeout = &metav1.Duration{Duration: config.DefaultTimeoutMinutes * time.Minute} - for _, op := range ops { - op(spec) - } - tr.Spec = *spec - } -} - -// TaskRunCancelled sets the status to cancel to the TaskRunSpec. -func TaskRunCancelled(spec *v1alpha1.TaskRunSpec) { - spec.Status = v1alpha1.TaskRunSpecStatusCancelled -} - -// TaskRunTaskRef sets the specified Task reference to the TaskRunSpec. -// Any number of TaskRef modifier can be passed to transform it. -func TaskRunTaskRef(name string, ops ...TaskRefOp) TaskRunSpecOp { - return func(spec *v1alpha1.TaskRunSpec) { - ref := &v1alpha1.TaskRef{Name: name} - for _, op := range ops { - op(ref) - } - spec.TaskRef = ref - } -} - -// TaskRunSpecStatus sets the Status in the Spec, used for operations -// such as cancelling executing TaskRuns. -func TaskRunSpecStatus(status v1alpha1.TaskRunSpecStatus) TaskRunSpecOp { - return func(spec *v1alpha1.TaskRunSpec) { - spec.Status = status - } -} - -// TaskRefKind set the specified kind to the TaskRef. -func TaskRefKind(kind v1alpha1.TaskKind) TaskRefOp { - return func(ref *v1alpha1.TaskRef) { - ref.Kind = kind - } -} - -// TaskRefAPIVersion sets the specified api version to the TaskRef. -func TaskRefAPIVersion(version string) TaskRefOp { - return func(ref *v1alpha1.TaskRef) { - ref.APIVersion = version - } -} - -// TaskRunTaskSpec sets the specified TaskRunSpec reference to the TaskRunSpec. -// Any number of TaskRunSpec modifier can be passed to transform it. -func TaskRunTaskSpec(ops ...TaskSpecOp) TaskRunSpecOp { - return func(spec *v1alpha1.TaskRunSpec) { - taskSpec := &v1alpha1.TaskSpec{} - for _, op := range ops { - op(taskSpec) - } - spec.TaskSpec = taskSpec - } -} - -// TaskRunServiceAccountName sets the serviceAccount to the TaskRunSpec. -func TaskRunServiceAccountName(sa string) TaskRunSpecOp { - return func(trs *v1alpha1.TaskRunSpec) { - trs.ServiceAccountName = sa - } -} - -// TaskRunParam sets the Params to the TaskSpec -func TaskRunParam(name, value string, additionalValues ...string) TaskRunSpecOp { - return func(spec *v1alpha1.TaskRunSpec) { - spec.Params = append(spec.Params, v1alpha1.Param{ - Name: name, - Value: *v1beta1.NewArrayOrString(value, additionalValues...), - }) - } -} - -// TaskRunResources sets the TaskRunResources to the TaskRunSpec -func TaskRunResources(ops ...TaskRunResourcesOp) TaskRunSpecOp { - return func(spec *v1alpha1.TaskRunSpec) { - r := &v1beta1.TaskRunResources{} - for _, op := range ops { - op(r) - } - spec.Resources = r - } -} - -// TaskRunResourcesInput adds a TaskRunResource as Inputs to the TaskRunResources -func TaskRunResourcesInput(name string, ops ...TaskResourceBindingOp) TaskRunResourcesOp { - return func(r *v1beta1.TaskRunResources) { - binding := &v1alpha1.TaskResourceBinding{ - PipelineResourceBinding: v1alpha1.PipelineResourceBinding{ - Name: name, - }, - } - for _, op := range ops { - op(binding) - } - r.Inputs = append(r.Inputs, *binding) - } -} - -// TaskRunResourcesOutput adds a TaskRunResource as Outputs to the TaskRunResources -func TaskRunResourcesOutput(name string, ops ...TaskResourceBindingOp) TaskRunResourcesOp { - return func(r *v1beta1.TaskRunResources) { - binding := &v1alpha1.TaskResourceBinding{ - PipelineResourceBinding: v1alpha1.PipelineResourceBinding{ - Name: name, - }, - } - for _, op := range ops { - op(binding) - } - r.Outputs = append(r.Outputs, *binding) - } -} - -// TaskRunInputs sets inputs to the TaskRunSpec. -// Any number of TaskRunInputs modifier can be passed to transform it. -func TaskRunInputs(ops ...TaskRunInputsOp) TaskRunSpecOp { - return func(spec *v1alpha1.TaskRunSpec) { - if spec.Inputs == nil { - spec.Inputs = &v1alpha1.TaskRunInputs{} - } - for _, op := range ops { - op(spec.Inputs) - } - } -} - -// TaskRunInputsResource adds a resource, with specified name, to the TaskRunInputs. -// Any number of TaskResourceBinding modifier can be passed to transform it. -func TaskRunInputsResource(name string, ops ...TaskResourceBindingOp) TaskRunInputsOp { - return func(i *v1alpha1.TaskRunInputs) { - binding := &v1alpha1.TaskResourceBinding{ - PipelineResourceBinding: v1alpha1.PipelineResourceBinding{ - Name: name, - }, - } - for _, op := range ops { - op(binding) - } - i.Resources = append(i.Resources, *binding) - } -} - -// TaskResourceBindingRef set the PipelineResourceRef name to the TaskResourceBinding. -func TaskResourceBindingRef(name string) TaskResourceBindingOp { - return func(b *v1alpha1.TaskResourceBinding) { - b.ResourceRef = &v1alpha1.PipelineResourceRef{ - Name: name, - } - } -} - -// TaskResourceBindingResourceSpec set the PipelineResourceResourceSpec to the TaskResourceBinding. -func TaskResourceBindingResourceSpec(spec *v1alpha1.PipelineResourceSpec) TaskResourceBindingOp { - return func(b *v1alpha1.TaskResourceBinding) { - b.ResourceSpec = spec - } -} - -// TaskResourceBindingRefAPIVersion set the PipelineResourceRef APIVersion to the TaskResourceBinding. -func TaskResourceBindingRefAPIVersion(version string) TaskResourceBindingOp { - return func(b *v1alpha1.TaskResourceBinding) { - b.ResourceRef.APIVersion = version - } -} - -// TaskResourceBindingPaths add any number of path to the TaskResourceBinding. -func TaskResourceBindingPaths(paths ...string) TaskResourceBindingOp { - return func(b *v1alpha1.TaskResourceBinding) { - b.Paths = paths - } -} - -// TaskRunOutputs sets inputs to the TaskRunSpec. -// Any number of TaskRunOutputs modifier can be passed to transform it. -func TaskRunOutputs(ops ...TaskRunOutputsOp) TaskRunSpecOp { - return func(spec *v1alpha1.TaskRunSpec) { - if spec.Outputs == nil { - spec.Outputs = &v1alpha1.TaskRunOutputs{} - } - for _, op := range ops { - op(spec.Outputs) - } - } -} - -// TaskRunOutputsResource adds a TaskResourceBinding, with specified name, to the TaskRunOutputs. -// Any number of TaskResourceBinding modifier can be passed to modifiy it. -func TaskRunOutputsResource(name string, ops ...TaskResourceBindingOp) TaskRunOutputsOp { - return func(i *v1alpha1.TaskRunOutputs) { - binding := &v1alpha1.TaskResourceBinding{ - PipelineResourceBinding: v1alpha1.PipelineResourceBinding{ - Name: name, - }, - } - for _, op := range ops { - op(binding) - } - i.Resources = append(i.Resources, *binding) - } -} - -// TaskRunWorkspaceEmptyDir adds a workspace binding to an empty dir volume source. -func TaskRunWorkspaceEmptyDir(name, subPath string) TaskRunSpecOp { - return func(spec *v1alpha1.TaskRunSpec) { - spec.Workspaces = append(spec.Workspaces, v1alpha1.WorkspaceBinding{ - Name: name, - SubPath: subPath, - EmptyDir: &corev1.EmptyDirVolumeSource{}, - }) - } -} - -// TaskRunWorkspacePVC adds a workspace binding to a PVC volume source. -func TaskRunWorkspacePVC(name, subPath, claimName string) TaskRunSpecOp { - return func(spec *v1alpha1.TaskRunSpec) { - spec.Workspaces = append(spec.Workspaces, v1alpha1.WorkspaceBinding{ - Name: name, - SubPath: subPath, - PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ - ClaimName: claimName, - }, - }) - } -} - -// TaskRunWorkspaceVolumeClaimTemplate adds a workspace binding with a VolumeClaimTemplate volume source. -func TaskRunWorkspaceVolumeClaimTemplate(name, subPath string, volumeClaimTemplate *corev1.PersistentVolumeClaim) TaskRunSpecOp { - return func(spec *v1alpha1.TaskRunSpec) { - spec.Workspaces = append(spec.Workspaces, v1alpha1.WorkspaceBinding{ - Name: name, - SubPath: subPath, - VolumeClaimTemplate: volumeClaimTemplate, - }) - } -} diff --git a/pkg/apis/pipeline/v1alpha1/pipelinerun_types_test.go b/pkg/apis/pipeline/v1alpha1/pipelinerun_types_test.go index 61603e95707..3c089f0fc05 100644 --- a/pkg/apis/pipeline/v1alpha1/pipelinerun_types_test.go +++ b/pkg/apis/pipeline/v1alpha1/pipelinerun_types_test.go @@ -22,7 +22,6 @@ import ( "time" "github.com/google/go-cmp/cmp" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" @@ -131,7 +130,11 @@ func TestPipelineRunHasVolumeClaimTemplate(t *testing.T) { } func TestPipelineRunKey(t *testing.T) { - pr := tb.PipelineRun("prunname") + pr := &v1alpha1.PipelineRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "prunname", + }, + } expectedKey := fmt.Sprintf("PipelineRun/%p", pr) if pr.GetRunKey() != expectedKey { t.Fatalf("Expected taskrun key to be %s but got %s", expectedKey, pr.GetRunKey()) @@ -206,14 +209,22 @@ func TestPipelineRunHasTimedOut(t *testing.T) { for _, tc := range tcs { t.Run(t.Name(), func(t *testing.T) { - pr := tb.PipelineRun("pr", - tb.PipelineRunSpec("test-pipeline", - tb.PipelineRunTimeout(tc.timeout), - ), - tb.PipelineRunStatus( - tb.PipelineRunStartTime(tc.starttime), - ), - ) + pr := &v1alpha1.PipelineRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "pr", + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: "test-pipeline", + }, + Timeout: &metav1.Duration{Duration: tc.timeout}, + }, + Status: v1alpha1.PipelineRunStatus{ + PipelineRunStatusFields: v1alpha1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: tc.starttime}, + }, + }, + } if pr.IsTimedOut() != tc.expected { t.Fatalf("Expected isTimedOut to be %t", tc.expected) @@ -230,10 +241,21 @@ func TestPipelineRunGetServiceAccountName(t *testing.T) { }{ { name: "default SA", - pr: tb.PipelineRun("pr", - tb.PipelineRunSpec("prs", - tb.PipelineRunServiceAccountName("defaultSA"), - tb.PipelineRunServiceAccountNameTask("taskName", "taskSA"))), + pr: &v1alpha1.PipelineRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "pr", + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: "prs", + }, + ServiceAccountName: "defaultSA", + ServiceAccountNames: []v1alpha1.PipelineRunSpecServiceAccountName{{ + TaskName: "taskName", + ServiceAccountName: "taskSA", + }}, + }, + }, saNames: map[string]string{ "unknown": "defaultSA", "taskName": "taskSA", @@ -241,12 +263,27 @@ func TestPipelineRunGetServiceAccountName(t *testing.T) { }, { name: "mixed default SA", - pr: tb.PipelineRun("defaultSA", - tb.PipelineRunSpec("defaultSA", - tb.PipelineRunServiceAccountName("defaultSA"), - tb.PipelineRunServiceAccountNameTask("task1", "task1SA"), - tb.PipelineRunServiceAccountNameTask("task2", "task2SA"), - )), + pr: &v1alpha1.PipelineRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "defaultSA", + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: "defaultSA", + }, + ServiceAccountName: "defaultSA", + ServiceAccountNames: []v1alpha1.PipelineRunSpecServiceAccountName{ + { + TaskName: "task1", + ServiceAccountName: "task1SA", + }, + { + TaskName: "task2", + ServiceAccountName: "task2SA", + }, + }, + }, + }, saNames: map[string]string{ "unknown": "defaultSA", "task1": "task1SA", diff --git a/pkg/apis/pipeline/v1alpha1/taskrun_types_test.go b/pkg/apis/pipeline/v1alpha1/taskrun_types_test.go index bc3a80e192e..7faf414875f 100644 --- a/pkg/apis/pipeline/v1alpha1/taskrun_types_test.go +++ b/pkg/apis/pipeline/v1alpha1/taskrun_types_test.go @@ -21,8 +21,9 @@ import ( "testing" "time" + duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" + "github.com/google/go-cmp/cmp" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/test/diff" @@ -37,12 +38,28 @@ func TestTaskRun_GetPipelineRunPVCName(t *testing.T) { tr *v1alpha1.TaskRun expectedPVCName string }{{ - name: "invalid owner reference", - tr: tb.TaskRun("taskrunname", tb.TaskRunOwnerReference("SomeOtherOwner", "testpr")), + name: "invalid owner reference", + tr: &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "taskrunname", + OwnerReferences: []metav1.OwnerReference{{ + Kind: "SomeOtherOwner", + Name: "testpr", + }}, + }, + }, expectedPVCName: "", }, { - name: "valid pipelinerun owner", - tr: tb.TaskRun("taskrunname", tb.TaskRunOwnerReference("PipelineRun", "testpr")), + name: "valid pipelinerun owner", + tr: &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "taskrunname", + OwnerReferences: []metav1.OwnerReference{{ + Kind: "PipelineRun", + Name: "testpr", + }}, + }, + }, expectedPVCName: "testpr-pvc", }, { name: "nil taskrun", @@ -64,11 +81,27 @@ func TestTaskRun_HasPipelineRun(t *testing.T) { want bool }{{ name: "invalid owner reference", - tr: tb.TaskRun("taskrunname", tb.TaskRunOwnerReference("SomeOtherOwner", "testpr")), + tr: &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "taskrunname", + OwnerReferences: []metav1.OwnerReference{{ + Kind: "SomeOtherOwner", + Name: "testpr", + }}, + }, + }, want: false, }, { name: "valid pipelinerun owner", - tr: tb.TaskRun("taskrunname", tb.TaskRunOwnerReference("PipelineRun", "testpr")), + tr: &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "taskrunname", + OwnerReferences: []metav1.OwnerReference{{ + Kind: "PipelineRun", + Name: "testpr", + }}, + }, + }, want: true, }} for _, tt := range tests { @@ -81,21 +114,29 @@ func TestTaskRun_HasPipelineRun(t *testing.T) { } func TestTaskRunIsDone(t *testing.T) { - tr := tb.TaskRun("", tb.TaskRunStatus(tb.StatusCondition( - apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionFalse, + tr := &v1alpha1.TaskRun{ + Status: v1alpha1.TaskRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + apis.Condition{ + Type: apis.ConditionSucceeded, + Status: corev1.ConditionFalse, + }, + }, + }, }, - ))) + } if !tr.IsDone() { t.Fatal("Expected pipelinerun status to be done") } } func TestTaskRunIsCancelled(t *testing.T) { - tr := tb.TaskRun("", tb.TaskRunSpec( - tb.TaskRunSpecStatus(v1alpha1.TaskRunSpecStatusCancelled)), - ) + tr := &v1alpha1.TaskRun{ + Spec: v1alpha1.TaskRunSpec{ + Status: v1alpha1.TaskRunSpecStatusCancelled, + }, + } if !tr.IsCancelled() { t.Fatal("Expected pipelinerun status to be cancelled") } @@ -121,7 +162,11 @@ func TestTaskRunHasVolumeClaimTemplate(t *testing.T) { } func TestTaskRunKey(t *testing.T) { - tr := tb.TaskRun("taskrunname") + tr := &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "taskrunname", + }, + } expectedKey := fmt.Sprintf("TaskRun/%p", tr) if tr.GetRunKey() != expectedKey { t.Fatalf("Expected taskrun key to be %s but got %s", expectedKey, tr.GetRunKey()) @@ -156,7 +201,11 @@ func TestTaskRunHasStarted(t *testing.T) { }} for _, tc := range params { t.Run(tc.name, func(t *testing.T) { - tr := tb.TaskRun("taskrunname") + tr := &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "taskrunname", + }, + } tr.Status = tc.trStatus if tr.HasStarted() != tc.expectedValue { t.Fatalf("Expected taskrun HasStarted() to return %t but got %t", tc.expectedValue, tr.HasStarted()) @@ -174,16 +223,25 @@ func TestTaskRunIsOfPipelinerun(t *testing.T) { expetectedPipelineRun string }{{ name: "yes", - tr: tb.TaskRun("taskrunname", - tb.TaskRunLabel(pipeline.PipelineLabelKey, "pipeline"), - tb.TaskRunLabel(pipeline.PipelineRunLabelKey, "pipelinerun"), - ), + tr: &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "taskrunname", + Labels: map[string]string{ + pipeline.PipelineLabelKey: "pipeline", + pipeline.PipelineRunLabelKey: "pipelinerun", + }, + }, + }, expectedValue: true, expetectedPipeline: "pipeline", expetectedPipelineRun: "pipelinerun", }, { - name: "no", - tr: tb.TaskRun("taskrunname"), + name: "no", + tr: &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "taskrunname", + }, + }, expectedValue: false, }} @@ -214,21 +272,74 @@ func TestHasTimedOut(t *testing.T) { expectedStatus bool }{{ name: "TaskRun not started", - taskRun: tb.TaskRun("test-taskrun-not-started", tb.TaskRunSpec( - tb.TaskRunTaskRef("task-name"), - ), tb.TaskRunStatus(tb.StatusCondition(apis.Condition{}), tb.TaskRunStartTime(zeroTime))), + taskRun: &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-taskrun-not-started", + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: "task-name", + }, + }, + Status: v1alpha1.TaskRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + apis.Condition{}, + }, + }, + TaskRunStatusFields: v1alpha1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: zeroTime}, + }, + }, + }, expectedStatus: false, }, { name: "TaskRun no timeout", - taskRun: tb.TaskRun("test-taskrun-no-timeout", tb.TaskRunSpec( - tb.TaskRunTaskRef("task-name"), tb.TaskRunTimeout(0), - ), tb.TaskRunStatus(tb.StatusCondition(apis.Condition{}), tb.TaskRunStartTime(time.Now().Add(-15*time.Hour)))), + taskRun: &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-taskrun-no-timeout", + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: "task-name", + }, + Timeout: &metav1.Duration{Duration: 0}, + }, + Status: v1alpha1.TaskRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + apis.Condition{}, + }, + }, + TaskRunStatusFields: v1alpha1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: time.Now().Add(-15 * time.Hour)}, + }, + }, + }, expectedStatus: false, }, { name: "TaskRun timed out", - taskRun: tb.TaskRun("test-taskrun-timeout", tb.TaskRunSpec( - tb.TaskRunTaskRef("task-name"), tb.TaskRunTimeout(10*time.Second), - ), tb.TaskRunStatus(tb.StatusCondition(apis.Condition{}), tb.TaskRunStartTime(time.Now().Add(-15*time.Second)))), + taskRun: &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-taskrun-timeout", + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: "task-name", + }, + Timeout: &metav1.Duration{Duration: 10 * time.Second}, + }, + Status: v1alpha1.TaskRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + apis.Condition{}, + }, + }, + TaskRunStatusFields: v1alpha1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: time.Now().Add(-15 * time.Second)}, + }, + }, + }, expectedStatus: true, }} diff --git a/pkg/apis/pipeline/v1alpha1/taskrun_validation_test.go b/pkg/apis/pipeline/v1alpha1/taskrun_validation_test.go index 947111ec9d5..b5f20e71c3d 100644 --- a/pkg/apis/pipeline/v1alpha1/taskrun_validation_test.go +++ b/pkg/apis/pipeline/v1alpha1/taskrun_validation_test.go @@ -22,7 +22,6 @@ import ( "time" "github.com/google/go-cmp/cmp" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/test/diff" @@ -38,11 +37,19 @@ func TestTaskRun_Invalid(t *testing.T) { want *apis.FieldError }{{ name: "invalid taskspec", - task: tb.TaskRun("taskmetaname"), + task: &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "taskmetaname", + }, + }, want: apis.ErrMissingField("spec"), }, { name: "invalid taskrun metadata", - task: tb.TaskRun("task,name"), + task: &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "task,name", + }, + }, want: &apis.FieldError{ Message: `invalid resource name "task,name": must be a valid DNS label`, Paths: []string{"metadata.name"}, @@ -59,9 +66,16 @@ func TestTaskRun_Invalid(t *testing.T) { } func TestTaskRun_Validate(t *testing.T) { - tr := tb.TaskRun("taskname", tb.TaskRunSpec( - tb.TaskRunTaskRef("taskrefname"), - )) + tr := &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "taskname", + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: "taskrefname", + }, + }, + } if err := tr.Validate(context.Background()); err != nil { t.Errorf("TaskRun.Validate() error = %v", err) } @@ -74,19 +88,45 @@ func TestTaskRun_Workspaces_Invalid(t *testing.T) { wantErr *apis.FieldError }{{ name: "make sure WorkspaceBinding validation invoked", - tr: tb.TaskRun("taskname", tb.TaskRunSpec( - tb.TaskRunTaskRef("task"), - // When using PVC it's required that you provide a volume name - tb.TaskRunWorkspacePVC("workspace", "", ""), - )), + tr: &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "taskname", + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: "task", + }, + Workspaces: []v1alpha1.WorkspaceBinding{{ + Name: "workspace", + PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ + ClaimName: "", + }, + }}, + }, + }, wantErr: apis.ErrMissingField("workspace.persistentvolumeclaim.claimname"), }, { name: "bind same workspace twice", - tr: tb.TaskRun("taskname", tb.TaskRunSpec( - tb.TaskRunTaskRef("task"), - tb.TaskRunWorkspaceEmptyDir("workspace", ""), - tb.TaskRunWorkspaceEmptyDir("workspace", ""), - )), + tr: &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "taskname", + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: "task", + }, + Workspaces: []v1alpha1.WorkspaceBinding{ + { + Name: "workspace", + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + { + Name: "workspace", + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + }, + }, wantErr: apis.ErrMultipleOneOf("spec.workspaces.name"), }} for _, ts := range tests { diff --git a/pkg/reconciler/pipelinerun/pipelinerun_test.go b/pkg/reconciler/pipelinerun/pipelinerun_test.go index 7a7c85b2a5f..fa9f935de5e 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun_test.go +++ b/pkg/reconciler/pipelinerun/pipelinerun_test.go @@ -30,7 +30,6 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/go-containerregistry/pkg/registry" - tbv1alpha1 "github.com/tektoncd/pipeline/internal/builder/v1alpha1" tb "github.com/tektoncd/pipeline/internal/builder/v1beta1" "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline" @@ -1243,8 +1242,18 @@ func TestUpdateTaskRunStateWithConditionChecks(t *testing.T) { successConditionCheckName := "success-condition" failingConditionCheckName := "fail-condition" - successCondition := tbv1alpha1.Condition("cond-1", tbv1alpha1.ConditionNamespace("foo")) - failingCondition := tbv1alpha1.Condition("cond-2", tbv1alpha1.ConditionNamespace("foo")) + successCondition := &v1alpha1.Condition{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cond-1", + Namespace: "foo", + }, + } + failingCondition := &v1alpha1.Condition{ + ObjectMeta: metav1.ObjectMeta{ + Name: "cond-2", + Namespace: "foo", + }, + } pipelineTask := v1beta1.PipelineTask{ TaskRef: &v1beta1.TaskRef{Name: "unit-test-task"}, @@ -3411,30 +3420,45 @@ func TestReconcileWithConditionChecks(t *testing.T) { names.TestingSeed() prName := "test-pipeline-run" conditions := []*v1alpha1.Condition{ - tbv1alpha1.Condition("cond-1", - tbv1alpha1.ConditionNamespace("foo"), - tbv1alpha1.ConditionLabels( - map[string]string{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "cond-1", + Namespace: "foo", + Labels: map[string]string{ "label-1": "value-1", "label-2": "value-2", - }), - tbv1alpha1.ConditionAnnotations( - map[string]string{ + }, + Annotations: map[string]string{ "annotation-1": "value-1", - }), - tbv1alpha1.ConditionSpec( - tbv1alpha1.ConditionSpecCheck("", "foo", tb.Args("bar")), - )), - tbv1alpha1.Condition("cond-2", - tbv1alpha1.ConditionNamespace("foo"), - tbv1alpha1.ConditionLabels( - map[string]string{ + }, + }, + Spec: v1alpha1.ConditionSpec{ + Check: v1alpha1.Step{ + Container: corev1.Container{ + Image: "foo", + Args: []string{"bar"}, + }, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "cond-2", + Namespace: "foo", + Labels: map[string]string{ "label-3": "value-3", "label-4": "value-4", - }), - tbv1alpha1.ConditionSpec( - tbv1alpha1.ConditionSpecCheck("", "foo", tb.Args("bar")), - )), + }, + }, + Spec: v1alpha1.ConditionSpec{ + Check: v1alpha1.Step{ + Container: corev1.Container{ + Image: "foo", + Args: []string{"bar"}, + }, + }, + }, + }, } ps := []*v1beta1.Pipeline{tb.Pipeline("test-pipeline", tb.PipelineNamespace("foo"), tb.PipelineSpec( tb.PipelineTask("hello-world-1", "hello-world", @@ -3491,11 +3515,20 @@ func TestReconcileWithFailingConditionChecks(t *testing.T) { // multiple conditions, some that fails. It verifies that reconcile is successful, taskruns are // created and the status is updated. It checks that the correct events are sent. names.TestingSeed() - conditions := []*v1alpha1.Condition{ - tbv1alpha1.Condition("always-false", tbv1alpha1.ConditionNamespace("foo"), tbv1alpha1.ConditionSpec( - tbv1alpha1.ConditionSpecCheck("", "foo", tb.Args("bar")), - )), - } + conditions := []*v1alpha1.Condition{{ + ObjectMeta: metav1.ObjectMeta{ + Name: "always-false", + Namespace: "foo", + }, + Spec: v1alpha1.ConditionSpec{ + Check: v1alpha1.Step{ + Container: corev1.Container{ + Image: "foo", + Args: []string{"bar"}, + }, + }, + }, + }} pipelineRunName := "test-pipeline-run-with-conditions" prccs := make(map[string]*v1beta1.PipelineRunConditionCheckStatus) @@ -4943,11 +4976,20 @@ func TestReconcileOutOfSyncPipelineRun(t *testing.T) { trs := []*v1beta1.TaskRun{taskRunDone, taskRunOrphaned, taskRunWithCondition, taskRunForOrphanedCondition, taskRunForConditionOfOrphanedTaskRun} runs := []*v1alpha1.Run{orphanedRun} - cs := []*v1alpha1.Condition{ - tbv1alpha1.Condition("always-true", tbv1alpha1.ConditionNamespace("foo"), tbv1alpha1.ConditionSpec( - tbv1alpha1.ConditionSpecCheck("", "foo", tbv1alpha1.Args("bar")), - )), - } + cs := []*v1alpha1.Condition{{ + ObjectMeta: metav1.ObjectMeta{ + Name: "always-true", + Namespace: "foo", + }, + Spec: v1alpha1.ConditionSpec{ + Check: v1alpha1.Step{ + Container: corev1.Container{ + Image: "foo", + Args: []string{"bar"}, + }, + }, + }, + }} cms := []*corev1.ConfigMap{ { diff --git a/pkg/reconciler/pipelinerun/resources/conditionresolution_test.go b/pkg/reconciler/pipelinerun/resources/conditionresolution_test.go index c92d3182300..a94a9151dbc 100644 --- a/pkg/reconciler/pipelinerun/resources/conditionresolution_test.go +++ b/pkg/reconciler/pipelinerun/resources/conditionresolution_test.go @@ -21,8 +21,6 @@ import ( "testing" "github.com/google/go-cmp/cmp" - tbv1alpha1 "github.com/tektoncd/pipeline/internal/builder/v1alpha1" - tb "github.com/tektoncd/pipeline/internal/builder/v1beta1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" @@ -33,7 +31,11 @@ import ( duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" ) -var c = tbv1alpha1.Condition("conditionname") +var c = &v1alpha1.Condition{ + ObjectMeta: metav1.ObjectMeta{ + Name: "conditionname", + }, +} var notStartedState = TaskConditionCheckState{{ ConditionCheckName: "foo", @@ -195,9 +197,19 @@ func TestResolvedConditionCheck_ConditionToTaskSpec(t *testing.T) { want v1beta1.TaskSpec }{{ name: "user-provided-container-name", - cond: tbv1alpha1.Condition("name", tbv1alpha1.ConditionSpec( - tbv1alpha1.ConditionSpecCheck("foo", "ubuntu"), - )), + cond: &v1alpha1.Condition{ + ObjectMeta: metav1.ObjectMeta{ + Name: "name", + }, + Spec: v1alpha1.ConditionSpec{ + Check: v1alpha1.Step{ + Container: corev1.Container{ + Name: "foo", + Image: "ubuntu", + }, + }, + }, + }, want: v1beta1.TaskSpec{ Steps: []v1beta1.Step{{Container: corev1.Container{ Name: "foo", @@ -206,9 +218,19 @@ func TestResolvedConditionCheck_ConditionToTaskSpec(t *testing.T) { }, }, { name: "default-container-name", - cond: tbv1alpha1.Condition("bar", tbv1alpha1.ConditionSpec( - tbv1alpha1.ConditionSpecCheck("", "ubuntu"), - )), + cond: &v1alpha1.Condition{ + ObjectMeta: metav1.ObjectMeta{ + Name: "bar", + }, + Spec: v1alpha1.ConditionSpec{ + Check: v1alpha1.Step{ + Container: corev1.Container{ + Name: "", + Image: "ubuntu", + }, + }, + }, + }, want: v1beta1.TaskSpec{ Steps: []v1beta1.Step{{Container: corev1.Container{ Name: "condition-check-bar", @@ -216,10 +238,20 @@ func TestResolvedConditionCheck_ConditionToTaskSpec(t *testing.T) { }}}, }, }, { - name: "default-container-name", - cond: tbv1alpha1.Condition("very-very-very-very-very-very-very-very-very-very-very-long-name", tbv1alpha1.ConditionSpec( - tbv1alpha1.ConditionSpecCheck("", "ubuntu"), - )), + name: "very-long-condition-name", + cond: &v1alpha1.Condition{ + ObjectMeta: metav1.ObjectMeta{ + Name: "very-very-very-very-very-very-very-very-very-very-very-long-name", + }, + Spec: v1alpha1.ConditionSpec{ + Check: v1alpha1.Step{ + Container: corev1.Container{ + Name: "", + Image: "ubuntu", + }, + }, + }, + }, want: v1beta1.TaskSpec{ Steps: []v1beta1.Step{{Container: corev1.Container{ // Shortened via: names.SimpleNameGenerator.RestrictLength @@ -229,12 +261,30 @@ func TestResolvedConditionCheck_ConditionToTaskSpec(t *testing.T) { }, }, { name: "with-input-params", - cond: tbv1alpha1.Condition("bar", tbv1alpha1.ConditionSpec( - tbv1alpha1.ConditionSpecCheck("$(params.name)", "$(params.img)", - tb.WorkingDir("$(params.not.replaced)")), - tbv1alpha1.ConditionParamSpec("name", v1beta1.ParamTypeString), - tbv1alpha1.ConditionParamSpec("img", v1beta1.ParamTypeString), - )), + cond: &v1alpha1.Condition{ + ObjectMeta: metav1.ObjectMeta{ + Name: "bar", + }, + Spec: v1alpha1.ConditionSpec{ + Check: v1alpha1.Step{ + Container: corev1.Container{ + Name: "$(params.name)", + Image: "$(params.img)", + WorkingDir: "$(params.not.replaced)", + }, + }, + Params: []v1alpha1.ParamSpec{ + { + Name: "name", + Type: v1beta1.ParamTypeString, + }, + { + Name: "img", + Type: v1beta1.ParamTypeString, + }, + }, + }, + }, want: v1beta1.TaskSpec{ Steps: []v1beta1.Step{{Container: corev1.Container{ Name: "$(inputs.params.name)", @@ -251,16 +301,37 @@ func TestResolvedConditionCheck_ConditionToTaskSpec(t *testing.T) { }, }, { name: "with-resources", - cond: tbv1alpha1.Condition("bar", tbv1alpha1.ConditionSpec( - tbv1alpha1.ConditionSpecCheck("name", "ubuntu", - tb.Args("$(resources.git-resource.revision)")), - tbv1alpha1.ConditionResource("git-resource", resourcev1alpha1.PipelineResourceTypeGit), - )), + cond: &v1alpha1.Condition{ + ObjectMeta: metav1.ObjectMeta{ + Name: "bar", + }, + Spec: v1alpha1.ConditionSpec{ + Check: v1alpha1.Step{ + Container: corev1.Container{ + Name: "name", + Image: "ubuntu", + Args: []string{"$(resources.git-resource.revision)"}, + }, + }, + Resources: []v1alpha1.ResourceDeclaration{{ + Name: "git-resource", + Type: resourcev1alpha1.PipelineResourceTypeGit, + }}, + }, + }, resolvedResources: map[string]*resourcev1alpha1.PipelineResource{ - "git-resource": tb.PipelineResource("git-resource", - tb.PipelineResourceSpec(resourcev1alpha1.PipelineResourceTypeGit, - tb.PipelineResourceSpecParam("revision", "master"), - )), + "git-resource": { + ObjectMeta: metav1.ObjectMeta{ + Name: "git-resource", + }, + Spec: resourcev1alpha1.PipelineResourceSpec{ + Type: resourcev1alpha1.PipelineResourceTypeGit, + Params: []resourcev1alpha1.ResourceParam{{ + Name: "revision", + Value: "master", + }}, + }, + }, }, want: v1beta1.TaskSpec{ Steps: []v1beta1.Step{{Container: corev1.Container{ @@ -296,7 +367,11 @@ func TestResolvedConditionCheck_ConditionToTaskSpec(t *testing.T) { func TestResolvedConditionCheck_ToTaskResourceBindings(t *testing.T) { rcc := ResolvedConditionCheck{ ResolvedResources: map[string]*resourcev1alpha1.PipelineResource{ - "git-resource": tb.PipelineResource("some-repo"), + "git-resource": { + ObjectMeta: metav1.ObjectMeta{ + Name: "some-repo", + }, + }, }, } diff --git a/pkg/reconciler/pipelinerun/resources/pipelineref_test.go b/pkg/reconciler/pipelinerun/resources/pipelineref_test.go index e9fdd941b05..d3914fa9893 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelineref_test.go +++ b/pkg/reconciler/pipelinerun/resources/pipelineref_test.go @@ -24,8 +24,6 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-containerregistry/pkg/registry" - ta "github.com/tektoncd/pipeline/internal/builder/v1alpha1" - tb "github.com/tektoncd/pipeline/internal/builder/v1beta1" "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" @@ -42,8 +40,16 @@ import ( ) var ( - simplePipeline = tb.Pipeline("simple", tb.PipelineType, tb.PipelineNamespace("default")) - dummyPipeline = tb.Pipeline("dummy", tb.PipelineType, tb.PipelineNamespace("default")) + dummyPipeline = &v1beta1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{ + Name: "dummy", + Namespace: "default", + }, + TypeMeta: metav1.TypeMeta{ + Kind: "Pipeline", + APIVersion: "tekton.dev/v1beta1", + }, + } ) func TestLocalPipelineRef(t *testing.T) { @@ -56,11 +62,11 @@ func TestLocalPipelineRef(t *testing.T) { }{ { name: "local-pipeline", - pipelines: []runtime.Object{simplePipeline, dummyPipeline}, + pipelines: []runtime.Object{simplePipeline(), dummyPipeline}, ref: &v1beta1.PipelineRef{ Name: "simple", }, - expected: simplePipeline, + expected: simplePipeline(), wantErr: false, }, { @@ -128,51 +134,68 @@ func TestGetPipelineFunc(t *testing.T) { }{{ name: "remote-pipeline", localPipelines: []runtime.Object{ - tb.Pipeline("simple", tb.PipelineType, tb.PipelineNamespace("default"), tb.PipelineSpec(tb.PipelineTask("something", "something"))), + simplePipelineWithBaseSpec(), dummyPipeline, }, - remotePipelines: []runtime.Object{simplePipeline, dummyPipeline}, + remotePipelines: []runtime.Object{simplePipeline(), dummyPipeline}, ref: &v1beta1.PipelineRef{ Name: "simple", Bundle: u.Host + "/remote-pipeline", }, - expected: simplePipeline, + expected: simplePipeline(), }, { name: "local-pipeline", localPipelines: []runtime.Object{ - tb.Pipeline("simple", tb.PipelineType, tb.PipelineNamespace("default"), tb.PipelineSpec(tb.PipelineTask("something", "something"))), + simplePipelineWithBaseSpec(), dummyPipeline, }, - remotePipelines: []runtime.Object{simplePipeline, dummyPipeline}, + remotePipelines: []runtime.Object{simplePipeline(), dummyPipeline}, ref: &v1beta1.PipelineRef{ Name: "simple", }, - expected: tb.Pipeline("simple", tb.PipelineType, tb.PipelineNamespace("default"), tb.PipelineSpec(tb.PipelineTask("something", "something"))), + expected: simplePipelineWithBaseSpec(), }, { name: "remote-pipeline-without-defaults", - localPipelines: []runtime.Object{simplePipeline}, + localPipelines: []runtime.Object{simplePipeline()}, remotePipelines: []runtime.Object{ - tb.Pipeline("simple", tb.PipelineType, tb.PipelineNamespace("default"), - tb.PipelineSpec(tb.PipelineTask("something", "something"), tb.PipelineParamSpec("foo", ""))), + simplePipelineWithSpecAndParam(""), dummyPipeline}, ref: &v1beta1.PipelineRef{ Name: "simple", Bundle: u.Host + "/remote-pipeline-without-defaults", }, - expected: tb.Pipeline("simple", tb.PipelineType, tb.PipelineNamespace("default"), - tb.PipelineSpec(tb.PipelineTask("something", "something", tb.PipelineTaskRefKind(v1beta1.NamespacedTaskKind)), tb.PipelineParamSpec("foo", v1beta1.ParamTypeString))), + expected: simplePipelineWithSpecParamAndKind(v1beta1.ParamTypeString, v1beta1.NamespacedTaskKind), }, { name: "remote-v1alpha1-pipeline-without-defaults", - localPipelines: []runtime.Object{simplePipeline}, + localPipelines: []runtime.Object{simplePipeline()}, remotePipelines: []runtime.Object{ - ta.Pipeline("simple", ta.PipelineType, ta.PipelineNamespace("default"), - ta.PipelineSpec(ta.PipelineTask("something", "something"), ta.PipelineParamSpec("foo", "")))}, + &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{ + Name: "simple", + Namespace: "default", + }, + TypeMeta: metav1.TypeMeta{ + Kind: "Pipeline", + APIVersion: "tekton.dev/v1alpha1", + }, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{{ + Name: "something", + TaskRef: &v1alpha1.TaskRef{ + Name: "something", + }, + }}, + Params: []v1alpha1.ParamSpec{{ + Name: "foo", + }}, + }, + }, + }, ref: &v1alpha1.PipelineRef{ Name: "simple", Bundle: u.Host + "/remote-v1alpha1-pipeline-without-defaults", }, - expected: tb.Pipeline("simple", tb.PipelineNamespace("default"), - tb.PipelineSpec(tb.PipelineTask("something", "something", tb.PipelineTaskRefKind(v1beta1.NamespacedTaskKind)), tb.PipelineParamSpec("foo", v1beta1.ParamTypeString))), + expected: simplePipelineWithSpecParamKindNoType(v1beta1.ParamTypeString, v1beta1.NamespacedTaskKind), }} for _, tc := range testcases { @@ -217,7 +240,7 @@ func TestGetPipelineFuncSpecAlreadyFetched(t *testing.T) { ctx := context.Background() ctx, cancel := context.WithCancel(ctx) defer cancel() - tektonclient := fake.NewSimpleClientset(simplePipeline, dummyPipeline) + tektonclient := fake.NewSimpleClientset(simplePipeline(), dummyPipeline) kubeclient := fakek8s.NewSimpleClientset(&v1.ServiceAccount{ ObjectMeta: metav1.ObjectMeta{ Namespace: "default", @@ -267,3 +290,61 @@ func TestGetPipelineFuncSpecAlreadyFetched(t *testing.T) { t.Error(diff) } } + +func basePipeline(name string) *v1beta1.Pipeline { + return &v1beta1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: "default", + }, + TypeMeta: metav1.TypeMeta{ + Kind: "Pipeline", + APIVersion: "tekton.dev/v1beta1", + }, + } +} + +func simplePipeline() *v1beta1.Pipeline { + return basePipeline("simple") +} + +func simplePipelineWithBaseSpec() *v1beta1.Pipeline { + p := simplePipeline() + p.Spec = v1beta1.PipelineSpec{ + Tasks: []v1beta1.PipelineTask{{ + Name: "something", + TaskRef: &v1beta1.TaskRef{ + Name: "something", + }, + }}, + } + + return p +} + +func simplePipelineWithSpecAndParam(pt v1alpha1.ParamType) *v1beta1.Pipeline { + p := simplePipelineWithBaseSpec() + p.Spec.Params = []v1beta1.ParamSpec{{ + Name: "foo", + Type: pt, + }} + + return p +} + +func simplePipelineWithSpecParamAndKind(pt v1beta1.ParamType, tk v1beta1.TaskKind) *v1beta1.Pipeline { + p := simplePipelineWithBaseSpec() + p.Spec.Params = []v1beta1.ParamSpec{{ + Name: "foo", + Type: pt, + }} + p.Spec.Tasks[0].TaskRef.Kind = tk + + return p +} + +func simplePipelineWithSpecParamKindNoType(pt v1beta1.ParamType, tk v1beta1.TaskKind) *v1beta1.Pipeline { + p := simplePipelineWithSpecParamAndKind(pt, tk) + p.TypeMeta = metav1.TypeMeta{} + return p +} diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go index f59fdce8884..4a5c86d8bcc 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go @@ -24,7 +24,6 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - tbv1alpha1 "github.com/tektoncd/pipeline/internal/builder/v1alpha1" tb "github.com/tektoncd/pipeline/internal/builder/v1beta1" "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" @@ -1670,10 +1669,6 @@ func TestGetResourcesFromBindings(t *testing.T) { } func TestGetResourcesFromBindings_Missing(t *testing.T) { - // p := tb.Pipeline("pipelines", "namespace", tb.PipelineSpec( - // tb.PipelineDeclaredResource("git-resource", "git"), - // tb.PipelineDeclaredResource("image-resource", "image"), - // )) pr := tb.PipelineRun("pipelinerun", tb.PipelineRunSpec("pipeline", tb.PipelineRunResourceBinding("git-resource", tb.PipelineResourceBindingRef("sweet-resource")), )) @@ -2408,9 +2403,17 @@ func TestResolveConditionCheck_UseExistingConditionCheckName(t *testing.T) { func TestResolvedConditionCheck_WithResources(t *testing.T) { names.TestingSeed() - condition := tbv1alpha1.Condition("always-true", tbv1alpha1.ConditionSpec( - tbv1alpha1.ConditionResource("workspace", resourcev1alpha1.PipelineResourceTypeGit), - )) + condition := &v1alpha1.Condition{ + ObjectMeta: metav1.ObjectMeta{ + Name: "always-true", + }, + Spec: v1alpha1.ConditionSpec{ + Resources: []v1alpha1.ResourceDeclaration{{ + Name: "workspace", + Type: resourcev1alpha1.PipelineResourceTypeGit, + }}, + }, + } gitResource := tb.PipelineResource("some-repo", tb.PipelineResourceNamespace("foo"), tb.PipelineResourceSpec( resourcev1alpha1.PipelineResourceTypeGit)) diff --git a/pkg/reconciler/taskrun/resources/taskref_test.go b/pkg/reconciler/taskrun/resources/taskref_test.go index 691b016da86..e8f29d3116e 100644 --- a/pkg/reconciler/taskrun/resources/taskref_test.go +++ b/pkg/reconciler/taskrun/resources/taskref_test.go @@ -24,7 +24,6 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-containerregistry/pkg/registry" - ta "github.com/tektoncd/pipeline/internal/builder/v1alpha1" tb "github.com/tektoncd/pipeline/internal/builder/v1beta1" "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" @@ -170,7 +169,28 @@ func TestGetTaskFunc(t *testing.T) { name: "remote-v1alpha1-task-without-defaults", localTasks: []runtime.Object{}, remoteTasks: []runtime.Object{ - ta.Task("simple", ta.TaskType, ta.TaskNamespace("default"), ta.TaskSpec(ta.TaskParam("foo", ""), ta.Step("something"))), + &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: "simple", + Namespace: "default", + }, + TypeMeta: metav1.TypeMeta{ + APIVersion: "tekton.dev/v1alpha1", + Kind: "Task", + }, + Spec: v1alpha1.TaskSpec{ + TaskSpec: v1beta1.TaskSpec{ + Params: []v1alpha1.ParamSpec{{ + Name: "foo", + }}, + Steps: []v1alpha1.Step{{ + Container: corev1.Container{ + Image: "something", + }, + }}, + }, + }, + }, }, ref: &v1alpha1.TaskRef{ Name: "simple", diff --git a/test/pipelinerun_test.go b/test/pipelinerun_test.go index 676f756d7b1..4853b0d2f4d 100644 --- a/test/pipelinerun_test.go +++ b/test/pipelinerun_test.go @@ -26,7 +26,6 @@ import ( "testing" "time" - tbv1alpha1 "github.com/tektoncd/pipeline/internal/builder/v1alpha1" tb "github.com/tektoncd/pipeline/internal/builder/v1beta1" "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" @@ -884,8 +883,20 @@ func getPipelineWithFailingCondition(suffix int, namespace string) *v1beta1.Pipe } func getFailingCondition() *v1alpha1.Condition { - return tbv1alpha1.Condition(cond1Name, tbv1alpha1.ConditionSpec(tbv1alpha1.ConditionSpecCheck("", "ubuntu", - tb.Command("/bin/bash"), tb.Args("exit 1")))) + return &v1alpha1.Condition{ + ObjectMeta: metav1.ObjectMeta{ + Name: cond1Name, + }, + Spec: v1alpha1.ConditionSpec{ + Check: v1alpha1.Step{ + Container: corev1.Container{ + Image: "ubuntu", + Command: []string{"/bin/bash"}, + Args: []string{"exit 1"}, + }, + }, + }, + } } func getConditionalPipelineRun(suffix int, namespace string) *v1beta1.PipelineRun { diff --git a/test/v1alpha1/artifact_bucket_test.go b/test/v1alpha1/artifact_bucket_test.go index 856ff2631d9..87388f576e0 100644 --- a/test/v1alpha1/artifact_bucket_test.go +++ b/test/v1alpha1/artifact_bucket_test.go @@ -26,7 +26,8 @@ import ( "testing" "time" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" corev1 "k8s.io/api/core/v1" @@ -72,28 +73,55 @@ func TestStorageBucketPipelineRun(t *testing.T) { defer deleteBucketSecret(ctx, c, t, namespace) t.Logf("Creating GCS bucket %s", bucketName) - createbuckettask := tb.Task("createbuckettask", tb.TaskSpec( - tb.TaskVolume("bucket-secret-volume", tb.VolumeSource(corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: bucketSecretName, + createbuckettask := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: "createbuckettask", + }, + Spec: v1alpha1.TaskSpec{ + TaskSpec: v1beta1.TaskSpec{ + Volumes: []corev1.Volume{{ + Name: "bucket-secret-volume", + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: bucketSecretName, + }, + }, + }}, + Steps: []v1alpha1.Step{{ + Container: corev1.Container{ + Image: "gcr.io/google.com/cloudsdktool/cloud-sdk:alpine", + Name: "step1", + Command: []string{"/bin/bash"}, + Args: []string{"-c", fmt.Sprintf("gcloud auth activate-service-account --key-file /var/secret/bucket-secret/bucket-secret-key && gsutil mb gs://%s", bucketName)}, + VolumeMounts: []corev1.VolumeMount{{ + Name: "bucket-secret-volume", + MountPath: fmt.Sprintf("/var/secret/%s", bucketSecretName), + }}, + Env: []corev1.EnvVar{{ + Name: "CREDENTIALS", + Value: fmt.Sprintf("/var/secret/%s/%s", bucketSecretName, bucketSecretKey), + }}, + }, + }}, }, - })), - tb.Step("gcr.io/google.com/cloudsdktool/cloud-sdk:alpine", tb.StepName("step1"), - tb.StepCommand("/bin/bash"), - tb.StepArgs("-c", fmt.Sprintf("gcloud auth activate-service-account --key-file /var/secret/bucket-secret/bucket-secret-key && gsutil mb gs://%s", bucketName)), - tb.StepVolumeMount("bucket-secret-volume", fmt.Sprintf("/var/secret/%s", bucketSecretName)), - tb.StepEnvVar("CREDENTIALS", fmt.Sprintf("/var/secret/%s/%s", bucketSecretName, bucketSecretKey)), - ), - ), - ) + }, + } t.Logf("Creating Task %s", "createbuckettask") if _, err := c.TaskClient.Create(ctx, createbuckettask, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Task `%s`: %s", "createbuckettask", err) } - createbuckettaskrun := tb.TaskRun("createbuckettaskrun", - tb.TaskRunSpec(tb.TaskRunTaskRef("createbuckettask"))) + createbuckettaskrun := &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "createbuckettaskrun", + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: "createbuckettask", + }, + }, + } t.Logf("Creating TaskRun %s", "createbuckettaskrun") if _, err := c.TaskRunClient.Create(ctx, createbuckettaskrun, metav1.CreateOptions{}); err != nil { @@ -124,59 +152,171 @@ func TestStorageBucketPipelineRun(t *testing.T) { defer resetConfigMap(ctx, t, c, systemNamespace, config.GetArtifactBucketConfigName(), originalConfigMapData) t.Logf("Creating Git PipelineResource %s", helloworldResourceName) - helloworldResource := tb.PipelineResource(helloworldResourceName, tb.PipelineResourceSpec( - v1alpha1.PipelineResourceTypeGit, - tb.PipelineResourceSpecParam("Url", "https://github.com/pivotal-nader-ziada/gohelloworld"), - tb.PipelineResourceSpecParam("Revision", "master"), - ), - ) + helloworldResource := &v1alpha1.PipelineResource{ + ObjectMeta: metav1.ObjectMeta{ + Name: helloworldResourceName, + }, + Spec: v1alpha1.PipelineResourceSpec{ + Type: v1alpha1.PipelineResourceTypeGit, + Params: []v1alpha1.ResourceParam{ + { + Name: "Url", + Value: "https://github.com/pivotal-nader-ziada/gohelloworld", + }, + { + Name: "Revision", + Value: "master", + }, + }, + }, + } if _, err := c.PipelineResourceClient.Create(ctx, helloworldResource, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Pipeline Resource `%s`: %s", helloworldResourceName, err) } t.Logf("Creating Task %s", addFileTaskName) - addFileTask := tb.Task(addFileTaskName, tb.TaskSpec( - tb.TaskInputs(tb.InputsResource(helloworldResourceName, v1alpha1.PipelineResourceTypeGit)), - tb.TaskOutputs(tb.OutputsResource(helloworldResourceName, v1alpha1.PipelineResourceTypeGit)), - tb.Step("ubuntu", tb.StepName("addfile"), tb.StepCommand("/bin/bash"), - tb.StepArgs("-c", "'#!/bin/bash\necho hello' > /workspace/helloworldgit/newfile"), - ), - tb.Step("ubuntu", tb.StepName("make-executable"), tb.StepCommand("chmod"), - tb.StepArgs("+x", "/workspace/helloworldgit/newfile")), - )) + addFileTask := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: addFileTaskName, + }, + Spec: v1alpha1.TaskSpec{ + Inputs: &v1alpha1.Inputs{ + Resources: []v1alpha1.TaskResource{{ + ResourceDeclaration: v1alpha1.ResourceDeclaration{ + Name: helloworldResourceName, + Type: v1alpha1.PipelineResourceTypeGit, + }, + }}, + }, + Outputs: &v1alpha1.Outputs{ + Resources: []v1alpha1.TaskResource{{ + ResourceDeclaration: v1alpha1.ResourceDeclaration{ + Name: helloworldResourceName, + Type: v1alpha1.PipelineResourceTypeGit, + }, + }}, + }, + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{ + { + Container: corev1.Container{ + Image: "ubuntu", + Name: "addfile", + Command: []string{"/bin/bash"}, + Args: []string{"-c", "'#!/bin/bash\necho hello' > /workspace/helloworldgit/newfile"}, + }, + }, + { + Container: corev1.Container{ + Image: "ubuntu", + Name: "make-executable", + Command: []string{"chmod"}, + Args: []string{"+x", "/workspace/helloworldgit/newfile"}, + }, + }, + }, + }, + }, + } if _, err := c.TaskClient.Create(ctx, addFileTask, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Task `%s`: %s", addFileTaskName, err) } t.Logf("Creating Task %s", runFileTaskName) - readFileTask := tb.Task(runFileTaskName, tb.TaskSpec( - tb.TaskInputs(tb.InputsResource(helloworldResourceName, v1alpha1.PipelineResourceTypeGit)), - tb.Step("ubuntu", tb.StepName("runfile"), tb.StepCommand("/workspace/helloworld/newfile")), - )) + readFileTask := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: runFileTaskName, + }, + Spec: v1alpha1.TaskSpec{ + Inputs: &v1alpha1.Inputs{ + Resources: []v1alpha1.TaskResource{{ + ResourceDeclaration: v1alpha1.ResourceDeclaration{ + Name: helloworldResourceName, + Type: v1alpha1.PipelineResourceTypeGit, + }, + }}, + }, + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{ + { + Container: corev1.Container{ + Image: "runfile", + Name: "addfile", + Command: []string{"/workspace/helloworld/newfile"}, + }, + }, + }, + }, + }, + } if _, err := c.TaskClient.Create(ctx, readFileTask, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Task `%s`: %s", runFileTaskName, err) } t.Logf("Creating Pipeline %s", bucketTestPipelineName) - bucketTestPipeline := tb.Pipeline(bucketTestPipelineName, tb.PipelineSpec( - tb.PipelineDeclaredResource("source-repo", "git"), - tb.PipelineTask("addfile", addFileTaskName, - tb.PipelineTaskInputResource("helloworldgit", "source-repo"), - tb.PipelineTaskOutputResource("helloworldgit", "source-repo"), - ), - tb.PipelineTask("runfile", runFileTaskName, - tb.PipelineTaskInputResource("helloworldgit", "source-repo", tb.From("addfile")), - ), - )) + bucketTestPipeline := &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{ + Name: bucketTestPipelineName, + }, + Spec: v1alpha1.PipelineSpec{ + Resources: []v1alpha1.PipelineDeclaredResource{{ + Name: "source-repo", + Type: "git", + }}, + Tasks: []v1alpha1.PipelineTask{ + { + TaskRef: &v1alpha1.TaskRef{ + Name: addFileTaskName, + }, + Name: "addfile", + Resources: &v1alpha1.PipelineTaskResources{ + Inputs: []v1alpha1.PipelineTaskInputResource{{ + Name: "helloworldgit", + Resource: "source-repo", + }}, + Outputs: []v1alpha1.PipelineTaskOutputResource{{ + Name: "helloworldgit", + Resource: "source-repo", + }}, + }, + }, + { + TaskRef: &v1alpha1.TaskRef{ + Name: runFileTaskName, + }, + Name: "runfile", + Resources: &v1alpha1.PipelineTaskResources{ + Inputs: []v1alpha1.PipelineTaskInputResource{{ + Name: "helloworldgit", + Resource: "source-repo", + From: []string{"addfile"}, + }}, + }, + }, + }, + }, + } if _, err := c.PipelineClient.Create(ctx, bucketTestPipeline, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Pipeline `%s`: %s", bucketTestPipelineName, err) } t.Logf("Creating PipelineRun %s", bucketTestPipelineRunName) - bucketTestPipelineRun := tb.PipelineRun(bucketTestPipelineRunName, tb.PipelineRunSpec( - bucketTestPipelineName, - tb.PipelineRunResourceBinding("source-repo", tb.PipelineResourceBindingRef(helloworldResourceName)), - )) + bucketTestPipelineRun := &v1alpha1.PipelineRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: bucketTestPipelineRunName, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: bucketTestPipelineRunName, + }, + Resources: []v1alpha1.PipelineResourceBinding{{ + Name: "source-repo", + ResourceRef: &v1alpha1.PipelineResourceRef{ + Name: helloworldResourceName, + }, + }}, + }, + } if _, err := c.PipelineRunClient.Create(ctx, bucketTestPipelineRun, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create PipelineRun `%s`: %s", bucketTestPipelineRunName, err) } @@ -238,28 +378,39 @@ func resetConfigMap(ctx context.Context, t *testing.T, c *clients, namespace, co } func runTaskToDeleteBucket(ctx context.Context, c *clients, t *testing.T, namespace, bucketName, bucketSecretName, bucketSecretKey string) { - deletelbuckettask := tb.Task("deletelbuckettask", tb.TaskSpec( - tb.TaskVolume("bucket-secret-volume", tb.VolumeSource(corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: bucketSecretName, + deletelbuckettask := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: "deletelbuckettask", + }, + Spec: v1alpha1.TaskSpec{ + TaskSpec: v1beta1.TaskSpec{ + Volumes: []corev1.Volume{{ + Name: "bucket-secret-volume", + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: bucketSecretName, + }, + }, + }}, }, - })), - tb.Step("gcr.io/google.com/cloudsdktool/cloud-sdk:alpine", tb.StepName("step1"), - tb.StepCommand("/bin/bash"), - tb.StepArgs("-c", fmt.Sprintf("gcloud auth activate-service-account --key-file /var/secret/bucket-secret/bucket-secret-key && gsutil rm -r gs://%s", bucketName)), - tb.StepVolumeMount("bucket-secret-volume", fmt.Sprintf("/var/secret/%s", bucketSecretName)), - tb.StepEnvVar("CREDENTIALS", fmt.Sprintf("/var/secret/%s/%s", bucketSecretName, bucketSecretKey)), - ), - ), - ) + }, + } t.Logf("Creating Task %s", "deletelbuckettask") if _, err := c.TaskClient.Create(ctx, deletelbuckettask, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Task `%s`: %s", "deletelbuckettask", err) } - deletelbuckettaskrun := tb.TaskRun("deletelbuckettaskrun", - tb.TaskRunSpec(tb.TaskRunTaskRef("deletelbuckettask"))) + deletelbuckettaskrun := &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "deletelbuckettaskrun", + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: "deletelbuckettask", + }, + }, + } t.Logf("Creating TaskRun %s", "deletelbuckettaskrun") if _, err := c.TaskRunClient.Create(ctx, deletelbuckettaskrun, metav1.CreateOptions{}); err != nil { diff --git a/test/v1alpha1/cluster_resource_test.go b/test/v1alpha1/cluster_resource_test.go index cdff08a6789..3d513a25ca9 100644 --- a/test/v1alpha1/cluster_resource_test.go +++ b/test/v1alpha1/cluster_resource_test.go @@ -22,7 +22,8 @@ import ( "context" "testing" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -77,15 +78,45 @@ func TestClusterResource(t *testing.T) { } func getClusterResource(namespace, name, sname string) *v1alpha1.PipelineResource { - return tb.PipelineResource(name, tb.PipelineResourceNamespace(namespace), tb.PipelineResourceSpec( - v1alpha1.PipelineResourceTypeCluster, - tb.PipelineResourceSpecParam("Name", "helloworld-cluster"), - tb.PipelineResourceSpecParam("Url", "https://1.1.1.1"), - tb.PipelineResourceSpecParam("username", "test-user"), - tb.PipelineResourceSpecParam("password", "test-password"), - tb.PipelineResourceSpecSecretParam("cadata", sname, "cadatakey"), - tb.PipelineResourceSpecSecretParam("token", sname, "tokenkey"), - )) + return &v1alpha1.PipelineResource{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, + }, + Spec: v1alpha1.PipelineResourceSpec{ + Type: v1alpha1.PipelineResourceTypeCluster, + Params: []v1alpha1.ResourceParam{ + { + Name: "Name", + Value: "helloworld-cluster", + }, + { + Name: "Url", + Value: "https://1.1.1.1", + }, + { + Name: "username", + Value: "test-user", + }, + { + Name: "password", + Value: "test-password", + }, + }, + SecretParams: []v1alpha1.SecretParam{ + { + FieldName: "cadata", + SecretKey: "cadatakey", + SecretName: sname, + }, + { + FieldName: "token", + SecretKey: "tokenkey", + SecretName: sname, + }, + }, + }, + } } func getClusterResourceTaskSecret(namespace, name string) *corev1.Secret { @@ -102,34 +133,81 @@ func getClusterResourceTaskSecret(namespace, name string) *corev1.Secret { } func getClusterResourceTask(name, configName string) *v1alpha1.Task { - return tb.Task(name, tb.TaskSpec( - tb.TaskInputs(tb.InputsResource("target-cluster", v1alpha1.PipelineResourceTypeCluster)), - tb.TaskVolume("config-vol", tb.VolumeSource(corev1.VolumeSource{ - ConfigMap: &corev1.ConfigMapVolumeSource{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: configName, + return &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + }, + Spec: v1alpha1.TaskSpec{ + Inputs: &v1alpha1.Inputs{ + Resources: []v1alpha1.TaskResource{{ + ResourceDeclaration: v1alpha1.ResourceDeclaration{ + Name: "target-cluster", + Type: v1alpha1.PipelineResourceTypeCluster, + }, + }}, + }, + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{ + { + Container: corev1.Container{ + Image: "ubuntu", + Name: "check-file-existence", + Command: []string{"cat"}, + Args: []string{"/workspace/target-cluster/kubeconfig"}, + }, + }, + { + Container: corev1.Container{ + Image: "ubuntu", + Name: "check-config-data", + Command: []string{"cat"}, + Args: []string{"/config/test.data"}, + VolumeMounts: []corev1.VolumeMount{{ + Name: "config-vol", + MountPath: "/config", + }}, + }, + }, + { + Container: corev1.Container{ + Image: "ubuntu", + Name: "check-contents", + Command: []string{"bash"}, + Args: []string{"-c", "cmp -b /workspace/target-cluster/kubeconfig /config/test.data"}, + VolumeMounts: []corev1.VolumeMount{{ + Name: "config-vol", + MountPath: "/config", + }}, + }, + }, }, }, - })), - tb.Step("ubuntu", tb.StepName("check-file-existence"), - tb.StepCommand("cat"), tb.StepArgs("/workspace/target-cluster/kubeconfig"), - ), - tb.Step("ubuntu", tb.StepName("check-config-data"), - tb.StepCommand("cat"), tb.StepArgs("/config/test.data"), - tb.StepVolumeMount("config-vol", "/config"), - ), - tb.Step("ubuntu", tb.StepName("check-contents"), - tb.StepCommand("bash"), tb.StepArgs("-c", "cmp -b /workspace/target-cluster/kubeconfig /config/test.data"), - tb.StepVolumeMount("config-vol", "/config"), - ), - )) + }, + } } func getClusterResourceTaskRun(namespace, name, taskName, resName string) *v1alpha1.TaskRun { - return tb.TaskRun(name, tb.TaskRunNamespace(namespace), tb.TaskRunSpec( - tb.TaskRunTaskRef(taskName), - tb.TaskRunInputs(tb.TaskRunInputsResource("target-cluster", tb.TaskResourceBindingRef(resName))), - )) + return &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: taskName, + }, + Inputs: &v1alpha1.TaskRunInputs{ + Resources: []v1alpha1.TaskResourceBinding{{ + PipelineResourceBinding: v1alpha1.PipelineResourceBinding{ + Name: "target-cluster", + ResourceRef: &v1alpha1.PipelineResourceRef{ + Name: resName, + }, + }, + }}, + }, + }, + } } func getClusterConfigMap(namespace, name string) *corev1.ConfigMap { diff --git a/test/v1alpha1/duplicate_test.go b/test/v1alpha1/duplicate_test.go index e69582a9401..7ccb5c93604 100644 --- a/test/v1alpha1/duplicate_test.go +++ b/test/v1alpha1/duplicate_test.go @@ -24,7 +24,10 @@ import ( "sync" "testing" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + corev1 "k8s.io/api/core/v1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" knativetest "knative.dev/pkg/test" @@ -48,12 +51,24 @@ func TestDuplicatePodTaskRun(t *testing.T) { taskrunName := helpers.ObjectNameForTest(t) t.Logf("Creating taskrun %q.", taskrunName) - taskrun := tb.TaskRun(taskrunName, tb.TaskRunSpec( - tb.TaskRunTaskSpec(tb.Step("busybox", - tb.StepCommand("/bin/echo"), - tb.StepArgs("simple"), - )), - )) + taskrun := &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: taskrunName, + }, + Spec: v1alpha1.TaskRunSpec{ + TaskSpec: &v1alpha1.TaskSpec{ + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{{ + Container: corev1.Container{ + Image: "busybox", + Command: []string{"/bin/echo"}, + Args: []string{"simple"}, + }, + }}, + }, + }, + }, + } if _, err := c.TaskRunClient.Create(ctx, taskrun, metav1.CreateOptions{}); err != nil { t.Fatalf("Error creating taskrun: %v", err) } diff --git a/test/v1alpha1/embed_test.go b/test/v1alpha1/embed_test.go index c2c467e1a9b..a65937e0cc4 100644 --- a/test/v1alpha1/embed_test.go +++ b/test/v1alpha1/embed_test.go @@ -23,7 +23,9 @@ import ( "fmt" "testing" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + corev1 "k8s.io/api/core/v1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" knativetest "knative.dev/pkg/test" @@ -67,15 +69,38 @@ func TestTaskRun_EmbeddedResource(t *testing.T) { } func getEmbeddedTask(args []string) *v1alpha1.Task { - return tb.Task(embedTaskName, - tb.TaskSpec( - tb.TaskInputs(tb.InputsResource("docs", v1alpha1.PipelineResourceTypeGit)), - tb.Step("ubuntu", - tb.StepCommand("/bin/bash"), - tb.StepArgs("-c", "cat /workspace/docs/LICENSE"), - ), - tb.Step("busybox", tb.StepCommand(args...)), - )) + return &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: embedTaskName, + }, + Spec: v1alpha1.TaskSpec{ + Inputs: &v1alpha1.Inputs{ + Resources: []v1alpha1.TaskResource{{ + ResourceDeclaration: v1alpha1.ResourceDeclaration{ + Name: "docs", + Type: v1alpha1.PipelineResourceTypeGit, + }, + }}, + }, + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{ + { + Container: corev1.Container{ + Image: "ubuntu", + Command: []string{"/bin/bash"}, + Args: []string{"-c", "cat /workspace/docs/LICENSE"}, + }, + }, + { + Container: corev1.Container{ + Image: "busybox", + Command: args, + }, + }, + }, + }, + }, + } } func getEmbeddedTaskRun(namespace string) *v1alpha1.TaskRun { @@ -86,11 +111,20 @@ func getEmbeddedTaskRun(namespace string) *v1alpha1.TaskRun { Value: "https://github.com/knative/docs", }}, } - return tb.TaskRun(embedTaskRunName, - tb.TaskRunNamespace(namespace), - tb.TaskRunSpec( - tb.TaskRunInputs( - tb.TaskRunInputsResource("docs", tb.TaskResourceBindingResourceSpec(testSpec)), - ), - tb.TaskRunTaskRef(embedTaskName))) + return &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: embedTaskRunName, + Namespace: namespace, + }, + Spec: v1alpha1.TaskRunSpec{ + Inputs: &v1alpha1.TaskRunInputs{ + Resources: []v1alpha1.TaskResourceBinding{{ + PipelineResourceBinding: v1alpha1.PipelineResourceBinding{ + Name: "docs", + ResourceSpec: testSpec, + }, + }}, + }, + }, + } } diff --git a/test/v1alpha1/kaniko_task_test.go b/test/v1alpha1/kaniko_task_test.go index a389ceb462d..734704a0f36 100644 --- a/test/v1alpha1/kaniko_task_test.go +++ b/test/v1alpha1/kaniko_task_test.go @@ -25,8 +25,9 @@ import ( "testing" "time" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/google/go-cmp/cmp" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -128,56 +129,125 @@ func TestKanikoTaskRun(t *testing.T) { } func getGitResource(namespace string) *v1alpha1.PipelineResource { - return tb.PipelineResource(kanikoGitResourceName, tb.PipelineResourceSpec( - v1alpha1.PipelineResourceTypeGit, - tb.PipelineResourceSpecParam("Url", "https://github.com/GoogleContainerTools/kaniko"), - tb.PipelineResourceSpecParam("Revision", revision), - )) + return &v1alpha1.PipelineResource{ + ObjectMeta: metav1.ObjectMeta{ + Name: kanikoGitResourceName, + }, + Spec: v1alpha1.PipelineResourceSpec{ + Type: v1alpha1.PipelineResourceTypeGit, + Params: []v1alpha1.ResourceParam{ + { + Name: "Url", + Value: "https://github.com/GoogleContainerTools/kaniko", + }, + { + Name: "Revision", + Value: revision, + }, + }, + }, + } } func getImageResource(namespace, repo string) *v1alpha1.PipelineResource { - return tb.PipelineResource(kanikoImageResourceName, tb.PipelineResourceSpec( - v1alpha1.PipelineResourceTypeImage, - tb.PipelineResourceSpecParam("url", repo), - )) + return &v1alpha1.PipelineResource{ + ObjectMeta: metav1.ObjectMeta{ + Name: kanikoImageResourceName, + }, + Spec: v1alpha1.PipelineResourceSpec{ + Type: v1alpha1.PipelineResourceTypeImage, + Params: []v1alpha1.ResourceParam{{ + Name: "url", + Value: repo, + }}, + }, + } } func getTask(repo, namespace string) *v1alpha1.Task { root := int64(0) - taskSpecOps := []tb.TaskSpecOp{ - tb.TaskInputs(tb.InputsResource("gitsource", v1alpha1.PipelineResourceTypeGit)), - tb.TaskOutputs(tb.OutputsResource("builtImage", v1alpha1.PipelineResourceTypeImage)), - } - stepOps := []tb.StepOp{ - tb.StepName("kaniko"), - tb.StepArgs( - "--dockerfile=/workspace/gitsource/integration/dockerfiles/Dockerfile_test_label", - fmt.Sprintf("--destination=%s", repo), - "--context=/workspace/gitsource", - "--oci-layout-path=/workspace/output/builtImage", - "--insecure", - "--insecure-pull", - "--insecure-registry=registry."+namespace+":5000/", - ), - tb.StepSecurityContext(&corev1.SecurityContext{RunAsUser: &root}), - } - step := tb.Step("gcr.io/kaniko-project/executor:v1.3.0", stepOps...) - taskSpecOps = append(taskSpecOps, step) - sidecar := tb.Sidecar("registry", "registry") - taskSpecOps = append(taskSpecOps, sidecar) - - return tb.Task(kanikoTaskName, tb.TaskSpec(taskSpecOps...)) + return &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: kanikoTaskName, + }, + Spec: v1alpha1.TaskSpec{ + Inputs: &v1alpha1.Inputs{ + Resources: []v1alpha1.TaskResource{{ + ResourceDeclaration: v1alpha1.ResourceDeclaration{ + Name: "gitsource", + Type: v1alpha1.PipelineResourceTypeGit, + }, + }}, + }, + Outputs: &v1alpha1.Outputs{ + Resources: []v1alpha1.TaskResource{{ + ResourceDeclaration: v1alpha1.ResourceDeclaration{ + Name: "builtImage", + Type: v1alpha1.PipelineResourceTypeImage, + }, + }}, + }, + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{{ + Container: corev1.Container{ + Image: "gcr.io/kaniko-project/executor:v1.3.0", + Name: "kaniko", + Args: []string{ + "--dockerfile=/workspace/gitsource/integration/dockerfiles/Dockerfile_test_label", + fmt.Sprintf("--destination=%s", repo), + "--context=/workspace/gitsource", + "--oci-layout-path=/workspace/output/builtImage", + "--insecure", + "--insecure-pull", + "--insecure-registry=registry." + namespace + ":5000/", + }, + SecurityContext: &corev1.SecurityContext{RunAsUser: &root}, + }, + }}, + Sidecars: []v1alpha1.Sidecar{{ + Container: corev1.Container{ + Image: "registry", + Name: "registry", + }, + }}, + }, + }, + } } func getTaskRun(namespace string) *v1alpha1.TaskRun { - return tb.TaskRun(kanikoTaskRunName, - tb.TaskRunNamespace(namespace), - tb.TaskRunSpec( - tb.TaskRunTaskRef(kanikoTaskName), - tb.TaskRunTimeout(2*time.Minute), - tb.TaskRunInputs(tb.TaskRunInputsResource("gitsource", tb.TaskResourceBindingRef(kanikoGitResourceName))), - tb.TaskRunOutputs(tb.TaskRunOutputsResource("builtImage", tb.TaskResourceBindingRef(kanikoImageResourceName))), - )) + return &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: kanikoTaskRunName, + Namespace: namespace, + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: kanikoTaskName, + }, + Timeout: &metav1.Duration{Duration: 2 * time.Minute}, + Inputs: &v1alpha1.TaskRunInputs{ + Resources: []v1alpha1.TaskResourceBinding{{ + PipelineResourceBinding: v1alpha1.PipelineResourceBinding{ + Name: "gitsource", + ResourceRef: &v1alpha1.PipelineResourceRef{ + Name: kanikoGitResourceName, + }, + }, + }}, + }, + Outputs: &v1alpha1.TaskRunOutputs{ + Resources: []v1alpha1.TaskResourceBinding{{ + PipelineResourceBinding: v1alpha1.PipelineResourceBinding{ + Name: "builtImage", + ResourceRef: &v1alpha1.PipelineResourceRef{ + Name: kanikoImageResourceName, + }, + }, + }}, + }, + }, + } } // getRemoteDigest starts a pod to query the registry from the namespace itself, using skopeo (and jq). diff --git a/test/v1alpha1/pipelinerun_test.go b/test/v1alpha1/pipelinerun_test.go index b0f7995eea2..80c10d85c31 100644 --- a/test/v1alpha1/pipelinerun_test.go +++ b/test/v1alpha1/pipelinerun_test.go @@ -26,7 +26,8 @@ import ( "testing" "time" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/artifacts" @@ -97,15 +98,36 @@ func TestPipelineRun(t *testing.T) { t.Fatalf("Failed to create SA `%s`: %s", getName(saName, index), err) } - task := tb.Task(getName(taskName, index), tb.TaskSpec( - tb.TaskInputs(tb.InputsParamSpec("path", v1alpha1.ParamTypeString), - tb.InputsParamSpec("dest", v1alpha1.ParamTypeString)), - // Reference build: https://github.com/knative/build/tree/master/test/docker-basic - tb.Step("gcr.io/tekton-releases/dogfooding/skopeo:latest", tb.StepName("config-docker"), - tb.StepCommand("skopeo"), - tb.StepArgs("copy", "$(inputs.params.path)", "$(inputs.params.dest)"), - ), - )) + task := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: getName(taskName, index), + }, + Spec: v1alpha1.TaskSpec{ + Inputs: &v1alpha1.Inputs{ + Params: []v1alpha1.ParamSpec{ + { + Name: "path", + Type: v1alpha1.ParamTypeString, + }, + { + Name: "dest", + Type: v1alpha1.ParamTypeString, + }, + }, + }, + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{{ + // Reference build: https://github.com/knative/build/tree/master/test/docker-basic + Container: corev1.Container{ + Name: "config-docker", + Image: "gcr.io/tekton-releases/dogfooding/skopeo:latest", + Command: []string{"skopeo"}, + Args: []string{"copy", "$(inputs.params.path)", "$(inputs.params.dest)"}, + }, + }}, + }, + }, + } if _, err := c.TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Task `%s`: %s", getName(taskName, index), err) } @@ -127,12 +149,23 @@ func TestPipelineRun(t *testing.T) { t.Fatalf("Failed to create Condition `%s`: %s", cond1Name, err) } - task := tb.Task(getName(taskName, index), tb.TaskSpec( - tb.Step("ubuntu", - tb.StepCommand("/bin/bash"), - tb.StepArgs("-c", "echo hello, world"), - ), - )) + task := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: getName(taskName, index), + }, + Spec: v1alpha1.TaskSpec{ + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{{ + Container: corev1.Container{ + Image: "ubuntu", + Command: []string{"/bin/bash"}, + Args: []string{"-c", "echo hello, world"}, + }, + }}, + }, + }, + } + if _, err := c.TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Task `%s`: %s", getName(taskName, index), err) } @@ -243,96 +276,300 @@ func TestPipelineRun(t *testing.T) { } func getHelloWorldPipelineWithSingularTask(suffix int) *v1alpha1.Pipeline { - return tb.Pipeline(getName(pipelineName, suffix), tb.PipelineSpec( - tb.PipelineParamSpec("path", v1alpha1.ParamTypeString), - tb.PipelineParamSpec("dest", v1alpha1.ParamTypeString), - tb.PipelineTask(task1Name, getName(taskName, suffix), - tb.PipelineTaskParam("path", "$(params.path)"), - tb.PipelineTaskParam("dest", "$(params.dest)")), - )) + return &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{ + Name: getName(pipelineName, suffix), + }, + Spec: v1alpha1.PipelineSpec{ + Params: []v1alpha1.ParamSpec{ + { + Name: "path", + Type: v1alpha1.ParamTypeString, + }, + { + Name: "dest", + Type: v1alpha1.ParamTypeString, + }, + }, + Tasks: []v1alpha1.PipelineTask{{ + Name: task1Name, + TaskRef: &v1alpha1.TaskRef{ + Name: getName(taskName, suffix), + }, + Params: []v1alpha1.Param{ + { + Name: "path", + Value: v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeString, + StringVal: "$(params.path)", + }, + }, + { + Name: "dest", + Value: v1alpha1.ArrayOrString{ + Type: v1alpha1.ParamTypeString, + StringVal: "$(params.dest)", + }, + }, + }, + }}, + }, + } } func getFanInFanOutTasks() []*v1alpha1.Task { - inWorkspaceResource := tb.InputsResource("workspace", v1alpha1.PipelineResourceTypeGit) - outWorkspaceResource := tb.OutputsResource("workspace", v1alpha1.PipelineResourceTypeGit) + inWorkspaceResource := v1alpha1.TaskResource{ + ResourceDeclaration: v1alpha1.ResourceDeclaration{ + Name: "workspace", + Type: v1alpha1.PipelineResourceTypeGit, + }, + } + outWorkspaceResource := v1alpha1.TaskResource{ + ResourceDeclaration: v1alpha1.ResourceDeclaration{ + Name: "workspace", + Type: v1alpha1.PipelineResourceTypeGit, + }, + } return []*v1alpha1.Task{ - tb.Task("create-file", tb.TaskSpec( - tb.TaskInputs(tb.InputsResource("workspace", v1alpha1.PipelineResourceTypeGit, - tb.ResourceTargetPath("brandnewspace"), - )), - tb.TaskOutputs(outWorkspaceResource), - tb.Step("ubuntu", tb.StepName("write-data-task-0-step-0"), tb.StepCommand("/bin/bash"), - tb.StepArgs("-c", "echo stuff > $(outputs.resources.workspace.path)/stuff"), - ), - tb.Step("ubuntu", tb.StepName("write-data-task-0-step-1"), tb.StepCommand("/bin/bash"), - tb.StepArgs("-c", "echo other > $(outputs.resources.workspace.path)/other"), - ), - )), - tb.Task("check-create-files-exists", tb.TaskSpec( - tb.TaskInputs(inWorkspaceResource), - tb.TaskOutputs(outWorkspaceResource), - tb.Step("ubuntu", tb.StepName("read-from-task-0"), tb.StepCommand("/bin/bash"), - tb.StepArgs("-c", "[[ stuff == $(cat $(inputs.resources.workspace.path)/stuff) ]]"), - ), - tb.Step("ubuntu", tb.StepName("write-data-task-1"), tb.StepCommand("/bin/bash"), - tb.StepArgs("-c", "echo something > $(outputs.resources.workspace.path)/something"), - ), - )), - tb.Task("check-create-files-exists-2", tb.TaskSpec( - tb.TaskInputs(inWorkspaceResource), - tb.TaskOutputs(outWorkspaceResource), - tb.Step("ubuntu", tb.StepName("read-from-task-0"), tb.StepCommand("/bin/bash"), - tb.StepArgs("-c", "[[ other == $(cat $(inputs.resources.workspace.path)/other) ]]"), - ), - tb.Step("ubuntu", tb.StepName("write-data-task-1"), tb.StepCommand("/bin/bash"), - tb.StepArgs("-c", "echo else > $(outputs.resources.workspace.path)/else"), - ), - )), - tb.Task("read-files", tb.TaskSpec( - tb.TaskInputs(tb.InputsResource("workspace", v1alpha1.PipelineResourceTypeGit, - tb.ResourceTargetPath("readingspace"), - )), - tb.Step("ubuntu", tb.StepName("read-from-task-0"), tb.StepCommand("/bin/bash"), - tb.StepArgs("-c", "[[ something == $(cat $(inputs.resources.workspace.path)/something) ]]"), - ), - tb.Step("ubuntu", tb.StepName("read-from-task-1"), tb.StepCommand("/bin/bash"), - tb.StepArgs("-c", "[[ else == $(cat $(inputs.resources.workspace.path)/else) ]]"), - ), - )), + { + ObjectMeta: metav1.ObjectMeta{ + Name: "create-file", + }, + Spec: v1alpha1.TaskSpec{ + Inputs: &v1alpha1.Inputs{ + Resources: []v1alpha1.TaskResource{{ + ResourceDeclaration: v1alpha1.ResourceDeclaration{ + Name: "workspace", + Type: v1alpha1.PipelineResourceTypeGit, + TargetPath: "brandnewspace", + }, + }}, + }, + Outputs: &v1alpha1.Outputs{ + Resources: []v1alpha1.TaskResource{outWorkspaceResource}, + }, + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{ + { + Container: corev1.Container{ + Name: "write-data-task-0-step-0", + Image: "ubuntu", + Command: []string{"/bin/bash"}, + Args: []string{"-c", "echo stuff > $(outputs.resources.workspace.path)/stuff"}, + }, + }, + { + Container: corev1.Container{ + Name: "write-data-task-0-step-1", + Image: "ubuntu", + Command: []string{"/bin/bash"}, + Args: []string{"-c", "echo other > $(outputs.resources.workspace.path)/other"}, + }, + }, + }, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "check-create-files-exists", + }, + Spec: v1alpha1.TaskSpec{ + Inputs: &v1alpha1.Inputs{ + Resources: []v1alpha1.TaskResource{inWorkspaceResource}, + }, + Outputs: &v1alpha1.Outputs{ + Resources: []v1alpha1.TaskResource{outWorkspaceResource}, + }, + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{ + { + Container: corev1.Container{ + Name: "read-from-task-0", + Image: "ubuntu", + Command: []string{"/bin/bash"}, + Args: []string{"-c", "[[ stuff == $(cat $(inputs.resources.workspace.path)/stuff) ]]"}, + }, + }, + { + Container: corev1.Container{ + Name: "write-data-task-1", + Image: "ubuntu", + Command: []string{"/bin/bash"}, + Args: []string{"-c", "echo something > $(outputs.resources.workspace.path)/something"}, + }, + }, + }, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "check-create-files-exists-2", + }, + Spec: v1alpha1.TaskSpec{ + Inputs: &v1alpha1.Inputs{ + Resources: []v1alpha1.TaskResource{inWorkspaceResource}, + }, + Outputs: &v1alpha1.Outputs{ + Resources: []v1alpha1.TaskResource{outWorkspaceResource}, + }, + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{ + { + Container: corev1.Container{ + Name: "read-from-task-0", + Image: "ubuntu", + Command: []string{"/bin/bash"}, + Args: []string{"-c", "[[ other == $(cat $(inputs.resources.workspace.path)/other) ]]"}, + }, + }, + { + Container: corev1.Container{ + Name: "write-data-task-1", + Image: "ubuntu", + Command: []string{"/bin/bash"}, + Args: []string{"-c", "echo else > $(outputs.resources.workspace.path)/else"}, + }, + }, + }, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "read-files", + }, + Spec: v1alpha1.TaskSpec{ + Inputs: &v1alpha1.Inputs{ + Resources: []v1alpha1.TaskResource{{ + ResourceDeclaration: v1alpha1.ResourceDeclaration{ + Name: "workspace", + Type: v1alpha1.PipelineResourceTypeGit, + TargetPath: "readingspace", + }, + }}, + }, + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{ + { + Container: corev1.Container{ + Name: "read-from-task-0", + Image: "ubuntu", + Command: []string{"/bin/bash"}, + Args: []string{"-c", "[[ something == $(cat $(inputs.resources.workspace.path)/something) ]]"}, + }, + }, + { + Container: corev1.Container{ + Name: "read-from-task-0", + Image: "ubuntu", + Command: []string{"/bin/bash"}, + Args: []string{"-c", "[[ else == $(cat $(inputs.resources.workspace.path)/else) ]]"}, + }, + }, + }, + }, + }, + }, } } func getFanInFanOutPipeline(suffix int) *v1alpha1.Pipeline { - outGitResource := tb.PipelineTaskOutputResource("workspace", "git-repo") - - return tb.Pipeline(getName(pipelineName, suffix), tb.PipelineSpec( - tb.PipelineDeclaredResource("git-repo", "git"), - tb.PipelineTask("create-file-kritis", "create-file", - tb.PipelineTaskInputResource("workspace", "git-repo"), - outGitResource, - ), - tb.PipelineTask("create-fan-out-1", "check-create-files-exists", - tb.PipelineTaskInputResource("workspace", "git-repo", tb.From("create-file-kritis")), - outGitResource, - ), - tb.PipelineTask("create-fan-out-2", "check-create-files-exists-2", - tb.PipelineTaskInputResource("workspace", "git-repo", tb.From("create-file-kritis")), - outGitResource, - ), - tb.PipelineTask("check-fan-in", "read-files", - tb.PipelineTaskInputResource("workspace", "git-repo", tb.From("create-fan-out-2", "create-fan-out-1")), - ), - )) + outGitResource := v1alpha1.PipelineTaskOutputResource{ + Name: "workspace", + Resource: "git-repo", + } + + return &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{ + Name: getName(pipelineName, suffix), + }, + Spec: v1alpha1.PipelineSpec{ + Resources: []v1alpha1.PipelineDeclaredResource{{ + Name: "git-repo", + Type: v1alpha1.PipelineResourceTypeGit, + }}, + Tasks: []v1alpha1.PipelineTask{ + { + Name: "create-file-kritis", + TaskRef: &v1alpha1.TaskRef{ + Name: "create-file", + }, + Resources: &v1alpha1.PipelineTaskResources{ + Inputs: []v1alpha1.PipelineTaskInputResource{{ + Name: "workspace", + Resource: "git-repo", + }}, + Outputs: []v1alpha1.PipelineTaskOutputResource{outGitResource}, + }, + }, + { + Name: "create-fan-out-1", + TaskRef: &v1alpha1.TaskRef{ + Name: "check-create-file-exists", + }, + Resources: &v1alpha1.PipelineTaskResources{ + Inputs: []v1alpha1.PipelineTaskInputResource{{ + Name: "workspace", + Resource: "git-repo", + From: []string{"create-file-kritis"}, + }}, + Outputs: []v1alpha1.PipelineTaskOutputResource{outGitResource}, + }, + }, + { + Name: "create-fan-out-2", + TaskRef: &v1alpha1.TaskRef{ + Name: "check-create-file-exists-2", + }, + Resources: &v1alpha1.PipelineTaskResources{ + Inputs: []v1alpha1.PipelineTaskInputResource{{ + Name: "workspace", + Resource: "git-repo", + From: []string{"create-file-kritis"}, + }}, + Outputs: []v1alpha1.PipelineTaskOutputResource{outGitResource}, + }, + }, + { + Name: "check-fan-in", + TaskRef: &v1alpha1.TaskRef{ + Name: "read-files", + }, + Resources: &v1alpha1.PipelineTaskResources{ + Inputs: []v1alpha1.PipelineTaskInputResource{{ + Name: "workspace", + Resource: "git-repo", + From: []string{"create-fan-out-2", "create-fan-out-1"}, + }}, + Outputs: []v1alpha1.PipelineTaskOutputResource{outGitResource}, + }, + }, + }, + }, + } } func getFanInFanOutGitResources() []*v1alpha1.PipelineResource { - return []*v1alpha1.PipelineResource{ - tb.PipelineResource("kritis-resource-git", tb.PipelineResourceSpec( - v1alpha1.PipelineResourceTypeGit, - tb.PipelineResourceSpecParam("Url", "https://github.com/grafeas/kritis"), - tb.PipelineResourceSpecParam("Revision", "master"), - )), - } + return []*v1alpha1.PipelineResource{{ + ObjectMeta: metav1.ObjectMeta{ + Name: "kritis-resource-git", + }, + Spec: v1alpha1.PipelineResourceSpec{ + Type: v1alpha1.PipelineResourceTypeGit, + Params: []v1alpha1.ResourceParam{ + { + Name: "Url", + Value: "https://github.com/grafeas/kritis", + }, + { + Name: "Revision", + Value: "master", + }, + }, + }, + }} } func getPipelineRunServiceAccount(suffix int) *corev1.ServiceAccount { @@ -346,10 +583,25 @@ func getPipelineRunServiceAccount(suffix int) *corev1.ServiceAccount { } } func getFanInFanOutPipelineRun(suffix int, namespace string) *v1alpha1.PipelineRun { - return tb.PipelineRun(getName(pipelineRunName, suffix), tb.PipelineRunNamespace(namespace), - tb.PipelineRunSpec(getName(pipelineName, suffix), - tb.PipelineRunResourceBinding("git-repo", tb.PipelineResourceBindingRef("kritis-resource-git")), - )) + return &v1alpha1.PipelineRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: getName(pipelineRunName, suffix), + Namespace: namespace, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: getName(pipelineName, suffix), + }, + Resources: []v1alpha1.PipelineResourceBinding{ + { + Name: "git-repo", + }, + { + Name: "kritis-resource-git", + }, + }, + }, + } } func getPipelineRunSecret(suffix int) *corev1.Secret { @@ -381,14 +633,31 @@ func getPipelineRunSecret(suffix int) *corev1.Secret { } func getHelloWorldPipelineRun(suffix int, namespace string) *v1alpha1.PipelineRun { - return tb.PipelineRun(getName(pipelineRunName, suffix), tb.PipelineRunNamespace(namespace), - tb.PipelineRunLabel("hello-world-key", "hello-world-value"), - tb.PipelineRunSpec(getName(pipelineName, suffix), - tb.PipelineRunParam("path", "docker://gcr.io/build-crd-testing/secret-sauce"), - tb.PipelineRunParam("dest", "dir:///tmp/"), - tb.PipelineRunServiceAccountName(fmt.Sprintf("%s%d", saName, suffix)), - ), - ) + return &v1alpha1.PipelineRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: getName(pipelineRunName, suffix), + Namespace: namespace, + Labels: map[string]string{ + "hello-world-key": "hello-world-value", + }, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: getName(pipelineName, suffix), + }, + ServiceAccountName: fmt.Sprintf("%s%d", saName, suffix), + Params: []v1alpha1.Param{ + { + Name: "path", + Value: *v1beta1.NewArrayOrString("docker://gcr.io/build-crd-testing/secret-sauce"), + }, + { + Name: "dest", + Value: *v1beta1.NewArrayOrString("dir:///tmp/"), + }, + }, + }, + } } func getName(namespace string, suffix int) string { @@ -551,20 +820,64 @@ func assertAnnotationsMatch(t *testing.T, expectedAnnotations, actualAnnotations } func getPipelineWithFailingCondition(suffix int) *v1alpha1.Pipeline { - return tb.Pipeline(getName(pipelineName, suffix), tb.PipelineSpec( - tb.PipelineTask(task1Name, getName(taskName, suffix), tb.PipelineTaskCondition(cond1Name)), - tb.PipelineTask("task2", getName(taskName, suffix), tb.RunAfter(task1Name)), - )) + return &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{ + Name: getName(pipelineName, suffix), + }, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{ + { + Name: task1Name, + TaskRef: &v1alpha1.TaskRef{ + Name: getName(taskName, suffix), + }, + Conditions: []v1alpha1.PipelineTaskCondition{{ + ConditionRef: cond1Name, + }}, + }, + { + Name: "task2", + TaskRef: &v1alpha1.TaskRef{ + Name: getName(taskName, suffix), + }, + RunAfter: []string{task1Name}, + }, + }, + }, + } } func getFailingCondition(namespace string) *v1alpha1.Condition { - return tb.Condition(cond1Name, tb.ConditionNamespace(namespace), tb.ConditionSpec(tb.ConditionSpecCheck("", "ubuntu", - tb.Command("/bin/bash"), tb.Args("exit 1")))) + return &v1alpha1.Condition{ + ObjectMeta: metav1.ObjectMeta{ + Name: cond1Name, + Namespace: namespace, + }, + Spec: v1alpha1.ConditionSpec{ + Check: v1alpha1.Step{ + Container: corev1.Container{ + Image: "ubuntu", + Command: []string{"/bin/bash"}, + Args: []string{"exit 1"}, + }, + }, + }, + } } func getConditionalPipelineRun(suffix int, namespace string) *v1alpha1.PipelineRun { - return tb.PipelineRun(getName(pipelineRunName, suffix), tb.PipelineRunNamespace(namespace), - tb.PipelineRunLabel("hello-world-key", "hello-world-value"), - tb.PipelineRunSpec(getName(pipelineName, suffix)), - ) + return &v1alpha1.PipelineRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: getName(pipelineRunName, suffix), + Namespace: namespace, + Labels: map[string]string{ + "hello-world-key": "hello-world-value", + }, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: getName(pipelineName, suffix), + }, + }, + } } diff --git a/test/v1alpha1/status_test.go b/test/v1alpha1/status_test.go index bba40b78377..5a72e98577a 100644 --- a/test/v1alpha1/status_test.go +++ b/test/v1alpha1/status_test.go @@ -22,7 +22,10 @@ import ( "context" "testing" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" knativetest "knative.dev/pkg/test" ) @@ -41,15 +44,35 @@ func TestTaskRunPipelineRunStatus(t *testing.T) { defer tearDown(ctx, t, c, namespace) t.Logf("Creating Task and TaskRun in namespace %s", namespace) - task := tb.Task("banana", tb.TaskSpec( - tb.Step("busybox", tb.StepCommand("ls", "-la")), - )) + task := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: "banana", + }, + Spec: v1alpha1.TaskSpec{ + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{{ + Container: corev1.Container{ + Image: "busybox", + Command: []string{"ls", "-la"}, + }, + }}, + }, + }, + } if _, err := c.TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Task: %s", err) } - taskRun := tb.TaskRun("apple", tb.TaskRunSpec( - tb.TaskRunTaskRef("banana"), tb.TaskRunServiceAccountName("inexistent"), - )) + taskRun := &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "apple", + }, + Spec: v1alpha1.TaskRunSpec{ + ServiceAccountName: "inexistent", + TaskRef: &v1alpha1.TaskRef{ + Name: "banana", + }, + }, + } if _, err := c.TaskRunClient.Create(ctx, taskRun, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create TaskRun: %s", err) } @@ -59,12 +82,32 @@ func TestTaskRunPipelineRunStatus(t *testing.T) { t.Errorf("Error waiting for TaskRun to finish: %s", err) } - pipeline := tb.Pipeline("tomatoes", - tb.PipelineSpec(tb.PipelineTask("foo", "banana")), - ) - pipelineRun := tb.PipelineRun("pear", tb.PipelineRunSpec( - "tomatoes", tb.PipelineRunServiceAccountName("inexistent"), - )) + pipeline := &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{ + Name: "tomatoes", + }, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{ + { + Name: "foo", + }, + { + Name: "banana", + }, + }, + }, + } + pipelineRun := &v1alpha1.PipelineRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: "pear", + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: "tomatoes", + }, + ServiceAccountName: "inexistent", + }, + } if _, err := c.PipelineClient.Create(ctx, pipeline, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Pipeline `%s`: %s", "tomatoes", err) } diff --git a/test/v1alpha1/taskrun_test.go b/test/v1alpha1/taskrun_test.go index 1dfbbcb90ef..f420a664aa7 100644 --- a/test/v1alpha1/taskrun_test.go +++ b/test/v1alpha1/taskrun_test.go @@ -23,9 +23,10 @@ import ( "strings" "testing" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -45,23 +46,51 @@ func TestTaskRunFailure(t *testing.T) { taskRunName := "failing-taskrun" t.Logf("Creating Task and TaskRun in namespace %s", namespace) - task := tb.Task("failing-task", tb.TaskSpec( - tb.Step("busybox", - tb.StepCommand("/bin/sh"), tb.StepArgs("-c", "echo hello"), - ), - tb.Step("busybox", - tb.StepCommand("/bin/sh"), tb.StepArgs("-c", "exit 1"), - ), - tb.Step("busybox", - tb.StepCommand("/bin/sh"), tb.StepArgs("-c", "sleep 30s"), - ), - )) + task := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: "failing-task", + }, + Spec: v1alpha1.TaskSpec{ + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{ + { + Container: corev1.Container{ + Image: "busybox", + Command: []string{"/bin/sh"}, + Args: []string{"-c", "echo hello"}, + }, + }, + { + Container: corev1.Container{ + Image: "busybox", + Command: []string{"/bin/sh"}, + Args: []string{"-c", "exit 1"}, + }, + }, + { + Container: corev1.Container{ + Image: "busybox", + Command: []string{"/bin/sh"}, + Args: []string{"-c", "sleep 30s"}, + }, + }, + }, + }, + }, + } if _, err := c.TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Task: %s", err) } - taskRun := tb.TaskRun(taskRunName, tb.TaskRunSpec( - tb.TaskRunTaskRef("failing-task"), - )) + taskRun := &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: taskRunName, + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: "failing-task", + }, + }, + } if _, err := c.TaskRunClient.Create(ctx, taskRun, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create TaskRun: %s", err) } @@ -125,18 +154,35 @@ func TestTaskRunStatus(t *testing.T) { fqImageName := "busybox@sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649" t.Logf("Creating Task and TaskRun in namespace %s", namespace) - task := tb.Task("status-task", tb.TaskSpec( - // This was the digest of the latest tag as of 8/12/2019 - tb.Step("busybox@sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649", - tb.StepCommand("/bin/sh"), tb.StepArgs("-c", "echo hello"), - ), - )) + task := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: "status-task", + }, + Spec: v1alpha1.TaskSpec{ + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{{ + Container: corev1.Container{ + Image: "busybox@sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649", + Command: []string{"/bin/sh"}, + Args: []string{"-c", "echo hello"}, + }, + }}, + }, + }, + } if _, err := c.TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Task: %s", err) } - taskRun := tb.TaskRun(taskRunName, tb.TaskRunSpec( - tb.TaskRunTaskRef("status-task"), - )) + taskRun := &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: taskRunName, + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: "status-task", + }, + }, + } if _, err := c.TaskRunClient.Create(ctx, taskRun, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create TaskRun: %s", err) } diff --git a/test/v1alpha1/timeout_test.go b/test/v1alpha1/timeout_test.go index 5d68f08559e..391c1533f1b 100644 --- a/test/v1alpha1/timeout_test.go +++ b/test/v1alpha1/timeout_test.go @@ -25,7 +25,8 @@ import ( "testing" "time" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -47,18 +48,51 @@ func TestPipelineRunTimeout(t *testing.T) { defer tearDown(context.Background(), t, c, namespace) t.Logf("Creating Task in namespace %s", namespace) - task := tb.Task(helpers.ObjectNameForTest(t), tb.TaskSpec( - tb.Step("busybox", tb.StepCommand("/bin/sh"), tb.StepArgs("-c", "sleep 10")))) + task := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: helpers.ObjectNameForTest(t), + }, + Spec: v1alpha1.TaskSpec{ + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{{ + Container: corev1.Container{ + Image: "busybox", + Command: []string{"/bin/sh"}, + Args: []string{"-c", "sleep 10"}, + }, + }}, + }, + }, + } + if _, err := c.TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Task %q: %s", task.Name, err) } - pipeline := tb.Pipeline(helpers.ObjectNameForTest(t), - tb.PipelineSpec(tb.PipelineTask("foo", task.Name)), - ) - pipelineRun := tb.PipelineRun(helpers.ObjectNameForTest(t), tb.PipelineRunSpec(pipeline.Name, - tb.PipelineRunTimeout(5*time.Second), - )) + pipeline := &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{ + Name: helpers.ObjectNameForTest(t), + }, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{{ + Name: "foo", + TaskRef: &v1alpha1.TaskRef{ + Name: task.Name, + }, + }}, + }, + } + pipelineRun := &v1alpha1.PipelineRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: helpers.ObjectNameForTest(t), + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: pipeline.Name, + }, + Timeout: &metav1.Duration{Duration: 5 * time.Second}, + }, + } if _, err := c.PipelineClient.Create(ctx, pipeline, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Pipeline `%s`: %s", pipeline.Name, err) } @@ -122,9 +156,29 @@ func TestPipelineRunTimeout(t *testing.T) { // Verify that we can create a second Pipeline using the same Task without a Pipeline-level timeout that will not // time out - secondPipeline := tb.Pipeline(helpers.ObjectNameForTest(t), - tb.PipelineSpec(tb.PipelineTask("foo", task.Name))) - secondPipelineRun := tb.PipelineRun(helpers.ObjectNameForTest(t), tb.PipelineRunSpec(secondPipeline.Name)) + secondPipeline := &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{ + Name: helpers.ObjectNameForTest(t), + }, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{{ + Name: "foo", + TaskRef: &v1alpha1.TaskRef{ + Name: task.Name, + }, + }}, + }, + } + secondPipelineRun := &v1alpha1.PipelineRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: helpers.ObjectNameForTest(t), + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: pipeline.Name, + }, + }, + } if _, err := c.PipelineClient.Create(ctx, secondPipeline, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Pipeline `%s`: %s", secondPipeline.Name, err) } @@ -149,16 +203,37 @@ func TestTaskRunTimeout(t *testing.T) { defer tearDown(context.Background(), t, c, namespace) t.Logf("Creating Task and TaskRun in namespace %s", namespace) - task := tb.Task(helpers.ObjectNameForTest(t), - tb.TaskSpec(tb.Step("busybox", tb.StepCommand("/bin/sh"), tb.StepArgs("-c", "sleep 3000")))) + task := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: helpers.ObjectNameForTest(t), + }, + Spec: v1alpha1.TaskSpec{ + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{{ + Container: corev1.Container{ + Image: "busybox", + Command: []string{"/bin/sh"}, + Args: []string{"-c", "sleep 3000"}, + }, + }}, + }, + }, + } if _, err := c.TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Task `%s`: %s", task.Name, err) } - taskRun := tb.TaskRun(helpers.ObjectNameForTest(t), tb.TaskRunSpec(tb.TaskRunTaskRef(task.Name), - // Do not reduce this timeout. Taskrun e2e test is also verifying - // if reconcile is triggered from timeout handler and not by pod informers - tb.TaskRunTimeout(30*time.Second))) + taskRun := &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: helpers.ObjectNameForTest(t), + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: task.Name, + }, + Timeout: &metav1.Duration{Duration: 30 * time.Second}, + }, + } if _, err := c.TaskRunClient.Create(ctx, taskRun, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create TaskRun `%s`: %s", taskRun.Name, err) } @@ -179,11 +254,38 @@ func TestPipelineTaskTimeout(t *testing.T) { defer tearDown(context.Background(), t, c, namespace) t.Logf("Creating Tasks in namespace %s", namespace) - task1 := tb.Task(helpers.ObjectNameForTest(t), tb.TaskSpec( - tb.Step("busybox", tb.StepCommand("sleep"), tb.StepArgs("1s")))) - - task2 := tb.Task(helpers.ObjectNameForTest(t), tb.TaskSpec( - tb.Step("busybox", tb.StepCommand("sleep"), tb.StepArgs("10s")))) + task1 := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: helpers.ObjectNameForTest(t), + }, + Spec: v1alpha1.TaskSpec{ + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{{ + Container: corev1.Container{ + Image: "busybox", + Command: []string{"sleep"}, + Args: []string{"1s"}, + }, + }}, + }, + }, + } + task2 := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: helpers.ObjectNameForTest(t), + }, + Spec: v1alpha1.TaskSpec{ + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{{ + Container: corev1.Container{ + Image: "busybox", + Command: []string{"sleep"}, + Args: []string{"10s"}, + }, + }}, + }, + }, + } if _, err := c.TaskClient.Create(ctx, task1, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Task `%s`: %s", task1.Name, err) @@ -192,14 +294,39 @@ func TestPipelineTaskTimeout(t *testing.T) { t.Fatalf("Failed to create Task `%s`: %s", task2.Name, err) } - pipeline := tb.Pipeline(helpers.ObjectNameForTest(t), - tb.PipelineSpec( - tb.PipelineTask("pipelinetask1", task1.Name, tb.PipelineTaskTimeout(60*time.Second)), - tb.PipelineTask("pipelinetask2", task2.Name, tb.PipelineTaskTimeout(5*time.Second)), - ), - ) - - pipelineRun := tb.PipelineRun(helpers.ObjectNameForTest(t), tb.PipelineRunSpec(pipeline.Name)) + pipeline := &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{ + Name: helpers.ObjectNameForTest(t), + }, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{ + { + Name: "pipelinetask1", + TaskRef: &v1alpha1.TaskRef{ + Name: task1.Name, + }, + Timeout: &metav1.Duration{Duration: 60 * time.Second}, + }, + { + Name: "pipelinetask2", + TaskRef: &v1alpha1.TaskRef{ + Name: task2.Name, + }, + Timeout: &metav1.Duration{Duration: 5 * time.Second}, + }, + }, + }, + } + pipelineRun := &v1alpha1.PipelineRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: helpers.ObjectNameForTest(t), + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: pipeline.Name, + }, + }, + } if _, err := c.PipelineClient.Create(ctx, pipeline, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Pipeline `%s`: %s", pipeline.Name, err) diff --git a/test/v1alpha1/workingdir_test.go b/test/v1alpha1/workingdir_test.go index 1909b50662a..248efbc564a 100644 --- a/test/v1alpha1/workingdir_test.go +++ b/test/v1alpha1/workingdir_test.go @@ -23,7 +23,9 @@ import ( "strings" "testing" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" knativetest "knative.dev/pkg/test" @@ -44,17 +46,38 @@ func TestWorkingDirCreated(t *testing.T) { knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf) defer tearDown(ctx, t, c, namespace) - task := tb.Task(wdTaskName, tb.TaskSpec( - tb.Step("ubuntu", tb.StepWorkingDir("/workspace/HELLOMOTO"), tb.StepArgs("-c", "echo YES")), - )) + task := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: wdTaskName, + }, + Spec: v1alpha1.TaskSpec{ + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{{ + Container: corev1.Container{ + Image: "ubuntu", + WorkingDir: "/workspace/HELLOMOTO", + Args: []string{"-c", "echo YES"}, + }, + }}, + }, + }, + } if _, err := c.TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Task: %s", err) } t.Logf("Creating TaskRun namespace %s", namespace) - taskRun := tb.TaskRun(wdTaskRunName, tb.TaskRunSpec( - tb.TaskRunTaskRef(wdTaskName), tb.TaskRunServiceAccountName("default"), - )) + taskRun := &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: wdTaskRunName, + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: wdTaskName, + }, + ServiceAccountName: "default", + }, + } if _, err := c.TaskRunClient.Create(ctx, taskRun, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create TaskRun: %s", err) } @@ -101,17 +124,38 @@ func TestWorkingDirIgnoredNonSlashWorkspace(t *testing.T) { knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf) defer tearDown(ctx, t, c, namespace) - task := tb.Task(wdTaskName, tb.TaskSpec( - tb.Step("ubuntu", tb.StepWorkingDir("/HELLOMOTO"), tb.StepArgs("-c", "echo YES")), - )) + task := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: wdTaskName, + }, + Spec: v1alpha1.TaskSpec{ + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{{ + Container: corev1.Container{ + Image: "ubuntu", + WorkingDir: "/HELLOMOTO", + Args: []string{"-c", "echo YES"}, + }, + }}, + }, + }, + } if _, err := c.TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Task: %s", err) } t.Logf("Creating TaskRun namespace %s", namespace) - taskRun := tb.TaskRun(wdTaskRunName, tb.TaskRunSpec( - tb.TaskRunTaskRef(wdTaskName), tb.TaskRunServiceAccountName("default"), - )) + taskRun := &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: wdTaskRunName, + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: wdTaskName, + }, + ServiceAccountName: "default", + }, + } if _, err := c.TaskRunClient.Create(ctx, taskRun, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create TaskRun: %s", err) } diff --git a/test/v1alpha1/workspace_test.go b/test/v1alpha1/workspace_test.go index 11b3dc311ab..c2eee18fd05 100644 --- a/test/v1alpha1/workspace_test.go +++ b/test/v1alpha1/workspace_test.go @@ -24,7 +24,9 @@ import ( "testing" "time" - tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" knativetest "knative.dev/pkg/test" @@ -42,18 +44,47 @@ func TestWorkspaceReadOnlyDisallowsWrite(t *testing.T) { knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf) defer tearDown(ctx, t, c, namespace) - task := tb.Task(taskName, tb.TaskSpec( - tb.Step("alpine", tb.StepScript("echo foo > /workspace/test/file")), - tb.TaskWorkspace("test", "test workspace", "/workspace/test", true), - )) + task := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: taskName, + }, + Spec: v1alpha1.TaskSpec{ + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{{ + Container: corev1.Container{ + Image: "alpine", + }, + Script: "echo foo > /workspace/test/file", + }}, + Workspaces: []v1alpha1.WorkspaceDeclaration{{ + Name: "test", + Description: "test workspace", + MountPath: "/workspace/test", + ReadOnly: true, + }}, + }, + }, + } if _, err := c.TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Task: %s", err) } - taskRun := tb.TaskRun(taskRunName, tb.TaskRunSpec( - tb.TaskRunTaskRef(taskName), tb.TaskRunServiceAccountName("default"), - tb.TaskRunWorkspaceEmptyDir("test", ""), - )) + taskRun := &v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: taskRunName, + }, + Spec: v1alpha1.TaskRunSpec{ + TaskRef: &v1alpha1.TaskRef{ + Name: taskName, + }, + ServiceAccountName: "default", + Workspaces: []v1alpha1.WorkspaceBinding{{ + Name: "test", + SubPath: "", + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }}, + }, + } if _, err := c.TaskRunClient.Create(ctx, taskRun, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create TaskRun: %s", err) } @@ -102,30 +133,73 @@ func TestWorkspacePipelineRunDuplicateWorkspaceEntriesInvalid(t *testing.T) { knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf) defer tearDown(ctx, t, c, namespace) - task := tb.Task(taskName, tb.TaskSpec( - tb.Step("alpine", tb.StepScript("cat /workspace/test/file")), - tb.TaskWorkspace("test", "test workspace", "/workspace/test/file", true), - )) + task := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: taskName, + }, + Spec: v1alpha1.TaskSpec{ + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{{ + Container: corev1.Container{ + Image: "alpine", + }, + Script: "cat /workspace/test/file", + }}, + Workspaces: []v1alpha1.WorkspaceDeclaration{{ + Name: "test", + Description: "test workspace", + MountPath: "/workspace/test/file", + ReadOnly: true, + }}, + }, + }, + } if _, err := c.TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Task: %s", err) } - pipeline := tb.Pipeline(pipelineName, tb.PipelineSpec( - tb.PipelineWorkspaceDeclaration("foo"), - tb.PipelineTask("task1", taskName, tb.PipelineTaskWorkspaceBinding("test", "foo", "")), - )) + pipeline := &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{ + Name: pipelineName, + }, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{{ + TaskRef: &v1alpha1.TaskRef{ + Name: taskName, + }, + Name: taskName, + Workspaces: []v1alpha1.WorkspacePipelineTaskBinding{{ + Name: "test", + Workspace: "foo", + SubPath: "", + }}, + }}, + }, + } if _, err := c.PipelineClient.Create(ctx, pipeline, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Pipeline: %s", err) } - pipelineRun := tb.PipelineRun(pipelineRunName, - tb.PipelineRunSpec( - pipelineName, - // These are the duplicated workspace entries that are being tested. - tb.PipelineRunWorkspaceBindingEmptyDir("foo"), - tb.PipelineRunWorkspaceBindingEmptyDir("foo"), - ), - ) + pipelineRun := &v1alpha1.PipelineRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: pipelineRunName, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: pipelineName, + }, + Workspaces: []v1alpha1.WorkspaceBinding{ + { + Name: "foo", + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + { + Name: "foo", + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + }, + } _, err := c.PipelineRunClient.Create(ctx, pipelineRun, metav1.CreateOptions{}) if err == nil || !strings.Contains(err.Error(), "provided by pipelinerun more than once") { @@ -146,27 +220,63 @@ func TestWorkspacePipelineRunMissingWorkspaceInvalid(t *testing.T) { knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf) defer tearDown(ctx, t, c, namespace) - task := tb.Task(taskName, tb.TaskSpec( - tb.Step("alpine", tb.StepScript("cat /workspace/test/file")), - tb.TaskWorkspace("test", "test workspace", "/workspace/test/file", true), - )) + task := &v1alpha1.Task{ + ObjectMeta: metav1.ObjectMeta{ + Name: taskName, + }, + Spec: v1alpha1.TaskSpec{ + TaskSpec: v1beta1.TaskSpec{ + Steps: []v1alpha1.Step{{ + Container: corev1.Container{ + Image: "alpine", + }, + Script: "cat /workspace/test/file", + }}, + Workspaces: []v1alpha1.WorkspaceDeclaration{{ + Name: "test", + Description: "test workspace", + MountPath: "/workspace/test/file", + ReadOnly: true, + }}, + }, + }, + } if _, err := c.TaskClient.Create(ctx, task, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Task: %s", err) } - pipeline := tb.Pipeline(pipelineName, tb.PipelineSpec( - tb.PipelineWorkspaceDeclaration("foo"), - tb.PipelineTask("task1", taskName, tb.PipelineTaskWorkspaceBinding("test", "foo", "")), - )) + pipeline := &v1alpha1.Pipeline{ + ObjectMeta: metav1.ObjectMeta{ + Name: pipelineName, + }, + Spec: v1alpha1.PipelineSpec{ + Tasks: []v1alpha1.PipelineTask{{ + TaskRef: &v1alpha1.TaskRef{ + Name: taskName, + }, + Name: taskName, + Workspaces: []v1alpha1.WorkspacePipelineTaskBinding{{ + Name: "test", + Workspace: "foo", + SubPath: "", + }}, + }}, + }, + } if _, err := c.PipelineClient.Create(ctx, pipeline, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create Pipeline: %s", err) } - pipelineRun := tb.PipelineRun(pipelineRunName, - tb.PipelineRunSpec( - pipelineName, - ), - ) + pipelineRun := &v1alpha1.PipelineRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: pipelineRunName, + }, + Spec: v1alpha1.PipelineRunSpec{ + PipelineRef: &v1alpha1.PipelineRef{ + Name: pipelineName, + }, + }, + } if _, err := c.PipelineRunClient.Create(ctx, pipelineRun, metav1.CreateOptions{}); err != nil { t.Fatalf("Failed to create PipelineRun: %s", err) }