From 813e54fc42537d3c19d842bdb45e125ad6f6d053 Mon Sep 17 00:00:00 2001 From: Vibhav Bobade Date: Tue, 17 Dec 2019 08:34:39 +0530 Subject: [PATCH] Reflect tektoncd/pipeline release version as an annotation on pod As a followup to https://github.com/tektoncd/pipeline/pull/1650 , the `tekton.dev/release` annotation is set on the pod to reflect the value of version.PipelineVersion Signed-off-by: Vibhav Bobade --- config/controller.yaml | 2 ++ pkg/pod/pod.go | 9 ++++++++- pkg/pod/pod_test.go | 3 +++ pkg/reconciler/taskrun/taskrun_test.go | 9 +++++++++ pkg/version/version.go | 2 +- tekton/publish.yaml | 3 +++ 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/config/controller.yaml b/config/controller.yaml index 6a3f8ba55fb..bcf7e9a8cc4 100644 --- a/config/controller.yaml +++ b/config/controller.yaml @@ -28,6 +28,8 @@ spec: metadata: annotations: cluster-autoscaler.kubernetes.io/safe-to-evict: "false" + # tekton.dev/release value replaced with inputs.params.versionTag in pipeline/tekton/publish.yaml + tekton.dev/release: "devel" labels: app: tekton-pipelines-controller app.kubernetes.io/name: tekton-pipelines diff --git a/pkg/pod/pod.go b/pkg/pod/pod.go index 0455968a9be..a7706b39842 100644 --- a/pkg/pod/pod.go +++ b/pkg/pod/pod.go @@ -23,6 +23,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/names" + "github.com/tektoncd/pipeline/pkg/version" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" @@ -42,6 +43,9 @@ const ( // These are effectively const, but Go doesn't have such an annotation. var ( + ReleaseAnnotation = "tekton.dev/release" + ReleaseAnnotationValue = version.PipelineVersion + groupVersionKind = schema.GroupVersionKind{ Group: v1alpha1.SchemeGroupVersion.Group, Version: v1alpha1.SchemeGroupVersion.Version, @@ -179,6 +183,9 @@ func MakePod(images pipeline.Images, taskRun *v1alpha1.TaskRun, taskSpec v1alpha mergedPodContainers = append(mergedPodContainers, sc) } + podAnnotations := taskRun.Annotations + podAnnotations[ReleaseAnnotation] = ReleaseAnnotationValue + return &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ // We execute the build's pod in the same namespace as where the build was @@ -193,7 +200,7 @@ func MakePod(images pipeline.Images, taskRun *v1alpha1.TaskRun, taskSpec v1alpha OwnerReferences: []metav1.OwnerReference{ *metav1.NewControllerRef(taskRun, groupVersionKind), }, - Annotations: taskRun.Annotations, + Annotations: podAnnotations, Labels: makeLabels(taskRun), }, Spec: corev1.PodSpec{ diff --git a/pkg/pod/pod_test.go b/pkg/pod/pod_test.go index 78bf091578a..7cb08169fe3 100644 --- a/pkg/pod/pod_test.go +++ b/pkg/pod/pod_test.go @@ -569,6 +569,9 @@ script-heredoc-randomly-generated-78c5n tr := &v1alpha1.TaskRun{ ObjectMeta: metav1.ObjectMeta{ Name: "taskrun-name", + Annotations: map[string]string{ + ReleaseAnnotation: ReleaseAnnotationValue, + }, }, Spec: c.trs, } diff --git a/pkg/reconciler/taskrun/taskrun_test.go b/pkg/reconciler/taskrun/taskrun_test.go index 229eab0fcdf..20527031860 100644 --- a/pkg/reconciler/taskrun/taskrun_test.go +++ b/pkg/reconciler/taskrun/taskrun_test.go @@ -268,6 +268,7 @@ func TestReconcile_ExplicitDefaultSA(t *testing.T) { name: "success", taskRun: taskRunSuccess, wantPod: tb.Pod("test-taskrun-run-success-pod-abcde", "foo", + tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue), tb.PodLabel(taskNameLabelKey, "test-task"), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-run-success"), tb.PodLabel(podconvert.ManagedByLabelKey, podconvert.ManagedByLabelValue), @@ -302,6 +303,7 @@ func TestReconcile_ExplicitDefaultSA(t *testing.T) { name: "serviceaccount", taskRun: taskRunWithSaSuccess, wantPod: tb.Pod("test-taskrun-with-sa-run-success-pod-abcde", "foo", + tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue), tb.PodLabel(taskNameLabelKey, "test-with-sa"), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-sa-run-success"), tb.PodLabel(podconvert.ManagedByLabelKey, podconvert.ManagedByLabelValue), @@ -519,6 +521,7 @@ func TestReconcile(t *testing.T) { name: "success", taskRun: taskRunSuccess, wantPod: tb.Pod("test-taskrun-run-success-pod-abcde", "foo", + tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue), tb.PodLabel(taskNameLabelKey, "test-task"), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-run-success"), tb.PodLabel(podconvert.ManagedByLabelKey, podconvert.ManagedByLabelValue), @@ -552,6 +555,7 @@ func TestReconcile(t *testing.T) { name: "serviceaccount", taskRun: taskRunWithSaSuccess, wantPod: tb.Pod("test-taskrun-with-sa-run-success-pod-abcde", "foo", + tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue), tb.PodLabel(taskNameLabelKey, "test-with-sa"), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-sa-run-success"), tb.PodLabel(podconvert.ManagedByLabelKey, podconvert.ManagedByLabelValue), @@ -586,6 +590,7 @@ func TestReconcile(t *testing.T) { name: "params", taskRun: taskRunSubstitution, wantPod: tb.Pod("test-taskrun-substitution-pod-abcde", "foo", + tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue), tb.PodLabel(taskNameLabelKey, "test-task-with-substitution"), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-substitution"), tb.PodLabel(podconvert.ManagedByLabelKey, podconvert.ManagedByLabelValue), @@ -657,6 +662,7 @@ func TestReconcile(t *testing.T) { name: "taskrun-with-taskspec", taskRun: taskRunWithTaskSpec, wantPod: tb.Pod("test-taskrun-with-taskspec-pod-abcde", "foo", + tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-taskspec"), tb.PodLabel(podconvert.ManagedByLabelKey, podconvert.ManagedByLabelValue), tb.PodOwnerReference("TaskRun", "test-taskrun-with-taskspec", @@ -706,6 +712,7 @@ func TestReconcile(t *testing.T) { name: "success-with-cluster-task", taskRun: taskRunWithClusterTask, wantPod: tb.Pod("test-taskrun-with-cluster-task-pod-abcde", "foo", + tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue), tb.PodLabel(taskNameLabelKey, "test-cluster-task"), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-cluster-task"), tb.PodLabel(podconvert.ManagedByLabelKey, podconvert.ManagedByLabelValue), @@ -739,6 +746,7 @@ func TestReconcile(t *testing.T) { name: "taskrun-with-resource-spec-task-spec", taskRun: taskRunWithResourceSpecAndTaskSpec, wantPod: tb.Pod("test-taskrun-with-resource-spec-pod-abcde", "foo", + tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-resource-spec"), tb.PodLabel(podconvert.ManagedByLabelKey, podconvert.ManagedByLabelValue), tb.PodOwnerReference("TaskRun", "test-taskrun-with-resource-spec", @@ -786,6 +794,7 @@ func TestReconcile(t *testing.T) { name: "taskrun-with-pod", taskRun: taskRunWithPod, wantPod: tb.Pod("test-taskrun-with-pod-pod-abcde", "foo", + tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue), tb.PodLabel(taskNameLabelKey, "test-task"), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-pod"), tb.PodLabel(podconvert.ManagedByLabelKey, podconvert.ManagedByLabelValue), diff --git a/pkg/version/version.go b/pkg/version/version.go index 5969a2f03d3..6342b175e8f 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -15,6 +15,6 @@ package version // NOTE: use go build -ldflags "-X github.com/tektoncd/pipeline/pkg/cmd/version.PipelineVersion=$(git describe)" -const devVersion = "dev" +const devVersion = "devel" var PipelineVersion = devVersion diff --git a/tekton/publish.yaml b/tekton/publish.yaml index 771bf8a9632..66c9befd179 100644 --- a/tekton/publish.yaml +++ b/tekton/publish.yaml @@ -139,6 +139,9 @@ spec: ln -s ${TMPDIR}/source.tar.gz ${d}/kodata/ done + # Rewrite "devel" to inputs.params.versionTag + sed -i 's/devel/$(inputs.params.versionTag)/g' /workspace/go/src/github.com/tektoncd/pipeline/config/controller.yaml + # Publish images and create release.yaml ko resolve --preserve-import-paths -t $(inputs.params.versionTag) -f /workspace/go/src/github.com/tektoncd/pipeline/config/ > /workspace/output/bucket/latest/release.yaml volumeMounts: