Skip to content

Commit

Permalink
Take -version into account in the controller ☕️
Browse files Browse the repository at this point in the history
Set the `version.PipelineVersion` properly in the controller main so
that we annotate the object with the version (instead of a blank string).

Signed-off-by: Vincent Demeester <[email protected]>
  • Loading branch information
vdemeester authored and tekton-robot committed Oct 7, 2020
1 parent 66096db commit f59e1be
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var (

func main() {
flag.Parse()
version.PipelineVersion = *versionGiven
version.SetVersion(*versionGiven)
images := pipeline.Images{
EntrypointImage: *entrypointImage,
NopImage: *nopImage,
Expand Down
5 changes: 2 additions & 3 deletions pkg/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ const (

// These are effectively const, but Go doesn't have such an annotation.
var (
ReleaseAnnotation = "pipeline.tekton.dev/release"
ReleaseAnnotationValue = version.PipelineVersion
ReleaseAnnotation = "pipeline.tekton.dev/release"

groupVersionKind = schema.GroupVersionKind{
Group: v1beta1.SchemeGroupVersion.Group,
Expand Down Expand Up @@ -251,7 +250,7 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1beta1.TaskRun, taskSpec
}

podAnnotations := taskRun.Annotations
podAnnotations[ReleaseAnnotation] = ReleaseAnnotationValue
podAnnotations[ReleaseAnnotation] = version.PipelineVersion

if shouldAddReadyAnnotationOnPodCreate(ctx, taskSpec.Sidecars) {
podAnnotations[readyAnnotation] = readyAnnotationValue
Expand Down
5 changes: 3 additions & 2 deletions pkg/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/system"
"github.com/tektoncd/pipeline/pkg/version"
"github.com/tektoncd/pipeline/test/diff"
"github.com/tektoncd/pipeline/test/names"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -1169,11 +1170,11 @@ script-heredoc-randomly-generated-78c5n
var trAnnotations map[string]string
if c.trAnnotation == nil {
trAnnotations = map[string]string{
ReleaseAnnotation: ReleaseAnnotationValue,
ReleaseAnnotation: version.PipelineVersion,
}
} else {
trAnnotations = c.trAnnotation
trAnnotations[ReleaseAnnotation] = ReleaseAnnotationValue
trAnnotations[ReleaseAnnotation] = version.PipelineVersion
}
tr := &v1beta1.TaskRun{
ObjectMeta: metav1.ObjectMeta{
Expand Down
25 changes: 13 additions & 12 deletions pkg/reconciler/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/tektoncd/pipeline/pkg/reconciler/volumeclaim"
"github.com/tektoncd/pipeline/pkg/system"
"github.com/tektoncd/pipeline/pkg/timeout"
"github.com/tektoncd/pipeline/pkg/version"
"github.com/tektoncd/pipeline/pkg/workspace"
test "github.com/tektoncd/pipeline/test"
"github.com/tektoncd/pipeline/test/diff"
Expand Down Expand Up @@ -427,7 +428,7 @@ func TestReconcile_ExplicitDefaultSA(t *testing.T) {
taskRun: taskRunSuccess,
wantPod: tb.Pod("test-taskrun-run-success-pod-abcde",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodLabel(taskNameLabelKey, "test-task"),
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-run-success"),
tb.PodLabel("app.kubernetes.io/managed-by", "tekton-pipelines"),
Expand Down Expand Up @@ -471,7 +472,7 @@ func TestReconcile_ExplicitDefaultSA(t *testing.T) {
taskRun: taskRunWithSaSuccess,
wantPod: tb.Pod("test-taskrun-with-sa-run-success-pod-abcde",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodLabel(taskNameLabelKey, "test-with-sa"),
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-sa-run-success"),
tb.PodLabel("app.kubernetes.io/managed-by", "tekton-pipelines"),
Expand Down Expand Up @@ -603,7 +604,7 @@ func TestReconcile_FeatureFlags(t *testing.T) {
featureFlag: "disable-home-env-overwrite",
wantPod: tb.Pod("test-taskrun-run-home-env-pod-abcde",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodLabel(taskNameLabelKey, "test-task-with-env-var"),
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-run-home-env"),
tb.PodLabel("app.kubernetes.io/managed-by", "tekton-pipelines"),
Expand Down Expand Up @@ -648,7 +649,7 @@ func TestReconcile_FeatureFlags(t *testing.T) {
featureFlag: "disable-working-directory-overwrite",
wantPod: tb.Pod("test-taskrun-run-working-dir-pod-abcde",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodLabel(taskNameLabelKey, "test-task"),
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-run-working-dir"),
tb.PodLabel("app.kubernetes.io/managed-by", "tekton-pipelines"),
Expand Down Expand Up @@ -973,7 +974,7 @@ func TestReconcile(t *testing.T) {
},
wantPod: tb.Pod("test-taskrun-run-success-pod-abcde",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodLabel(taskNameLabelKey, "test-task"),
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-run-success"),
tb.PodLabel("app.kubernetes.io/managed-by", "tekton-pipelines"),
Expand Down Expand Up @@ -1021,7 +1022,7 @@ func TestReconcile(t *testing.T) {
},
wantPod: tb.Pod("test-taskrun-with-sa-run-success-pod-abcde",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodLabel(taskNameLabelKey, "test-with-sa"),
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-sa-run-success"),
tb.PodLabel("app.kubernetes.io/managed-by", "tekton-pipelines"),
Expand Down Expand Up @@ -1069,7 +1070,7 @@ func TestReconcile(t *testing.T) {
},
wantPod: tb.Pod("test-taskrun-substitution-pod-abcde",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodLabel(taskNameLabelKey, "test-task-with-substitution"),
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-substitution"),
tb.PodLabel("app.kubernetes.io/managed-by", "tekton-pipelines"),
Expand Down Expand Up @@ -1204,7 +1205,7 @@ func TestReconcile(t *testing.T) {
},
wantPod: tb.Pod("test-taskrun-with-taskspec-pod-abcde",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-taskspec"),
tb.PodLabel("app.kubernetes.io/managed-by", "tekton-pipelines"),
tb.PodOwnerReference("TaskRun", "test-taskrun-with-taskspec",
Expand Down Expand Up @@ -1276,7 +1277,7 @@ func TestReconcile(t *testing.T) {
},
wantPod: tb.Pod("test-taskrun-with-cluster-task-pod-abcde",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodLabel(taskNameLabelKey, "test-cluster-task"),
tb.PodLabel(clusterTaskNameLabelKey, "test-cluster-task"),
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-cluster-task"),
Expand Down Expand Up @@ -1325,7 +1326,7 @@ func TestReconcile(t *testing.T) {
},
wantPod: tb.Pod("test-taskrun-with-resource-spec-pod-abcde",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-resource-spec"),
tb.PodLabel("app.kubernetes.io/managed-by", "tekton-pipelines"),
tb.PodOwnerReference("TaskRun", "test-taskrun-with-resource-spec",
Expand Down Expand Up @@ -1398,7 +1399,7 @@ func TestReconcile(t *testing.T) {
},
wantPod: tb.Pod("test-taskrun-with-pod-pod-abcde",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodLabel(taskNameLabelKey, "test-task"),
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-pod"),
tb.PodLabel("app.kubernetes.io/managed-by", "tekton-pipelines"),
Expand Down Expand Up @@ -1445,7 +1446,7 @@ func TestReconcile(t *testing.T) {
},
wantPod: tb.Pod("test-taskrun-with-credentials-variable-pod-9l9zj",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-credentials-variable"),
tb.PodLabel("app.kubernetes.io/managed-by", "tekton-pipelines"),
tb.PodOwnerReference("TaskRun", "test-taskrun-with-credentials-variable",
Expand Down
4 changes: 4 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
package version

var PipelineVersion = ""

func SetVersion(version string) {
PipelineVersion = version
}
6 changes: 6 additions & 0 deletions test/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/pod"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
knativetest "knative.dev/pkg/test"
Expand Down Expand Up @@ -119,6 +120,11 @@ func TestTaskRunFailure(t *testing.T) {
if d := cmp.Diff(taskrun.Status.Steps, expectedStepState, ignoreTerminatedFields, ignoreStepFields); d != "" {
t.Fatalf("-got, +want: %v", d)
}

releaseAnnotation, ok := taskrun.Annotations[pod.ReleaseAnnotation]
if !ok || releaseAnnotation != "devel" {
t.Fatalf("expected Taskrun to be annotated with %s=devel, got %s=%s", pod.ReleaseAnnotation, pod.ReleaseAnnotation, releaseAnnotation)
}
}

func TestTaskRunStatus(t *testing.T) {
Expand Down

0 comments on commit f59e1be

Please sign in to comment.