Skip to content

Commit

Permalink
Reflect tektoncd/pipeline release version as an annotation on pod
Browse files Browse the repository at this point in the history
As a followup to #1650 ,
the `tekton.dev/release` annotation is set on the pod to reflect
the value of version.PipelineVersion

Signed-off-by: Vibhav Bobade <[email protected]>
  • Loading branch information
waveywaves committed Dec 20, 2019
1 parent 0f20c35 commit 813e54f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion pkg/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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{
Expand Down
3 changes: 3 additions & 0 deletions pkg/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/reconciler/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions tekton/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 813e54f

Please sign in to comment.