Skip to content

Commit 813e54f

Browse files
committed
Reflect tektoncd/pipeline release version as an annotation on pod
As a followup to tektoncd#1650 , the `tekton.dev/release` annotation is set on the pod to reflect the value of version.PipelineVersion Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
1 parent 0f20c35 commit 813e54f

File tree

6 files changed

+26
-2
lines changed

6 files changed

+26
-2
lines changed

config/controller.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ spec:
2828
metadata:
2929
annotations:
3030
cluster-autoscaler.kubernetes.io/safe-to-evict: "false"
31+
# tekton.dev/release value replaced with inputs.params.versionTag in pipeline/tekton/publish.yaml
32+
tekton.dev/release: "devel"
3133
labels:
3234
app: tekton-pipelines-controller
3335
app.kubernetes.io/name: tekton-pipelines

pkg/pod/pod.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
2424
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
2525
"github.com/tektoncd/pipeline/pkg/names"
26+
"github.com/tektoncd/pipeline/pkg/version"
2627
corev1 "k8s.io/api/core/v1"
2728
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2829
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -42,6 +43,9 @@ const (
4243

4344
// These are effectively const, but Go doesn't have such an annotation.
4445
var (
46+
ReleaseAnnotation = "tekton.dev/release"
47+
ReleaseAnnotationValue = version.PipelineVersion
48+
4549
groupVersionKind = schema.GroupVersionKind{
4650
Group: v1alpha1.SchemeGroupVersion.Group,
4751
Version: v1alpha1.SchemeGroupVersion.Version,
@@ -179,6 +183,9 @@ func MakePod(images pipeline.Images, taskRun *v1alpha1.TaskRun, taskSpec v1alpha
179183
mergedPodContainers = append(mergedPodContainers, sc)
180184
}
181185

186+
podAnnotations := taskRun.Annotations
187+
podAnnotations[ReleaseAnnotation] = ReleaseAnnotationValue
188+
182189
return &corev1.Pod{
183190
ObjectMeta: metav1.ObjectMeta{
184191
// 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
193200
OwnerReferences: []metav1.OwnerReference{
194201
*metav1.NewControllerRef(taskRun, groupVersionKind),
195202
},
196-
Annotations: taskRun.Annotations,
203+
Annotations: podAnnotations,
197204
Labels: makeLabels(taskRun),
198205
},
199206
Spec: corev1.PodSpec{

pkg/pod/pod_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,9 @@ script-heredoc-randomly-generated-78c5n
569569
tr := &v1alpha1.TaskRun{
570570
ObjectMeta: metav1.ObjectMeta{
571571
Name: "taskrun-name",
572+
Annotations: map[string]string{
573+
ReleaseAnnotation: ReleaseAnnotationValue,
574+
},
572575
},
573576
Spec: c.trs,
574577
}

pkg/reconciler/taskrun/taskrun_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ func TestReconcile_ExplicitDefaultSA(t *testing.T) {
268268
name: "success",
269269
taskRun: taskRunSuccess,
270270
wantPod: tb.Pod("test-taskrun-run-success-pod-abcde", "foo",
271+
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
271272
tb.PodLabel(taskNameLabelKey, "test-task"),
272273
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-run-success"),
273274
tb.PodLabel(podconvert.ManagedByLabelKey, podconvert.ManagedByLabelValue),
@@ -302,6 +303,7 @@ func TestReconcile_ExplicitDefaultSA(t *testing.T) {
302303
name: "serviceaccount",
303304
taskRun: taskRunWithSaSuccess,
304305
wantPod: tb.Pod("test-taskrun-with-sa-run-success-pod-abcde", "foo",
306+
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
305307
tb.PodLabel(taskNameLabelKey, "test-with-sa"),
306308
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-sa-run-success"),
307309
tb.PodLabel(podconvert.ManagedByLabelKey, podconvert.ManagedByLabelValue),
@@ -519,6 +521,7 @@ func TestReconcile(t *testing.T) {
519521
name: "success",
520522
taskRun: taskRunSuccess,
521523
wantPod: tb.Pod("test-taskrun-run-success-pod-abcde", "foo",
524+
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
522525
tb.PodLabel(taskNameLabelKey, "test-task"),
523526
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-run-success"),
524527
tb.PodLabel(podconvert.ManagedByLabelKey, podconvert.ManagedByLabelValue),
@@ -552,6 +555,7 @@ func TestReconcile(t *testing.T) {
552555
name: "serviceaccount",
553556
taskRun: taskRunWithSaSuccess,
554557
wantPod: tb.Pod("test-taskrun-with-sa-run-success-pod-abcde", "foo",
558+
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
555559
tb.PodLabel(taskNameLabelKey, "test-with-sa"),
556560
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-sa-run-success"),
557561
tb.PodLabel(podconvert.ManagedByLabelKey, podconvert.ManagedByLabelValue),
@@ -586,6 +590,7 @@ func TestReconcile(t *testing.T) {
586590
name: "params",
587591
taskRun: taskRunSubstitution,
588592
wantPod: tb.Pod("test-taskrun-substitution-pod-abcde", "foo",
593+
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
589594
tb.PodLabel(taskNameLabelKey, "test-task-with-substitution"),
590595
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-substitution"),
591596
tb.PodLabel(podconvert.ManagedByLabelKey, podconvert.ManagedByLabelValue),
@@ -657,6 +662,7 @@ func TestReconcile(t *testing.T) {
657662
name: "taskrun-with-taskspec",
658663
taskRun: taskRunWithTaskSpec,
659664
wantPod: tb.Pod("test-taskrun-with-taskspec-pod-abcde", "foo",
665+
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
660666
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-taskspec"),
661667
tb.PodLabel(podconvert.ManagedByLabelKey, podconvert.ManagedByLabelValue),
662668
tb.PodOwnerReference("TaskRun", "test-taskrun-with-taskspec",
@@ -706,6 +712,7 @@ func TestReconcile(t *testing.T) {
706712
name: "success-with-cluster-task",
707713
taskRun: taskRunWithClusterTask,
708714
wantPod: tb.Pod("test-taskrun-with-cluster-task-pod-abcde", "foo",
715+
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
709716
tb.PodLabel(taskNameLabelKey, "test-cluster-task"),
710717
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-cluster-task"),
711718
tb.PodLabel(podconvert.ManagedByLabelKey, podconvert.ManagedByLabelValue),
@@ -739,6 +746,7 @@ func TestReconcile(t *testing.T) {
739746
name: "taskrun-with-resource-spec-task-spec",
740747
taskRun: taskRunWithResourceSpecAndTaskSpec,
741748
wantPod: tb.Pod("test-taskrun-with-resource-spec-pod-abcde", "foo",
749+
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
742750
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-resource-spec"),
743751
tb.PodLabel(podconvert.ManagedByLabelKey, podconvert.ManagedByLabelValue),
744752
tb.PodOwnerReference("TaskRun", "test-taskrun-with-resource-spec",
@@ -786,6 +794,7 @@ func TestReconcile(t *testing.T) {
786794
name: "taskrun-with-pod",
787795
taskRun: taskRunWithPod,
788796
wantPod: tb.Pod("test-taskrun-with-pod-pod-abcde", "foo",
797+
tb.PodAnnotation(podconvert.ReleaseAnnotation, podconvert.ReleaseAnnotationValue),
789798
tb.PodLabel(taskNameLabelKey, "test-task"),
790799
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-pod"),
791800
tb.PodLabel(podconvert.ManagedByLabelKey, podconvert.ManagedByLabelValue),

pkg/version/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
package version
1616

1717
// NOTE: use go build -ldflags "-X github.com/tektoncd/pipeline/pkg/cmd/version.PipelineVersion=$(git describe)"
18-
const devVersion = "dev"
18+
const devVersion = "devel"
1919

2020
var PipelineVersion = devVersion

tekton/publish.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ spec:
139139
ln -s ${TMPDIR}/source.tar.gz ${d}/kodata/
140140
done
141141
142+
# Rewrite "devel" to inputs.params.versionTag
143+
sed -i 's/devel/$(inputs.params.versionTag)/g' /workspace/go/src/github.com/tektoncd/pipeline/config/controller.yaml
144+
142145
# Publish images and create release.yaml
143146
ko resolve --preserve-import-paths -t $(inputs.params.versionTag) -f /workspace/go/src/github.com/tektoncd/pipeline/config/ > /workspace/output/bucket/latest/release.yaml
144147
volumeMounts:

0 commit comments

Comments
 (0)