Skip to content

Commit

Permalink
Externalize Affinity Assistant image
Browse files Browse the repository at this point in the history
Container images should not be hardcoded.
This commit externalize what image should be used for the Affinity Assistant.

/kind misc
  • Loading branch information
jlpettersson committed Jun 8, 2020
1 parent 51df0a8 commit 013d64c
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 10 deletions.
6 changes: 4 additions & 2 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ const (
var (
entrypointImage = flag.String("entrypoint-image", "override-with-entrypoint:latest",
"The container image containing our entrypoint binary.")
nopImage = flag.String("nop-image", "tianon/true", "The container image used to stop sidecars")
gitImage = flag.String("git-image", "override-with-git:latest",
nopImage = flag.String("nop-image", "tianon/true", "The container image used to stop sidecars")
affinityAssistantImage = flag.String("affinity-assistant-image", "nginx", "The container image used for the Affinity Assistant")
gitImage = flag.String("git-image", "override-with-git:latest",
"The container image containing our Git binary.")
credsImage = flag.String("creds-image", "override-with-creds:latest",
"The container image for preparing our Build's credentials.")
Expand All @@ -60,6 +61,7 @@ func main() {
images := pipeline.Images{
EntrypointImage: *entrypointImage,
NopImage: *nopImage,
AffinityAssistantImage: *affinityAssistantImage,
GitImage: *gitImage,
CredsImage: *credsImage,
KubeconfigWriterImage: *kubeconfigWriterImage,
Expand Down
5 changes: 5 additions & 0 deletions config/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ spec:
"-pr-image", "github.com/tektoncd/pipeline/cmd/pullrequest-init",
"-build-gcs-fetcher-image", "github.com/tektoncd/pipeline/vendor/github.com/GoogleCloudPlatform/cloud-builders/gcs-fetcher/cmd/gcs-fetcher",

# This image is used as a placeholder pod, the Affinity Assistant
# TODO(#2640) We may want to create a custom, minimal binary
# As of June 8, 2020, tag 1.19.0
"-affinity-assistant-image", "nginx@sha256:c870bf53de0357813af37b9500cb1c2ff9fb4c00120d5fe1d75c21591293c34d",

# These images are pulled from Dockerhub, by digest, as of May 19, 2020.
# As of May 29, 2020 new sha for nop image
"-nop-image", "tianon/true@sha256:009cce421096698832595ce039aa13fa44327d96beedb84282a69d3dbcf5a81b",
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/pipeline/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type Images struct {
EntrypointImage string
// NopImage is the container image used to kill sidecars.
NopImage string
// AffinityAssistantImage is the container image used for the Affinity Assistant.
AffinityAssistantImage string
// GitImage is the container image with Git that we use to implement the Git source step.
GitImage string
// CredsImage is the container image used to initialize credentials before the build runs.
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/resource/v1alpha1/storage/build_gcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
var images = pipeline.Images{
EntrypointImage: "override-with-entrypoint:latest",
NopImage: "tianon/true",
AffinityAssistantImage: "nginx",
GitImage: "override-with-git:latest",
CredsImage: "override-with-creds:latest",
KubeconfigWriterImage: "override-with-kubeconfig-writer:latest",
Expand Down
1 change: 1 addition & 0 deletions pkg/artifacts/artifact_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
images = pipeline.Images{
EntrypointImage: "override-with-entrypoint:latest",
NopImage: "tianon/true",
AffinityAssistantImage: "nginx",
GitImage: "override-with-git:latest",
CredsImage: "override-with-creds:latest",
KubeconfigWriterImage: "override-with-kubeconfig-writer:latest",
Expand Down
11 changes: 5 additions & 6 deletions pkg/reconciler/pipelinerun/affinity_assistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ func (c *Reconciler) createAffinityAssistants(wb []v1alpha1.WorkspaceBinding, pr
claimName := getClaimName(w, pr.GetOwnerReference())
switch {
case apierrors.IsNotFound(err):
_, err := c.KubeClientSet.AppsV1().StatefulSets(namespace).Create(affinityAssistantStatefulSet(affinityAssistantName, pr, claimName))
affinityAssistantStatefulSet := affinityAssistantStatefulSet(affinityAssistantName, pr, claimName, c.Images.AffinityAssistantImage)
_, err := c.KubeClientSet.AppsV1().StatefulSets(namespace).Create(affinityAssistantStatefulSet)
if err != nil {
errs = append(errs, fmt.Errorf("failed to create StatefulSet %s: %s", affinityAssistantName, err))
}
Expand Down Expand Up @@ -113,7 +114,7 @@ func getStatefulSetLabels(pr *v1beta1.PipelineRun, affinityAssistantName string)
return labels
}

func affinityAssistantStatefulSet(name string, pr *v1beta1.PipelineRun, claimName string) *appsv1.StatefulSet {
func affinityAssistantStatefulSet(name string, pr *v1beta1.PipelineRun, claimName string, affinityAssistantImage string) *appsv1.StatefulSet {
// We want a singleton pod
replicas := int32(1)

Expand All @@ -130,10 +131,8 @@ func affinityAssistantStatefulSet(name string, pr *v1beta1.PipelineRun, claimNam
}

containers := []corev1.Container{{
Name: "affinity-assistant",

//TODO(#2640) We may want to create a custom, minimal binary
Image: "nginx",
Name: "affinity-assistant",
Image: affinityAssistantImage,

// Set requests == limits to get QoS class _Guaranteed_.
// See https://kubernetes.io/docs/tasks/configure-pod-container/quality-service-pod/#create-a-pod-that-gets-assigned-a-qos-class-of-guaranteed
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/pipelinerun/affinity_assistant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestThatCustomTolerationsAndNodeSelectorArePropagatedToAffinityAssistant(t
},
}

stsWithTolerationsAndNodeSelector := affinityAssistantStatefulSet("test-assistant", prWithCustomPodTemplate, "mypvc")
stsWithTolerationsAndNodeSelector := affinityAssistantStatefulSet("test-assistant", prWithCustomPodTemplate, "mypvc", "nginx")

if len(stsWithTolerationsAndNodeSelector.Spec.Template.Spec.Tolerations) != 1 {
t.Errorf("expected Tolerations in the StatefulSet")
Expand All @@ -125,7 +125,7 @@ func TestThatTheAffinityAssistantIsWithoutNodeSelectorAndTolerations(t *testing.
Spec: v1beta1.PipelineRunSpec{},
}

stsWithoutTolerationsAndNodeSelector := affinityAssistantStatefulSet("test-assistant", prWithoutCustomPodTemplate, "mypvc")
stsWithoutTolerationsAndNodeSelector := affinityAssistantStatefulSet("test-assistant", prWithoutCustomPodTemplate, "mypvc", "nginx")

if len(stsWithoutTolerationsAndNodeSelector.Spec.Template.Spec.Tolerations) != 0 {
t.Errorf("unexpected Tolerations in the StatefulSet")
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var (
images = pipeline.Images{
EntrypointImage: "override-with-entrypoint:latest",
NopImage: "tianon/true",
AffinityAssistantImage: "nginx",
GitImage: "override-with-git:latest",
CredsImage: "override-with-creds:latest",
KubeconfigWriterImage: "override-with-kubeconfig-writer:latest",
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/taskrun/resources/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (
images = pipeline.Images{
EntrypointImage: "override-with-entrypoint:latest",
NopImage: "tianon/true",
AffinityAssistantImage: "nginx",
GitImage: "override-with-git:latest",
CredsImage: "override-with-creds:latest",
KubeconfigWriterImage: "override-with-kubeconfig-writer-image:latest",
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/taskrun/resources/input_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
images = pipeline.Images{
EntrypointImage: "override-with-entrypoint:latest",
NopImage: "tianon/true",
AffinityAssistantImage: "nginx",
GitImage: "override-with-git:latest",
CredsImage: "override-with-creds:latest",
KubeconfigWriterImage: "override-with-kubeconfig-writer:latest",
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var (
images = pipeline.Images{
EntrypointImage: "override-with-entrypoint:latest",
NopImage: "tianon/true",
AffinityAssistantImage: "nginx",
GitImage: "override-with-git:latest",
CredsImage: "override-with-creds:latest",
KubeconfigWriterImage: "override-with-kubeconfig-writer:latest",
Expand Down

0 comments on commit 013d64c

Please sign in to comment.