Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tekton-owned Step, StepTemplate, and Sidecar #4778

Merged
merged 1 commit into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require (
cloud.google.com/go/compute v1.5.0 // indirect
contrib.go.opencensus.io/exporter/ocagent v0.7.1-0.20200907061046-05415f1de66d // indirect
contrib.go.opencensus.io/exporter/prometheus v0.4.0 // indirect
github.com/Azure/azure-sdk-for-go v62.0.0+incompatible // indirect
github.com/Azure/azure-sdk-for-go v63.3.0+incompatible // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.24 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.18 // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1alpha1/cluster_task_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func TestClusterTaskConversion(t *testing.T) {
},
Spec: TaskSpec{
TaskSpec: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{Container: corev1.Container{
Steps: []v1beta1.Step{{
Image: "foo",
}}},
}},
Volumes: []corev1.Volume{{}},
Params: []v1beta1.ParamSpec{{
Name: "param-1",
Expand Down
23 changes: 9 additions & 14 deletions pkg/apis/pipeline/v1alpha1/condition_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/test/diff"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
)
Expand All @@ -33,10 +32,10 @@ func TestCondition_Validate(t *testing.T) {
c := v1alpha1.Condition{
ObjectMeta: metav1.ObjectMeta{Name: "condname"},
Spec: v1alpha1.ConditionSpec{
Check: v1alpha1.Step{Container: corev1.Container{
Check: v1alpha1.Step{
Name: "cname",
Image: "ubuntu",
}},
},
Params: []v1alpha1.ParamSpec{{
Name: "paramname",
Type: v1alpha1.ParamTypeString,
Expand Down Expand Up @@ -67,9 +66,9 @@ func TestCondition_Invalid(t *testing.T) {
cond: &v1alpha1.Condition{
ObjectMeta: metav1.ObjectMeta{Name: "condname"},
Spec: v1alpha1.ConditionSpec{
Check: v1alpha1.Step{Container: corev1.Container{
Check: v1alpha1.Step{
Image: "",
}},
},
},
},
expectedError: apis.FieldError{
Expand All @@ -82,11 +81,9 @@ func TestCondition_Invalid(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: "condname"},
Spec: v1alpha1.ConditionSpec{
Check: v1alpha1.Step{
Container: corev1.Container{
Image: "image",
Command: []string{"exit", "0"},
},
Script: "echo foo",
Image: "image",
Command: []string{"exit", "0"},
Script: "echo foo",
},
},
},
Expand All @@ -100,10 +97,8 @@ func TestCondition_Invalid(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: "condname"},
Spec: v1alpha1.ConditionSpec{
Check: v1alpha1.Step{
Container: corev1.Container{
Name: "Cname",
Image: "image",
},
Name: "Cname",
Image: "image",
},
},
},
Expand Down
3 changes: 1 addition & 2 deletions pkg/apis/pipeline/v1alpha1/container_replacements.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ package v1alpha1

import (
"github.com/tektoncd/pipeline/pkg/substitution"
corev1 "k8s.io/api/core/v1"
)

// ApplyContainerReplacements replaces ${...} expressions in the container's name, image, args, env, command, workingDir,
// and volumes.
func ApplyContainerReplacements(step *corev1.Container, stringReplacements map[string]string, arrayReplacements map[string][]string) {
func ApplyContainerReplacements(step *Step, stringReplacements map[string]string, arrayReplacements map[string][]string) {
step.Name = substitution.ApplyReplacements(step.Name, stringReplacements)
step.Image = substitution.ApplyReplacements(step.Image, stringReplacements)

Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/pipeline/v1alpha1/container_replacements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestApplyContainerReplacements(t *testing.T) {
"array.replace.me": {"val1", "val2"},
}

s := corev1.Container{
s := v1alpha1.Step{
Name: "$(replace.me)",
Image: "$(replace.me)",
Command: []string{"$(array.replace.me)"},
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestApplyContainerReplacements(t *testing.T) {
}},
}

expected := corev1.Container{
expected := v1alpha1.Step{
Name: "replaced!",
Image: "replaced!",
Command: []string{"val1", "val2"},
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestApplyContainerReplacements(t *testing.T) {
}

func TestApplyContainerReplacements_NotDefined(t *testing.T) {
s := corev1.Container{
s := v1alpha1.Step{
Name: "$(params.not.defined)",
}
replacements := map[string]string{
Expand All @@ -138,7 +138,7 @@ func TestApplyContainerReplacements_NotDefined(t *testing.T) {
"array.replace.me": {"val1", "val2"},
}

expected := corev1.Container{
expected := v1alpha1.Step{
Name: "$(params.not.defined)",
}
v1alpha1.ApplyContainerReplacements(&s, replacements, arrayReplacements)
Expand Down
9 changes: 4 additions & 5 deletions pkg/apis/pipeline/v1alpha1/pipeline_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1"
"github.com/tektoncd/pipeline/test/diff"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
)
Expand Down Expand Up @@ -105,9 +104,9 @@ func TestPipelineConversion_Success(t *testing.T) {
}, {
Name: "task2",
TaskSpec: &TaskSpec{TaskSpec: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{Container: corev1.Container{
Steps: []v1beta1.Step{{
Image: "foo",
}}},
}},
}},
RunAfter: []string{"task1"},
}},
Expand Down Expand Up @@ -162,9 +161,9 @@ func TestPipelineConversion_Failure(t *testing.T) {
Name: "task2",
TaskSpec: &TaskSpec{
TaskSpec: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{Container: corev1.Container{
Steps: []v1beta1.Step{{
Image: "foo",
}}},
}},
Resources: &v1beta1.TaskResources{
Inputs: []v1beta1.TaskResource{{ResourceDeclaration: v1beta1.ResourceDeclaration{
Name: "input-1",
Expand Down
9 changes: 4 additions & 5 deletions pkg/apis/pipeline/v1alpha1/pipeline_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -157,10 +156,10 @@ func TestPipeline_Validate(t *testing.T) {
Name: "foo",
TaskRef: &v1alpha1.TaskRef{Name: "foo-task"},
TaskSpec: &v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{
Steps: []v1alpha1.Step{{Container: corev1.Container{
Steps: []v1alpha1.Step{{
Name: "foo",
Image: "bar",
}}},
}},
}},
}},
},
Expand All @@ -186,10 +185,10 @@ func TestPipeline_Validate(t *testing.T) {
Tasks: []v1alpha1.PipelineTask{{
Name: "foo",
TaskSpec: &v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{
Steps: []v1alpha1.Step{{Container: corev1.Container{
Steps: []v1alpha1.Step{{
Name: "foo",
Image: "bar",
}}},
}},
}},
}},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1alpha1/pipelinerun_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ func TestPipelineRunConversion(t *testing.T) {
}, {
Name: "task2",
TaskSpec: &TaskSpec{TaskSpec: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{Container: corev1.Container{
Steps: []v1beta1.Step{{
Image: "foo",
}}},
}},
}},
RunAfter: []string{"task1"},
}},
Expand Down
26 changes: 9 additions & 17 deletions pkg/apis/pipeline/v1alpha1/resource_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import (
)

var (
prependStep = corev1.Container{
prependStep = v1alpha1.Step{
Name: "prepend-step",
Image: "dummy",
Command: []string{"doit"},
Args: []string{"stuff", "things"},
}
appendStep = corev1.Container{
appendStep = v1alpha1.Step{
Name: "append-step",
Image: "dummy",
Command: []string{"doit"},
Expand All @@ -47,15 +47,11 @@ var (
type TestTaskModifier struct{}

func (tm *TestTaskModifier) GetStepsToPrepend() []v1alpha1.Step {
return []v1alpha1.Step{{
Container: prependStep,
}}
return []v1alpha1.Step{prependStep}
}

func (tm *TestTaskModifier) GetStepsToAppend() []v1alpha1.Step {
return []v1alpha1.Step{{
Container: appendStep,
}}
return []v1alpha1.Step{appendStep}
}

func (tm *TestTaskModifier) GetVolumes() []corev1.Volume {
Expand Down Expand Up @@ -84,11 +80,7 @@ func TestApplyTaskModifier(t *testing.T) {
}

expectedTaskSpec := v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{
Steps: []v1alpha1.Step{{
Container: prependStep,
}, {
Container: appendStep,
}},
Steps: []v1alpha1.Step{prependStep, appendStep},
Volumes: []corev1.Volume{
volume,
},
Expand All @@ -108,22 +100,22 @@ func TestApplyTaskModifier_AlreadyAdded(t *testing.T) {
}{{
name: "prepend already added",
ts: v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{
Steps: []v1alpha1.Step{{Container: prependStep}},
Steps: []v1alpha1.Step{prependStep},
}},
}, {
name: "append already added",
ts: v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{
Steps: []v1alpha1.Step{{Container: appendStep}},
Steps: []v1alpha1.Step{appendStep},
}},
}, {
name: "both steps already added",
ts: v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{
Steps: []v1alpha1.Step{{Container: prependStep}, {Container: appendStep}},
Steps: []v1alpha1.Step{prependStep, appendStep},
}},
}, {
name: "both steps already added reverse order",
ts: v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{
Steps: []v1alpha1.Step{{Container: appendStep}, {Container: prependStep}},
Steps: []v1alpha1.Step{appendStep, prependStep},
}},
}, {
name: "volume with same name but diff content already added",
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1alpha1/step_replacements.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ import (
// ApplyStepReplacements applies variable interpolation on a Step.
func ApplyStepReplacements(step *Step, stringReplacements map[string]string, arrayReplacements map[string][]string) {
step.Script = substitution.ApplyReplacements(step.Script, stringReplacements)
ApplyContainerReplacements(&step.Container, stringReplacements, arrayReplacements)
ApplyContainerReplacements(step, stringReplacements, arrayReplacements)
}
Loading