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

[cherry-pick] Take -version into account in the controller ☕️ #3369

Merged
merged 1 commit into from
Oct 12, 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: 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 @@ -250,7 +249,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 @@ -29,6 +29,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 @@ -1121,11 +1122,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 @@ -25,6 +25,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 @@ -114,6 +115,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