From 7b2ab24acf8f4fbffde0a8c0e47b0dcace09205d Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Mon, 27 Jan 2020 12:24:30 +0100 Subject: [PATCH] =?UTF-8?q?Refactor=20the=20webhook/main.go=20to=20use=20l?= =?UTF-8?q?atest=20knative/pkg=20=F0=9F=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is way simpler to follow. Signed-off-by: Vincent Demeester --- cmd/webhook/main.go | 119 ++++++++++++++++-- config/webhook.yaml | 2 + go.mod | 1 + go.sum | 6 + pkg/apis/pipeline/v1alpha1/types_test.go | 14 +-- pkg/apis/pipeline/v1alpha2/types_test.go | 13 +- pkg/apis/resource/v1alpha1/types_test.go | 4 +- pkg/reconciler/pipelinerun/metrics_test.go | 3 + .../pipelinerun/pipelinerun_test.go | 26 ++-- test/init_test.go | 6 +- .../knative.dev/pkg/metrics/testing/config.go | 27 ++++ vendor/modules.txt | 1 + 12 files changed, 180 insertions(+), 42 deletions(-) create mode 100644 vendor/knative.dev/pkg/metrics/testing/config.go diff --git a/cmd/webhook/main.go b/cmd/webhook/main.go index 495f8f8639f..1e0528e84ff 100644 --- a/cmd/webhook/main.go +++ b/cmd/webhook/main.go @@ -18,29 +18,127 @@ package main import ( "context" - "flag" - "log" "os" - apiconfig "github.com/tektoncd/pipeline/pkg/apis/config" + defaultconfig "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/contexts" - tklogging "github.com/tektoncd/pipeline/pkg/logging" - "github.com/tektoncd/pipeline/pkg/system" - "go.uber.org/zap" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/client-go/kubernetes" - "k8s.io/client-go/rest" "knative.dev/pkg/configmap" + "knative.dev/pkg/controller" + "knative.dev/pkg/injection/sharedmain" "knative.dev/pkg/logging" - "knative.dev/pkg/logging/logkey" "knative.dev/pkg/signals" "knative.dev/pkg/webhook" + "knative.dev/pkg/webhook/certificates" + "knative.dev/pkg/webhook/configmaps" + "knative.dev/pkg/webhook/resourcesemantics" + "knative.dev/pkg/webhook/resourcesemantics/defaulting" + "knative.dev/pkg/webhook/resourcesemantics/validation" ) // WebhookLogKey is the name of the logger for the webhook cmd const WebhookLogKey = "webhook" +var types = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{ + v1alpha1.SchemeGroupVersion.WithKind("Pipeline"): &v1alpha1.Pipeline{}, + v1alpha1.SchemeGroupVersion.WithKind("Task"): &v1alpha1.Task{}, + v1alpha1.SchemeGroupVersion.WithKind("ClusterTask"): &v1alpha1.ClusterTask{}, + v1alpha1.SchemeGroupVersion.WithKind("TaskRun"): &v1alpha1.TaskRun{}, + v1alpha1.SchemeGroupVersion.WithKind("PipelineRun"): &v1alpha1.PipelineRun{}, + v1alpha1.SchemeGroupVersion.WithKind("Condition"): &v1alpha1.Condition{}, + v1alpha1.SchemeGroupVersion.WithKind("PipelineResource"): &v1alpha1.PipelineResource{}, +} + +func NewDefaultingAdmissionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl { + // Decorate contexts with the current state of the config. + store := defaultconfig.NewStore(logging.FromContext(ctx).Named("config-store")) + store.WatchConfigs(cmw) + + return defaulting.NewAdmissionController(ctx, + + // Name of the resource webhook. + "webhook.pipeline.tekton.dev", + + // The path on which to serve the webhook. + "/defaulting", + + // The resources to validate and default. + types, + + // A function that infuses the context passed to Validate/SetDefaults with custom metadata. + func(ctx context.Context) context.Context { + // FIXME(vdemeester) uncomment that for auto-conversion + // return v1alpha2.WithUpgradeViaDefaulting(store.ToContext(ctx)) + return contexts.WithDefaultConfigurationName(store.ToContext(ctx)) + }, + + // Whether to disallow unknown fields. + true, + ) +} + +func NewValidationAdmissionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl { + return validation.NewAdmissionController(ctx, + + // Name of the resource webhook. + "validation.webhook.pipeline.tekton.dev", + + // The path on which to serve the webhook. + "/resource-validation", + + // The resources to validate and default. + types, + + // A function that infuses the context passed to Validate/SetDefaults with custom metadata. + func(ctx context.Context) context.Context { + return ctx + }, + + // Whether to disallow unknown fields. + true, + ) +} + +func NewConfigValidationController(ctx context.Context, cmw configmap.Watcher) *controller.Impl { + return configmaps.NewAdmissionController(ctx, + + // Name of the configmap webhook. + "config.webhook.pipeline.tekton.dev", + + // The path on which to serve the webhook. + "/config-validation", + + // The configmaps to validate. + configmap.Constructors{ + logging.ConfigMapName(): logging.NewConfigFromConfigMap, + defaultconfig.DefaultsConfigName: defaultconfig.NewDefaultsFromConfigMap, + }, + ) +} + +func main() { + serviceName := os.Getenv("WEBHOOK_SERVICE_NAME") + if serviceName == "" { + serviceName = "tekton-pipelines-webhook" + } + + // Set up a signal context with our webhook options + ctx := webhook.WithOptions(signals.NewContext(), webhook.Options{ + ServiceName: serviceName, + Port: 8443, + SecretName: "webhook-certs", + }) + + sharedmain.MainWithContext(ctx, "webhook", + certificates.NewController, + NewDefaultingAdmissionController, + NewValidationAdmissionController, + NewConfigValidationController, + ) +} + +/* func main() { flag.Parse() cm, err := configmap.Load("/etc/config-logging") @@ -96,7 +194,7 @@ func main() { WebhookName: "webhook.tekton.dev", ResourceAdmissionControllerPath: "/", } - resourceHandlers := map[schema.GroupVersionKind]webhook.GenericCRD{ + resourceHandlers := map[schema.GroupVersionKind]resourcesemantics.GenericCRD{ v1alpha1.SchemeGroupVersion.WithKind("Pipeline"): &v1alpha1.Pipeline{}, v1alpha1.SchemeGroupVersion.WithKind("Task"): &v1alpha1.Task{}, v1alpha1.SchemeGroupVersion.WithKind("ClusterTask"): &v1alpha1.ClusterTask{}, @@ -125,3 +223,4 @@ func main() { logger.Fatal("Error running admission controller", zap.Error(err)) } } +*/ diff --git a/config/webhook.yaml b/config/webhook.yaml index 022bb8cf826..114349db12c 100644 --- a/config/webhook.yaml +++ b/config/webhook.yaml @@ -55,6 +55,8 @@ spec: fieldPath: metadata.namespace - name: WEBHOOK_SERVICE_NAME value: tekton-pipelines-webhook + - name: METRICS_DOMAIN + value: tekton.dev/pipeline volumes: - name: config-logging configMap: diff --git a/go.mod b/go.mod index 49b6026e06a..d67316e45af 100644 --- a/go.mod +++ b/go.mod @@ -20,6 +20,7 @@ require ( github.com/imdario/mergo v0.3.8 // indirect github.com/jenkins-x/go-scm v1.5.65 github.com/json-iterator/go v1.1.8 // indirect + github.com/markbates/inflect v1.0.4 // indirect github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a // indirect github.com/mitchellh/go-homedir v1.1.0 github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 // indirect diff --git a/go.sum b/go.sum index f10963b3e8b..befc4a61452 100644 --- a/go.sum +++ b/go.sum @@ -197,6 +197,8 @@ github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gobuffalo/envy v1.6.5 h1:X3is06x7v0nW2xiy2yFbbIjwHz57CD6z6MkvqULTCm8= +github.com/gobuffalo/envy v1.6.5/go.mod h1:N+GkhhZ/93bGZc6ZKhJLP6+m+tCNPKwgSpH9kaifseQ= github.com/gogo/googleapis v1.1.0 h1:kFkMAZBNAn4j7K0GiZr8cRYzejq68VbheufiV3YuyFI= github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -304,6 +306,8 @@ github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJS github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/joefitzgerald/rainbow-reporter v0.1.0/go.mod h1:481CNgqmVHQZzdIbN52CupLJyoVwB10FQ/IQlF1pdL8= +github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs= @@ -340,6 +344,8 @@ github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.7.0 h1:aizVhC/NAAcKWb+5QsU1iNOZb4Yws5UO2I+aIprQITM= github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs= +github.com/markbates/inflect v1.0.4 h1:5fh1gzTFhfae06u3hzHYO9xe3l3v3nW5Pwt3naLTP5g= +github.com/markbates/inflect v1.0.4/go.mod h1:1fR9+pO2KHEO9ZRtto13gDwwZaAKstQzferVeWqbgNs= github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a h1:+J2gw7Bw77w/fbK7wnNJJDKmw1IbWft2Ul5BzrG1Qm8= github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a/go.mod h1:M1qoD/MqPgTZIk0EWKB38wE28ACRfVcn+cU08jyArI0= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= diff --git a/pkg/apis/pipeline/v1alpha1/types_test.go b/pkg/apis/pipeline/v1alpha1/types_test.go index ebf697c3ca6..85999a4e3b4 100644 --- a/pkg/apis/pipeline/v1alpha1/types_test.go +++ b/pkg/apis/pipeline/v1alpha1/types_test.go @@ -20,15 +20,15 @@ import ( "testing" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" - "knative.dev/pkg/webhook" + "knative.dev/pkg/webhook/resourcesemantics" ) func TestTypes(t *testing.T) { // Assert that types satisfy webhook interface. - var _ webhook.GenericCRD = (*v1alpha1.ClusterTask)(nil) - var _ webhook.GenericCRD = (*v1alpha1.TaskRun)(nil) - var _ webhook.GenericCRD = (*v1alpha1.PipelineResource)(nil) - var _ webhook.GenericCRD = (*v1alpha1.Task)(nil) - var _ webhook.GenericCRD = (*v1alpha1.TaskRun)(nil) - var _ webhook.GenericCRD = (*v1alpha1.Condition)(nil) + var _ resourcesemantics.GenericCRD = (*v1alpha1.ClusterTask)(nil) + var _ resourcesemantics.GenericCRD = (*v1alpha1.TaskRun)(nil) + var _ resourcesemantics.GenericCRD = (*v1alpha1.PipelineResource)(nil) + var _ resourcesemantics.GenericCRD = (*v1alpha1.Task)(nil) + var _ resourcesemantics.GenericCRD = (*v1alpha1.TaskRun)(nil) + var _ resourcesemantics.GenericCRD = (*v1alpha1.Condition)(nil) } diff --git a/pkg/apis/pipeline/v1alpha2/types_test.go b/pkg/apis/pipeline/v1alpha2/types_test.go index ac4346cacce..705c238e779 100644 --- a/pkg/apis/pipeline/v1alpha2/types_test.go +++ b/pkg/apis/pipeline/v1alpha2/types_test.go @@ -20,15 +20,14 @@ import ( "testing" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha2" - "knative.dev/pkg/webhook" + "knative.dev/pkg/webhook/resourcesemantics" ) func TestTypes(t *testing.T) { // Assert that types satisfy webhook interface. - // var _ webhook.GenericCRD = (*v1alpha2.ClusterTask)(nil) - // var _ webhook.GenericCRD = (*v1alpha2.TaskRun)(nil) - // var _ webhook.GenericCRD = (*v1alpha2.PipelineResource)(nil) - var _ webhook.GenericCRD = (*v1alpha2.Task)(nil) - // var _ webhook.GenericCRD = (*v1alpha2.TaskRun)(nil) - // var _ webhook.GenericCRD = (*v1alpha2.Condition)(nil) + // var _ resourcesemantics.GenericCRD = (*v1alpha2.ClusterTask)(nil) + var _ resourcesemantics.GenericCRD = (*v1alpha2.TaskRun)(nil) + var _ resourcesemantics.GenericCRD = (*v1alpha2.Task)(nil) + var _ resourcesemantics.GenericCRD = (*v1alpha2.Pipeline)(nil) + // var _ resourcesemantics.GenericCRD = (*v1alpha2.Condition)(nil) } diff --git a/pkg/apis/resource/v1alpha1/types_test.go b/pkg/apis/resource/v1alpha1/types_test.go index 05f615069fd..3beb13d0b5a 100644 --- a/pkg/apis/resource/v1alpha1/types_test.go +++ b/pkg/apis/resource/v1alpha1/types_test.go @@ -20,10 +20,10 @@ import ( "testing" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "knative.dev/pkg/webhook" + "knative.dev/pkg/webhook/resourcesemantics" ) func TestTypes(t *testing.T) { // Assert that types satisfy webhook interface. - var _ webhook.GenericCRD = (*v1alpha1.PipelineResource)(nil) + var _ resourcesemantics.GenericCRD = (*v1alpha1.PipelineResource)(nil) } diff --git a/pkg/reconciler/pipelinerun/metrics_test.go b/pkg/reconciler/pipelinerun/metrics_test.go index 37050865395..bc125221eca 100644 --- a/pkg/reconciler/pipelinerun/metrics_test.go +++ b/pkg/reconciler/pipelinerun/metrics_test.go @@ -27,6 +27,9 @@ import ( corev1 "k8s.io/api/core/v1" "knative.dev/pkg/apis" "knative.dev/pkg/metrics/metricstest" + + // Required to setup metrics env for testing + _ "knative.dev/pkg/metrics/testing" rtesting "knative.dev/pkg/reconciler/testing" ) diff --git a/pkg/reconciler/pipelinerun/pipelinerun_test.go b/pkg/reconciler/pipelinerun/pipelinerun_test.go index a8e392249ed..c25e9c6dd82 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun_test.go +++ b/pkg/reconciler/pipelinerun/pipelinerun_test.go @@ -209,7 +209,7 @@ func TestReconcile(t *testing.T) { t.Log("actions", clients.Pipeline.Actions()) // Check that the PipelineRun was reconciled correctly - reconciledRun, err := clients.Pipeline.Tekton().PipelineRuns("foo").Get("test-pipeline-run-success", metav1.GetOptions{}) + reconciledRun, err := clients.Pipeline.TektonV1alpha1().PipelineRuns("foo").Get("test-pipeline-run-success", metav1.GetOptions{}) if err != nil { t.Fatalf("Somehow had error getting reconciled run out of fake client: %s", err) } @@ -328,7 +328,7 @@ func TestReconcile_PipelineSpecTaskSpec(t *testing.T) { t.Log("actions", clients.Pipeline.Actions()) // Check that the PipelineRun was reconciled correctly - reconciledRun, err := clients.Pipeline.Tekton().PipelineRuns("foo").Get("test-pipeline-run-success", metav1.GetOptions{}) + reconciledRun, err := clients.Pipeline.TektonV1alpha1().PipelineRuns("foo").Get("test-pipeline-run-success", metav1.GetOptions{}) if err != nil { t.Fatalf("Somehow had error getting reconciled run out of fake client: %s", err) } @@ -814,7 +814,7 @@ func TestReconcileOnCompletedPipelineRun(t *testing.T) { } // Check that the PipelineRun was reconciled correctly - reconciledRun, err := clients.Pipeline.Tekton().PipelineRuns("foo").Get("test-pipeline-run-completed", metav1.GetOptions{}) + reconciledRun, err := clients.Pipeline.TektonV1alpha1().PipelineRuns("foo").Get("test-pipeline-run-completed", metav1.GetOptions{}) if err != nil { t.Fatalf("Somehow had error getting completed reconciled run out of fake client: %s", err) } @@ -878,7 +878,7 @@ func TestReconcileOnCancelledPipelineRun(t *testing.T) { } // Check that the PipelineRun was reconciled correctly - reconciledRun, err := clients.Pipeline.Tekton().PipelineRuns("foo").Get("test-pipeline-run-cancelled", metav1.GetOptions{}) + reconciledRun, err := clients.Pipeline.TektonV1alpha1().PipelineRuns("foo").Get("test-pipeline-run-cancelled", metav1.GetOptions{}) if err != nil { t.Fatalf("Somehow had error getting completed reconciled run out of fake client: %s", err) } @@ -924,7 +924,7 @@ func TestReconcileWithTimeout(t *testing.T) { } // Check that the PipelineRun was reconciled correctly - reconciledRun, err := clients.Pipeline.Tekton().PipelineRuns("foo").Get("test-pipeline-run-with-timeout", metav1.GetOptions{}) + reconciledRun, err := clients.Pipeline.TektonV1alpha1().PipelineRuns("foo").Get("test-pipeline-run-with-timeout", metav1.GetOptions{}) if err != nil { t.Fatalf("Somehow had error getting completed reconciled run out of fake client: %s", err) } @@ -978,7 +978,7 @@ func TestReconcileWithoutPVC(t *testing.T) { } // Check that the PipelineRun was reconciled correctly - reconciledRun, err := clients.Pipeline.Tekton().PipelineRuns("foo").Get("test-pipeline-run", metav1.GetOptions{}) + reconciledRun, err := clients.Pipeline.TektonV1alpha1().PipelineRuns("foo").Get("test-pipeline-run", metav1.GetOptions{}) if err != nil { t.Fatalf("Somehow had error getting reconciled run out of fake client: %s", err) } @@ -1026,7 +1026,7 @@ func TestReconcileCancelledPipelineRun(t *testing.T) { } // Check that the PipelineRun was reconciled correctly - reconciledRun, err := clients.Pipeline.Tekton().PipelineRuns("foo").Get("test-pipeline-run-with-timeout", metav1.GetOptions{}) + reconciledRun, err := clients.Pipeline.TektonV1alpha1().PipelineRuns("foo").Get("test-pipeline-run-with-timeout", metav1.GetOptions{}) if err != nil { t.Fatalf("Somehow had error getting completed reconciled run out of fake client: %s", err) } @@ -1094,7 +1094,7 @@ func TestReconcilePropagateLabels(t *testing.T) { } // Check that the PipelineRun was reconciled correctly - _, err = clients.Pipeline.Tekton().PipelineRuns("foo").Get("test-pipeline-run-with-labels", metav1.GetOptions{}) + _, err = clients.Pipeline.TektonV1alpha1().PipelineRuns("foo").Get("test-pipeline-run-with-labels", metav1.GetOptions{}) if err != nil { t.Fatalf("Somehow had error getting completed reconciled run out of fake client: %s", err) } @@ -1145,7 +1145,7 @@ func TestReconcileWithDifferentServiceAccounts(t *testing.T) { } // Check that the PipelineRun was reconciled correctly - _, err = clients.Pipeline.Tekton().PipelineRuns("foo").Get("test-pipeline-run-different-service-accs", metav1.GetOptions{}) + _, err = clients.Pipeline.TektonV1alpha1().PipelineRuns("foo").Get("test-pipeline-run-different-service-accs", metav1.GetOptions{}) if err != nil { t.Fatalf("Somehow had error getting completed reconciled run out of fake client: %s", err) } @@ -1181,7 +1181,7 @@ func TestReconcileWithDifferentServiceAccounts(t *testing.T) { } for i := range ps[0].Spec.Tasks { // Check that the expected TaskRun was created - actual, err := clients.Pipeline.Tekton().TaskRuns("foo").Get(taskRunNames[i], metav1.GetOptions{}) + actual, err := clients.Pipeline.TektonV1alpha1().TaskRuns("foo").Get(taskRunNames[i], metav1.GetOptions{}) if err != nil { t.Fatalf("Expected a TaskRun to be created, but it wasn't: %s", err) } @@ -1322,7 +1322,7 @@ func TestReconcilePropagateAnnotations(t *testing.T) { } // Check that the PipelineRun was reconciled correctly - _, err = clients.Pipeline.Tekton().PipelineRuns("foo").Get("test-pipeline-run-with-annotations", metav1.GetOptions{}) + _, err = clients.Pipeline.TektonV1alpha1().PipelineRuns("foo").Get("test-pipeline-run-with-annotations", metav1.GetOptions{}) if err != nil { t.Fatalf("Somehow had error getting completed reconciled run out of fake client: %s", err) } @@ -1453,7 +1453,7 @@ func TestReconcileWithConditionChecks(t *testing.T) { } // Check that the PipelineRun was reconciled correctly - _, err = clients.Pipeline.Tekton().PipelineRuns("foo").Get(prName, metav1.GetOptions{}) + _, err = clients.Pipeline.TektonV1alpha1().PipelineRuns("foo").Get(prName, metav1.GetOptions{}) if err != nil { t.Fatalf("Somehow had error getting completed reconciled run out of fake client: %s", err) } @@ -1566,7 +1566,7 @@ func TestReconcileWithFailingConditionChecks(t *testing.T) { } // Check that the PipelineRun was reconciled correctly - _, err = clients.Pipeline.Tekton().PipelineRuns("foo").Get("test-pipeline-run-with-conditions", metav1.GetOptions{}) + _, err = clients.Pipeline.TektonV1alpha1().PipelineRuns("foo").Get("test-pipeline-run-with-conditions", metav1.GetOptions{}) if err != nil { t.Fatalf("Somehow had error getting completed reconciled run out of fake client: %s", err) } diff --git a/test/init_test.go b/test/init_test.go index d224d564a4b..089f64a16da 100644 --- a/test/init_test.go +++ b/test/init_test.go @@ -111,9 +111,9 @@ func initializeLogsAndMetrics(t *testing.T) { flag.Set("alsologtostderr", "true") logging.InitializeLogger(knativetest.Flags.LogVerbose) - if knativetest.Flags.EmitMetrics { - logging.InitializeMetricExporter(t.Name()) - } + //if knativetest.Flags.EmitMetrics { + logging.InitializeMetricExporter(t.Name()) + //} }) } diff --git a/vendor/knative.dev/pkg/metrics/testing/config.go b/vendor/knative.dev/pkg/metrics/testing/config.go new file mode 100644 index 00000000000..a0932f005e5 --- /dev/null +++ b/vendor/knative.dev/pkg/metrics/testing/config.go @@ -0,0 +1,27 @@ +/* +Copyright 2019 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package testing + +import ( + "os" + + "knative.dev/pkg/metrics" +) + +func init() { + os.Setenv(metrics.DomainEnv, "knative.dev/testing") +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 65b80ce3291..dceff0a8ab1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -863,6 +863,7 @@ knative.dev/pkg/logging/testing knative.dev/pkg/metrics knative.dev/pkg/metrics/metricskey knative.dev/pkg/metrics/metricstest +knative.dev/pkg/metrics/testing knative.dev/pkg/profiling knative.dev/pkg/ptr knative.dev/pkg/reconciler/testing