Skip to content

Commit

Permalink
Ensure nop always runs last
Browse files Browse the repository at this point in the history
  • Loading branch information
dicarlo2 committed Apr 3, 2019
1 parent 9428c43 commit 20065bf
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 22 deletions.
5 changes: 0 additions & 5 deletions pkg/reconciler/v1alpha1/taskrun/resources/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ var (
// The container used to initialize credentials before the build runs.
credsImage = flag.String("creds-image", "override-with-creds:latest",
"The container image for preparing our Build's credentials.")
// The container that just prints build successful.
nopImage = flag.String("nop-image", "override-with-nop:latest",
"The container image run at the end of the build to log build success")
)

func makeCredentialInitializer(serviceAccountName, namespace string, kubeclient kubernetes.Interface) (*corev1.Container, []corev1.Volume, error) {
Expand Down Expand Up @@ -220,8 +217,6 @@ func MakePod(taskRun *v1alpha1.TaskRun, taskSpec v1alpha1.TaskSpec, kubeclient k
}
gibberish := hex.EncodeToString(b)

podContainers = append(podContainers, corev1.Container{Name: "nop", Image: *nopImage, Command: []string{"/ko-app/nop"}})

return &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
// We execute the build's pod in the same namespace as where the build was
Expand Down
9 changes: 0 additions & 9 deletions pkg/reconciler/v1alpha1/taskrun/resources/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ import (

var (
ignorePrivateResourceFields = cmpopts.IgnoreUnexported(resource.Quantity{})
nopContainer = corev1.Container{
Name: "nop",
Image: *nopImage,
Command: []string{"/ko-app/nop"},
}
)

func TestMakePod(t *testing.T) {
Expand Down Expand Up @@ -105,7 +100,6 @@ func TestMakePod(t *testing.T) {
VolumeMounts: implicitVolumeMounts,
WorkingDir: workspaceDir,
},
nopContainer,
},
Volumes: implicitVolumes,
},
Expand Down Expand Up @@ -144,7 +138,6 @@ func TestMakePod(t *testing.T) {
VolumeMounts: implicitVolumeMounts,
WorkingDir: workspaceDir,
},
nopContainer,
},
Volumes: implicitVolumesWithSecrets,
},
Expand Down Expand Up @@ -177,7 +170,6 @@ func TestMakePod(t *testing.T) {
VolumeMounts: implicitVolumeMounts,
WorkingDir: workspaceDir,
},
nopContainer,
},
Volumes: implicitVolumes,
},
Expand Down Expand Up @@ -210,7 +202,6 @@ func TestMakePod(t *testing.T) {
VolumeMounts: implicitVolumeMounts,
WorkingDir: workspaceDir,
},
nopContainer,
},
Volumes: implicitVolumes,
},
Expand Down
9 changes: 9 additions & 0 deletions pkg/reconciler/v1alpha1/taskrun/taskrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package taskrun

import (
"context"
"flag"
"fmt"
"reflect"
"time"
Expand Down Expand Up @@ -68,6 +69,12 @@ const (
taskRunControllerName = "TaskRun"
)

var (
// The container that just prints build successful.
nopImage = flag.String("nop-image", "override-with-nop:latest",
"The container image run at the end of the build to log build success")
)

// Reconciler implements controller.Reconciler for Configuration resources.
type Reconciler struct {
*reconciler.Base
Expand Down Expand Up @@ -462,6 +469,8 @@ func (c *Reconciler) createPod(tr *v1alpha1.TaskRun, ts *v1alpha1.TaskSpec, task
return nil, err
}

ts.Steps = append(ts.Steps, corev1.Container{Name: "nop", Image: *nopImage, Command: []string{"/ko-app/nop"}})

ts, err = createRedirectedTaskSpec(c.KubeClientSet, ts, tr, c.cache, c.Logger)
if err != nil {
return nil, fmt.Errorf("couldn't create redirected TaskSpec: %v", err)
Expand Down
80 changes: 72 additions & 8 deletions pkg/reconciler/v1alpha1/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,15 @@ func TestReconcile(t *testing.T) {
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
),
tb.PodContainer("nop", "override-with-nop:latest", tb.Command("/ko-app/nop")),
tb.PodContainer("build-step-nop", "override-with-nop:latest",
tb.Command(entrypointLocation),
tb.WorkingDir(workspaceDir),
tb.Args("-wait_file", "/builder/tools/0", "-post_file", "/builder/tools/1", "-entrypoint", "/ko-app/nop", "--"),
tb.EnvVar("HOME", "/builder/home"),
tb.VolumeMount("tools", "/builder/tools"),
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
),
),
),
}, {
Expand All @@ -339,7 +347,15 @@ func TestReconcile(t *testing.T) {
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
),
tb.PodContainer("nop", "override-with-nop:latest", tb.Command("/ko-app/nop")),
tb.PodContainer("build-step-nop", "override-with-nop:latest",
tb.Command(entrypointLocation),
tb.WorkingDir(workspaceDir),
tb.Args("-wait_file", "/builder/tools/0", "-post_file", "/builder/tools/1", "-entrypoint", "/ko-app/nop", "--"),
tb.EnvVar("HOME", "/builder/home"),
tb.VolumeMount("tools", "/builder/tools"),
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
),
),
),
}, {
Expand Down Expand Up @@ -393,7 +409,15 @@ func TestReconcile(t *testing.T) {
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
),
tb.PodContainer("nop", "override-with-nop:latest", tb.Command("/ko-app/nop")),
tb.PodContainer("build-step-nop", "override-with-nop:latest",
tb.Command(entrypointLocation),
tb.WorkingDir(workspaceDir),
tb.Args("-wait_file", "/builder/tools/2", "-post_file", "/builder/tools/3", "-entrypoint", "/ko-app/nop", "--"),
tb.EnvVar("HOME", "/builder/home"),
tb.VolumeMount("tools", "/builder/tools"),
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
),
),
),
}, {
Expand Down Expand Up @@ -491,7 +515,15 @@ func TestReconcile(t *testing.T) {
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
),
tb.PodContainer("nop", "override-with-nop:latest", tb.Command("/ko-app/nop")),
tb.PodContainer("build-step-nop", "override-with-nop:latest",
tb.Command(entrypointLocation),
tb.WorkingDir(workspaceDir),
tb.Args("-wait_file", "/builder/tools/6", "-post_file", "/builder/tools/7", "-entrypoint", "/ko-app/nop", "--"),
tb.EnvVar("HOME", "/builder/home"),
tb.VolumeMount("tools", "/builder/tools"),
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
),
),
),
}, {
Expand Down Expand Up @@ -527,7 +559,15 @@ func TestReconcile(t *testing.T) {
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
),
tb.PodContainer("nop", "override-with-nop:latest", tb.Command("/ko-app/nop")),
tb.PodContainer("build-step-nop", "override-with-nop:latest",
tb.Command(entrypointLocation),
tb.WorkingDir(workspaceDir),
tb.Args("-wait_file", "/builder/tools/1", "-post_file", "/builder/tools/2", "-entrypoint", "/ko-app/nop", "--"),
tb.EnvVar("HOME", "/builder/home"),
tb.VolumeMount("tools", "/builder/tools"),
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
),
),
),
}, {
Expand All @@ -553,7 +593,15 @@ func TestReconcile(t *testing.T) {
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
),
tb.PodContainer("nop", "override-with-nop:latest", tb.Command("/ko-app/nop")),
tb.PodContainer("build-step-nop", "override-with-nop:latest",
tb.Command(entrypointLocation),
tb.WorkingDir(workspaceDir),
tb.Args("-wait_file", "/builder/tools/0", "-post_file", "/builder/tools/1", "-entrypoint", "/ko-app/nop", "--"),
tb.EnvVar("HOME", "/builder/home"),
tb.VolumeMount("tools", "/builder/tools"),
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
),
),
),
}, {
Expand Down Expand Up @@ -589,7 +637,15 @@ func TestReconcile(t *testing.T) {
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
),
tb.PodContainer("nop", "override-with-nop:latest", tb.Command("/ko-app/nop")),
tb.PodContainer("build-step-nop", "override-with-nop:latest",
tb.Command(entrypointLocation),
tb.WorkingDir(workspaceDir),
tb.Args("-wait_file", "/builder/tools/1", "-post_file", "/builder/tools/2", "-entrypoint", "/ko-app/nop", "--"),
tb.EnvVar("HOME", "/builder/home"),
tb.VolumeMount("tools", "/builder/tools"),
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
),
),
),
}, {
Expand All @@ -616,7 +672,15 @@ func TestReconcile(t *testing.T) {
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
),
tb.PodContainer("nop", "override-with-nop:latest", tb.Command("/ko-app/nop")),
tb.PodContainer("build-step-nop", "override-with-nop:latest",
tb.Command(entrypointLocation),
tb.WorkingDir(workspaceDir),
tb.Args("-wait_file", "/builder/tools/0", "-post_file", "/builder/tools/1", "-entrypoint", "/ko-app/nop", "--"),
tb.EnvVar("HOME", "/builder/home"),
tb.VolumeMount("tools", "/builder/tools"),
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
),
),
),
}} {
Expand Down

0 comments on commit 20065bf

Please sign in to comment.