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

Use knative.dev/pkg/changeset #4126

Merged
merged 2 commits into from
Aug 4, 2021
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
3 changes: 0 additions & 3 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun"
"github.com/tektoncd/pipeline/pkg/reconciler/taskrun"
"github.com/tektoncd/pipeline/pkg/version"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/rest"
filteredinformerfactory "knative.dev/pkg/client/injection/kube/informers/factory/filtered"
Expand All @@ -51,7 +50,6 @@ var (
prImage = flag.String("pr-image", "", "The container image containing our PR binary.")
imageDigestExporterImage = flag.String("imagedigest-exporter-image", "", "The container image containing our image digest exporter binary.")
namespace = flag.String("namespace", corev1.NamespaceAll, "Namespace to restrict informer to. Optional, defaults to all namespaces.")
versionGiven = flag.String("version", "devel", "Version of Tekton running")
threadsPerController = flag.Int("threads-per-controller", controller.DefaultThreadsPerController, "Threads (goroutines) to create per controller")
disableHighAvailability = flag.Bool("disable-ha", false, "Whether to disable high-availability functionality for this component. This flag will be deprecated "+
"and removed when we have promoted this feature to stable, so do not pass it without filing an "+
Expand All @@ -61,7 +59,6 @@ var (
func main() {
cfg := sharedmain.ParseAndGetConfigOrDie()
controller.DefaultThreadsPerController = *threadsPerController
version.SetVersion(*versionGiven)
images := pipeline.Images{
EntrypointImage: *entrypointImage,
NopImage: *nopImage,
Expand Down
2 changes: 0 additions & 2 deletions config/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ spec:
- name: tekton-pipelines-controller
image: ko://github.com/tektoncd/pipeline/cmd/controller
args: [
# Version, to be replace at release time
"-version", "devel",
# These images are built on-demand by `ko resolve` and are replaced
# by image references by digest.
"-kubeconfig-writer-image", "ko://github.com/tektoncd/pipeline/cmd/kubeconfigwriter",
Expand Down
8 changes: 6 additions & 2 deletions pkg/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import (
"github.com/tektoncd/pipeline/pkg/apis/pipeline/pod"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/names"
"github.com/tektoncd/pipeline/pkg/version"
"github.com/tektoncd/pipeline/pkg/workspace"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes"
"knative.dev/pkg/changeset"
)

const (
Expand Down Expand Up @@ -290,7 +290,11 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1beta1.TaskRun, taskSpec
}

podAnnotations := taskRun.Annotations
podAnnotations[ReleaseAnnotation] = version.PipelineVersion
version, err := changeset.Get()
if err != nil {
return nil, err
}
podAnnotations[ReleaseAnnotation] = version
Comment on lines +293 to +297
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should log something and print unknown here instead of erroring out, wdyt @mattmoor ?


if shouldAddReadyAnnotationOnPodCreate(ctx, taskSpec.Sidecars) {
podAnnotations[readyAnnotation] = readyAnnotationValue
Expand Down
22 changes: 17 additions & 5 deletions pkg/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package pod
import (
"context"
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
Expand All @@ -31,13 +32,13 @@ import (
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/pod"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/version"
"github.com/tektoncd/pipeline/test/diff"
"github.com/tektoncd/pipeline/test/names"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
fakek8s "k8s.io/client-go/kubernetes/fake"
"knative.dev/pkg/changeset"
logtesting "knative.dev/pkg/logging/testing"
"knative.dev/pkg/system"

Expand All @@ -57,8 +58,19 @@ var (
featureFlagDisableHomeEnvKey = "disable-home-env-overwrite"
featureFlagDisableWorkingDirKey = "disable-working-directory-overwrite"
featureFlagSetReadyAnnotationOnPodCreate = "enable-ready-annotation-on-pod-create"

fakeVersion string
)

func init() {
os.Setenv("KO_DATA_PATH", "./testdata/")
commit, err := changeset.Get()
if err != nil {
panic(err)
}
fakeVersion = commit
}

func TestPodBuild(t *testing.T) {
secretsVolume := corev1.Volume{
Name: "tekton-internal-secret-volume-multi-creds-9l9zj",
Expand Down Expand Up @@ -1464,11 +1476,11 @@ _EOF_
var trAnnotations map[string]string
if c.trAnnotation == nil {
trAnnotations = map[string]string{
ReleaseAnnotation: version.PipelineVersion,
ReleaseAnnotation: fakeVersion,
}
} else {
trAnnotations = c.trAnnotation
trAnnotations[ReleaseAnnotation] = version.PipelineVersion
trAnnotations[ReleaseAnnotation] = fakeVersion
}
tr := &v1beta1.TaskRun{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -1618,11 +1630,11 @@ func TestPodBuildwithAlphaAPIEnabled(t *testing.T) {
var trAnnotations map[string]string
if c.trAnnotation == nil {
trAnnotations = map[string]string{
ReleaseAnnotation: version.PipelineVersion,
ReleaseAnnotation: fakeVersion,
}
} else {
trAnnotations = c.trAnnotation
trAnnotations[ReleaseAnnotation] = version.PipelineVersion
trAnnotations[ReleaseAnnotation] = fakeVersion
}
tr := &v1beta1.TaskRun{
ObjectMeta: metav1.ObjectMeta{
Expand Down
1 change: 1 addition & 0 deletions pkg/pod/testdata/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a728ce3c3d717fe52ff0b1eb71d357460498115c
39 changes: 25 additions & 14 deletions pkg/reconciler/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"net/http/httptest"
"net/url"
"os"
"regexp"
"strings"
"testing"
Expand All @@ -40,7 +41,6 @@ import (
"github.com/tektoncd/pipeline/pkg/reconciler/events/cloudevent"
ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing"
"github.com/tektoncd/pipeline/pkg/reconciler/volumeclaim"
"github.com/tektoncd/pipeline/pkg/version"
"github.com/tektoncd/pipeline/pkg/workspace"
"github.com/tektoncd/pipeline/test"
"github.com/tektoncd/pipeline/test/diff"
Expand All @@ -56,6 +56,7 @@ import (
ktesting "k8s.io/client-go/testing"
"k8s.io/client-go/tools/record"
"knative.dev/pkg/apis"
"knative.dev/pkg/changeset"
cminformer "knative.dev/pkg/configmap/informer"
"knative.dev/pkg/controller"
"knative.dev/pkg/kmeta"
Expand Down Expand Up @@ -235,8 +236,18 @@ var (
actualOps = append(actualOps, ops...)
return tb.PodInitContainer("place-tools", "override-with-entrypoint:latest", actualOps...)
}
fakeVersion string
)

func init() {
os.Setenv("KO_DATA_PATH", "./testdata/")
commit, err := changeset.Get()
if err != nil {
panic(err)
}
fakeVersion = commit
}

func getRunName(tr *v1beta1.TaskRun) string {
return strings.Join([]string{tr.Namespace, tr.Name}, "/")
}
Expand Down Expand Up @@ -435,7 +446,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, version.PipelineVersion),
tb.PodAnnotation(podconvert.ReleaseAnnotation, fakeVersion),
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 @@ -477,7 +488,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, version.PipelineVersion),
tb.PodAnnotation(podconvert.ReleaseAnnotation, fakeVersion),
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 @@ -607,7 +618,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, version.PipelineVersion),
tb.PodAnnotation(podconvert.ReleaseAnnotation, fakeVersion),
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 @@ -651,7 +662,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, version.PipelineVersion),
tb.PodAnnotation(podconvert.ReleaseAnnotation, fakeVersion),
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 @@ -995,7 +1006,7 @@ func TestReconcile(t *testing.T) {
},
wantPod: tb.Pod("test-taskrun-run-success-pod-abcde",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodAnnotation(podconvert.ReleaseAnnotation, fakeVersion),
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 @@ -1041,7 +1052,7 @@ func TestReconcile(t *testing.T) {
},
wantPod: tb.Pod("test-taskrun-with-sa-run-success-pod-abcde",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodAnnotation(podconvert.ReleaseAnnotation, fakeVersion),
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 @@ -1087,7 +1098,7 @@ func TestReconcile(t *testing.T) {
},
wantPod: tb.Pod("test-taskrun-substitution-pod-abcde",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodAnnotation(podconvert.ReleaseAnnotation, fakeVersion),
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 @@ -1213,7 +1224,7 @@ func TestReconcile(t *testing.T) {
},
wantPod: tb.Pod("test-taskrun-with-taskspec-pod-abcde",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodAnnotation(podconvert.ReleaseAnnotation, fakeVersion),
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 @@ -1279,7 +1290,7 @@ func TestReconcile(t *testing.T) {
},
wantPod: tb.Pod("test-taskrun-with-cluster-task-pod-abcde",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodAnnotation(podconvert.ReleaseAnnotation, fakeVersion),
tb.PodLabel(clusterTaskNameLabelKey, "test-cluster-task"),
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-cluster-task"),
tb.PodLabel("app.kubernetes.io/managed-by", "tekton-pipelines"),
Expand Down Expand Up @@ -1325,7 +1336,7 @@ func TestReconcile(t *testing.T) {
},
wantPod: tb.Pod("test-taskrun-with-resource-spec-pod-abcde",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodAnnotation(podconvert.ReleaseAnnotation, fakeVersion),
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 @@ -1392,7 +1403,7 @@ func TestReconcile(t *testing.T) {
},
wantPod: tb.Pod("test-taskrun-with-pod-pod-abcde",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodAnnotation(podconvert.ReleaseAnnotation, fakeVersion),
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 @@ -1437,7 +1448,7 @@ func TestReconcile(t *testing.T) {
},
wantPod: tb.Pod("test-taskrun-with-credentials-variable-pod-9l9zj",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodAnnotation(podconvert.ReleaseAnnotation, fakeVersion),
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 Expand Up @@ -1482,7 +1493,7 @@ func TestReconcile(t *testing.T) {
},
wantPod: tb.Pod("test-taskrun-bundle-pod-abcde",
tb.PodNamespace("foo"),
tb.PodAnnotation(podconvert.ReleaseAnnotation, version.PipelineVersion),
tb.PodAnnotation(podconvert.ReleaseAnnotation, fakeVersion),
tb.PodLabel(taskNameLabelKey, "test-task"),
tb.PodLabel(taskRunNameLabelKey, "test-taskrun-bundle"),
tb.PodLabel("app.kubernetes.io/managed-by", "tekton-pipelines"),
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/taskrun/testdata/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/v1.2.3
1 change: 1 addition & 0 deletions pkg/reconciler/taskrun/testdata/refs/heads/v1.2.3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a728ce3c3d717fe52ff0b1eb71d357460498115c
21 changes: 0 additions & 21 deletions pkg/version/version.go

This file was deleted.

2 changes: 1 addition & 1 deletion tekton/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ spec:
done

# Rewrite "devel" to params.versionTag
sed -i -e 's/\(pipeline.tekton.dev\/release\): "devel"/\1: "$(params.versionTag)"/g' -e 's/\(app.kubernetes.io\/version\): "devel"/\1: "$(params.versionTag)"/g' -e 's/\(version\): "devel"/\1: "$(params.versionTag)"/g' -e 's/\("-version"\), "devel"/\1, "$(params.versionTag)"/g' ${PROJECT_ROOT}/config/*.yaml
sed -i -e 's/\(pipeline.tekton.dev\/release\): "devel"/\1: "$(params.versionTag)"/g' -e 's/\(app.kubernetes.io\/version\): "devel"/\1: "$(params.versionTag)"/g' -e 's/\(version\): "devel"/\1: "$(params.versionTag)"/g' ${PROJECT_ROOT}/config/*.yaml

# Publish images and create release.yaml
mkdir -p $OUTPUT_RELEASE_DIR
Expand Down
6 changes: 3 additions & 3 deletions test/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ func TestTaskRunFailure(t *testing.T) {
}

releaseAnnotation, ok := taskrun.Annotations[pod.ReleaseAnnotation]
// Nightly release tag looks like v20210323-0593c7bef3
nightlyReleaseRegexp := regexp.MustCompile("^v[0-9]{8}-[0-9a-z]{10}$")
if !ok || !(releaseAnnotation == "devel" || nightlyReleaseRegexp.MatchString(releaseAnnotation)) {
// This should always contain a commit truncated to ~7 characters (based on knative.dev/pkg/changeset)
commitIDRegexp := regexp.MustCompile(`^[a-f0-9]{7}$`)
if !ok || !commitIDRegexp.MatchString(releaseAnnotation) {
t.Fatalf("expected Taskrun to be annotated with %s=devel or with nightly release tag, got %s=%s", pod.ReleaseAnnotation, pod.ReleaseAnnotation, releaseAnnotation)
}
}
Expand Down