Skip to content

Commit

Permalink
Add Tekton-owned Container struct
Browse files Browse the repository at this point in the history
This commit copies the Container struct from Kubernetes into Tekton, and
replaces Task.Step.Container, Task.Sidecar.Container, and Task.StepTemplate
with this new struct. This change breaks the Tekton Go libraries, but does not
require any changes to the yaml that users provide. This should not change anything
for users who do not use the Go libraries.

The reason for this change is to have more control over our Task API. For example,
we may want to modify the Container fields we support, or change fields to string types
to allow them to be parameterized. This commit is the first step towards being able to make changes
to parts of the Task API embedded in Container.
  • Loading branch information
lbernick committed Apr 28, 2022
1 parent 2b85382 commit 1739621
Show file tree
Hide file tree
Showing 71 changed files with 2,238 additions and 746 deletions.
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.

2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1alpha1/cluster_task_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestClusterTaskConversion(t *testing.T) {
},
Spec: TaskSpec{
TaskSpec: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{Container: corev1.Container{
Steps: []v1beta1.Step{{StepContainer: Container{
Image: "foo",
}}},
Volumes: []corev1.Volume{{}},
Expand Down
9 changes: 4 additions & 5 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,7 +32,7 @@ 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{StepContainer: v1alpha1.Container{
Name: "cname",
Image: "ubuntu",
}},
Expand Down Expand Up @@ -67,7 +66,7 @@ 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{StepContainer: v1alpha1.Container{
Image: "",
}},
},
Expand All @@ -82,7 +81,7 @@ func TestCondition_Invalid(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: "condname"},
Spec: v1alpha1.ConditionSpec{
Check: v1alpha1.Step{
Container: corev1.Container{
StepContainer: v1alpha1.Container{
Image: "image",
Command: []string{"exit", "0"},
},
Expand All @@ -100,7 +99,7 @@ func TestCondition_Invalid(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: "condname"},
Spec: v1alpha1.ConditionSpec{
Check: v1alpha1.Step{
Container: corev1.Container{
StepContainer: v1alpha1.Container{
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 *Container, 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.Container{
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.Container{
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.Container{
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.Container{
Name: "$(params.not.defined)",
}
v1alpha1.ApplyContainerReplacements(&s, replacements, arrayReplacements)
Expand Down
5 changes: 2 additions & 3 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,7 +104,7 @@ func TestPipelineConversion_Success(t *testing.T) {
}, {
Name: "task2",
TaskSpec: &TaskSpec{TaskSpec: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{Container: corev1.Container{
Steps: []v1beta1.Step{{StepContainer: Container{
Image: "foo",
}}},
}},
Expand Down Expand Up @@ -162,7 +161,7 @@ func TestPipelineConversion_Failure(t *testing.T) {
Name: "task2",
TaskSpec: &TaskSpec{
TaskSpec: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{Container: corev1.Container{
Steps: []v1beta1.Step{{StepContainer: Container{
Image: "foo",
}}},
Resources: &v1beta1.TaskResources{
Expand Down
5 changes: 2 additions & 3 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,7 +156,7 @@ 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{{StepContainer: v1alpha1.Container{
Name: "foo",
Image: "bar",
}}},
Expand Down Expand Up @@ -186,7 +185,7 @@ 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{{StepContainer: v1alpha1.Container{
Name: "foo",
Image: "bar",
}}},
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1alpha1/pipelinerun_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestPipelineRunConversion(t *testing.T) {
}, {
Name: "task2",
TaskSpec: &TaskSpec{TaskSpec: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{Container: corev1.Container{
Steps: []v1beta1.Step{{StepContainer: Container{
Image: "foo",
}}},
}},
Expand Down
20 changes: 10 additions & 10 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.Container{
Name: "prepend-step",
Image: "dummy",
Command: []string{"doit"},
Args: []string{"stuff", "things"},
}
appendStep = corev1.Container{
appendStep = v1alpha1.Container{
Name: "append-step",
Image: "dummy",
Command: []string{"doit"},
Expand All @@ -48,13 +48,13 @@ type TestTaskModifier struct{}

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

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

Expand Down Expand Up @@ -85,9 +85,9 @@ func TestApplyTaskModifier(t *testing.T) {

expectedTaskSpec := v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{
Steps: []v1alpha1.Step{{
Container: prependStep,
StepContainer: prependStep,
}, {
Container: appendStep,
StepContainer: appendStep,
}},
Volumes: []corev1.Volume{
volume,
Expand All @@ -108,22 +108,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{{StepContainer: prependStep}},
}},
}, {
name: "append already added",
ts: v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{
Steps: []v1alpha1.Step{{Container: appendStep}},
Steps: []v1alpha1.Step{{StepContainer: appendStep}},
}},
}, {
name: "both steps already added",
ts: v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{
Steps: []v1alpha1.Step{{Container: prependStep}, {Container: appendStep}},
Steps: []v1alpha1.Step{{StepContainer: prependStep}, {StepContainer: appendStep}},
}},
}, {
name: "both steps already added reverse order",
ts: v1alpha1.TaskSpec{TaskSpec: v1beta1.TaskSpec{
Steps: []v1alpha1.Step{{Container: appendStep}, {Container: prependStep}},
Steps: []v1alpha1.Step{{StepContainer: appendStep}, {StepContainer: 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.StepContainer, stringReplacements, arrayReplacements)
}
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1alpha1/step_replacements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestApplyStepReplacements(t *testing.T) {

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

expected := v1alpha1.Step{
Script: "replaced!",
Container: corev1.Container{
StepContainer: v1alpha1.Container{
Name: "replaced!",
Image: "replaced!",
Command: []string{"val1", "val2"},
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1alpha1/task_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestTaskConversion(t *testing.T) {
Spec: TaskSpec{
TaskSpec: v1beta1.TaskSpec{
Description: "test",
Steps: []v1beta1.Step{{Container: corev1.Container{
Steps: []v1beta1.Step{{StepContainer: Container{
Image: "foo",
}}},
Volumes: []corev1.Volume{{}},
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/pipeline/v1alpha1/task_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ type Step = v1beta1.Step
// Sidecar has nearly the same data structure as Step, consisting of a Container and an optional Script, but does not have the ability to timeout.
type Sidecar = v1beta1.Sidecar

// Container describes a container which runs a Step or Sidecar
type Container = v1beta1.StepContainer

// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1alpha1/task_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (ts *TaskSpec) Validate(ctx context.Context) *apis.FieldError {
// validateDeclaredWorkspaces will make sure that the declared workspaces do not try to use
// a mount path which conflicts with any other declared workspaces, with the explicitly
// declared volume mounts, or with the stepTemplate. The names must also be unique.
func validateDeclaredWorkspaces(workspaces []WorkspaceDeclaration, steps []Step, stepTemplate *corev1.Container) *apis.FieldError {
func validateDeclaredWorkspaces(workspaces []WorkspaceDeclaration, steps []Step, stepTemplate *Container) *apis.FieldError {
mountPaths := sets.NewString()
for _, step := range steps {
for _, vm := range step.VolumeMounts {
Expand Down
Loading

0 comments on commit 1739621

Please sign in to comment.