Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflect tektoncd/pipeline release version as an annotation on pod #1758

Merged
merged 1 commit into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -39,6 +40,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 @@ -186,6 +190,9 @@ func MakePod(images pipeline.Images, taskRun *v1alpha1.TaskRun, taskSpec v1alpha
priorityClassName = *taskRun.Spec.PodTemplate.PriorityClassName
}

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 @@ -200,7 +207,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 @@ -589,6 +589,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
waveywaves marked this conversation as resolved.
Show resolved Hide resolved
# 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