From a28b2c7795b972be217e224e184303173d528b26 Mon Sep 17 00:00:00 2001 From: Korbinian Stoemmer Date: Mon, 17 Aug 2020 08:14:22 +0200 Subject: [PATCH] deploy event-source-adapter as apps/deployment instead of ksvc (#9186) * replace ksvc by deployment * bump image * update rbac * dd missing files * add simple service test * add more tests * reorder imports * add metrics port * add missing permissions * fix port name must be 15chars or shorter * remove serving from the upgrade test * bump image * fix rbac for upgrade test * add label for podmonitor * update latency dashboard * fix delivery dashboard * fix tracing * Apply suggestions from code review Co-authored-by: Nils Schmidt * fix comments * remove tracing env var support * dep ensure * fix latency dashboard * fix resources/knative-eventing/charts/event-mesh-dashboard/templates/event-mesh-delivery.yaml * RC from @anishj0shi: Remove dead code and unnecessary type check * Use same cloudevents client in integration test and adapter * Incorporate review comments from sayanh * Incorporate review comments round #2 from sayanh * Remove copy right note in non-autogenerated files * Remove copy right note in autogenerated files (using codegen) * Remove copy right note in resources files * Use Fatal with zap.Error logging * Fix style * Add "Connectivity Validator -> HTTP Source" panel * Incorporate review comments from marcobebway * Add post-upgrade hook to delete orphaned ksvcs * Fix dashboard (order and double graphs in validator->http event source) * Use internal logger * Introduce app label for http source pod for inclusion in pods dashboard * Fix style Co-authored-by: Nils Schmidt Co-authored-by: Nils Schmidt --- components/event-sources/Gopkg.lock | 98 +---- components/event-sources/Gopkg.toml | 3 - components/event-sources/Makefile | 14 - .../event-sources/adapter/http/adapter.go | 69 ++- .../adapter/http/adapter_integration_test.go | 13 +- .../event-sources/apis/sources/register.go | 16 - .../sources/v1alpha1/deepcopy_generated.go | 16 - .../apis/sources/v1alpha1/doc.go | 16 - .../apis/sources/v1alpha1/http_lifecycle.go | 58 ++- .../apis/sources/v1alpha1/http_types.go | 16 - .../apis/sources/v1alpha1/register.go | 16 - .../clientset/internalclientset/clientset.go | 16 - .../clientset/internalclientset/doc.go | 16 - .../fake/clientset_generated.go | 16 - .../clientset/internalclientset/fake/doc.go | 16 - .../internalclientset/fake/register.go | 16 - .../clientset/internalclientset/scheme/doc.go | 16 - .../internalclientset/scheme/register.go | 16 - .../typed/sources/v1alpha1/doc.go | 16 - .../typed/sources/v1alpha1/fake/doc.go | 16 - .../sources/v1alpha1/fake/fake_httpsource.go | 16 - .../v1alpha1/fake/fake_sources_client.go | 16 - .../sources/v1alpha1/generated_expansion.go | 16 - .../typed/sources/v1alpha1/httpsource.go | 16 - .../typed/sources/v1alpha1/sources_client.go | 16 - .../informer/externalversions/factory.go | 16 - .../informer/externalversions/generic.go | 16 - .../internalinterfaces/factory_interfaces.go | 16 - .../externalversions/sources/interface.go | 16 - .../sources/v1alpha1/httpsource.go | 16 - .../sources/v1alpha1/interface.go | 16 - .../generated/injection/client/client.go | 16 - .../generated/injection/client/fake/fake.go | 16 - .../injection/informers/factory/factory.go | 16 - .../injection/informers/factory/fake/fake.go | 16 - .../sources/v1alpha1/httpsource/fake/fake.go | 16 - .../sources/v1alpha1/httpsource/httpsource.go | 16 - .../injection/istio/client/client.go | 16 - .../injection/istio/client/fake/fake.go | 16 - .../v1alpha1/meshpolicy/fake/fake.go | 16 - .../v1alpha1/meshpolicy/meshpolicy.go | 16 - .../v1alpha1/policy/fake/fake.go | 16 - .../authentication/v1alpha1/policy/policy.go | 16 - .../istio/informers/factory/factory.go | 16 - .../istio/informers/factory/fake/fake.go | 16 - .../sources/v1alpha1/expansion_generated.go | 16 - .../lister/sources/v1alpha1/httpsource.go | 16 - .../cmd/controller-manager/main.go | 16 - .../event-sources/cmd/http-adapter/main.go | 28 +- components/event-sources/config/200-rbac.yaml | 44 +- .../config/300-httpsource-crd.yaml | 14 - .../config/400-config-logging.yaml | 14 - .../config/400-config-observability.yaml | 14 - .../config/500-sources-controller.yaml | 14 - .../config/samples/dummy-httpsource.yaml | 14 - .../event-sources/hack/boilerplate.go.txt | 16 - .../event-sources/reconciler/errors/errors.go | 16 - .../reconciler/errors/errors_test.go | 16 - .../event-sources/reconciler/errors/skip.go | 16 - .../reconciler/errors/skip_test.go | 16 - .../reconciler/httpsource/adapter_config.go | 24 +- .../reconciler/httpsource/controller.go | 33 +- .../reconciler/httpsource/controller_test.go | 26 +- .../reconciler/httpsource/event.go | 16 - .../reconciler/httpsource/reconcile.go | 260 +++++++----- .../reconciler/httpsource/reconcile_test.go | 395 +++++++----------- .../reconciler/object/channel.go | 17 - .../reconciler/object/channel_test.go | 51 ++- .../reconciler/object/deployment.go | 142 +++++++ .../reconciler/object/deployment_test.go | 119 ++++++ .../reconciler/object/equality.go | 115 +++-- .../reconciler/object/equality_test.go | 237 +++++++---- .../event-sources/reconciler/object/label.go | 25 +- .../event-sources/reconciler/object/object.go | 16 - .../reconciler/object/object_test.go | 20 +- .../event-sources/reconciler/object/policy.go | 21 +- .../reconciler/object/policy_test.go | 19 +- .../reconciler/object/service.go | 133 +----- .../reconciler/object/service_test.go | 122 ++---- .../reconciler/testing/configmap.go | 16 - .../event-sources/reconciler/testing/env.go | 16 - .../reconciler/testing/factory.go | 25 +- .../reconciler/testing/listers.go | 50 +-- .../test/fixtures/deployment.json | 143 +++++++ .../event-sources/test/fixtures/ksvc.json | 118 ------ .../event-sources/test/fixtures/service.json | 44 ++ resources/event-sources/post-upgrade.sh | 27 ++ .../event-sources/templates/200-rbac.yaml | 31 +- .../templates/500-sources-controller.yaml | 2 - .../templates/post-upgrade-hook.yaml | 91 ++++ resources/event-sources/values.yaml | 4 +- .../templates/event-mesh-delivery.yaml | 12 +- .../event-mesh-latency-dashboard.yaml | 168 +++++++- .../templates/pod-monitor.yaml | 2 +- tests/end-to-end/upgrade/Gopkg.lock | 46 +- tests/end-to-end/upgrade/Gopkg.toml | 4 - .../upgrade/chart/upgrade/templates/rbac.yaml | 4 +- .../upgrade/chart/upgrade/values.yaml | 2 +- tests/end-to-end/upgrade/main.go | 8 +- .../upgrade/pkg/tests/eventmesh/eventmesh.go | 9 +- .../tests/eventmesh/helpers/application.go | 24 +- .../upgrade/pkg/tests/eventmesh/setup.go | 2 +- 102 files changed, 1611 insertions(+), 2177 deletions(-) delete mode 100644 components/event-sources/hack/boilerplate.go.txt create mode 100644 components/event-sources/reconciler/object/deployment.go create mode 100644 components/event-sources/reconciler/object/deployment_test.go create mode 100644 components/event-sources/test/fixtures/deployment.json delete mode 100644 components/event-sources/test/fixtures/ksvc.json create mode 100644 components/event-sources/test/fixtures/service.json create mode 100755 resources/event-sources/post-upgrade.sh create mode 100644 resources/event-sources/templates/post-upgrade-hook.yaml diff --git a/components/event-sources/Gopkg.lock b/components/event-sources/Gopkg.lock index 585a66e1e077..1c5cf62483f3 100644 --- a/components/event-sources/Gopkg.lock +++ b/components/event-sources/Gopkg.lock @@ -166,14 +166,6 @@ revision = "026c730a0dcc5d11f93f1cf1cc65b01247ea7b6f" version = "v4.5.0" -[[projects]] - digest = "1:2cd7915ab26ede7d95b8749e6b1f933f1c6d5398030684e6505940a10f31cfda" - name = "github.com/ghodss/yaml" - packages = ["."] - pruneopts = "T" - revision = "0ca9ea5df5451ffdf184b4428c902747c2c11cd7" - version = "v1.0.0" - [[projects]] digest = "1:6ba54872416168c7f2a8349a681f919ead947cacde2d8e663dfbafeeaf13b17a" name = "github.com/gogo/protobuf" @@ -231,13 +223,6 @@ pruneopts = "T" revision = "6f77996f0c42f7b84e5a2b252227263f93432e9b" -[[projects]] - digest = "1:cd294c5be5e2f5c7c642c50e4f1c190cdf72fd7a72094351985b97aa0cdeefcb" - name = "github.com/google/go-containerregistry" - packages = ["pkg/name"] - pruneopts = "T" - revision = "b02d448a3705facf11018efff34f1d2830be5724" - [[projects]] digest = "1:a6181aca1fd5e27103f9a920876f29ac72854df7345a39f3b01e61c8c94cc8af" name = "github.com/google/gofuzz" @@ -1377,7 +1362,12 @@ "client/injection/ducks/duck/v1/addressable/fake", "client/injection/kube/client", "client/injection/kube/client/fake", + "client/injection/kube/informers/apps/v1/deployment", + "client/injection/kube/informers/apps/v1/deployment/fake", + "client/injection/kube/informers/core/v1/service", + "client/injection/kube/informers/core/v1/service/fake", "client/injection/kube/informers/factory", + "client/injection/kube/informers/factory/fake", "codegen/cmd/injection-gen", "codegen/cmd/injection-gen/args", "codegen/cmd/injection-gen/generators", @@ -1413,61 +1403,6 @@ pruneopts = "T" revision = "b8dc5fbc6d2f4717a69d15382921a51f93ab4cbb" -[[projects]] - branch = "release-0.12" - digest = "1:1d242c5c4e479bf32943c6358122c5662f95e8e7d753b282e053e8108a1f1955" - name = "knative.dev/serving" - packages = [ - "pkg/apis/autoscaling", - "pkg/apis/autoscaling/v1alpha1", - "pkg/apis/config", - "pkg/apis/networking", - "pkg/apis/networking/v1alpha1", - "pkg/apis/serving", - "pkg/apis/serving/v1", - "pkg/apis/serving/v1alpha1", - "pkg/apis/serving/v1beta1", - "pkg/client/clientset/versioned", - "pkg/client/clientset/versioned/fake", - "pkg/client/clientset/versioned/scheme", - "pkg/client/clientset/versioned/typed/autoscaling/v1alpha1", - "pkg/client/clientset/versioned/typed/autoscaling/v1alpha1/fake", - "pkg/client/clientset/versioned/typed/networking/v1alpha1", - "pkg/client/clientset/versioned/typed/networking/v1alpha1/fake", - "pkg/client/clientset/versioned/typed/serving/v1", - "pkg/client/clientset/versioned/typed/serving/v1/fake", - "pkg/client/clientset/versioned/typed/serving/v1alpha1", - "pkg/client/clientset/versioned/typed/serving/v1alpha1/fake", - "pkg/client/clientset/versioned/typed/serving/v1beta1", - "pkg/client/clientset/versioned/typed/serving/v1beta1/fake", - "pkg/client/informers/externalversions", - "pkg/client/informers/externalversions/autoscaling", - "pkg/client/informers/externalversions/autoscaling/v1alpha1", - "pkg/client/informers/externalversions/internalinterfaces", - "pkg/client/informers/externalversions/networking", - "pkg/client/informers/externalversions/networking/v1alpha1", - "pkg/client/informers/externalversions/serving", - "pkg/client/informers/externalversions/serving/v1", - "pkg/client/informers/externalversions/serving/v1alpha1", - "pkg/client/informers/externalversions/serving/v1beta1", - "pkg/client/injection/client", - "pkg/client/injection/client/fake", - "pkg/client/injection/informers/factory", - "pkg/client/injection/informers/factory/fake", - "pkg/client/injection/informers/serving/v1alpha1/service", - "pkg/client/injection/informers/serving/v1alpha1/service/fake", - "pkg/client/listers/autoscaling/v1alpha1", - "pkg/client/listers/networking/v1alpha1", - "pkg/client/listers/serving/v1", - "pkg/client/listers/serving/v1alpha1", - "pkg/client/listers/serving/v1beta1", - "pkg/gc", - "pkg/network", - "pkg/reconciler/route/config", - ] - pruneopts = "T" - revision = "e4922e8a9ec460e78ab02ef598e042650131d6fe" - [[projects]] digest = "1:7719608fe0b52a4ece56c2dde37bedd95b938677d1ab0f84b8a7852e4c59f849" name = "sigs.k8s.io/yaml" @@ -1497,6 +1432,7 @@ "istio.io/client-go/pkg/informers/externalversions", "istio.io/client-go/pkg/informers/externalversions/authentication/v1alpha1", "istio.io/client-go/pkg/listers/authentication/v1alpha1", + "k8s.io/api/apps/v1", "k8s.io/api/core/v1", "k8s.io/apimachinery/pkg/api/errors", "k8s.io/apimachinery/pkg/api/meta", @@ -1514,7 +1450,10 @@ "k8s.io/apimachinery/pkg/watch", "k8s.io/client-go/discovery", "k8s.io/client-go/discovery/fake", + "k8s.io/client-go/kubernetes/fake", "k8s.io/client-go/kubernetes/scheme", + "k8s.io/client-go/listers/apps/v1", + "k8s.io/client-go/listers/core/v1", "k8s.io/client-go/plugin/pkg/client/auth/gcp", "k8s.io/client-go/rest", "k8s.io/client-go/testing", @@ -1538,15 +1477,17 @@ "knative.dev/eventing/pkg/legacyclient/clientset/versioned/fake", "knative.dev/eventing/pkg/legacyclient/injection/client/fake", "knative.dev/eventing/pkg/reconciler", - "knative.dev/eventing/pkg/tracing", "knative.dev/eventing/pkg/utils", "knative.dev/pkg/apis", - "knative.dev/pkg/apis/duck/v1", "knative.dev/pkg/apis/duck/v1alpha1", "knative.dev/pkg/apis/duck/v1beta1", "knative.dev/pkg/client/injection/ducks/duck/v1/addressable", "knative.dev/pkg/client/injection/ducks/duck/v1/addressable/fake", "knative.dev/pkg/client/injection/kube/client/fake", + "knative.dev/pkg/client/injection/kube/informers/apps/v1/deployment", + "knative.dev/pkg/client/injection/kube/informers/apps/v1/deployment/fake", + "knative.dev/pkg/client/injection/kube/informers/core/v1/service", + "knative.dev/pkg/client/injection/kube/informers/core/v1/service/fake", "knative.dev/pkg/codegen/cmd/injection-gen", "knative.dev/pkg/configmap", "knative.dev/pkg/controller", @@ -1564,19 +1505,6 @@ "knative.dev/pkg/source", "knative.dev/pkg/system", "knative.dev/pkg/tracing", - "knative.dev/pkg/tracing/config", - "knative.dev/serving/pkg/apis/autoscaling", - "knative.dev/serving/pkg/apis/serving", - "knative.dev/serving/pkg/apis/serving/v1", - "knative.dev/serving/pkg/apis/serving/v1alpha1", - "knative.dev/serving/pkg/client/clientset/versioned/fake", - "knative.dev/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1", - "knative.dev/serving/pkg/client/injection/client", - "knative.dev/serving/pkg/client/injection/client/fake", - "knative.dev/serving/pkg/client/injection/informers/serving/v1alpha1/service", - "knative.dev/serving/pkg/client/injection/informers/serving/v1alpha1/service/fake", - "knative.dev/serving/pkg/client/listers/serving/v1alpha1", - "knative.dev/serving/pkg/reconciler/route/config", ] solver-name = "gps-cdcl" solver-version = 1 diff --git a/components/event-sources/Gopkg.toml b/components/event-sources/Gopkg.toml index e7233be2753e..ba8993b0470c 100644 --- a/components/event-sources/Gopkg.toml +++ b/components/event-sources/Gopkg.toml @@ -15,9 +15,6 @@ required = [ revision = "b7391e95e576cacdcdd422573063bc057239113d" # Direct dependencies -[[constraint]] - name = "knative.dev/serving" - branch = "release-0.12" [[constraint]] name = "knative.dev/pkg" branch = "release-0.12" diff --git a/components/event-sources/Makefile b/components/event-sources/Makefile index bd41662c5c51..452c2d836410 100644 --- a/components/event-sources/Makefile +++ b/components/event-sources/Makefile @@ -1,17 +1,3 @@ -# Copyright 2019 The Kyma 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 -# -# http://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. - APP_NAME = event-sources APP_PATH = components/event-sources BUILDPACK = eu.gcr.io/kyma-project/test-infra/buildpack-golang-toolbox:v20200423-1d9d6590 diff --git a/components/event-sources/adapter/http/adapter.go b/components/event-sources/adapter/http/adapter.go index f614f3c373fe..c6521a7b82cf 100644 --- a/components/event-sources/adapter/http/adapter.go +++ b/components/event-sources/adapter/http/adapter.go @@ -3,29 +3,32 @@ package http import ( "context" "fmt" - "log" "net/http" + "net/url" cloudevents "github.com/cloudevents/sdk-go" + cloudeventshttp "github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http" "github.com/pkg/errors" "go.opencensus.io/trace" "go.uber.org/zap" "knative.dev/eventing/pkg/adapter" + "knative.dev/eventing/pkg/kncloudevents" "knative.dev/eventing/pkg/utils" "knative.dev/pkg/logging" "knative.dev/pkg/source" - "knative.dev/pkg/tracing" + pkgtracing "knative.dev/pkg/tracing" "github.com/kyma-project/kyma/components/event-sources/apis/sources" ) +var _ adapter.EnvConfigAccessor = (*envConfig)(nil) + type envConfig struct { adapter.EnvConfig EventSource string `envconfig:"EVENT_SOURCE" required:"true"` // PORT as required by knative serving runtime contract - Port int `envconfig:"PORT" required:"true" default:"8080"` - TracingEnabled bool `envconfig:"TRACING_ENABLED" default:"true"` + Port int `envconfig:"PORT" required:"true" default:"8080"` } func (e *envConfig) GetSource() string { @@ -36,10 +39,6 @@ func (e *envConfig) GetPort() int { return e.Port } -func (e *envConfig) IsTracingEnabled() bool { - return e.TracingEnabled -} - type httpAdapter struct { ceClient cloudevents.Client statsReporter source.StatsReporter @@ -52,9 +51,13 @@ type AdapterEnvConfigAccessor interface { adapter.EnvConfigAccessor GetSource() string GetPort() int - IsTracingEnabled() bool } +const ( + defaultMaxIdleConnections = 1000 + defaultMaxIdleConnectionsPerHost = 1000 +) + const resourceGroup = "http." + sources.GroupName const ( @@ -90,32 +93,49 @@ func NewAdapter(ctx context.Context, processed adapter.EnvConfigAccessor, ceClie } } -// Start is the entrypoint for the adapter and is called by sharedmain coming from pkg/adapter -func (h *httpAdapter) Start(_ <-chan struct{}) error { - - t, err := cloudevents.NewHTTPTransport( - cloudevents.WithPort(h.accessor.GetPort()), +// NewCloudEventsClient creates a new client for receiving and sending cloud events +func NewCloudEventsClient(port int) (cloudevents.Client, error) { + options := []cloudeventshttp.Option{ + cloudevents.WithBinaryEncoding(), + cloudevents.WithMiddleware(pkgtracing.HTTPSpanMiddleware), + cloudevents.WithPort(port), cloudevents.WithPath(endpointCE), cloudevents.WithMiddleware(WithReadinessMiddleware), - cloudevents.WithMiddleware(tracing.HTTPSpanMiddleware), + } + + httpTransport, err := cloudevents.NewHTTPTransport( + options..., ) if err != nil { - return errors.Wrap(err, "failed to create transport") + return nil, errors.Wrap(err, "failed to create transport") } - c, err := cloudevents.NewClient(t) + connectionArgs := kncloudevents.ConnectionArgs{ + MaxIdleConns: defaultMaxIdleConnections, + MaxIdleConnsPerHost: defaultMaxIdleConnectionsPerHost, + } + + ceClient, err := kncloudevents.NewDefaultClientGivenHttpTransport( + httpTransport, + &connectionArgs) + if err != nil { - return errors.Wrap(err, "failed to create client") + return nil, errors.Wrap(err, "failed to create client") } + return ceClient, nil +} + +// Start is the entrypoint for the adapter and is called by sharedmain coming from pkg/adapter +func (h *httpAdapter) Start(_ <-chan struct{}) error { - log.Printf("listening on :%d%s\n", h.accessor.GetPort(), endpointCE) + h.logger.Info("listening on", zap.String("address", fmt.Sprintf("%d%s", h.accessor.GetPort(), endpointCE))) // note about graceful shutdown: // TLDR; StartReceiver unblocks as soon as a stop signal is received // `StartReceiver` waits internally until `ctx.Done()` does not block anymore // the context `h.adapterContext` returns a channel (when calling `ctx.Done()`) // which is closed as soon as a stop signal is received, see https://github.com/knative/pkg/blob/master/signals/signal.go#L37 - if err := c.StartReceiver(h.adapterContext, h.serveHTTP); err != nil { + if err := h.ceClient.StartReceiver(h.adapterContext, h.serveHTTP); err != nil { return errors.Wrap(err, "error occurred while serving") } h.logger.Info("adapter stopped") @@ -176,8 +196,13 @@ func (h *httpAdapter) serveHTTP(ctx context.Context, event cloudevents.Event, re // Shamelessly copied from https://github.com/knative/eventing/blob/5631d771968bbf00e64988a0e4217c2915ee778e/pkg/broker/ingress/ingress_handler.go#L116 // Due to an issue in utils.ContextFrom, we don't retain the original trace context from ctx, so // bring it in manually. - sendingCTX := utils.ContextFrom(tctx, nil) - sendingCTX = trace.NewContext(sendingCTX, trace.FromContext(ctx)) + uri, err := url.Parse(h.accessor.GetSinkURI()) + if err != nil { + return err + } + sendingCTX := utils.ContextFrom(tctx, uri) + trc := trace.FromContext(ctx) + sendingCTX = trace.NewContext(sendingCTX, trc) rctx, revt, err := h.ceClient.Send(sendingCTX, event) if err != nil { h.logger.Error("failed to send cloudevent to sink", zap.Error(err), zap.Any("sink", h.accessor.GetSinkURI())) diff --git a/components/event-sources/adapter/http/adapter_integration_test.go b/components/event-sources/adapter/http/adapter_integration_test.go index ab35e2172a87..2a40d080bfc4 100644 --- a/components/event-sources/adapter/http/adapter_integration_test.go +++ b/components/event-sources/adapter/http/adapter_integration_test.go @@ -355,7 +355,11 @@ func TestAdapterShutdown(t *testing.T) { // used to simulate sending a stop signal ctx, cancelFunc := context.WithCancel(ctx) - httpAdapter := NewAdapter(ctx, c, nil, nil) + sinkClient, err := kncloudevents.NewDefaultClient(c.GetSinkURI()) + if err != nil { + t.Fatal("error building cloud event client", zap.Error(err)) + } + httpAdapter := NewAdapter(ctx, c, sinkClient, nil) stopChannel := make(chan error) // start adapter @@ -432,11 +436,12 @@ func waitAdapterReady(t *testing.T, adapterURI string) { } // startHttpAdapter starts the adapter with a cloudevents client configured with the test sink as target -func startHttpAdapter(t *testing.T, c adapter.EnvConfigAccessor, ctx context.Context) *adapter.Adapter { - sinkClient, err := kncloudevents.NewDefaultClient(c.GetSinkURI()) +func startHttpAdapter(t *testing.T, c *envConfig, ctx context.Context) *adapter.Adapter { + sinkClient, err := NewCloudEventsClient(c.GetPort()) if err != nil { - t.Fatal("error building cloud event client", zap.Error(err)) + t.Fatalf("error while creating sinkclient: %+v", err) } + statsReporter, err := source.NewStatsReporter() if err != nil { t.Errorf("error building statsreporter: %v", err) diff --git a/components/event-sources/apis/sources/register.go b/components/event-sources/apis/sources/register.go index 78b6aef10454..2887f84c1aef 100644 --- a/components/event-sources/apis/sources/register.go +++ b/components/event-sources/apis/sources/register.go @@ -1,19 +1,3 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 sources const ( diff --git a/components/event-sources/apis/sources/v1alpha1/deepcopy_generated.go b/components/event-sources/apis/sources/v1alpha1/deepcopy_generated.go index 2af2c931a257..6227b68bec9a 100644 --- a/components/event-sources/apis/sources/v1alpha1/deepcopy_generated.go +++ b/components/event-sources/apis/sources/v1alpha1/deepcopy_generated.go @@ -1,21 +1,5 @@ // +build !ignore_autogenerated -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by deepcopy-gen. DO NOT EDIT. package v1alpha1 diff --git a/components/event-sources/apis/sources/v1alpha1/doc.go b/components/event-sources/apis/sources/v1alpha1/doc.go index 64f2a0464c15..6a81e16c50c2 100644 --- a/components/event-sources/apis/sources/v1alpha1/doc.go +++ b/components/event-sources/apis/sources/v1alpha1/doc.go @@ -1,19 +1,3 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 v1alpha1 contains the definition of custom API objects. // +k8s:deepcopy-gen=package // +groupName=sources.kyma-project.io diff --git a/components/event-sources/apis/sources/v1alpha1/http_lifecycle.go b/components/event-sources/apis/sources/v1alpha1/http_lifecycle.go index 9d9548eb7242..108245ee62e6 100644 --- a/components/event-sources/apis/sources/v1alpha1/http_lifecycle.go +++ b/components/event-sources/apis/sources/v1alpha1/http_lifecycle.go @@ -1,28 +1,13 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 v1alpha1 import ( + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" + "knative.dev/pkg/apis" authenticationv1alpha1 "istio.io/client-go/pkg/apis/authentication/v1alpha1" - "knative.dev/pkg/apis" - servingv1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" ) const ( @@ -35,13 +20,19 @@ const ( HTTPConditionDeployed apis.ConditionType = "Deployed" // HTTPConditionPolicyCreated has status True when the Policy for - // Knative service has been successfully created. + // Deployment has been successfully created. HTTPConditionPolicyCreated apis.ConditionType = "PolicyCreated" + + // HTTPConditionServiceCreated has status True when the Service for + // Deployment has been successfully created. + HTTPConditionServiceCreated apis.ConditionType = "ServiceCreated" ) var httpCondSet = apis.NewLivingConditionSet( HTTPConditionSinkProvided, HTTPConditionDeployed, + HTTPConditionPolicyCreated, + HTTPConditionServiceCreated, ) // HTTPSourceGVK returns a GroupVersionKind for the HTTPSource type. @@ -60,10 +51,11 @@ func (s *HTTPSource) ToKey() string { } const ( - HTTPSourceReasonSinkNotFound = "SinkNotFound" - HTTPSourceReasonSinkEmpty = "EmptySinkURI" - HTTPSourceReasonServiceNotReady = "ServiceNotReady" - HTTPSourceReasonPolicyNotCreated = "PolicyNotCreated" + HTTPSourceReasonSinkNotFound = "SinkNotFound" + HTTPSourceReasonSinkEmpty = "EmptySinkURI" + HTTPSourceReasonServiceNotReady = "ServiceNotReady" + HTTPSourceReasonPolicyNotCreated = "PolicyNotCreated" + HTTPSourceReasonServiceNotCreated = "ServiceNotCreated" ) // InitializeConditions sets relevant unset conditions to Unknown state. @@ -82,6 +74,16 @@ func (s *HTTPSourceStatus) MarkSink(uri string) { httpCondSet.Manage(s).MarkTrue(HTTPConditionSinkProvided) } +// MarkServiceCreated sets the ServiceCreated condition to True once a Service is created. +func (s *HTTPSourceStatus) MarkServiceCreated(service *corev1.Service) { + if service == nil { + httpCondSet.Manage(s).MarkUnknown(HTTPConditionServiceCreated, + HTTPSourceReasonServiceNotCreated, "The Service is not created") + return + } + httpCondSet.Manage(s).MarkTrue(HTTPConditionServiceCreated) +} + // MarkPolicyCreated sets the PolicyCreated condition to True once a Policy is created. func (s *HTTPSourceStatus) MarkPolicyCreated(policy *authenticationv1alpha1.Policy) { if policy == nil { @@ -100,19 +102,15 @@ func (s *HTTPSourceStatus) MarkNoSink() { HTTPSourceReasonSinkNotFound, "The sink does not exist or its URL is not set") } -// PropagateServiceReady uses the readiness of the provided Knative Service to +// PropagateDeploymentReady uses the readiness of the provided Deployment to // determine whether the Deployed condition should be marked as true or false. -func (s *HTTPSourceStatus) PropagateServiceReady(ksvc *servingv1alpha1.Service) { - if ksvc.Status.IsReady() { +func (s *HTTPSourceStatus) PropagateDeploymentReady(deployment *appsv1.Deployment) { + if deployment.Status.AvailableReplicas > 0 { httpCondSet.Manage(s).MarkTrue(HTTPConditionDeployed) return } msg := "The adapter Service is not yet ready" - ksvcCondReady := ksvc.Status.GetCondition(servingv1alpha1.ServiceConditionReady) - if ksvcCondReady != nil && ksvcCondReady.Message != "" { - msg += ": " + ksvcCondReady.Message - } httpCondSet.Manage(s).MarkFalse(HTTPConditionDeployed, HTTPSourceReasonServiceNotReady, msg) } diff --git a/components/event-sources/apis/sources/v1alpha1/http_types.go b/components/event-sources/apis/sources/v1alpha1/http_types.go index 07f7dc61ab89..daa18cf27664 100644 --- a/components/event-sources/apis/sources/v1alpha1/http_types.go +++ b/components/event-sources/apis/sources/v1alpha1/http_types.go @@ -1,19 +1,3 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 v1alpha1 import ( diff --git a/components/event-sources/apis/sources/v1alpha1/register.go b/components/event-sources/apis/sources/v1alpha1/register.go index 6fc4c528b1a1..8d543a06db91 100644 --- a/components/event-sources/apis/sources/v1alpha1/register.go +++ b/components/event-sources/apis/sources/v1alpha1/register.go @@ -1,19 +1,3 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 v1alpha1 import ( diff --git a/components/event-sources/client/generated/clientset/internalclientset/clientset.go b/components/event-sources/client/generated/clientset/internalclientset/clientset.go index 3f52398253df..877da98715d6 100644 --- a/components/event-sources/client/generated/clientset/internalclientset/clientset.go +++ b/components/event-sources/client/generated/clientset/internalclientset/clientset.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by client-gen. DO NOT EDIT. package internalclientset diff --git a/components/event-sources/client/generated/clientset/internalclientset/doc.go b/components/event-sources/client/generated/clientset/internalclientset/doc.go index 881da9585d95..c4ae65d85dd9 100644 --- a/components/event-sources/client/generated/clientset/internalclientset/doc.go +++ b/components/event-sources/client/generated/clientset/internalclientset/doc.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by client-gen. DO NOT EDIT. // This package has the automatically generated clientset. diff --git a/components/event-sources/client/generated/clientset/internalclientset/fake/clientset_generated.go b/components/event-sources/client/generated/clientset/internalclientset/fake/clientset_generated.go index 319542d4ac3f..6dd86f1dda68 100644 --- a/components/event-sources/client/generated/clientset/internalclientset/fake/clientset_generated.go +++ b/components/event-sources/client/generated/clientset/internalclientset/fake/clientset_generated.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by client-gen. DO NOT EDIT. package fake diff --git a/components/event-sources/client/generated/clientset/internalclientset/fake/doc.go b/components/event-sources/client/generated/clientset/internalclientset/fake/doc.go index ac52d3fa87ea..3630ed1cd17d 100644 --- a/components/event-sources/client/generated/clientset/internalclientset/fake/doc.go +++ b/components/event-sources/client/generated/clientset/internalclientset/fake/doc.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by client-gen. DO NOT EDIT. // This package has the automatically generated fake clientset. diff --git a/components/event-sources/client/generated/clientset/internalclientset/fake/register.go b/components/event-sources/client/generated/clientset/internalclientset/fake/register.go index f0386c920569..c3918a826ac6 100644 --- a/components/event-sources/client/generated/clientset/internalclientset/fake/register.go +++ b/components/event-sources/client/generated/clientset/internalclientset/fake/register.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by client-gen. DO NOT EDIT. package fake diff --git a/components/event-sources/client/generated/clientset/internalclientset/scheme/doc.go b/components/event-sources/client/generated/clientset/internalclientset/scheme/doc.go index ec30339967c9..14db57a58f8d 100644 --- a/components/event-sources/client/generated/clientset/internalclientset/scheme/doc.go +++ b/components/event-sources/client/generated/clientset/internalclientset/scheme/doc.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by client-gen. DO NOT EDIT. // This package contains the scheme of the automatically generated clientset. diff --git a/components/event-sources/client/generated/clientset/internalclientset/scheme/register.go b/components/event-sources/client/generated/clientset/internalclientset/scheme/register.go index a548eeb062db..2268a7c1a0f3 100644 --- a/components/event-sources/client/generated/clientset/internalclientset/scheme/register.go +++ b/components/event-sources/client/generated/clientset/internalclientset/scheme/register.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by client-gen. DO NOT EDIT. package scheme diff --git a/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/doc.go b/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/doc.go index 03b779914abe..93a7ca4e0e2b 100644 --- a/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/doc.go +++ b/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/doc.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by client-gen. DO NOT EDIT. // This package has the automatically generated typed clients. diff --git a/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/fake/doc.go b/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/fake/doc.go index ca3443a33c9b..2b5ba4c8e442 100644 --- a/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/fake/doc.go +++ b/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/fake/doc.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by client-gen. DO NOT EDIT. // Package fake has the automatically generated clients. diff --git a/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/fake/fake_httpsource.go b/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/fake/fake_httpsource.go index 2aad26ad34a6..1b4561c82720 100644 --- a/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/fake/fake_httpsource.go +++ b/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/fake/fake_httpsource.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by client-gen. DO NOT EDIT. package fake diff --git a/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/fake/fake_sources_client.go b/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/fake/fake_sources_client.go index 3c08d583b9b5..0b73af31a59b 100644 --- a/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/fake/fake_sources_client.go +++ b/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/fake/fake_sources_client.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by client-gen. DO NOT EDIT. package fake diff --git a/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/generated_expansion.go b/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/generated_expansion.go index 092325f34acc..5c9c0639053e 100644 --- a/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/generated_expansion.go +++ b/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/generated_expansion.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by client-gen. DO NOT EDIT. package v1alpha1 diff --git a/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/httpsource.go b/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/httpsource.go index 6f2dc843667c..352a6db1530b 100644 --- a/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/httpsource.go +++ b/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/httpsource.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by client-gen. DO NOT EDIT. package v1alpha1 diff --git a/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/sources_client.go b/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/sources_client.go index b8b414b5399a..8f6a48647557 100644 --- a/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/sources_client.go +++ b/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1/sources_client.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by client-gen. DO NOT EDIT. package v1alpha1 diff --git a/components/event-sources/client/generated/informer/externalversions/factory.go b/components/event-sources/client/generated/informer/externalversions/factory.go index 63933e26270e..9cfca2906b12 100644 --- a/components/event-sources/client/generated/informer/externalversions/factory.go +++ b/components/event-sources/client/generated/informer/externalversions/factory.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by informer-gen. DO NOT EDIT. package externalversions diff --git a/components/event-sources/client/generated/informer/externalversions/generic.go b/components/event-sources/client/generated/informer/externalversions/generic.go index aa1338db8215..2a5d6fe46fd9 100644 --- a/components/event-sources/client/generated/informer/externalversions/generic.go +++ b/components/event-sources/client/generated/informer/externalversions/generic.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by informer-gen. DO NOT EDIT. package externalversions diff --git a/components/event-sources/client/generated/informer/externalversions/internalinterfaces/factory_interfaces.go b/components/event-sources/client/generated/informer/externalversions/internalinterfaces/factory_interfaces.go index ffb179a86c6c..02e84bcd89ef 100644 --- a/components/event-sources/client/generated/informer/externalversions/internalinterfaces/factory_interfaces.go +++ b/components/event-sources/client/generated/informer/externalversions/internalinterfaces/factory_interfaces.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by informer-gen. DO NOT EDIT. package internalinterfaces diff --git a/components/event-sources/client/generated/informer/externalversions/sources/interface.go b/components/event-sources/client/generated/informer/externalversions/sources/interface.go index 53f1f5c29625..456bfc40ef1e 100644 --- a/components/event-sources/client/generated/informer/externalversions/sources/interface.go +++ b/components/event-sources/client/generated/informer/externalversions/sources/interface.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by informer-gen. DO NOT EDIT. package sources diff --git a/components/event-sources/client/generated/informer/externalversions/sources/v1alpha1/httpsource.go b/components/event-sources/client/generated/informer/externalversions/sources/v1alpha1/httpsource.go index bea4bfbdf9b0..47402496f9ed 100644 --- a/components/event-sources/client/generated/informer/externalversions/sources/v1alpha1/httpsource.go +++ b/components/event-sources/client/generated/informer/externalversions/sources/v1alpha1/httpsource.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by informer-gen. DO NOT EDIT. package v1alpha1 diff --git a/components/event-sources/client/generated/informer/externalversions/sources/v1alpha1/interface.go b/components/event-sources/client/generated/informer/externalversions/sources/v1alpha1/interface.go index 45479e9f0ed3..cbd339585c97 100644 --- a/components/event-sources/client/generated/informer/externalversions/sources/v1alpha1/interface.go +++ b/components/event-sources/client/generated/informer/externalversions/sources/v1alpha1/interface.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by informer-gen. DO NOT EDIT. package v1alpha1 diff --git a/components/event-sources/client/generated/injection/client/client.go b/components/event-sources/client/generated/injection/client/client.go index 78503789ce26..0e8dfe17642e 100644 --- a/components/event-sources/client/generated/injection/client/client.go +++ b/components/event-sources/client/generated/injection/client/client.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by injection-gen. DO NOT EDIT. package client diff --git a/components/event-sources/client/generated/injection/client/fake/fake.go b/components/event-sources/client/generated/injection/client/fake/fake.go index 96114490a7d2..504a1d050d9c 100644 --- a/components/event-sources/client/generated/injection/client/fake/fake.go +++ b/components/event-sources/client/generated/injection/client/fake/fake.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by injection-gen. DO NOT EDIT. package fake diff --git a/components/event-sources/client/generated/injection/informers/factory/factory.go b/components/event-sources/client/generated/injection/informers/factory/factory.go index dddc4d573d25..2e0b33c1665e 100644 --- a/components/event-sources/client/generated/injection/informers/factory/factory.go +++ b/components/event-sources/client/generated/injection/informers/factory/factory.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by injection-gen. DO NOT EDIT. package factory diff --git a/components/event-sources/client/generated/injection/informers/factory/fake/fake.go b/components/event-sources/client/generated/injection/informers/factory/fake/fake.go index 97bddeaedd9a..decf3723a2a8 100644 --- a/components/event-sources/client/generated/injection/informers/factory/fake/fake.go +++ b/components/event-sources/client/generated/injection/informers/factory/fake/fake.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by injection-gen. DO NOT EDIT. package fake diff --git a/components/event-sources/client/generated/injection/informers/sources/v1alpha1/httpsource/fake/fake.go b/components/event-sources/client/generated/injection/informers/sources/v1alpha1/httpsource/fake/fake.go index a05678f972ea..1d3dca0b78fc 100644 --- a/components/event-sources/client/generated/injection/informers/sources/v1alpha1/httpsource/fake/fake.go +++ b/components/event-sources/client/generated/injection/informers/sources/v1alpha1/httpsource/fake/fake.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by injection-gen. DO NOT EDIT. package fake diff --git a/components/event-sources/client/generated/injection/informers/sources/v1alpha1/httpsource/httpsource.go b/components/event-sources/client/generated/injection/informers/sources/v1alpha1/httpsource/httpsource.go index 6afd1ab17968..a71eda3b7339 100644 --- a/components/event-sources/client/generated/injection/informers/sources/v1alpha1/httpsource/httpsource.go +++ b/components/event-sources/client/generated/injection/informers/sources/v1alpha1/httpsource/httpsource.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by injection-gen. DO NOT EDIT. package httpsource diff --git a/components/event-sources/client/generated/injection/istio/client/client.go b/components/event-sources/client/generated/injection/istio/client/client.go index a2acbc461f38..d792eac8d631 100644 --- a/components/event-sources/client/generated/injection/istio/client/client.go +++ b/components/event-sources/client/generated/injection/istio/client/client.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by injection-gen. DO NOT EDIT. package client diff --git a/components/event-sources/client/generated/injection/istio/client/fake/fake.go b/components/event-sources/client/generated/injection/istio/client/fake/fake.go index 5e8fc29e4961..c58efd2f1efc 100644 --- a/components/event-sources/client/generated/injection/istio/client/fake/fake.go +++ b/components/event-sources/client/generated/injection/istio/client/fake/fake.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by injection-gen. DO NOT EDIT. package fake diff --git a/components/event-sources/client/generated/injection/istio/informers/authentication/v1alpha1/meshpolicy/fake/fake.go b/components/event-sources/client/generated/injection/istio/informers/authentication/v1alpha1/meshpolicy/fake/fake.go index 26204e7a762e..101586fdb89d 100644 --- a/components/event-sources/client/generated/injection/istio/informers/authentication/v1alpha1/meshpolicy/fake/fake.go +++ b/components/event-sources/client/generated/injection/istio/informers/authentication/v1alpha1/meshpolicy/fake/fake.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by injection-gen. DO NOT EDIT. package fake diff --git a/components/event-sources/client/generated/injection/istio/informers/authentication/v1alpha1/meshpolicy/meshpolicy.go b/components/event-sources/client/generated/injection/istio/informers/authentication/v1alpha1/meshpolicy/meshpolicy.go index 9306f2f82666..d8b863c6e221 100644 --- a/components/event-sources/client/generated/injection/istio/informers/authentication/v1alpha1/meshpolicy/meshpolicy.go +++ b/components/event-sources/client/generated/injection/istio/informers/authentication/v1alpha1/meshpolicy/meshpolicy.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by injection-gen. DO NOT EDIT. package meshpolicy diff --git a/components/event-sources/client/generated/injection/istio/informers/authentication/v1alpha1/policy/fake/fake.go b/components/event-sources/client/generated/injection/istio/informers/authentication/v1alpha1/policy/fake/fake.go index 02613ecd6617..de66852e6f5f 100644 --- a/components/event-sources/client/generated/injection/istio/informers/authentication/v1alpha1/policy/fake/fake.go +++ b/components/event-sources/client/generated/injection/istio/informers/authentication/v1alpha1/policy/fake/fake.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by injection-gen. DO NOT EDIT. package fake diff --git a/components/event-sources/client/generated/injection/istio/informers/authentication/v1alpha1/policy/policy.go b/components/event-sources/client/generated/injection/istio/informers/authentication/v1alpha1/policy/policy.go index 64953fe40d83..f366c6847428 100644 --- a/components/event-sources/client/generated/injection/istio/informers/authentication/v1alpha1/policy/policy.go +++ b/components/event-sources/client/generated/injection/istio/informers/authentication/v1alpha1/policy/policy.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by injection-gen. DO NOT EDIT. package policy diff --git a/components/event-sources/client/generated/injection/istio/informers/factory/factory.go b/components/event-sources/client/generated/injection/istio/informers/factory/factory.go index 1813da91845f..f5e2308b8d70 100644 --- a/components/event-sources/client/generated/injection/istio/informers/factory/factory.go +++ b/components/event-sources/client/generated/injection/istio/informers/factory/factory.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by injection-gen. DO NOT EDIT. package factory diff --git a/components/event-sources/client/generated/injection/istio/informers/factory/fake/fake.go b/components/event-sources/client/generated/injection/istio/informers/factory/fake/fake.go index 72a79c2e5009..2bdd305b325a 100644 --- a/components/event-sources/client/generated/injection/istio/informers/factory/fake/fake.go +++ b/components/event-sources/client/generated/injection/istio/informers/factory/fake/fake.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by injection-gen. DO NOT EDIT. package fake diff --git a/components/event-sources/client/generated/lister/sources/v1alpha1/expansion_generated.go b/components/event-sources/client/generated/lister/sources/v1alpha1/expansion_generated.go index e310482c03f2..a09660b3a2f6 100644 --- a/components/event-sources/client/generated/lister/sources/v1alpha1/expansion_generated.go +++ b/components/event-sources/client/generated/lister/sources/v1alpha1/expansion_generated.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by lister-gen. DO NOT EDIT. package v1alpha1 diff --git a/components/event-sources/client/generated/lister/sources/v1alpha1/httpsource.go b/components/event-sources/client/generated/lister/sources/v1alpha1/httpsource.go index b01cbd951912..e3296014bfa2 100644 --- a/components/event-sources/client/generated/lister/sources/v1alpha1/httpsource.go +++ b/components/event-sources/client/generated/lister/sources/v1alpha1/httpsource.go @@ -1,19 +1,3 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - // Code generated by lister-gen. DO NOT EDIT. package v1alpha1 diff --git a/components/event-sources/cmd/controller-manager/main.go b/components/event-sources/cmd/controller-manager/main.go index 273fda3934d8..e2b93466d5ce 100644 --- a/components/event-sources/cmd/controller-manager/main.go +++ b/components/event-sources/cmd/controller-manager/main.go @@ -1,19 +1,3 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 main import ( diff --git a/components/event-sources/cmd/http-adapter/main.go b/components/event-sources/cmd/http-adapter/main.go index 52c38de2dd66..7e4563e9dfae 100644 --- a/components/event-sources/cmd/http-adapter/main.go +++ b/components/event-sources/cmd/http-adapter/main.go @@ -11,22 +11,15 @@ import ( "go.opencensus.io/stats/view" "go.uber.org/zap" "knative.dev/eventing/pkg/adapter" - "knative.dev/eventing/pkg/kncloudevents" - "knative.dev/eventing/pkg/tracing" "knative.dev/pkg/logging" "knative.dev/pkg/metrics" "knative.dev/pkg/profiling" "knative.dev/pkg/signals" "knative.dev/pkg/source" - tracingconfig "knative.dev/pkg/tracing/config" eshttp "github.com/kyma-project/kyma/components/event-sources/adapter/http" ) -var DisabledTracingConfig = &tracingconfig.Config{ - Backend: tracingconfig.None, -} - func main() { setupAdapter("http-source", eshttp.NewEnvConfig, eshttp.NewAdapter) } @@ -97,27 +90,14 @@ func setupAdapter(component string, ector adapter.EnvConfigConstructor, ctor ada logger.Error("error building statsreporter", zap.Error(err)) } - tracingCfg := DisabledTracingConfig - - switch v := interface{}(ector).(type) { - case eshttp.AdapterEnvConfigAccessor: - if v.IsTracingEnabled() { - tracingCfg = tracing.OnePercentSampling - } - } - if err = tracing.SetupStaticPublishing(logger, "", tracingCfg); err != nil { - // If tracing doesn't work, we will log an error, but allow the adapter - // to continue to start. - logger.Error("Error setting up trace publishing", zap.Error(err)) - } - - eventsClient, err := kncloudevents.NewDefaultClient(env.GetSinkURI()) + v := env.(eshttp.AdapterEnvConfigAccessor) + ceClient, err := eshttp.NewCloudEventsClient(v.GetPort()) if err != nil { - logger.Fatal("error building cloud event client", zap.Error(err)) + logger.Fatal("Could not create cloudevents client", zap.Error(err)) } // Configuring the adapter - adptr := ctor(ctx, env, eventsClient, reporter) + adptr := ctor(ctx, env, ceClient, reporter) logger.Info("Starting Receive Adapter", zap.Any("adapter", adptr)) diff --git a/components/event-sources/config/200-rbac.yaml b/components/event-sources/config/200-rbac.yaml index e5180fcdaf9f..89840e178041 100644 --- a/components/event-sources/config/200-rbac.yaml +++ b/components/event-sources/config/200-rbac.yaml @@ -1,17 +1,3 @@ -# Copyright 2019 The Kyma 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 -# -# http://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. - apiVersion: v1 kind: ServiceAccount metadata: @@ -23,6 +9,26 @@ kind: ClusterRole metadata: name: event-sources-controller-manager rules: + - apiGroups: + - "" + resources: + - services + verbs: + - get + - list + - create + - update + - watch + - apiGroups: + - apps + resources: + - deployments + verbs: + - get + - list + - create + - update + - watch # Metrics/logging configs - apiGroups: - "" @@ -46,16 +52,6 @@ rules: - httpsources/status verbs: - update - # Knative Services - - apiGroups: - - serving.knative.dev - resources: - - services - verbs: - - list - - watch - - create - - update # Channels - apiGroups: - messaging.knative.dev diff --git a/components/event-sources/config/300-httpsource-crd.yaml b/components/event-sources/config/300-httpsource-crd.yaml index 89ba2e965c3c..6083bc55f59f 100644 --- a/components/event-sources/config/300-httpsource-crd.yaml +++ b/components/event-sources/config/300-httpsource-crd.yaml @@ -1,17 +1,3 @@ -# Copyright 2019 The Kyma 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 -# -# http://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. - apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: diff --git a/components/event-sources/config/400-config-logging.yaml b/components/event-sources/config/400-config-logging.yaml index 2483d8ef5b9a..2702bce70330 100644 --- a/components/event-sources/config/400-config-logging.yaml +++ b/components/event-sources/config/400-config-logging.yaml @@ -1,17 +1,3 @@ -# Copyright 2019 The Kyma 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 -# -# http://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. - apiVersion: v1 kind: ConfigMap metadata: diff --git a/components/event-sources/config/400-config-observability.yaml b/components/event-sources/config/400-config-observability.yaml index 5dfe18f41c4f..f2721919be3a 100644 --- a/components/event-sources/config/400-config-observability.yaml +++ b/components/event-sources/config/400-config-observability.yaml @@ -1,17 +1,3 @@ -# Copyright 2019 The Kyma 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 -# -# http://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. - apiVersion: v1 kind: ConfigMap metadata: diff --git a/components/event-sources/config/500-sources-controller.yaml b/components/event-sources/config/500-sources-controller.yaml index 8084f66e5013..0e750edddb65 100644 --- a/components/event-sources/config/500-sources-controller.yaml +++ b/components/event-sources/config/500-sources-controller.yaml @@ -1,17 +1,3 @@ -# Copyright 2019 The Kyma 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 -# -# http://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. - apiVersion: apps/v1 kind: Deployment metadata: diff --git a/components/event-sources/config/samples/dummy-httpsource.yaml b/components/event-sources/config/samples/dummy-httpsource.yaml index e517e879dc92..6dc248c563c4 100644 --- a/components/event-sources/config/samples/dummy-httpsource.yaml +++ b/components/event-sources/config/samples/dummy-httpsource.yaml @@ -1,17 +1,3 @@ -# Copyright 2019 The Kyma 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 -# -# http://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. - apiVersion: sources.kyma-project.io/v1alpha1 kind: HTTPSource metadata: diff --git a/components/event-sources/hack/boilerplate.go.txt b/components/event-sources/hack/boilerplate.go.txt deleted file mode 100644 index cb1da3e49a67..000000000000 --- a/components/event-sources/hack/boilerplate.go.txt +++ /dev/null @@ -1,16 +0,0 @@ -/* -Copyright 2020 The Kyma 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 - - http://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. -*/ - diff --git a/components/event-sources/reconciler/errors/errors.go b/components/event-sources/reconciler/errors/errors.go index 5cc0948c77c1..e3890cd2766a 100644 --- a/components/event-sources/reconciler/errors/errors.go +++ b/components/event-sources/reconciler/errors/errors.go @@ -1,19 +1,3 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 errors contains custom error types and error utilities for reconcilers. package errors diff --git a/components/event-sources/reconciler/errors/errors_test.go b/components/event-sources/reconciler/errors/errors_test.go index cf8c698f4135..e76c03a63a48 100644 --- a/components/event-sources/reconciler/errors/errors_test.go +++ b/components/event-sources/reconciler/errors/errors_test.go @@ -1,19 +1,3 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 errors import ( diff --git a/components/event-sources/reconciler/errors/skip.go b/components/event-sources/reconciler/errors/skip.go index cc76239d7d78..5613a5ef9cfb 100644 --- a/components/event-sources/reconciler/errors/skip.go +++ b/components/event-sources/reconciler/errors/skip.go @@ -1,19 +1,3 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 errors // skippable is a type of error that can skip reconciliation retries. diff --git a/components/event-sources/reconciler/errors/skip_test.go b/components/event-sources/reconciler/errors/skip_test.go index fa73ee158323..9f41df19718b 100644 --- a/components/event-sources/reconciler/errors/skip_test.go +++ b/components/event-sources/reconciler/errors/skip_test.go @@ -1,19 +1,3 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 errors import ( diff --git a/components/event-sources/reconciler/httpsource/adapter_config.go b/components/event-sources/reconciler/httpsource/adapter_config.go index a1677089c049..df05beaffca1 100644 --- a/components/event-sources/reconciler/httpsource/adapter_config.go +++ b/components/event-sources/reconciler/httpsource/adapter_config.go @@ -1,24 +1,7 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 httpsource import ( corev1 "k8s.io/api/core/v1" - "knative.dev/pkg/logging" "knative.dev/pkg/metrics" ) @@ -26,11 +9,12 @@ import ( const ( component = "httpsource" - // Ports 9090-9091 are reserved for the Serving queue proxy (knative.dev/serving/pkg/apis/networking) adapterMetricsPort = 9092 - dashboardLabelKey = "kyma-project.io/dashboard" - dashboardLabelValue = "event-mesh" + dashboardLabelKey = "kyma-project.io/dashboard" + dashboardLabelValue = "event-mesh" + eventSourceLabelKey = "kyma-project.io/eventsource" + eventSourceLabelValue = "http" ) // httpAdapterEnvConfig contains properties used to configure the HTTP adapter. diff --git a/components/event-sources/reconciler/httpsource/controller.go b/components/event-sources/reconciler/httpsource/controller.go index 879e67bd698e..c3aa58a8965b 100644 --- a/components/event-sources/reconciler/httpsource/controller.go +++ b/components/event-sources/reconciler/httpsource/controller.go @@ -1,19 +1,3 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 httpsource implements a controller for the HTTPSource custom resource. package httpsource @@ -21,20 +5,18 @@ import ( "context" "github.com/kelseyhightower/envconfig" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/tools/cache" - messaginginformersv1alpha1 "knative.dev/eventing/pkg/client/injection/informers/messaging/v1alpha1/channel" "knative.dev/eventing/pkg/reconciler" + deploymentinformer "knative.dev/pkg/client/injection/kube/informers/apps/v1/deployment" + serviceinformer "knative.dev/pkg/client/injection/kube/informers/core/v1/service" "knative.dev/pkg/configmap" "knative.dev/pkg/controller" "knative.dev/pkg/logging" "knative.dev/pkg/metrics" "knative.dev/pkg/resolver" - servingclient "knative.dev/serving/pkg/client/injection/client" - knserviceinformersv1alpha1 "knative.dev/serving/pkg/client/injection/informers/serving/v1alpha1/service" sourcesv1alpha1 "github.com/kyma-project/kyma/components/event-sources/apis/sources/v1alpha1" sourcesscheme "github.com/kyma-project/kyma/components/event-sources/client/generated/clientset/internalclientset/scheme" @@ -65,20 +47,21 @@ func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl envconfig.MustProcess("http_adapter", adapterEnvCfg) httpSourceInformer := httpsourceinformersv1alpha1.Get(ctx) - knServiceInformer := knserviceinformersv1alpha1.Get(ctx) + deploymentInformer := deploymentinformer.Get(ctx) chInformer := messaginginformersv1alpha1.Get(ctx) policyInformer := policyinformersv1alpha1.Get(ctx) + serviceInformer := serviceinformer.Get(ctx) rb := reconciler.NewBase(ctx, controllerAgentName, cmw) r := &Reconciler{ Base: rb, adapterEnvCfg: adapterEnvCfg, httpsourceLister: httpSourceInformer.Lister(), - ksvcLister: knServiceInformer.Lister(), + deploymentLister: deploymentInformer.Lister(), chLister: chInformer.Lister(), policyLister: policyInformer.Lister(), + serviceLister: serviceInformer.Lister(), sourcesClient: sourcesclient.Get(ctx).SourcesV1alpha1(), - servingClient: servingclient.Get(ctx).ServingV1alpha1(), messagingClient: rb.EventingClientSet.MessagingV1alpha1(), authClient: istioclient.Get(ctx).AuthenticationV1alpha1(), } @@ -94,11 +77,11 @@ func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl FilterFunc: controller.Filter(sourcesv1alpha1.HTTPSourceGVK()), Handler: controller.HandleAll(impl.EnqueueControllerOf), } - knServiceInformer.Informer().AddEventHandler(eventHandler) + deploymentInformer.Informer().AddEventHandler(eventHandler) chInformer.Informer().AddEventHandler(eventHandler) - policyInformer.Informer().AddEventHandler(eventHandler) + serviceInformer.Informer().AddEventHandler(eventHandler) // watch for changes to metrics/logging configs diff --git a/components/event-sources/reconciler/httpsource/controller_test.go b/components/event-sources/reconciler/httpsource/controller_test.go index 74f2353f5cbe..da47d68aff62 100644 --- a/components/event-sources/reconciler/httpsource/controller_test.go +++ b/components/event-sources/reconciler/httpsource/controller_test.go @@ -1,19 +1,3 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 httpsource import ( @@ -37,8 +21,8 @@ import ( // Link fake informers and clients accessed by our controller _ "knative.dev/eventing/pkg/client/injection/informers/messaging/v1alpha1/channel/fake" _ "knative.dev/pkg/client/injection/ducks/duck/v1/addressable/fake" - _ "knative.dev/serving/pkg/client/injection/client/fake" - _ "knative.dev/serving/pkg/client/injection/informers/serving/v1alpha1/service/fake" + _ "knative.dev/pkg/client/injection/kube/informers/apps/v1/deployment/fake" + _ "knative.dev/pkg/client/injection/kube/informers/core/v1/service/fake" _ "github.com/kyma-project/kyma/components/event-sources/client/generated/injection/client/fake" _ "github.com/kyma-project/kyma/components/event-sources/client/generated/injection/informers/sources/v1alpha1/httpsource/fake" @@ -47,7 +31,6 @@ import ( ) const adapterImageEnvVar = "HTTP_ADAPTER_IMAGE" -const adapterTracingEnabledEnvVar = "HTTP_ADAPTER_TRACING_ENABLED" func TestNewController(t *testing.T) { defer func() { @@ -58,7 +41,6 @@ func TestNewController(t *testing.T) { defer SetEnvVar(t, adapterImageEnvVar, "some-image")() defer SetEnvVar(t, metrics.DomainEnv, "testing")() - defer SetEnvVar(t, adapterTracingEnabledEnvVar, "true")() cmw := configmap.NewStaticWatcher( NewConfigMap("", metrics.ConfigMapName()), @@ -66,8 +48,8 @@ func TestNewController(t *testing.T) { ) ctx, informers := rt.SetupFakeContext(t) - // expected informers: HTTPSource, Channel, Knative Service, Policy - if expect, got := 4, len(informers); got != expect { + // expected informers: HTTPSource, Channel, Deployment, Policy, Service + if expect, got := 5, len(informers); got != expect { t.Errorf("Expected %d injected informers, got %d", expect, got) } diff --git a/components/event-sources/reconciler/httpsource/event.go b/components/event-sources/reconciler/httpsource/event.go index 6c0f496ab774..5a96f64be858 100644 --- a/components/event-sources/reconciler/httpsource/event.go +++ b/components/event-sources/reconciler/httpsource/event.go @@ -1,19 +1,3 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 httpsource import ( diff --git a/components/event-sources/reconciler/httpsource/reconcile.go b/components/event-sources/reconciler/httpsource/reconcile.go index 58cb6a6fe350..c9cc0c2642e0 100644 --- a/components/event-sources/reconciler/httpsource/reconcile.go +++ b/components/event-sources/reconciler/httpsource/reconcile.go @@ -1,36 +1,20 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 httpsource import ( "context" - "fmt" "reflect" "strconv" pkgerrors "github.com/pkg/errors" - - corev1 "k8s.io/api/core/v1" - apierrors "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/client-go/tools/cache" - authenticationv1alpha1 "istio.io/client-go/pkg/apis/authentication/v1alpha1" authenticationclientv1alpha1 "istio.io/client-go/pkg/clientset/versioned/typed/authentication/v1alpha1" authenticationlistersv1alpha1 "istio.io/client-go/pkg/listers/authentication/v1alpha1" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" + appslistersv1 "k8s.io/client-go/listers/apps/v1" + v1 "k8s.io/client-go/listers/core/v1" + "k8s.io/client-go/tools/cache" messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" messagingclientv1alpha1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/messaging/v1alpha1" messaginglistersv1alpha1 "knative.dev/eventing/pkg/client/listers/messaging/v1alpha1" @@ -38,10 +22,6 @@ import ( apisv1beta1 "knative.dev/pkg/apis/duck/v1beta1" "knative.dev/pkg/controller" "knative.dev/pkg/resolver" - servingv1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" - servingclientv1alpha1 "knative.dev/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1" - servinglistersv1alpha1 "knative.dev/serving/pkg/client/listers/serving/v1alpha1" - routeconfig "knative.dev/serving/pkg/reconciler/route/config" sourcesv1alpha1 "github.com/kyma-project/kyma/components/event-sources/apis/sources/v1alpha1" sourcesclientv1alpha1 "github.com/kyma-project/kyma/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1" @@ -62,13 +42,13 @@ type Reconciler struct { // listers index properties about resources httpsourceLister sourceslistersv1alpha1.HTTPSourceLister - ksvcLister servinglistersv1alpha1.ServiceLister + deploymentLister appslistersv1.DeploymentLister chLister messaginglistersv1alpha1.ChannelLister policyLister authenticationlistersv1alpha1.PolicyLister + serviceLister v1.ServiceLister // clients allow interactions with API objects sourcesClient sourcesclientv1alpha1.SourcesV1alpha1Interface - servingClient servingclientv1alpha1.ServingV1alpha1Interface messagingClient messagingclientv1alpha1.MessagingV1alpha1Interface authClient authenticationclientv1alpha1.AuthenticationV1alpha1Interface @@ -80,22 +60,28 @@ type Reconciler struct { const ( // Common // see https://github.com/knative/eventing/blob/release-0.10/pkg/adapter/config.go - sinkURIEnvVar = "SINK_URI" - namespaceEnvVar = "NAMESPACE" - metricsConfigEnvVar = "K_METRICS_CONFIG" - loggingConfigEnvVar = "K_LOGGING_CONFIG" - tracingEnvVar = "TRACING_ENABLED" + sinkURIEnvVar = "SINK_URI" + namespaceEnvVar = "NAMESPACE" + metricsConfigEnvVar = "K_METRICS_CONFIG" + loggingConfigEnvVar = "K_LOGGING_CONFIG" + adapterPortEnvVar = "PORT" + adapterContainerName = "source" + portName = "http-cloudevent" + externalPort = 80 + metricsPort = 9092 + metricsPortName = "http-usermetric" // HTTP adapter specific eventSourceEnvVar = "EVENT_SOURCE" - - // Private svc suffix of an Ksvc - privateSvcSuffix = "-private" ) const adapterHealthEndpoint = "/healthz" +const adapterPort = 8080 -const applicationNameLabelKey = "application-name" +const ( + applicationNameLabelKey = "application-name" + applicationLabelKey = "app" +) // Reconcile compares the actual state of a HTTPSource object referenced by key // with its desired state, and attempts to converge the two. @@ -110,17 +96,22 @@ func (r *Reconciler) Reconcile(ctx context.Context, key string) error { return err } - ksvc, err := r.reconcileAdapter(src, ch) + deployment, err := r.reconcileAdapter(src, ch) if err != nil { return err } - policy, err := r.reconcilePolicy(src, ksvc) + service, err := r.reconcileService(src, deployment) if err != nil { return err } - return r.syncStatus(src, ch, ksvc, policy) + policy, err := r.reconcilePolicy(src, deployment) + if err != nil { + return err + } + + return r.syncStatus(src, ch, deployment, policy, service) } // httpSourceByKey retrieves a HTTPSource object from a lister by ns/name key. @@ -161,17 +152,39 @@ func (r *Reconciler) reconcileSink(src *sourcesv1alpha1.HTTPSource) (*messagingv } // reconcilePolicy reconciles the state of the Policy. -func (r *Reconciler) reconcilePolicy(src *sourcesv1alpha1.HTTPSource, ksvc *servingv1alpha1.Service) (*authenticationv1alpha1.Policy, error) { - if ksvc == nil { - r.Logger.Info("Skipping creation of Istio Policy as there is no ksvc yet") +func (r *Reconciler) reconcileService(src *sourcesv1alpha1.HTTPSource, deployment *appsv1.Deployment) (*corev1.Service, error) { + if deployment == nil { + r.Logger.Info("Skipping creation of Service as there is no deployment yet") return nil, nil } + desiredService := r.makeService(src) + currentService, err := r.getOrCreateService(src, desiredService) + if err != nil { + return nil, err + } - if ksvc.Status.ConfigurationStatusFields.LatestCreatedRevisionName == "" { + object.ApplyExistingServiceAttributes(currentService, desiredService) + + _, err = r.syncService(src, currentService, desiredService) + if err != nil { + return nil, pkgerrors.Wrap(err, "failed to synchronize Service") + } + + return desiredService, nil +} + +// reconcilePolicy reconciles the state of the Policy. +func (r *Reconciler) reconcilePolicy(src *sourcesv1alpha1.HTTPSource, deployment *appsv1.Deployment) (*authenticationv1alpha1.Policy, error) { + if deployment == nil { + r.Logger.Info("Skipping creation of Istio Policy as there is no deployment yet") + return nil, nil + } + + if deployment.Status.AvailableReplicas == 0 { r.Logger.Info("Skipping creation of Istio Policy as there is no revision yet") return nil, nil } - desiredPolicy := r.makePolicy(src, ksvc) + desiredPolicy := r.makePolicy(src, deployment) currentPolicy, err := r.getOrCreatePolicy(src, desiredPolicy) if err != nil { return nil, err @@ -179,7 +192,7 @@ func (r *Reconciler) reconcilePolicy(src *sourcesv1alpha1.HTTPSource, ksvc *serv object.ApplyExistingPolicyAttributes(currentPolicy, desiredPolicy) - currentPolicy, err = r.syncPolicy(src, currentPolicy, desiredPolicy) + _, err = r.syncPolicy(src, currentPolicy, desiredPolicy) if err != nil { return nil, pkgerrors.Wrap(err, "failed to synchronize Istio Policy") } @@ -189,7 +202,7 @@ func (r *Reconciler) reconcilePolicy(src *sourcesv1alpha1.HTTPSource, ksvc *serv // reconcileAdapter reconciles the state of the HTTP adapter. func (r *Reconciler) reconcileAdapter(src *sourcesv1alpha1.HTTPSource, - sink *messagingv1alpha1.Channel) (*servingv1alpha1.Service, error) { + sink *messagingv1alpha1.Channel) (*appsv1.Deployment, error) { sinkURI, err := getSinkURI(sink, r.sinkResolver, src) if err != nil { @@ -197,43 +210,43 @@ func (r *Reconciler) reconcileAdapter(src *sourcesv1alpha1.HTTPSource, return nil, nil } - desiredKsvc := r.makeKnService(src, sinkURI, r.adapterLoggingCfg, r.adapterMetricsCfg) + desiredDeployment := r.makeDeployment(src, sinkURI, r.adapterLoggingCfg, r.adapterMetricsCfg) - currentKsvc, err := r.getOrCreateKnService(src, desiredKsvc) + currentDeployment, err := r.getOrCreateDeployment(src, desiredDeployment) if err != nil { return nil, err } - object.ApplyExistingServiceAttributes(currentKsvc, desiredKsvc) + object.ApplyExistingDeploymentAttributes(currentDeployment, desiredDeployment) - currentKsvc, err = r.syncKnService(src, currentKsvc, desiredKsvc) + currentDeployment, err = r.syncDeployment(src, currentDeployment, desiredDeployment) if err != nil { - return nil, pkgerrors.Wrap(err, "failed to synchronize Knative Service") + return nil, pkgerrors.Wrap(err, "failed to synchronize Deployment") } - return currentKsvc, nil + return currentDeployment, nil } -// getOrCreateKnService returns the existing Knative Service for a given +// getOrCreateDeployment returns the existing Deployment for a given // HTTPSource, or creates it if it is missing. -func (r *Reconciler) getOrCreateKnService(src *sourcesv1alpha1.HTTPSource, - desiredKsvc *servingv1alpha1.Service) (*servingv1alpha1.Service, error) { +func (r *Reconciler) getOrCreateDeployment(src *sourcesv1alpha1.HTTPSource, + desiredDeployment *appsv1.Deployment) (*appsv1.Deployment, error) { - ksvc, err := r.ksvcLister.Services(src.Namespace).Get(src.Name) + deployment, err := r.deploymentLister.Deployments(src.Namespace).Get(src.Name) switch { case apierrors.IsNotFound(err): - ksvc, err = r.servingClient.Services(src.Namespace).Create(desiredKsvc) + deployment, err = r.KubeClientSet.AppsV1().Deployments(src.Namespace).Create(desiredDeployment) if err != nil { - r.eventWarn(src, failedCreateReason, "Creation failed for Knative Service %q", desiredKsvc.Name) - return nil, pkgerrors.Wrap(err, "failed to create Knative Service") + r.eventWarn(src, failedCreateReason, "Creation failed for Deployment %q", desiredDeployment.Name) + return nil, pkgerrors.Wrap(err, "failed to create Deployment") } - r.event(src, createReason, "Created Knative Service %q", ksvc.Name) + r.event(src, createReason, "Created Deployment %q", deployment.Name) case err != nil: - return nil, pkgerrors.Wrap(err, "failed to get Knative Service from cache") + return nil, pkgerrors.Wrap(err, "failed to get Deployment from cache") } - return ksvc, nil + return deployment, nil } // getOrCreateChannel returns the existing Channel for a given HTTPSource, or @@ -258,6 +271,27 @@ func (r *Reconciler) getOrCreateChannel(src *sourcesv1alpha1.HTTPSource, return ch, nil } +// getOrCreateService returns the existing Service for a Deployment, or +// creates it if it is missing. +func (r *Reconciler) getOrCreateService(src *sourcesv1alpha1.HTTPSource, + desiredService *corev1.Service) (*corev1.Service, error) { + service, err := r.serviceLister.Services(src.Namespace).Get(desiredService.Name) + switch { + case apierrors.IsNotFound(err): + service, err = r.KubeClientSet.CoreV1().Services(src.Namespace).Create(desiredService) + if err != nil { + r.eventWarn(src, failedCreateReason, "Creation failed for Service %q", desiredService.Name) + return nil, pkgerrors.Wrap(err, "failed to create Service") + } + r.event(src, createReason, "Created Service %q", service.Name) + + case err != nil: + return nil, pkgerrors.Wrap(err, "failed to get Service from cache") + } + + return service, nil +} + // getOrCreatePolicy returns the existing Policy for a Revision of a KnativeService, or // creates it if it is missing. func (r *Reconciler) getOrCreatePolicy(src *sourcesv1alpha1.HTTPSource, @@ -279,27 +313,32 @@ func (r *Reconciler) getOrCreatePolicy(src *sourcesv1alpha1.HTTPSource, return policy, nil } -// makeKnService returns the desired Knative Service object for a given -// HTTPSource. An optional Knative Service can be passed as parameter, in which +// makeDeployment returns the desired Deployment object for a given +// HTTPSource. An optional Deployment can be passed as parameter, in which // case some of its attributes are used to generate the desired state. -func (r *Reconciler) makeKnService(src *sourcesv1alpha1.HTTPSource, - sinkURI, loggingCfg, metricsCfg string) *servingv1alpha1.Service { +func (r *Reconciler) makeDeployment(src *sourcesv1alpha1.HTTPSource, + sinkURI, loggingCfg, metricsCfg string) *appsv1.Deployment { - return object.NewService(src.Namespace, src.Name, + return object.NewDeployment(src.Namespace, src.Name, + object.WithReplicas(1), + object.WithName(adapterContainerName), object.WithImage(r.adapterEnvCfg.Image), - object.WithPort(r.adapterEnvCfg.Port), - object.WithMinScale(1), + object.WithPort(r.adapterEnvCfg.Port, portName), + object.WithPort(metricsPort, metricsPortName), object.WithEnvVar(eventSourceEnvVar, src.Spec.Source), object.WithEnvVar(sinkURIEnvVar, sinkURI), object.WithEnvVar(namespaceEnvVar, src.Namespace), object.WithEnvVar(metricsConfigEnvVar, metricsCfg), object.WithEnvVar(loggingConfigEnvVar, loggingCfg), - object.WithEnvVar(tracingEnvVar, strconv.FormatBool(r.adapterEnvCfg.TracingEnabled)), - object.WithProbe(adapterHealthEndpoint), + object.WithEnvVar(adapterPortEnvVar, strconv.Itoa(adapterPort)), + object.WithProbe(adapterHealthEndpoint, adapterPort), object.WithControllerRef(src.ToOwner()), - object.WithLabel(routeconfig.VisibilityLabelKey, routeconfig.VisibilityClusterLocal), object.WithLabel(applicationNameLabelKey, src.Name), + object.WithMatchLabelsSelector(applicationNameLabelKey, src.Name), + object.WithPodLabel(applicationNameLabelKey, src.Name), + object.WithPodLabel(applicationLabelKey, src.Name), object.WithPodLabel(dashboardLabelKey, dashboardLabelValue), + object.WithPodLabel(eventSourceLabelKey, eventSourceLabelValue), ) } @@ -311,35 +350,47 @@ func (r *Reconciler) makeChannel(src *sourcesv1alpha1.HTTPSource) *messagingv1al ) } -// makePolicy returns the desired Policy object for a given Ksvc per HTTPSource. -func (r *Reconciler) makePolicy(src *sourcesv1alpha1.HTTPSource, ksvc *servingv1alpha1.Service) *authenticationv1alpha1.Policy { - // Using the private k8s svc of a ksvc which has the metrics ports - name := fmt.Sprintf("%s%s", ksvc.Status.ConfigurationStatusFields.LatestCreatedRevisionName, privateSvcSuffix) - return object.NewPolicy(src.Namespace, name, +// makeService returns the desired Service object for a given HTTPSource. +func (r *Reconciler) makeService(src *sourcesv1alpha1.HTTPSource) *corev1.Service { + + return object.NewService(src.Namespace, src.Name, + object.WithControllerRef(src.ToOwner()), + object.WithSelector(applicationNameLabelKey, src.Name), + object.WithServicePort(portName, externalPort, int(r.adapterEnvCfg.Port)), + object.WithServicePort(metricsPortName, metricsPort, metricsPort), + object.WithLabel(applicationNameLabelKey, src.Name), + object.WithLabel(dashboardLabelKey, dashboardLabelValue), + ) +} + +// makePolicy returns the desired Policy object for a given Deployment per HTTPSource. +func (r *Reconciler) makePolicy(src *sourcesv1alpha1.HTTPSource, deployment *appsv1.Deployment) *authenticationv1alpha1.Policy { + // Using the private k8s svc of a deployment which has the metrics ports + return object.NewPolicy(src.Namespace, deployment.Name, object.WithControllerRef(src.ToOwner()), object.WithLabel(applicationNameLabelKey, src.Name), - object.WithTarget(name), + object.WithTarget(deployment.Name), object.WithPermissiveMode(), ) } -// syncKnService synchronizes the desired state of a Knative Service against +// syncDeployment synchronizes the desired state of a Deployment against // its current state in the running cluster. -func (r *Reconciler) syncKnService(src *sourcesv1alpha1.HTTPSource, - currentKsvc, desiredKsvc *servingv1alpha1.Service) (*servingv1alpha1.Service, error) { +func (r *Reconciler) syncDeployment(src *sourcesv1alpha1.HTTPSource, + currentDeployment, desiredDeployment *appsv1.Deployment) (*appsv1.Deployment, error) { - if object.Semantic.DeepEqual(currentKsvc, desiredKsvc) { - return currentKsvc, nil + if object.Semantic.DeepEqual(currentDeployment, desiredDeployment) { + return currentDeployment, nil } - ksvc, err := r.servingClient.Services(currentKsvc.Namespace).Update(desiredKsvc) + deployment, err := r.KubeClientSet.AppsV1().Deployments(currentDeployment.Namespace).Update(desiredDeployment) if err != nil { - r.eventWarn(src, failedUpdateReason, "Update failed for Knative Service %q", desiredKsvc.Name) + r.eventWarn(src, failedUpdateReason, "Update failed for Deployment %q", desiredDeployment.Name) return nil, err } - r.event(src, updateReason, "Updated Knative Service %q", ksvc.Name) + r.event(src, updateReason, "Updated Deployment %q", deployment.Name) - return ksvc, nil + return deployment, nil } // syncChannel synchronizes the desired state of a Channel against its current @@ -361,10 +412,28 @@ func (r *Reconciler) syncChannel(src *sourcesv1alpha1.HTTPSource, return ch, nil } +// syncService synchronizes the desired state of a Service against its current +// state in the running cluster. +func (r *Reconciler) syncService(src *sourcesv1alpha1.HTTPSource, + currentSvc, desiredSvc *corev1.Service) (*corev1.Service, error) { + + if object.Semantic.DeepEqual(currentSvc, desiredSvc) { + return currentSvc, nil + } + + svc, err := r.KubeClientSet.CoreV1().Services(currentSvc.Namespace).Update(desiredSvc) + if err != nil { + r.eventWarn(src, failedUpdateReason, "Update failed for Service %q", desiredSvc.Name) + return nil, err + } + r.event(src, updateReason, "Updated Service %q", svc.Name) + + return svc, nil +} + // syncPolicy synchronizes the desired state of a Policy against its current // state in the running cluster. -func (r *Reconciler) syncPolicy(src *sourcesv1alpha1.HTTPSource, - currentPolicy, desiredPolicy *authenticationv1alpha1.Policy) (*authenticationv1alpha1.Policy, error) { +func (r *Reconciler) syncPolicy(src *sourcesv1alpha1.HTTPSource, currentPolicy, desiredPolicy *authenticationv1alpha1.Policy) (*authenticationv1alpha1.Policy, error) { if object.Semantic.DeepEqual(currentPolicy, desiredPolicy) { return currentPolicy, nil @@ -382,10 +451,10 @@ func (r *Reconciler) syncPolicy(src *sourcesv1alpha1.HTTPSource, // syncStatus ensures the status of a given HTTPSource is up-to-date. func (r *Reconciler) syncStatus(src *sourcesv1alpha1.HTTPSource, - ch *messagingv1alpha1.Channel, ksvc *servingv1alpha1.Service, policy *authenticationv1alpha1.Policy) error { + ch *messagingv1alpha1.Channel, deployment *appsv1.Deployment, policy *authenticationv1alpha1.Policy, service *corev1.Service) error { currentStatus := &src.Status - expectedStatus := r.computeStatus(src, ch, ksvc, policy) + expectedStatus := r.computeStatus(src, ch, deployment, policy, service) if reflect.DeepEqual(currentStatus, expectedStatus) { return nil @@ -406,7 +475,7 @@ func (r *Reconciler) syncStatus(src *sourcesv1alpha1.HTTPSource, // computeStatus returns the expected status of a given HTTPSource. func (r *Reconciler) computeStatus(src *sourcesv1alpha1.HTTPSource, ch *messagingv1alpha1.Channel, - ksvc *servingv1alpha1.Service, policy *authenticationv1alpha1.Policy) *sourcesv1alpha1.HTTPSourceStatus { + deployment *appsv1.Deployment, policy *authenticationv1alpha1.Policy, service *corev1.Service) *sourcesv1alpha1.HTTPSourceStatus { status := src.Status.DeepCopy() status.InitializeConditions() @@ -418,9 +487,10 @@ func (r *Reconciler) computeStatus(src *sourcesv1alpha1.HTTPSource, ch *messagin } status.MarkSink(sinkURI) status.MarkPolicyCreated(policy) + status.MarkServiceCreated(service) - if ksvc != nil { - status.PropagateServiceReady(ksvc) + if deployment != nil { + status.PropagateDeploymentReady(deployment) } return status diff --git a/components/event-sources/reconciler/httpsource/reconcile_test.go b/components/event-sources/reconciler/httpsource/reconcile_test.go index 57525f9d7ca4..63eb3c1d733b 100644 --- a/components/event-sources/reconciler/httpsource/reconcile_test.go +++ b/components/event-sources/reconciler/httpsource/reconcile_test.go @@ -1,19 +1,3 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 httpsource import ( @@ -22,19 +6,22 @@ import ( "testing" pkgerrors "github.com/pkg/errors" + authenticationv1alpha1api "istio.io/api/authentication/v1alpha1" + authv1alpha1 "istio.io/client-go/pkg/apis/authentication/v1alpha1" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/intstr" k8stesting "k8s.io/client-go/testing" - - authenticationv1alpha1api "istio.io/api/authentication/v1alpha1" - authv1alpha1 "istio.io/client-go/pkg/apis/authentication/v1alpha1" messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" "knative.dev/eventing/pkg/reconciler" "knative.dev/pkg/apis" duckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1" + "knative.dev/pkg/client/injection/ducks/duck/v1/addressable" + _ "knative.dev/pkg/client/injection/ducks/duck/v1/addressable/fake" "knative.dev/pkg/configmap" "knative.dev/pkg/controller" "knative.dev/pkg/logging" @@ -42,14 +29,6 @@ import ( "knative.dev/pkg/ptr" rt "knative.dev/pkg/reconciler/testing" "knative.dev/pkg/resolver" - "knative.dev/serving/pkg/apis/autoscaling" - servingv1 "knative.dev/serving/pkg/apis/serving/v1" - servingv1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" - fakeservingclient "knative.dev/serving/pkg/client/injection/client/fake" - routeconfig "knative.dev/serving/pkg/reconciler/route/config" - - "knative.dev/pkg/client/injection/ducks/duck/v1/addressable" - _ "knative.dev/pkg/client/injection/ducks/duck/v1/addressable/fake" sourcesv1alpha1 "github.com/kyma-project/kyma/components/event-sources/apis/sources/v1alpha1" fakesourcesclient "github.com/kyma-project/kyma/components/event-sources/client/generated/injection/client/fake" @@ -58,18 +37,17 @@ import ( ) const ( - tNs = "testns" - tName = "test" - tUID = types.UID("00000000-0000-0000-0000-000000000000") - tImg = "sources.kyma-project.io/http:latest" - tPort = 8080 - tSinkURI = "http://" + tName + "-kn-channel." + tNs + ".svc.cluster.local" - tTracingEnabled = true - tSource = "varkes" - tRevision = "varkes-foo" - tPolicy = "varkes-foo-private" - tRevisionSvc = "varkes-foo-private" - tTargetPort = "http-usermetric" + tNs = "testns" + tName = "test" + tUID = types.UID("00000000-0000-0000-0000-000000000000") + tImg = "sources.kyma-project.io/http:latest" + tExternalPort = 80 + tPort = 8080 + tSinkURI = "http://" + tName + "-kn-channel." + tNs + ".svc.cluster.local" + tSource = "varkes" + tPolicy = "test" + tRevisionSvc = "test" + tTargetPort = "http-usermetric" tMetricsDomain = "testing" ) @@ -117,8 +95,8 @@ var tEnvVars = []corev1.EnvVar{ Name: loggingConfigEnvVar, Value: `{"zap-logger-config":"{\"level\": \"info\"}"}`, }, { - Name: tracingEnvVar, - Value: strconv.FormatBool(tTracingEnabled), + Name: adapterPortEnvVar, + Value: strconv.Itoa(adapterPort), }, } @@ -153,7 +131,7 @@ func TestReconcile(t *testing.T) { }, WantUpdates: nil, WantStatusUpdates: []k8stesting.UpdateActionImpl{{ - Object: newSourceWithoutSink(), // "Deployed" condition remains Unknown + Object: newSource(WithoutSink), // "Deployed" condition remains Unknown }}, WantEvents: []string{ rt.Eventf(corev1.EventTypeNormal, string(createReason), "Created Channel %q", tName), @@ -163,10 +141,11 @@ func TestReconcile(t *testing.T) { Name: "Everything up-to-date", Key: tNs + "/" + tName, Objects: []runtime.Object{ - newSourceDeployedWithSinkAndPolicy(), - newServiceReady(), + newSource(Deployed, WithSink, WithPolicy, WithService), + newDeploymentAvailable(), newChannelReady(), newPolicyWithSpec(), + newService(), }, WantCreates: nil, WantUpdates: nil, @@ -176,22 +155,23 @@ func TestReconcile(t *testing.T) { Name: "Adapter Service spec does not match expectation", Key: tNs + "/" + tName, Objects: []runtime.Object{ - newSourceDeployedWithSinkAndPolicy(), - func() *servingv1alpha1.Service { - svc := newServiceReady() - svc.Labels["some-label"] = "unexpected" - return svc + newSource(Deployed, WithSink, WithPolicy, WithService), + func() *appsv1.Deployment { + deploy := newDeploymentAvailable() + deploy.Labels["some-label"] = "unexpected" + return deploy }(), newChannelReady(), newPolicyWithSpec(), + newService(), }, WantCreates: nil, WantUpdates: []k8stesting.UpdateActionImpl{{ - Object: newServiceReady(), + Object: newDeploymentAvailable(), }}, WantStatusUpdates: nil, WantEvents: []string{ - rt.Eventf(corev1.EventTypeNormal, string(updateReason), "Updated Knative Service %q", tName), + rt.Eventf(corev1.EventTypeNormal, string(updateReason), "Updated Deployment %q", tName), }, }, @@ -201,8 +181,8 @@ func TestReconcile(t *testing.T) { Name: "Channel missing", Key: tNs + "/" + tName, Objects: []runtime.Object{ - newSourceDeployedWithoutSink(), - newServiceReady(), + newSource(Deployed, WithoutSink), + newDeploymentAvailable(), }, WantCreates: []runtime.Object{ newChannelNotReady(), @@ -217,13 +197,14 @@ func TestReconcile(t *testing.T) { Name: "Channel spec does not match expectation", Key: tNs + "/" + tName, Objects: []runtime.Object{ - newSourceDeployedWithSinkAndPolicy(), - newServiceReady(), + newSource(Deployed, WithSink, WithPolicy, WithService), + newDeploymentAvailable(), func() *messagingv1alpha1.Channel { ch := newChannelReady() ch.Labels["some-label"] = "unexpected" return ch }(), + newService(), newPolicyWithSpec(), }, WantCreates: nil, @@ -239,12 +220,13 @@ func TestReconcile(t *testing.T) { /* Policy synchronization */ { - Name: "Policy missing when a Knative Revision is missing", + Name: "Policy missing when deployment not available", Key: tNs + "/" + tName, Objects: []runtime.Object{ - newSourceNotDeployedWithSinkWithoutPolicy(), - newServiceNotReady(), + newSource(NotDeployed, WithSink, WithoutPolicy, WithService), + newDeploymentNotAvailable(), newChannelReady(), + newService(), }, WantCreates: nil, WantUpdates: nil, @@ -255,9 +237,10 @@ func TestReconcile(t *testing.T) { Name: "Policy created", Key: tNs + "/" + tName, Objects: []runtime.Object{ - newSourceDeployedWithSinkAndPolicy(), - newServiceReady(), + newSource(Deployed, WithSink, WithPolicy, WithService), + newDeploymentAvailable(), newChannelReady(), + newService(), }, WantCreates: []runtime.Object{ newPolicyWithSpec(), @@ -268,30 +251,14 @@ func TestReconcile(t *testing.T) { rt.Eventf(corev1.EventTypeNormal, string(createReason), "Created Istio Policy %q", tPolicy), }, }, - - /* Status updates */ - - { - Name: "Adapter Service deployment in progress with a Knative Revision in status", - Key: tNs + "/" + tName, - Objects: []runtime.Object{ - newSourceNotDeployedWithSinkWithPolicy(), - newServiceNotReadyWithRevision(), - newChannelReady(), - newPolicyWithSpec(), - }, - WantCreates: nil, - WantUpdates: nil, - WantStatusUpdates: nil, - WantEvents: nil, - }, { - Name: "Adapter Service deployment in progress without a Revision", + Name: "Adapter deployment in progress", Key: tNs + "/" + tName, Objects: []runtime.Object{ - newSourceNotDeployedWithSinkWithoutPolicy(), - newServiceNotReady(), + newSource(NotDeployed, WithSink, WithoutPolicy, WithService), + newDeploymentNotAvailable(), newChannelReady(), + newService(), }, WantCreates: nil, WantUpdates: nil, @@ -302,15 +269,16 @@ func TestReconcile(t *testing.T) { Name: "Adapter Service became ready", Key: tNs + "/" + tName, Objects: []runtime.Object{ - newSourceNotDeployedWithSinkWithPolicy(), - newServiceReady(), + newSource(NotDeployed, WithSink, WithService, WithPolicy), + newDeploymentAvailable(), newChannelReady(), newPolicyWithSpec(), + newService(), }, WantCreates: nil, WantUpdates: nil, WantStatusUpdates: []k8stesting.UpdateActionImpl{{ - Object: newSourceDeployedWithSinkAndPolicy(), + Object: newSource(Deployed, WithSink, WithService, WithPolicy), }}, WantEvents: nil, }, @@ -318,14 +286,15 @@ func TestReconcile(t *testing.T) { Name: "Adapter Service became not ready", Key: tNs + "/" + tName, Objects: []runtime.Object{ - newSourceDeployedWithSinkWithoutPolicy(), - newServiceNotReady(), + newSource(Deployed, WithSink, WithService, WithoutPolicy), + newDeploymentNotAvailable(), newChannelReady(), + newService(), }, WantCreates: nil, WantUpdates: nil, WantStatusUpdates: []k8stesting.UpdateActionImpl{{ - Object: newSourceNotDeployedWithSinkWithoutPolicy(), + Object: newSource(NotDeployed, WithSink, WithService, WithoutPolicy), }}, WantEvents: nil, }, @@ -333,16 +302,17 @@ func TestReconcile(t *testing.T) { Name: "Channel becomes available", Key: tNs + "/" + tName, Objects: []runtime.Object{ - newSourceDeployedWithoutSinkWithoutPolicy(), - newServiceReady(), + newSource(Deployed, WithoutSink, WithoutPolicy, WithService), + newDeploymentAvailable(), newChannelReady(), + newService(), }, WantCreates: []runtime.Object{ newPolicyWithSpec(), }, WantUpdates: nil, WantStatusUpdates: []k8stesting.UpdateActionImpl{{ - Object: newSourceDeployedWithSinkAndPolicy(), + Object: newSource(Deployed, WithSink, WithPolicy, WithService), }}, WantEvents: []string{ rt.Eventf(corev1.EventTypeNormal, string(createReason), "Created Istio Policy %q", tPolicy), @@ -352,14 +322,15 @@ func TestReconcile(t *testing.T) { Name: "Channel becomes unavailable", Key: tNs + "/" + tName, Objects: []runtime.Object{ - newSourceDeployedWithSink(), - newServiceNotReady(), + newSource(Deployed, WithSink, WithService), + newDeploymentAvailable(), newChannelNotReady(), + newService(), }, WantCreates: nil, WantUpdates: nil, WantStatusUpdates: []k8stesting.UpdateActionImpl{{ - Object: newSourceDeployedWithoutSink(), // previous Deployed status remains + Object: newSource(Deployed, WithService, WithoutSink), // previous Deployed status remains }}, WantEvents: nil, }, @@ -378,16 +349,15 @@ func TestReconcile(t *testing.T) { r := &Reconciler{ Base: rb, adapterEnvCfg: &httpAdapterEnvConfig{ - Image: tImg, - Port: tPort, - TracingEnabled: tTracingEnabled, + Image: tImg, + Port: tPort, }, httpsourceLister: ls.GetHTTPSourceLister(), - ksvcLister: ls.GetServiceLister(), + deploymentLister: ls.GetDeploymentLister(), chLister: ls.GetChannelLister(), policyLister: ls.GetPolicyLister(), + serviceLister: ls.GetServiceLister(), sourcesClient: fakesourcesclient.Get(ctx).SourcesV1alpha1(), - servingClient: fakeservingclient.Get(ctx).ServingV1alpha1(), messagingClient: rb.EventingClientSet.MessagingV1alpha1(), authClient: fakeistioclient.Get(ctx).AuthenticationV1alpha1(), sinkResolver: resolver.NewURIResolver(ctx, func(types.NamespacedName) {}), @@ -402,8 +372,10 @@ func TestReconcile(t *testing.T) { testCases.Test(t, MakeFactory(ctor)) } +type SourceOption func(*sourcesv1alpha1.HTTPSource) + // newSource returns a test HTTPSource object with pre-filled metadata. -func newSource() *sourcesv1alpha1.HTTPSource { +func newSource(opts ...SourceOption) *sourcesv1alpha1.HTTPSource { src := &sourcesv1alpha1.HTTPSource{ ObjectMeta: metav1.ObjectMeta{ Namespace: tNs, @@ -417,108 +389,43 @@ func newSource() *sourcesv1alpha1.HTTPSource { src.Status.InitializeConditions() - return src -} - -// Deployed: Unknown, SinkProvided: False -func newSourceWithoutSink() *sourcesv1alpha1.HTTPSource { - src := newSource() - src.Status.MarkNoSink() - return src -} - -// Deployed: True, SinkProvided: True -func newSourceDeployedWithSink() *sourcesv1alpha1.HTTPSource { - src := newSource() - src.Status.PropagateServiceReady(newServiceReady()) - src.Status.MarkSink(tSinkURI) - return src -} + for _, opt := range opts { + opt(src) + } -// Deployed: True, SinkProvided: True, Policy: False -func newSourceDeployedWithSinkAndNoPolicy() *sourcesv1alpha1.HTTPSource { - src := newSource() - src.Status.PropagateServiceReady(newServiceNotReady()) - src.Status.MarkSink(tSinkURI) - src.Status.MarkPolicyCreated(nil) return src } -// Deployed: True, SinkProvided: False, Policy: True -func newSourceDeployedWithoutSinkWithPolicy() *sourcesv1alpha1.HTTPSource { - src := newSource() - src.Status.PropagateServiceReady(newServiceReady()) +func WithoutSink(src *sourcesv1alpha1.HTTPSource) { src.Status.MarkNoSink() - src.Status.MarkPolicyCreated(newPolicyWithSpec()) - return src } -// Deployed: True, SinkProvided: True, Policy: True -func newSourceDeployedWithSinkAndPolicy() *sourcesv1alpha1.HTTPSource { - src := newSource() - src.Status.PropagateServiceReady(newServiceReady()) +func WithSink(src *sourcesv1alpha1.HTTPSource) { src.Status.MarkSink(tSinkURI) - src.Status.MarkPolicyCreated(newPolicyWithSpec()) - return src } -// Deployed: True, SinkProvided: False -func newSourceDeployedWithoutSink() *sourcesv1alpha1.HTTPSource { - src := newSource() - src.Status.PropagateServiceReady(newServiceReady()) - src.Status.MarkNoSink() - return src +func WithService(src *sourcesv1alpha1.HTTPSource) { + src.Status.MarkServiceCreated(newService()) } -// Deployed: True, SinkProvided: False, PolicyCreated: False -func newSourceDeployedWithoutSinkWithoutPolicy() *sourcesv1alpha1.HTTPSource { - src := newSource() - src.Status.PropagateServiceReady(newServiceReady()) - src.Status.MarkNoSink() - src.Status.MarkPolicyCreated(nil) - return src +func WithoutService(src *sourcesv1alpha1.HTTPSource) { + src.Status.MarkServiceCreated(nil) } -func newSourceDeployedWithSinkWithoutPolicy() *sourcesv1alpha1.HTTPSource { - src := newSource() - src.Status.PropagateServiceReady(newServiceReady()) - src.Status.MarkSink(tSinkURI) - src.Status.MarkPolicyCreated(nil) - return src -} - -// Deployed: False, SinkProvided: True -func newSourceNotDeployedWithSink() *sourcesv1alpha1.HTTPSource { - src := newSource() - src.Status.PropagateServiceReady(newServiceNotReady()) - src.Status.MarkSink(tSinkURI) - return src +func WithPolicy(src *sourcesv1alpha1.HTTPSource) { + src.Status.MarkPolicyCreated(newPolicyWithSpec()) } -// Deployed: False, SinkProvided: True, PolicyCreated: False -func newSourceNotDeployedWithSinkWithoutPolicy() *sourcesv1alpha1.HTTPSource { - src := newSource() - src.Status.PropagateServiceReady(newServiceNotReady()) - src.Status.MarkSink(tSinkURI) +func WithoutPolicy(src *sourcesv1alpha1.HTTPSource) { src.Status.MarkPolicyCreated(nil) - return src } -// Deployed: False, SinkProvided: True, PolicyCreated: True -func newSourceNotDeployedWithSinkWithPolicy() *sourcesv1alpha1.HTTPSource { - src := newSource() - src.Status.PropagateServiceReady(newServiceNotReady()) - src.Status.MarkSink(tSinkURI) - src.Status.MarkPolicyCreated(newPolicyWithSpec()) - return src +func Deployed(src *sourcesv1alpha1.HTTPSource) { + src.Status.PropagateDeploymentReady(newDeploymentAvailable()) } -// Deployed: True, SinkProvided: True, PolicyCreated: True -func newSourceDeployedWithPolicy() *sourcesv1alpha1.HTTPSource { - src := newSource() - src.Status.PropagateServiceReady(newServiceReady()) - src.Status.MarkPolicyCreated(newPolicyWithSpec()) - return src +func NotDeployed(src *sourcesv1alpha1.HTTPSource) { + src.Status.PropagateDeploymentReady(newDeploymentNotAvailable()) } // newChannel returns a test Channel object with pre-filled metadata. @@ -605,83 +512,99 @@ func newChannelNotReady() *messagingv1alpha1.Channel { return ch } -// newService returns a test Service object with pre-filled metadata. -func newService() *servingv1alpha1.Service { - return &servingv1alpha1.Service{ +// newDeployment returns a test Service object with pre-filled metadata. +func newDeployment() *appsv1.Deployment { + var replicas int32 = 1 + return &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ Namespace: tNs, Name: tName, Labels: map[string]string{ - routeconfig.VisibilityLabelKey: routeconfig.VisibilityClusterLocal, - applicationNameLabelKey: tName, + applicationNameLabelKey: tName, }, OwnerReferences: []metav1.OwnerReference{tOwnerRef}, }, - Spec: servingv1alpha1.ServiceSpec{ - ConfigurationSpec: servingv1alpha1.ConfigurationSpec{ - Template: &servingv1alpha1.RevisionTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - autoscaling.MinScaleAnnotationKey: "1", + Spec: appsv1.DeploymentSpec{ + Replicas: &replicas, + Selector: &metav1.LabelSelector{MatchLabels: map[string]string{applicationNameLabelKey: tName}}, + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Labels: map[string]string{ + dashboardLabelKey: dashboardLabelValue, + eventSourceLabelKey: eventSourceLabelValue, + applicationNameLabelKey: tName, + applicationLabelKey: tName, + }, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{{ + Image: tImg, + Ports: []corev1.ContainerPort{{ + Name: portName, + ContainerPort: tPort, }, - Labels: map[string]string{ - dashboardLabelKey: dashboardLabelValue, + { + Name: metricsPortName, + ContainerPort: metricsPort, + }, }, - }, - Spec: servingv1alpha1.RevisionSpec{ - RevisionSpec: servingv1.RevisionSpec{ - PodSpec: corev1.PodSpec{ - Containers: []corev1.Container{{ - Image: tImg, - Ports: []corev1.ContainerPort{{ - ContainerPort: tPort, - }}, - Env: tEnvVars, - ReadinessProbe: &corev1.Probe{ - Handler: corev1.Handler{ - HTTPGet: &corev1.HTTPGetAction{ - Path: adapterHealthEndpoint, - }, - }, - }, - }}, + Name: adapterContainerName, + Env: tEnvVars, + ReadinessProbe: &corev1.Probe{ + Handler: corev1.Handler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: adapterHealthEndpoint, + Port: intstr.FromInt(adapterPort), + }, }, }, }, + }, }, }, }, } } -// Ready: True -func newServiceReady() *servingv1alpha1.Service { - svc := newService() - svc.Status.SetConditions(apis.Conditions{{ - Type: apis.ConditionReady, - Status: corev1.ConditionTrue, - }}) - svc.Status.ConfigurationStatusFields.LatestCreatedRevisionName = tRevision - return svc +// Available: True +func newDeploymentAvailable() *appsv1.Deployment { + deploy := newDeployment() + deploy.Status.AvailableReplicas = 1 + return deploy } -// Ready: False -func newServiceNotReady() *servingv1alpha1.Service { - svc := newService() - svc.Status.SetConditions(apis.Conditions{{ - Type: apis.ConditionReady, - Status: corev1.ConditionFalse, - }}) - return svc +// Available: False +func newDeploymentNotAvailable() *appsv1.Deployment { + deploy := newDeployment() + deploy.Status.AvailableReplicas = 0 + return deploy } -// Ready: False with a Revision -func newServiceNotReadyWithRevision() *servingv1alpha1.Service { - svc := newService() - svc.Status.SetConditions(apis.Conditions{{ - Type: apis.ConditionReady, - Status: corev1.ConditionFalse, - }}) - svc.Status.ConfigurationStatusFields.LatestCreatedRevisionName = tRevision - return svc +func newService() *corev1.Service { + return &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: tNs, + Name: tName, + Labels: map[string]string{ + dashboardLabelKey: dashboardLabelValue, + applicationNameLabelKey: tName, + }, + }, + Spec: corev1.ServiceSpec{ + Ports: []corev1.ServicePort{ + { + Name: portName, + Port: tExternalPort, + TargetPort: intstr.FromInt(tPort), + }, + { + Name: metricsPortName, + Port: metricsPort, + TargetPort: intstr.FromInt(metricsPort), + }, + }, + Selector: tChLabels, + }, + } + } diff --git a/components/event-sources/reconciler/object/channel.go b/components/event-sources/reconciler/object/channel.go index ba12a6768049..87e2f07dabf0 100644 --- a/components/event-sources/reconciler/object/channel.go +++ b/components/event-sources/reconciler/object/channel.go @@ -1,24 +1,7 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 object import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" ) diff --git a/components/event-sources/reconciler/object/channel_test.go b/components/event-sources/reconciler/object/channel_test.go index d97eaa1a6183..e0dd6dab4735 100644 --- a/components/event-sources/reconciler/object/channel_test.go +++ b/components/event-sources/reconciler/object/channel_test.go @@ -1,28 +1,10 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 object import ( "testing" "github.com/google/go-cmp/cmp" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" ) @@ -40,3 +22,36 @@ func TestNewChannel(t *testing.T) { t.Errorf("Unexpected diff: (-:expect, +:got) %s", d) } } + +func TestApplyExistingChannelAttributes(t *testing.T) { + existingChannel := &messagingv1alpha1.Channel{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: tNs, + Name: tName, + ResourceVersion: "1", + Annotations: map[string]string{ + knativeMessagingAnnotations[0]: "1", + "another-annotation": "some-value", + }, + }, + } + + // Service with empty spec, status, annotations, ... + channel := NewChannel(tNs, tName) + ApplyExistingChannelAttributes(existingChannel, channel) + + expectedChannel := &messagingv1alpha1.Channel{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: tNs, + Name: tName, + ResourceVersion: "1", + Annotations: map[string]string{ + knativeMessagingAnnotations[0]: "1", + }, + }, + } + + if d := cmp.Diff(expectedChannel, channel); d != "" { + t.Errorf("Unexpected diff: (-:expect, +:got) %s", d) + } +} diff --git a/components/event-sources/reconciler/object/deployment.go b/components/event-sources/reconciler/object/deployment.go new file mode 100644 index 000000000000..0d5f510b37b6 --- /dev/null +++ b/components/event-sources/reconciler/object/deployment.go @@ -0,0 +1,142 @@ +package object + +import ( + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +// NewDeployment creates a Service object. +func NewDeployment(ns, name string, opts ...ObjectOption) *appsv1.Deployment { + d := &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: ns, + Name: name, + }, + } + + for _, opt := range opts { + opt(d) + } + + return d +} + +// WithName sets the container name of a Deployment +func WithName(name string) ObjectOption { + return func(o metav1.Object) { + d := o.(*appsv1.Deployment) + firstDeploymentContainer(d).Name = name + } +} + +// WithMatchLabelsSelector sets the selector of a Deployment +func WithMatchLabelsSelector(key, value string) ObjectOption { + return func(o metav1.Object) { + d := o.(*appsv1.Deployment) + d.Spec.Selector = &metav1.LabelSelector{MatchLabels: map[string]string{key: value}} + } +} + +// WithImage sets the container image of a Service. +func WithImage(img string) ObjectOption { + return func(o metav1.Object) { + d := o.(*appsv1.Deployment) + firstDeploymentContainer(d).Image = img + } +} + +// WithImage sets the container image of a Service. +func WithReplicas(replicas int) ObjectOption { + return func(o metav1.Object) { + d := o.(*appsv1.Deployment) + replica32 := int32(replicas) + d.Spec.Replicas = &replica32 + } +} + +// WithPort sets the container port of a Service. +func WithPort(port int32, name string) ObjectOption { + return func(o metav1.Object) { + d := o.(*appsv1.Deployment) + ports := &firstDeploymentContainer(d).Ports + + *ports = append(*ports, corev1.ContainerPort{ + ContainerPort: port, + Name: name, + }) + } +} + +// WithPodLabel sets a label on a Service's template +func WithPodLabel(key, val string) ObjectOption { + return func(o metav1.Object) { + d := o.(*appsv1.Deployment) + + tpl := d.Spec.Template + if tpl.ObjectMeta.Labels == nil { + tpl.ObjectMeta.Labels = make(map[string]string) + } + tpl.ObjectMeta.Labels[key] = val + d.Spec.Template = tpl + } +} + +// WithEnvVar sets the value of a container env var. +func WithEnvVar(name, val string) ObjectOption { + return func(o metav1.Object) { + d := o.(*appsv1.Deployment) + envvars := &firstDeploymentContainer(d).Env + + *envvars = append(*envvars, corev1.EnvVar{ + Name: name, + Value: val, + }) + } +} + +// WithProbe sets the HTTP readiness probe of a container. +func WithProbe(path string, port int) ObjectOption { + return func(o metav1.Object) { + d := o.(*appsv1.Deployment) + + firstDeploymentContainer(d).ReadinessProbe = &corev1.Probe{ + Handler: corev1.Handler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: path, + Port: intstr.FromInt(port), + // setting port explicitly is illegal in a Deployment + }, + }, + } + } +} + +// firstDeploymentContainer returns the first Container definition of a Deployment. A +// new empty Container is injected if the Service does not contain any. +func firstDeploymentContainer(d *appsv1.Deployment) *corev1.Container { + containers := &d.Spec.Template.Spec.Containers + if *containers == nil { + *containers = make([]corev1.Container, 1) + } + return &(*containers)[0] +} + +// ApplyExistingDeploymentAttributes copies some important annotations from a given +// source Service to a destination Service. +func ApplyExistingDeploymentAttributes(src, dst *appsv1.Deployment) { + // resourceVersion must be returned to the API server + // unmodified for optimistic concurrency, as per Kubernetes API + // conventions + dst.ResourceVersion = src.ResourceVersion + + for _, ann := range deploymentAnnotations { + if val, ok := src.Annotations[ann]; ok { + metav1.SetMetaDataAnnotation(&dst.ObjectMeta, ann, val) + } + } + + // preserve status to avoid resetting conditions + dst.Status = src.Status +} diff --git a/components/event-sources/reconciler/object/deployment_test.go b/components/event-sources/reconciler/object/deployment_test.go new file mode 100644 index 000000000000..bc27317f0915 --- /dev/null +++ b/components/event-sources/reconciler/object/deployment_test.go @@ -0,0 +1,119 @@ +package object + +import ( + "testing" + + "github.com/google/go-cmp/cmp" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +const ( + tPodLabelKey = "podlabelkey" + tPodLabelValue = "podlabelvalue" + tContainerName = "testname" + tPortName1 = "first" + tPortName2 = "second" +) + +func TestNewDeployment(t *testing.T) { + const img = "registry/image:tag" + var replicas int32 = 3 + + deployment := NewDeployment(tNs, tName, + WithPort(8080, tPortName1), + WithImage(img), + WithEnvVar("TEST_ENV1", "val1"), + WithPort(8081, tPortName2), + WithProbe("/are/you/alive", 8080), + WithEnvVar("TEST_ENV2", "val2"), + WithPodLabel(tPodLabelKey, tPodLabelValue), + WithName(tContainerName), + WithMatchLabelsSelector(tPodLabelKey, tPodLabelValue), + WithReplicas(3), + ) + + expectDeployment := &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: tNs, + Name: tName, + }, + Spec: appsv1.DeploymentSpec{ + Replicas: &replicas, + Selector: &metav1.LabelSelector{MatchLabels: map[string]string{tPodLabelKey: tPodLabelValue}}, + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{tPodLabelKey: tPodLabelValue}}, + Spec: corev1.PodSpec{ + + Containers: []corev1.Container{{ + Name: tContainerName, + Image: img, + Ports: []corev1.ContainerPort{{ + ContainerPort: 8080, + Name: tPortName1, + }, { + ContainerPort: 8081, + Name: tPortName2, + }}, + Env: []corev1.EnvVar{{ + Name: "TEST_ENV1", + Value: "val1", + }, { + Name: "TEST_ENV2", + Value: "val2", + }}, + ReadinessProbe: &corev1.Probe{ + Handler: corev1.Handler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/are/you/alive", + Port: intstr.FromInt(8080), + }, + }, + }, + }}, + }, + }, + }, + } + + if d := cmp.Diff(expectDeployment, deployment); d != "" { + t.Errorf("Unexpected diff: (-:expect, +:got) %s", d) + } +} + +func TestAppApplyExistingServiceAttributes(t *testing.T) { + existingDeployment := &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: tNs, + Name: tName, + ResourceVersion: "1", + Annotations: map[string]string{ + deploymentAnnotations[0]: "1", + "another-annotation": "some-value", + }, + }, + Status: appsv1.DeploymentStatus{}, + } + + // Service with empty spec, status, annotations, ... + deployment := NewDeployment(tNs, tName) + ApplyExistingDeploymentAttributes(existingDeployment, deployment) + + expectDeployment := &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: tNs, + Name: tName, + ResourceVersion: "1", + Annotations: map[string]string{ + deploymentAnnotations[0]: "1", + }, + }, + Status: appsv1.DeploymentStatus{}, + } + + if d := cmp.Diff(expectDeployment, deployment); d != "" { + t.Errorf("Unexpected diff: (-:expect, +:got) %s", d) + } +} diff --git a/components/event-sources/reconciler/object/equality.go b/components/event-sources/reconciler/object/equality.go index d3463c67a4cf..e16a9f2c758d 100644 --- a/components/event-sources/reconciler/object/equality.go +++ b/components/event-sources/reconciler/object/equality.go @@ -1,38 +1,22 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 object import ( "reflect" + authenticationv1alpha1 "istio.io/client-go/pkg/apis/authentication/v1alpha1" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/conversion" - - authenticationv1alpha1 "istio.io/client-go/pkg/apis/authentication/v1alpha1" messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" - servingv1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" ) // Semantic can do semantic deep equality checks for API objects. Fields which // are not relevant for the reconciliation logic are intentionally omitted. var Semantic = conversion.EqualitiesOrDie( channelEqual, - ksvcEqual, policyEqual, + deploymentEqual, + serviceEqual, ) // policyEqual asserts the equality of two Policy objects. @@ -78,8 +62,8 @@ func channelEqual(c1, c2 *messagingv1alpha1.Channel) bool { return true } -// ksvcEqual asserts the equality of two Knative Service objects. -func ksvcEqual(s1, s2 *servingv1alpha1.Service) bool { +// deploymentEqual asserts the equality of two Deployment objects. +func deploymentEqual(s1, s2 *appsv1.Deployment) bool { if s1 == s2 { return true } @@ -94,34 +78,76 @@ func ksvcEqual(s1, s2 *servingv1alpha1.Service) bool { return false } - cst1 := s1.Spec.ConfigurationSpec.Template - cst2 := s2.Spec.ConfigurationSpec.Template - if cst1 == nil && cst2 != nil { + cst1 := s1.Spec.Template + cst2 := s2.Spec.Template + + if !reflect.DeepEqual(cst1.Annotations, cst2.Annotations) { + return false } - if cst1 != nil { - if cst2 == nil { - return false - } - if !reflect.DeepEqual(cst1.Annotations, cst2.Annotations) { - return false - } + if !reflect.DeepEqual(cst1.Labels, cst2.Labels) { + return false + } - if !reflect.DeepEqual(cst1.Labels, cst2.Labels) { - return false - } + ps1 := &cst1.Spec + ps2 := &cst2.Spec + if !podSpecEqual(ps1, ps2) { + return false + } - ps1 := &cst1.Spec.PodSpec - ps2 := &cst2.Spec.PodSpec - if !podSpecEqual(ps1, ps2) { + return true +} + +func serviceEqual(s1, s2 *corev1.Service) bool { + if s1 == s2 { + return true + } + if s1 == nil || s2 == nil { + return false + } + + if !reflect.DeepEqual(s1.Labels, s2.Labels) { + return false + } + if !reflect.DeepEqual(s1.Annotations, s2.Annotations) { + return false + } + sp1, sp2 := s1.Spec.Ports, s2.Spec.Ports + if len(sp1) != len(sp2) { + return false + } + for i := range sp1 { + p1, p2 := &sp1[i], &sp2[i] + + if p1.Name != p2.Name || + p1.TargetPort != p2.TargetPort || + realProto(p1.Protocol) != realProto(p2.Protocol) || p1.Port != p2.Port { return false } } + if !reflect.DeepEqual(s1.Spec.Selector, s2.Spec.Selector) { + return false + } + + spec1, spec2 := s1.Spec, s2.Spec + if getServiceType(spec1.Type) != getServiceType(spec2.Type) { + return false + } + if spec1.ClusterIP != spec2.ClusterIP { + return false + } return true } +func getServiceType(typ corev1.ServiceType) corev1.ServiceType { + if typ == "" { + return corev1.ServiceTypeClusterIP + } + return typ +} + // podSpecEqual asserts the equality of two PodSpec objects. func podSpecEqual(ps1, ps2 *corev1.PodSpec) bool { if ps1 == ps2 { @@ -205,13 +231,14 @@ func probeEqual(p1, p2 *corev1.Probe) bool { return false } - if p1.InitialDelaySeconds != p2.InitialDelaySeconds || - p1.TimeoutSeconds != p2.TimeoutSeconds || - p1.PeriodSeconds != p2.PeriodSeconds || - // Knative sets a default when that value is 0 - p1.SuccessThreshold != p2.SuccessThreshold && !(p1.SuccessThreshold == 0 || p2.SuccessThreshold == 0) || - p1.FailureThreshold != p2.FailureThreshold { + isInitialDelaySecondsEqual := p1.InitialDelaySeconds != p2.InitialDelaySeconds + isTimeoutSecondsEqual := p1.TimeoutSeconds != p2.TimeoutSeconds && p1.TimeoutSeconds != 0 && p2.TimeoutSeconds != 0 + isPeriodSecondsEqual := p1.PeriodSeconds != p2.PeriodSeconds && p1.PeriodSeconds != 0 && p2.PeriodSeconds != 0 + // Knative sets a default when that value is 0 + isSuccessThresholdEqual := p1.SuccessThreshold != p2.SuccessThreshold && p1.SuccessThreshold != 0 && p2.SuccessThreshold != 0 + isFailureThresholdEqual := p1.FailureThreshold != p2.FailureThreshold && p1.FailureThreshold != 0 && p2.FailureThreshold != 0 + if isInitialDelaySecondsEqual || isTimeoutSecondsEqual || isPeriodSecondsEqual || isSuccessThresholdEqual || isFailureThresholdEqual { return false } diff --git a/components/event-sources/reconciler/object/equality_test.go b/components/event-sources/reconciler/object/equality_test.go index bd1c2dc90728..85c28e11fe90 100644 --- a/components/event-sources/reconciler/object/equality_test.go +++ b/components/event-sources/reconciler/object/equality_test.go @@ -1,19 +1,3 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 object import ( @@ -25,26 +9,26 @@ import ( "testing" "github.com/pkg/errors" - + authenticationv1alpha1api "istio.io/api/authentication/v1alpha1" + authenticationv1alpha1 "istio.io/client-go/pkg/apis/authentication/v1alpha1" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" - - authenticationv1alpha1api "istio.io/api/authentication/v1alpha1" - authenticationv1alpha1 "istio.io/client-go/pkg/apis/authentication/v1alpha1" messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" - servingv1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" ) const ( - fixtureChannelPath = "../../test/fixtures/channel.json" - fixtureKsvcPath = "../../test/fixtures/ksvc.json" - fixturePolicyPath = "../../test/fixtures/policy.json" + fixtureChannelPath = "../../test/fixtures/channel.json" + fixturePolicyPath = "../../test/fixtures/policy.json" + fixtureDeploymentPath = "../../test/fixtures/deployment.json" + fixtureServicePath = "../../test/fixtures/service.json" ) var fixtureChannel *messagingv1alpha1.Channel -var fixtureKsvc *servingv1alpha1.Service +var fixtureDeployment *appsv1.Deployment var fixturePolicy *authenticationv1alpha1.Policy +var fixtureService *corev1.Service func TestMain(m *testing.M) { var err error @@ -54,16 +38,21 @@ func TestMain(m *testing.M) { panic(errors.Wrap(err, "loading Channel from fixtures")) } - fixtureKsvc = &servingv1alpha1.Service{} - if err = loadFixture(fixtureKsvcPath, fixtureKsvc); err != nil { - panic(errors.Wrap(err, "loading Knative Service from fixtures")) - } - fixturePolicy = &authenticationv1alpha1.Policy{} if err = loadFixture(fixturePolicyPath, fixturePolicy); err != nil { panic(errors.Wrap(err, "loading Policy from fixtures")) } + fixtureDeployment = &appsv1.Deployment{} + if err = loadFixture(fixtureDeploymentPath, fixtureDeployment); err != nil { + panic(errors.Wrap(err, "loading Deployment from fixtures")) + } + + fixtureService = &corev1.Service{} + if err = loadFixture(fixtureServicePath, fixtureService); err != nil { + panic(errors.Wrap(err, "loading Deployment from fixtures")) + } + os.Exit(m.Run()) } @@ -150,106 +139,192 @@ func TestChannelEqual(t *testing.T) { } } -func TestKsvcEqual(t *testing.T) { - ksvc := fixtureKsvc +func TestDeploymentEqual(t *testing.T) { + deployment := fixtureDeployment - if !ksvcEqual(nil, nil) { + if !deploymentEqual(nil, nil) { t.Error("Two nil elements should be equal") } testCases := map[string]struct { - prep func() *servingv1alpha1.Service + prep func() *appsv1.Deployment expect bool }{ "not equal when one element is nil": { - func() *servingv1alpha1.Service { + func() *appsv1.Deployment { return nil }, false, }, "not equal when labels differ": { - func() *servingv1alpha1.Service { - ksvcCopy := ksvc.DeepCopy() - ksvcCopy.Labels["foo"] += "test" - return ksvcCopy + func() *appsv1.Deployment { + deploymentCopy := deployment.DeepCopy() + deploymentCopy.Labels["foo"] += "test" + return deploymentCopy }, false, }, "not equal when annotations differ": { - func() *servingv1alpha1.Service { - ksvcCopy := ksvc.DeepCopy() - ksvcCopy.Annotations["foo"] += "test" - return ksvcCopy + func() *appsv1.Deployment { + deploymentCopy := deployment.DeepCopy() + deploymentCopy.Annotations["foo"] += "test" + return deploymentCopy }, false, }, "not equal when template annotations differ": { - func() *servingv1alpha1.Service { - ksvcCopy := ksvc.DeepCopy() - ksvc.Spec.ConfigurationSpec.Template.ObjectMeta.Annotations["foo"] += "test" - return ksvcCopy + func() *appsv1.Deployment { + deploymentCopy := deployment.DeepCopy() + deployment.Spec.Template.ObjectMeta.Annotations["foo"] += "test" + return deploymentCopy }, false, }, "not equal when template labels differ": { - func() *servingv1alpha1.Service { - ksvcCopy := ksvc.DeepCopy() - ksvc.Spec.ConfigurationSpec.Template.ObjectMeta.Labels["foo"] += "test" - return ksvcCopy + func() *appsv1.Deployment { + deploymentCopy := deployment.DeepCopy() + deployment.Spec.Template.ObjectMeta.Labels["foo"] += "test" + return deploymentCopy }, false, }, "equal when other fields differ": { - func() *servingv1alpha1.Service { - ksvcCopy := ksvc.DeepCopy() + func() *appsv1.Deployment { + deploymentCopy := deployment.DeepCopy() // metadata - lbls := ksvcCopy.Labels - anns := ksvcCopy.Annotations + lbls := deploymentCopy.Labels + anns := deploymentCopy.Annotations - m := &ksvcCopy.ObjectMeta + m := &deploymentCopy.ObjectMeta m.Reset() m.Labels = lbls m.Annotations = anns // spec - sp := &ksvcCopy.Spec + sp := &deploymentCopy.Spec - tplAnns := sp.ConfigurationSpec.Template.ObjectMeta.Annotations - tplLbls := sp.ConfigurationSpec.Template.ObjectMeta.Labels - ps := sp.ConfigurationSpec.Template.Spec.PodSpec + tplAnns := sp.Template.ObjectMeta.Annotations + tplLbls := sp.Template.ObjectMeta.Labels + ps := sp.Template.Spec - *sp = servingv1alpha1.ServiceSpec{} // reset - sp.ConfigurationSpec.Template = &servingv1alpha1.RevisionTemplateSpec{} - sp.ConfigurationSpec.Template.ObjectMeta.Annotations = tplAnns - sp.ConfigurationSpec.Template.ObjectMeta.Labels = tplLbls - sp.ConfigurationSpec.Template.Spec.PodSpec = ps + *sp = appsv1.DeploymentSpec{} // reset + sp.Template = corev1.PodTemplateSpec{} + sp.Template.ObjectMeta.Annotations = tplAnns + sp.Template.ObjectMeta.Labels = tplLbls + sp.Template.Spec = ps // status - st := &ksvcCopy.Status - *st = servingv1alpha1.ServiceStatus{} // reset + st := &deploymentCopy.Status + *st = appsv1.DeploymentStatus{} // reset + + return deploymentCopy + }, + true, + }, + } + + for name, tc := range testCases { + t.Run(name, func(t *testing.T) { + testDeployment := tc.prep() + if deploymentEqual(testDeployment, deployment) != tc.expect { + t.Errorf("Expected output to be %t", tc.expect) + } + }) + } +} + +func TestServiceEqual(t *testing.T) { + svc := fixtureService + + if !serviceEqual(nil, nil) { + t.Error("Two nil elements should be equal") + } - return ksvcCopy + testCases := map[string]struct { + prep func() *corev1.Service + expect bool + }{ + "not equal when one element is nil": { + func() *corev1.Service { + return nil + }, + false, + }, + "not equal when labels differ": { + func() *corev1.Service { + svcCopy := svc.DeepCopy() + svcCopy.Labels["foo"] += "test" + return svcCopy + }, + false, + }, + "not equal when annotations differ": { + func() *corev1.Service { + svcCopy := svc.DeepCopy() + svcCopy.Annotations = map[string]string{"a": "b"} + return svcCopy + }, + false, + }, + "not equal when type differs": { + func() *corev1.Service { + svcCopy := svc.DeepCopy() + svcCopy.Spec.Type = corev1.ServiceTypeExternalName + return svcCopy + }, + false, + }, + "equal when type gets defaulted": { + func() *corev1.Service { + svcCopy := svc.DeepCopy() + svcCopy.Spec.Type = "" + return svcCopy }, true, }, + "not equal when ClusterIP differs": { + func() *corev1.Service { + svcCopy := svc.DeepCopy() + svcCopy.Spec.ClusterIP = "1.1.1.1" + return svcCopy + }, + false, + }, + "not equal when Ports differs": { + func() *corev1.Service { + svcCopy := svc.DeepCopy() + svcCopy.Spec.Ports = []corev1.ServicePort{} + return svcCopy + }, + false, + }, + "not equal when selector differs": { + func() *corev1.Service { + svcCopy := svc.DeepCopy() + svcCopy.Spec.Selector = map[string]string{"a": "b"} + return svcCopy + }, + false, + }, } for name, tc := range testCases { t.Run(name, func(t *testing.T) { - testKsvc := tc.prep() - if ksvcEqual(testKsvc, ksvc) != tc.expect { + testService := tc.prep() + if serviceEqual(testService, svc) != tc.expect { t.Errorf("Expected output to be %t", tc.expect) } }) } + } func TestPodSpecEqual(t *testing.T) { - ps := &fixtureKsvc.Spec.ConfigurationSpec.Template.Spec.PodSpec + ps := &fixtureDeployment.Spec.Template.Spec if ps.Containers == nil { - t.Fatalf("Test requires fixture object %s to have a least one Container", fixtureKsvcPath) + t.Fatalf("Test requires fixture object %s to have a least one Container", fixtureDeploymentPath) } if !podSpecEqual(nil, nil) { @@ -310,16 +385,16 @@ func TestPodSpecEqual(t *testing.T) { } func TestContainerEqual(t *testing.T) { - cs := fixtureKsvc.Spec.ConfigurationSpec.Template.Spec.PodSpec.Containers + cs := fixtureDeployment.Spec.Template.Spec.Containers if cs == nil { - t.Fatalf("Test requires fixture object %s to have a least one Container", fixtureKsvcPath) + t.Fatalf("Test requires fixture object %s to have a least one Container", fixtureDeploymentPath) } if cs[0].Ports == nil { - t.Fatalf("Test requires fixture object %s to have a least one ContainerPort", fixtureKsvcPath) + t.Fatalf("Test requires fixture object %s to have a least one ContainerPort", fixtureDeploymentPath) } if cs[0].Env == nil { - t.Fatalf("Test requires fixture object %s to have a least one EnvVar", fixtureKsvcPath) + t.Fatalf("Test requires fixture object %s to have a least one EnvVar", fixtureDeploymentPath) } c := &cs[0] @@ -424,13 +499,13 @@ func TestContainerEqual(t *testing.T) { } func TestProbeEqual(t *testing.T) { - cs := fixtureKsvc.Spec.ConfigurationSpec.Template.Spec.PodSpec.Containers + cs := fixtureDeployment.Spec.Template.Spec.Containers if cs == nil || cs[0].ReadinessProbe == nil { - t.Fatalf("Test requires fixture object %s to have a configured ReadinessProbe", fixtureKsvcPath) + t.Fatalf("Test requires fixture object %s to have a configured ReadinessProbe", fixtureDeploymentPath) } if cs[0].ReadinessProbe.SuccessThreshold == 0 { - t.Fatalf("Test requires fixture object %s ReadinessProbe to have a defined SuccessThreshold", fixtureKsvcPath) + t.Fatalf("Test requires fixture object %s ReadinessProbe to have a defined SuccessThreshold", fixtureDeploymentPath) } p := cs[0].ReadinessProbe @@ -598,10 +673,10 @@ func TestEnvEqual(t *testing.T) { } } func TestHandlerEqual(t *testing.T) { - cs := fixtureKsvc.Spec.ConfigurationSpec.Template.Spec.PodSpec.Containers + cs := fixtureDeployment.Spec.Template.Spec.Containers if cs == nil || cs[0].ReadinessProbe == nil || cs[0].ReadinessProbe.HTTPGet == nil { - t.Fatalf("Test requires fixture object %s to have a configured HTTPGet Handler", fixtureKsvcPath) + t.Fatalf("Test requires fixture object %s to have a configured HTTPGet Handler", fixtureDeploymentPath) } httpH := &cs[0].ReadinessProbe.Handler diff --git a/components/event-sources/reconciler/object/label.go b/components/event-sources/reconciler/object/label.go index 797d9f3d475d..6620c918b4b7 100644 --- a/components/event-sources/reconciler/object/label.go +++ b/components/event-sources/reconciler/object/label.go @@ -1,25 +1,8 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 object import ( "knative.dev/eventing/pkg/apis/messaging" "knative.dev/pkg/apis" - "knative.dev/serving/pkg/apis/serving" ) // List of annotations set on Knative Messaging objects by the Knative Eventing @@ -29,9 +12,7 @@ var knativeMessagingAnnotations = []string{ messaging.GroupName + apis.UpdaterAnnotationSuffix, } -// List of annotations set on Knative Serving objects by the Knative Serving -// admission webhook. -var knativeServingAnnotations = []string{ - serving.GroupName + apis.CreatorAnnotationSuffix, - serving.GroupName + apis.UpdaterAnnotationSuffix, +// List of annotations set on Deployment objects +var deploymentAnnotations = []string{ + "deployment.kubernetes.io/revision", } diff --git a/components/event-sources/reconciler/object/object.go b/components/event-sources/reconciler/object/object.go index 9f50448941b5..75647d11297d 100644 --- a/components/event-sources/reconciler/object/object.go +++ b/components/event-sources/reconciler/object/object.go @@ -1,19 +1,3 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 object contains utilities for creating and comparing API objects. package object diff --git a/components/event-sources/reconciler/object/object_test.go b/components/event-sources/reconciler/object/object_test.go index 8289a63e3483..48cec2bbb9aa 100644 --- a/components/event-sources/reconciler/object/object_test.go +++ b/components/event-sources/reconciler/object/object_test.go @@ -1,29 +1,11 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 object import ( "testing" "github.com/google/go-cmp/cmp" - - "knative.dev/pkg/ptr" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "knative.dev/pkg/ptr" ) const ( diff --git a/components/event-sources/reconciler/object/policy.go b/components/event-sources/reconciler/object/policy.go index 5649f51d4f49..fd68227531cd 100644 --- a/components/event-sources/reconciler/object/policy.go +++ b/components/event-sources/reconciler/object/policy.go @@ -1,26 +1,9 @@ -/* -Copyright 2020 The Kyma 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 - - http://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 object import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - authenticationv1alpha1api "istio.io/api/authentication/v1alpha1" authenticationv1alpha1 "istio.io/client-go/pkg/apis/authentication/v1alpha1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) const targetPort = "http-usermetric" @@ -50,7 +33,7 @@ func ApplyExistingPolicyAttributes(src, dst *authenticationv1alpha1.Policy) { dst.ResourceVersion = src.ResourceVersion } -// WithTarget sets the target name of the Policy for a Knative Service which +// WithTarget sets the target name of the Policy for a Deployment which // has metrics end-point func WithTarget(target string) ObjectOption { return func(o metav1.Object) { diff --git a/components/event-sources/reconciler/object/policy_test.go b/components/event-sources/reconciler/object/policy_test.go index fd937fdae48a..4135e6e004fd 100644 --- a/components/event-sources/reconciler/object/policy_test.go +++ b/components/event-sources/reconciler/object/policy_test.go @@ -1,29 +1,12 @@ -/* -Copyright 2020 The Kyma 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 - - http://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 object import ( "testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/google/go-cmp/cmp" authenticationv1alpha1api "istio.io/api/authentication/v1alpha1" authenticationv1alpha1 "istio.io/client-go/pkg/apis/authentication/v1alpha1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) const ( diff --git a/components/event-sources/reconciler/object/service.go b/components/event-sources/reconciler/object/service.go index 8be4ceadff00..b8961567eeb0 100644 --- a/components/event-sources/reconciler/object/service.go +++ b/components/event-sources/reconciler/object/service.go @@ -1,34 +1,14 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 object import ( - "strconv" - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - "knative.dev/serving/pkg/apis/autoscaling" - servingv1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" + "k8s.io/apimachinery/pkg/util/intstr" ) // NewService creates a Service object. -func NewService(ns, name string, opts ...ObjectOption) *servingv1alpha1.Service { - s := &servingv1alpha1.Service{ +func NewService(ns, name string, opts ...ObjectOption) *corev1.Service { + s := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ Namespace: ns, Name: name, @@ -42,115 +22,30 @@ func NewService(ns, name string, opts ...ObjectOption) *servingv1alpha1.Service return s } -// WithImage sets the container image of a Service. -func WithImage(img string) ObjectOption { - return func(o metav1.Object) { - s := o.(*servingv1alpha1.Service) - firstServiceContainer(s).Image = img - } -} - -// WithPort sets the container port of a Service. -func WithPort(port int32) ObjectOption { - return func(o metav1.Object) { - s := o.(*servingv1alpha1.Service) - ports := &firstServiceContainer(s).Ports - - *ports = append(*ports, corev1.ContainerPort{ - // empty name defaults to http/1.1 protocol - ContainerPort: port, - }) - } -} - -// WithMinScale specifies the minimum number of Pods this Service should have -// at any given time. -func WithMinScale(replicas int) ObjectOption { - return func(o metav1.Object) { - s := o.(*servingv1alpha1.Service) - - tpl := &s.Spec.ConfigurationSpec.Template - if *tpl == nil { - *tpl = &servingv1alpha1.RevisionTemplateSpec{} - } - metav1.SetMetaDataAnnotation(&(*tpl).ObjectMeta, autoscaling.MinScaleAnnotationKey, strconv.Itoa(replicas)) - } -} - -// WithPodLabel sets a label on a Service's template -func WithPodLabel(key, val string) ObjectOption { +func WithSelector(key, value string) ObjectOption { return func(o metav1.Object) { - s := o.(*servingv1alpha1.Service) - - tpl := &s.Spec.ConfigurationSpec.Template - if *tpl == nil { - *tpl = &servingv1alpha1.RevisionTemplateSpec{} - } - if (*tpl).ObjectMeta.Labels == nil { - (*tpl).ObjectMeta.Labels = make(map[string]string) - } - (*tpl).ObjectMeta.Labels[key] = val + s := o.(*corev1.Service) + s.Spec.Selector = map[string]string{key: value} } } -// WithEnvVar sets the value of a container env var. -func WithEnvVar(name, val string) ObjectOption { +func WithServicePort(name string, port int, containerPort int) ObjectOption { return func(o metav1.Object) { - s := o.(*servingv1alpha1.Service) - envvars := &firstServiceContainer(s).Env - - *envvars = append(*envvars, corev1.EnvVar{ - Name: name, - Value: val, + s := o.(*corev1.Service) + s.Spec.Ports = append(s.Spec.Ports, corev1.ServicePort{ + Name: name, + Port: int32(port), + TargetPort: intstr.FromInt(containerPort), }) } } -// WithProbe sets the HTTP readiness probe of a container. -func WithProbe(path string) ObjectOption { - return func(o metav1.Object) { - s := o.(*servingv1alpha1.Service) - - firstServiceContainer(s).ReadinessProbe = &corev1.Probe{ - Handler: corev1.Handler{ - HTTPGet: &corev1.HTTPGetAction{ - Path: path, - // setting port explicitely is illegal in a Knative Service - }, - }, - } - } -} - -// firstServiceContainer returns the first Container definition of a Service. A -// new empty Container is injected if the Service does not contain any. -func firstServiceContainer(s *servingv1alpha1.Service) *corev1.Container { - if s.Spec.ConfigurationSpec.Template == nil { - s.Spec.ConfigurationSpec.Template = &servingv1alpha1.RevisionTemplateSpec{} - } - - containers := &s.Spec.ConfigurationSpec.Template.Spec.Containers - if *containers == nil { - *containers = make([]corev1.Container, 1) - } - return &(*containers)[0] -} - // ApplyExistingServiceAttributes copies some important attributes from a given // source Service to a destination Service. -func ApplyExistingServiceAttributes(src, dst *servingv1alpha1.Service) { +func ApplyExistingServiceAttributes(src, dst *corev1.Service) { // resourceVersion must be returned to the API server // unmodified for optimistic concurrency, as per Kubernetes API // conventions dst.ResourceVersion = src.ResourceVersion - - // immutable Knative annotations must be preserved - for _, ann := range knativeServingAnnotations { - if val, ok := src.Annotations[ann]; ok { - metav1.SetMetaDataAnnotation(&dst.ObjectMeta, ann, val) - } - } - - // preserve status to avoid resetting conditions - dst.Status = src.Status + dst.Spec.ClusterIP = src.Spec.ClusterIP } diff --git a/components/event-sources/reconciler/object/service_test.go b/components/event-sources/reconciler/object/service_test.go index 3969388229ff..bf6fe1241b43 100644 --- a/components/event-sources/reconciler/object/service_test.go +++ b/components/event-sources/reconciler/object/service_test.go @@ -1,131 +1,85 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 object import ( "testing" "github.com/google/go-cmp/cmp" - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) - duckv1 "knative.dev/pkg/apis/duck/v1" - servingv1 "knative.dev/serving/pkg/apis/serving/v1" - servingv1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" +const ( + tSelLabelKey = "sellabelkey" + tSelLabelValue = "sellabelvalue" + tPortName = "portName" + tExternalPort = 80 + tContainerPort = 8080 + tLabelKey = "labelkey" + tLabelValue = "labelvalue" ) func TestNewService(t *testing.T) { - const img = "registry/image:tag" - - ksvc := NewService(tNs, tName, - WithPort(8080), - WithImage(img), - WithEnvVar("TEST_ENV1", "val1"), - WithPort(8081), - WithProbe("/are/you/alive"), - WithEnvVar("TEST_ENV2", "val2"), - ) + service := NewService(tNs, tName, + WithSelector(tSelLabelKey, tSelLabelValue), + WithServicePort(tPortName, tExternalPort, tContainerPort), + WithLabel(tLabelKey, tLabelValue)) - expectKsvc := &servingv1alpha1.Service{ + expectedService := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ Namespace: tNs, Name: tName, + Labels: map[string]string{ + tLabelKey: tLabelValue, + }, }, - Spec: servingv1alpha1.ServiceSpec{ - ConfigurationSpec: servingv1alpha1.ConfigurationSpec{ - Template: &servingv1alpha1.RevisionTemplateSpec{ - Spec: servingv1alpha1.RevisionSpec{ - RevisionSpec: servingv1.RevisionSpec{ - PodSpec: corev1.PodSpec{ - Containers: []corev1.Container{{ - Image: img, - Ports: []corev1.ContainerPort{{ - ContainerPort: 8080, - }, { - ContainerPort: 8081, - }}, - Env: []corev1.EnvVar{{ - Name: "TEST_ENV1", - Value: "val1", - }, { - Name: "TEST_ENV2", - Value: "val2", - }}, - ReadinessProbe: &corev1.Probe{ - Handler: corev1.Handler{ - HTTPGet: &corev1.HTTPGetAction{ - Path: "/are/you/alive", - }, - }, - }, - }}, - }, - }, - }, + Spec: corev1.ServiceSpec{ + Ports: []corev1.ServicePort{ + { + Name: tPortName, + Port: tExternalPort, + TargetPort: intstr.FromInt(tContainerPort), }, }, + Selector: map[string]string{ + tSelLabelKey: tSelLabelValue, + }, }, } - if d := cmp.Diff(expectKsvc, ksvc); d != "" { + if d := cmp.Diff(expectedService, service); d != "" { t.Errorf("Unexpected diff: (-:expect, +:got) %s", d) } } -func TestAppApplyExistingServiceAttributes(t *testing.T) { - existingKsvc := &servingv1alpha1.Service{ +func TestApplyExistingServiceAttributes(t *testing.T) { + existingService := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ Namespace: tNs, Name: tName, ResourceVersion: "1", - Annotations: map[string]string{ - knativeServingAnnotations[0]: "some-user", - "another-annotation": "some-value", - }, }, - Status: servingv1alpha1.ServiceStatus{ - Status: duckv1.Status{ - ObservedGeneration: 1, - }, + Spec: corev1.ServiceSpec{ + ClusterIP: "1.1.1.1", }, } // Service with empty spec, status, annotations, ... - ksvc := NewService(tNs, tName) - ApplyExistingServiceAttributes(existingKsvc, ksvc) + service := NewService(tNs, tName) + ApplyExistingServiceAttributes(existingService, service) - expectKsvc := &servingv1alpha1.Service{ + expectedService := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ Namespace: tNs, Name: tName, ResourceVersion: "1", - Annotations: map[string]string{ - knativeServingAnnotations[0]: "some-user", - }, }, - Status: servingv1alpha1.ServiceStatus{ - Status: duckv1.Status{ - ObservedGeneration: 1, - }, + Spec: corev1.ServiceSpec{ + ClusterIP: "1.1.1.1", }, } - if d := cmp.Diff(expectKsvc, ksvc); d != "" { + if d := cmp.Diff(expectedService, service); d != "" { t.Errorf("Unexpected diff: (-:expect, +:got) %s", d) } } diff --git a/components/event-sources/reconciler/testing/configmap.go b/components/event-sources/reconciler/testing/configmap.go index 9c76e7cb1065..5dc9e5a08fba 100644 --- a/components/event-sources/reconciler/testing/configmap.go +++ b/components/event-sources/reconciler/testing/configmap.go @@ -1,19 +1,3 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 ( diff --git a/components/event-sources/reconciler/testing/env.go b/components/event-sources/reconciler/testing/env.go index 1c1f5917482e..c0e08f62eedd 100644 --- a/components/event-sources/reconciler/testing/env.go +++ b/components/event-sources/reconciler/testing/env.go @@ -1,19 +1,3 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 ( diff --git a/components/event-sources/reconciler/testing/factory.go b/components/event-sources/reconciler/testing/factory.go index 8ac20f57748f..3338a657576d 100644 --- a/components/event-sources/reconciler/testing/factory.go +++ b/components/event-sources/reconciler/testing/factory.go @@ -1,19 +1,3 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 ( @@ -25,7 +9,6 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/tools/record" - fakeeventingclient "knative.dev/eventing/pkg/client/injection/client/fake" fakelegacyclient "knative.dev/eventing/pkg/legacyclient/injection/client/fake" fakekubeclient "knative.dev/pkg/client/injection/kube/client/fake" @@ -34,7 +17,6 @@ import ( "knative.dev/pkg/logging" logtesting "knative.dev/pkg/logging/testing" rt "knative.dev/pkg/reconciler/testing" - fakeservingclient "knative.dev/serving/pkg/client/injection/client/fake" fakesourcesclient "github.com/kyma-project/kyma/components/event-sources/client/generated/injection/client/fake" fakeistioclient "github.com/kyma-project/kyma/components/event-sources/client/generated/injection/istio/client/fake" @@ -61,7 +43,6 @@ func MakeFactory(ctor Ctor) rt.Factory { ctx = logging.WithLogger(ctx, logtesting.TestLogger(t)) ctx, sourcesClient := fakesourcesclient.With(ctx, ls.GetSourcesObjects()...) - ctx, servingClient := fakeservingclient.With(ctx, ls.GetServingObjects()...) ctx, eventingClient := fakeeventingclient.With(ctx, ls.GetEventingObjects()...) ctx, legacyClient := fakelegacyclient.With(ctx, ls.GetLegacyObjects()...) ctx, istioClient := fakeistioclient.With(ctx, ls.GetIstioObjects()...) @@ -69,7 +50,9 @@ func MakeFactory(ctor Ctor) rt.Factory { ctx, _ = fakedynamicclient.With(ctx, scheme, ToUnstructured(t, scheme, ls.GetEventingObjects())...) // also inject fake k8s client which is accessed by reconciler.Base - ctx, _ = fakekubeclient.With(ctx) + k8sobjects := ls.GetCoreObjects() + k8sobjects = append(k8sobjects, ls.GetAppsObjects()...) + ctx, kubeClient := fakekubeclient.With(ctx, k8sobjects...) eventRecorder := record.NewFakeRecorder(maxEventBufferSize) ctx = controller.WithEventRecorder(ctx, eventRecorder) @@ -77,7 +60,7 @@ func MakeFactory(ctor Ctor) rt.Factory { // set up Controller from fakes c := ctor(t, ctx, &ls) - actionRecorderList := rt.ActionRecorderList{sourcesClient, servingClient, eventingClient, istioClient, legacyClient} + actionRecorderList := rt.ActionRecorderList{sourcesClient, eventingClient, istioClient, legacyClient, kubeClient} eventList := rt.EventList{Recorder: eventRecorder} statsReporter := &rt.FakeStatsReporter{} diff --git a/components/event-sources/reconciler/testing/listers.go b/components/event-sources/reconciler/testing/listers.go index 485090bdeed6..9940646e8bd1 100644 --- a/components/event-sources/reconciler/testing/listers.go +++ b/components/event-sources/reconciler/testing/listers.go @@ -1,51 +1,35 @@ -/* -Copyright 2019 The Kyma 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 - - http://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 ( pkgerrors "github.com/pkg/errors" - authv1alpha1 "istio.io/client-go/pkg/apis/authentication/v1alpha1" fakeistioclientset "istio.io/client-go/pkg/clientset/versioned/fake" authenticationlistersv1alpha1 "istio.io/client-go/pkg/listers/authentication/v1alpha1" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" + fakekubeclientset "k8s.io/client-go/kubernetes/fake" + appslistersv1 "k8s.io/client-go/listers/apps/v1" + corelistersv1 "k8s.io/client-go/listers/core/v1" "k8s.io/client-go/tools/cache" messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" fakeeventingclientset "knative.dev/eventing/pkg/client/clientset/versioned/fake" messaginglistersv1alpha1 "knative.dev/eventing/pkg/client/listers/messaging/v1alpha1" fakelegacyclientset "knative.dev/eventing/pkg/legacyclient/clientset/versioned/fake" + _ "knative.dev/pkg/client/injection/ducks/duck/v1/addressable/fake" rt "knative.dev/pkg/reconciler/testing" - servingv1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1" - fakeservingclientset "knative.dev/serving/pkg/client/clientset/versioned/fake" - servinglistersv1alpha1 "knative.dev/serving/pkg/client/listers/serving/v1alpha1" sourcesv1alpha1 "github.com/kyma-project/kyma/components/event-sources/apis/sources/v1alpha1" fakesourcesclientset "github.com/kyma-project/kyma/components/event-sources/client/generated/clientset/internalclientset/fake" sourceslistersv1alpha1 "github.com/kyma-project/kyma/components/event-sources/client/generated/lister/sources/v1alpha1" - - _ "knative.dev/pkg/client/injection/ducks/duck/v1/addressable/fake" ) var clientSetSchemes = []func(*runtime.Scheme) error{ - fakeservingclientset.AddToScheme, fakesourcesclientset.AddToScheme, fakeeventingclientset.AddToScheme, fakelegacyclientset.AddToScheme, fakeistioclientset.AddToScheme, + fakekubeclientset.AddToScheme, } type Listers struct { @@ -82,12 +66,16 @@ func (l *Listers) GetSourcesObjects() []runtime.Object { return l.sorter.ObjectsForSchemeFunc(fakesourcesclientset.AddToScheme) } -func (l *Listers) GetLegacyObjects() []runtime.Object { - return l.sorter.ObjectsForSchemeFunc(fakelegacyclientset.AddToScheme) +func (l *Listers) GetCoreObjects() []runtime.Object { + return l.sorter.ObjectsForSchemeFunc(corev1.AddToScheme) +} + +func (l *Listers) GetAppsObjects() []runtime.Object { + return l.sorter.ObjectsForSchemeFunc(appsv1.AddToScheme) } -func (l *Listers) GetServingObjects() []runtime.Object { - return l.sorter.ObjectsForSchemeFunc(fakeservingclientset.AddToScheme) +func (l *Listers) GetLegacyObjects() []runtime.Object { + return l.sorter.ObjectsForSchemeFunc(fakelegacyclientset.AddToScheme) } func (l *Listers) GetEventingObjects() []runtime.Object { @@ -102,8 +90,8 @@ func (l *Listers) GetHTTPSourceLister() sourceslistersv1alpha1.HTTPSourceLister return sourceslistersv1alpha1.NewHTTPSourceLister(l.IndexerFor(&sourcesv1alpha1.HTTPSource{})) } -func (l *Listers) GetServiceLister() servinglistersv1alpha1.ServiceLister { - return servinglistersv1alpha1.NewServiceLister(l.IndexerFor(&servingv1alpha1.Service{})) +func (l *Listers) GetDeploymentLister() appslistersv1.DeploymentLister { + return appslistersv1.NewDeploymentLister(l.IndexerFor(&appsv1.Deployment{})) } func (l *Listers) GetChannelLister() messaginglistersv1alpha1.ChannelLister { @@ -113,3 +101,7 @@ func (l *Listers) GetChannelLister() messaginglistersv1alpha1.ChannelLister { func (l *Listers) GetPolicyLister() authenticationlistersv1alpha1.PolicyLister { return authenticationlistersv1alpha1.NewPolicyLister(l.IndexerFor(&authv1alpha1.Policy{})) } + +func (l *Listers) GetServiceLister() corelistersv1.ServiceLister { + return corelistersv1.NewServiceLister(l.IndexerFor(&corev1.Service{})) +} diff --git a/components/event-sources/test/fixtures/deployment.json b/components/event-sources/test/fixtures/deployment.json new file mode 100644 index 000000000000..a6bc2a0bf342 --- /dev/null +++ b/components/event-sources/test/fixtures/deployment.json @@ -0,0 +1,143 @@ +{ + "apiVersion": "apps/v1", + "kind": "Deployment", + "metadata": { + "annotations": { + "deployment.kubernetes.io/revision": "1" + }, + "creationTimestamp": "2020-07-30T10:00:40Z", + "generation": 906632, + "labels": { + "application-name": "blumpf" + }, + "name": "blumpf", + "namespace": "kyma-integration", + "ownerReferences": [ + { + "apiVersion": "sources.kyma-project.io/v1alpha1", + "blockOwnerDeletion": true, + "controller": true, + "kind": "HTTPSource", + "name": "blumpf", + "uid": "2eb734df-0715-4976-83ca-37da7adad44f" + } + ], + "resourceVersion": "5795750", + "selfLink": "/apis/apps/v1/namespaces/kyma-integration/deployments/blumpf", + "uid": "26ca84e4-df95-4941-a95a-bed17ab64cb6" + }, + "spec": { + "progressDeadlineSeconds": 600, + "replicas": 1, + "revisionHistoryLimit": 10, + "selector": { + "matchLabels": { + "application-name": "blumpf" + } + }, + "strategy": { + "rollingUpdate": { + "maxSurge": "25%", + "maxUnavailable": "25%" + }, + "type": "RollingUpdate" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "application-name": "blumpf", + "kyma-project.io/dashboard": "event-mesh" + }, + "annotations": { + "foo": "bar" + } + }, + "spec": { + "containers": [ + { + "env": [ + { + "name": "EVENT_SOURCE", + "value": "blumpf" + }, + { + "name": "SINK_URI", + "value": "http://blumpf-kn-channel.kyma-integration.svc.cluster.local" + }, + { + "name": "NAMESPACE", + "value": "kyma-integration" + }, + { + "name": "K_METRICS_CONFIG", + "value": "{\"Domain\":\"kyma-project.io/controller-manager\",\"Component\":\"httpsource\",\"PrometheusPort\":9092,\"ConfigMap\":{\"_example\":\"################################\\n# #\\n# EXAMPLE CONFIGURATION #\\n# #\\n################################\\n\\n# This block is not actually functional configuration,\\n# but serves to illustrate the available configuration\\n# options and document them in a way that is accessible\\n# to users that `kubectl edit` this config map.\\n#\\n# These sample configuration options may be copied out of\\n# this example block and unindented to be in the data block\\n# to actually change the configuration.\\n\\n# metrics.backend-destination field specifies the system metrics destination.\\n# It supports either prometheus (the default) or stackdriver.\\n# Note: Using stackdriver will incur additional charges\\nmetrics.backend-destination: prometheus\\n\\n# metrics.request-metrics-backend-destination specifies the request metrics\\n# destination. If non-empty, it enables queue proxy to send request metrics.\\n# Currently supported values: prometheus, stackdriver.\\nmetrics.request-metrics-backend-destination: prometheus\\n\\n# metrics.stackdriver-project-id field specifies the stackdriver project ID. This\\n# field is optional. When running on GCE, application default credentials will be\\n# used if this field is not provided.\\nmetrics.stackdriver-project-id: \\\"\\u003cyour stackdriver project id\\u003e\\\"\\n\\n# metrics.allow-stackdriver-custom-metrics indicates whether it is allowed to send metrics to\\n# Stackdriver using \\\"global\\\" resource type and custom metric type if the\\n# metrics are not supported by \\\"knative_broker\\\", \\\"knative_trigger\\\", and \\\"knative_source\\\" resource types.\\n# Setting this flag to \\\"true\\\" could cause extra Stackdriver charge.\\n# If metrics.backend-destination is not Stackdriver, this is ignored.\\nmetrics.allow-stackdriver-custom-metrics: \\\"false\\\"\\n\"}}" + }, + { + "name": "K_LOGGING_CONFIG", + "value": "{\"zap-logger-config\":\"{\\n \\\"level\\\": \\\"info\\\",\\n \\\"development\\\": false,\\n \\\"outputPaths\\\": [\\\"stdout\\\"],\\n \\\"errorOutputPaths\\\": [\\\"stderr\\\"],\\n \\\"encoding\\\": \\\"json\\\",\\n \\\"encoderConfig\\\": {\\n \\\"timeKey\\\": \\\"ts\\\",\\n \\\"levelKey\\\": \\\"level\\\",\\n \\\"nameKey\\\": \\\"logger\\\",\\n \\\"callerKey\\\": \\\"caller\\\",\\n \\\"messageKey\\\": \\\"msg\\\",\\n \\\"stacktraceKey\\\": \\\"stacktrace\\\",\\n \\\"lineEnding\\\": \\\"\\\",\\n \\\"levelEncoder\\\": \\\"\\\",\\n \\\"timeEncoder\\\": \\\"iso8601\\\",\\n \\\"durationEncoder\\\": \\\"\\\",\\n \\\"callerEncoder\\\": \\\"\\\"\\n }\\n}\\n\"}" + }, + { + "name": "PORT", + "value": "8080" + } + ], + "image": "eu.gcr.io/kyma-project/event-sources-http-adapter:08b6fe17", + "imagePullPolicy": "IfNotPresent", + "name": "source", + "ports": [ + { + "containerPort": 8080, + "protocol": "TCP" + } + ], + "readinessProbe": { + "failureThreshold": 3, + "httpGet": { + "path": "/healthz", + "port": 8080, + "scheme": "HTTP" + }, + "periodSeconds": 10, + "successThreshold": 1, + "timeoutSeconds": 1 + }, + "resources": {}, + "terminationMessagePath": "/dev/termination-log", + "terminationMessagePolicy": "File" + } + ], + "dnsPolicy": "ClusterFirst", + "restartPolicy": "Always", + "schedulerName": "default-scheduler", + "securityContext": {}, + "terminationGracePeriodSeconds": 30 + } + } + }, + "status": { + "availableReplicas": 1, + "conditions": [ + { + "lastTransitionTime": "2020-07-30T10:00:52Z", + "lastUpdateTime": "2020-07-30T10:00:52Z", + "message": "Deployment has minimum availability.", + "reason": "MinimumReplicasAvailable", + "status": "True", + "type": "Available" + }, + { + "lastTransitionTime": "2020-07-30T10:00:40Z", + "lastUpdateTime": "2020-07-30T10:00:52Z", + "message": "ReplicaSet \"blumpf-59b6cf4ff5\" has successfully progressed.", + "reason": "NewReplicaSetAvailable", + "status": "True", + "type": "Progressing" + } + ], + "observedGeneration": 906632, + "readyReplicas": 1, + "replicas": 1, + "updatedReplicas": 1 + } +} diff --git a/components/event-sources/test/fixtures/ksvc.json b/components/event-sources/test/fixtures/ksvc.json deleted file mode 100644 index 95e90a19a304..000000000000 --- a/components/event-sources/test/fixtures/ksvc.json +++ /dev/null @@ -1,118 +0,0 @@ -{ - "apiVersion": "serving.knative.dev/v1alpha1", - "kind": "Service", - "metadata": { - "annotations": { - "serving.knative.dev/creator": "system:serviceaccount:kyma-system:event-sources-controller-manager", - "serving.knative.dev/lastModifier": "system:serviceaccount:kyma-system:event-sources-controller-manager" - }, - "creationTimestamp": "2019-11-04T15:26:24Z", - "generation": 1, - "labels": { - "serving.knative.dev/visibility": "cluster-local", - "application-name": "dummy" - }, - "name": "dummy", - "namespace": "default", - "ownerReferences": [ - { - "apiVersion": "sources.kyma-project.io/v1alpha1", - "blockOwnerDeletion": true, - "controller": true, - "kind": "HTTPSource", - "name": "dummy", - "uid": "7015d5ce-c3cf-4ad4-add2-8d6e43cb7522" - } - ], - "resourceVersion": "267750", - "selfLink": "/apis/serving.knative.dev/v1alpha1/namespaces/default/services/dummy", - "uid": "bb3c04fa-7f61-451d-bd6e-6e9d88bb5e6b" - }, - "spec": { - "template": { - "metadata": { - "annotations": { - "autoscaling.knative.dev/minScale": "1" - }, - "labels": { - "kyma-project.io/dashboard": "event-mesh" - }, - "creationTimestamp": null - }, - "spec": { - "containerConcurrency": 0, - "containers": [ - { - "env": [ - { - "name": "SINK_URI", - "value": "http://dummy-kn-channel.default.svc.cluster.local" - }, - { - "name": "NAMESPACE", - "value": "default" - }, - { - "name": "K_METRICS_CONFIG", - "value": "{\"Domain\":\"kyma-project.io/event-sources\",\"Component\":\"httpsource\",\"PrometheusPort\":0,\"ConfigMap\":{\"metrics.backend\":\"prometheus\"}}" - }, - { - "name": "K_LOGGING_CONFIG", - "value": "{\"zap-logger-config\":\"{\\n \\\"level\\\": \\\"info\\\",\\n \\\"development\\\": false,\\n \\\"outputPaths\\\": [\\\"stdout\\\"],\\n \\\"errorOutputPaths\\\": [\\\"stderr\\\"],\\n \\\"encoding\\\": \\\"json\\\",\\n \\\"encoderConfig\\\": {\\n \\\"timeKey\\\": \\\"ts\\\",\\n \\\"levelKey\\\": \\\"level\\\",\\n \\\"nameKey\\\": \\\"logger\\\",\\n \\\"callerKey\\\": \\\"caller\\\",\\n \\\"messageKey\\\": \\\"msg\\\",\\n \\\"stacktraceKey\\\": \\\"stacktrace\\\",\\n \\\"lineEnding\\\": \\\"\\\",\\n \\\"levelEncoder\\\": \\\"\\\",\\n \\\"timeEncoder\\\": \\\"iso8601\\\",\\n \\\"durationEncoder\\\": \\\"\\\",\\n \\\"callerEncoder\\\": \\\"\\\"\\n }\\n}\"}" - } - ], - "image": "example.com/http-adapter", - "name": "user-container", - "ports": [ - { - "containerPort": 8080, - "protocol": "TCP" - } - ], - "readinessProbe": { - "httpGet": { - "path": "/healthz", - "port": 0 - }, - "successThreshold": 1 - }, - "resources": {} - } - ], - "timeoutSeconds": 300 - } - }, - "traffic": [ - { - "latestRevision": true, - "percent": 100 - } - ] - }, - "status": { - "conditions": [ - { - "lastTransitionTime": "2019-11-04T15:26:25Z", - "status": "Unknown", - "type": "ConfigurationsReady" - }, - { - "lastTransitionTime": "2019-11-04T15:26:25Z", - "message": "Configuration \"dummy\" is waiting for a Revision to become ready.", - "reason": "RevisionMissing", - "status": "Unknown", - "type": "Ready" - }, - { - "lastTransitionTime": "2019-11-04T15:26:25Z", - "message": "Configuration \"dummy\" is waiting for a Revision to become ready.", - "reason": "RevisionMissing", - "status": "Unknown", - "type": "RoutesReady" - } - ], - "latestCreatedRevisionName": "dummy-pnfbg", - "observedGeneration": 1, - "url": "http://dummy.default.example.com" - } -} diff --git a/components/event-sources/test/fixtures/service.json b/components/event-sources/test/fixtures/service.json new file mode 100644 index 000000000000..7f8f35665de3 --- /dev/null +++ b/components/event-sources/test/fixtures/service.json @@ -0,0 +1,44 @@ +{ + "apiVersion": "v1", + "kind": "Service", + "metadata": { + "creationTimestamp": "2020-08-05T09:25:38Z", + "labels": { + "application-name": "varkes" + }, + "name": "varkes", + "namespace": "kyma-integration", + "ownerReferences": [ + { + "apiVersion": "sources.kyma-project.io/v1alpha1", + "blockOwnerDeletion": true, + "controller": true, + "kind": "HTTPSource", + "name": "varkes", + "uid": "670dccfe-c577-4ef1-836f-a52db4e3dce3" + } + ], + "resourceVersion": "24062", + "selfLink": "/api/v1/namespaces/kyma-integration/services/varkes", + "uid": "4ea36557-51a3-46ee-a4ea-adedbdfc7ede" + }, + "spec": { + "clusterIP": "10.3.246.21", + "ports": [ + { + "name": "http-cloudevent", + "port": 80, + "protocol": "TCP", + "targetPort": 8080 + } + ], + "selector": { + "application-name": "varkes" + }, + "sessionAffinity": "None", + "type": "ClusterIP" + }, + "status": { + "loadBalancer": {} + } +} diff --git a/resources/event-sources/post-upgrade.sh b/resources/event-sources/post-upgrade.sh new file mode 100755 index 000000000000..8841da28ec67 --- /dev/null +++ b/resources/event-sources/post-upgrade.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -eu -o pipefail + +readonly KSVC_RESOURCE_TYPE="services.serving.knative.dev" +readonly KSVC_NAMESPACE="kyma-integration" + +function delete_orphaned_ksvcs() { + local -r ksvcs=$(kubectl get "${KSVC_RESOURCE_TYPE}" -n "${KSVC_NAMESPACE}" -ojson | jq -c ".items[]") + if [[ -z ${ksvcs} ]]; then + echo "There are not any Knative Services in namespace ${KSVC_NAMESPACE}. Skipping..." + return 0 + fi + + IFS=$'\n' + for ksvc in ${ksvcs} + do + does_belong_to_httpsource=$(echo "${ksvc}" | jq '.metadata.ownerReferences | .[] | select(.kind=="HTTPSource")' ) + if [[ ! -z "${does_belong_to_httpsource}" ]]; then + ksvc_name=$(echo "${ksvc}" | jq -r '.metadata.name' ) + echo "Found a ksvc with name ${ksvc_name} which belongs to HTTPSource ... deleting ..." + kubectl delete -n "${KSVC_NAMESPACE}" "${KSVC_RESOURCE_TYPE}" "${ksvc_name}" + fi + done +} + +delete_orphaned_ksvcs diff --git a/resources/event-sources/templates/200-rbac.yaml b/resources/event-sources/templates/200-rbac.yaml index ba9bcda39c3f..c65b3d4155bb 100644 --- a/resources/event-sources/templates/200-rbac.yaml +++ b/resources/event-sources/templates/200-rbac.yaml @@ -9,6 +9,27 @@ kind: ClusterRole metadata: name: {{ template "controller-manager.fullname" . }} rules: + - apiGroups: + - "" + resources: + - services + verbs: + - get + - list + - create + - update + - watch + - apiGroups: + - apps + resources: + - deployments + verbs: + - get + - list + - create + - update + - watch + # Metrics/logging configs - apiGroups: - "" @@ -32,16 +53,6 @@ rules: - httpsources/status verbs: - update - # Knative Services - - apiGroups: - - serving.knative.dev - resources: - - services - verbs: - - list - - watch - - create - - update # Channels - apiGroups: - messaging.knative.dev diff --git a/resources/event-sources/templates/500-sources-controller.yaml b/resources/event-sources/templates/500-sources-controller.yaml index 2c2883c21a99..b08cb753f130 100644 --- a/resources/event-sources/templates/500-sources-controller.yaml +++ b/resources/event-sources/templates/500-sources-controller.yaml @@ -35,5 +35,3 @@ spec: value: kyma-project.io/controller-manager - name: HTTP_ADAPTER_IMAGE value: "{{ .Values.global.containerRegistry.path }}/{{ .Values.global.httpAdapter.dir }}{{ .Values.global.httpAdapter.image }}:{{ .Values.global.httpAdapter.version }}" - - name: HTTP_ADAPTER_TRACING_ENABLED - value: "{{ .Values.global.httpAdapter.tracingEnabled }}" diff --git a/resources/event-sources/templates/post-upgrade-hook.yaml b/resources/event-sources/templates/post-upgrade-hook.yaml new file mode 100644 index 000000000000..b362e5061bf6 --- /dev/null +++ b/resources/event-sources/templates/post-upgrade-hook.yaml @@ -0,0 +1,91 @@ +# About: +# This post-upgrade job deletes knative services which belong to HTTPSource +# The knative services got replaced by deployments and are not required anymore +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ .Release.Name }}-post-upgrade + namespace: {{ .Release.Namespace }} + labels: + app: {{ .Release.Name }}-post-upgrade + annotations: + helm.sh/hook: "post-upgrade" + helm.sh/hook-delete-policy: "hook-succeeded,before-hook-creation" + helm.sh/hook-weight: "0" +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ .Release.Name }}-post-upgrade + labels: + app: {{ .Release.Name }}-post-upgrade + annotations: + helm.sh/hook: "post-upgrade" + helm.sh/hook-delete-policy: "hook-succeeded,before-hook-creation" + helm.sh/hook-weight: "0" +rules: + - apiGroups: ["serving.knative.dev"] + resources: ["services"] + verbs: ["get", "list", "delete"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ .Release.Name }}-post-upgrade + labels: + app: {{ .Release.Name }}-post-upgrade + annotations: + helm.sh/hook: "post-upgrade" + helm.sh/hook-delete-policy: "hook-succeeded,before-hook-creation" + helm.sh/hook-weight: "1" +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ .Release.Name }}-post-upgrade +subjects: + - kind: ServiceAccount + name: {{ .Release.Name }}-post-upgrade + namespace: {{ .Release.Namespace }} +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ .Release.Name }}-post-upgrade + namespace: {{ .Release.Namespace }} + labels: + app: {{ .Release.Name }}-post-upgrade + annotations: + helm.sh/hook: "post-upgrade" + helm.sh/hook-delete-policy: "hook-succeeded,before-hook-creation" + helm.sh/hook-weight: "2" + sidecar.istio.io/inject: "false" +spec: + backoffLimit: 1 + template: + metadata: + annotations: + sidecar.istio.io/inject: "false" + labels: + app: {{ .Release.Name }}-post-upgrade + name: {{ .Release.Name }}-post-upgrade + spec: + serviceAccountName: {{ .Release.Name }}-post-upgrade + restartPolicy: Never + containers: + - name: {{ .Release.Name }}-post-upgrade + image: eu.gcr.io/kyma-project/test-infra/alpine-kubectl:v20200507-070ff576 + command: + - "/bin/bash" + args: + - "-c" + - | +{{ .Files.Get "post-upgrade.sh" | indent 14 }} + terminationMessagePolicy: "FallbackToLogsOnError" + resources: + requests: + cpu: 200m + memory: 128Mi + limits: + cpu: 200m + memory: 128Mi diff --git a/resources/event-sources/values.yaml b/resources/event-sources/values.yaml index 215e8f4109c5..20acfa4b09d4 100644 --- a/resources/event-sources/values.yaml +++ b/resources/event-sources/values.yaml @@ -5,9 +5,9 @@ global: name: controller-manager image: event-sources-controller-manager dir: '' - version: PR-9040 + version: PR-9186 httpAdapter: image: event-sources-http-adapter dir: '' - version: PR-9040 + version: PR-9186 tracingEnabled: "true" diff --git a/resources/knative-eventing/charts/event-mesh-dashboard/templates/event-mesh-delivery.yaml b/resources/knative-eventing/charts/event-mesh-dashboard/templates/event-mesh-delivery.yaml index 909b34a2894c..f3270def4200 100644 --- a/resources/knative-eventing/charts/event-mesh-dashboard/templates/event-mesh-delivery.yaml +++ b/resources/knative-eventing/charts/event-mesh-dashboard/templates/event-mesh-delivery.yaml @@ -192,7 +192,7 @@ data: "steppedLine": false, "targets": [ { - "expr": "rate(revision_app_request_count{configuration_name=\"$app\",container_name=\"queue-proxy\",namespace_name=\"kyma-integration\",response_code_class=\"2xx\",revision_name=~\"$app-.*\",service_name=~\"$app\"}[5m])", + "expr": "rate(httpsource_event_count{container=\"source\",namespace=\"kyma-integration\",response_code_class=\"2xx\",event_source=\"$app\"}[5m])", "format": "time_series", "hide": false, "instant": false, @@ -201,13 +201,13 @@ data: "refId": "A" }, { - "expr": "rate(revision_app_request_count{configuration_name=\"$app\",container_name=\"queue-proxy\",namespace_name=\"kyma-integration\",response_code_class=\"4xx\",revision_name=~\"$app-.*\",service_name=~\"$app\"}[5m])", + "expr": "rate(httpsource_event_count{container=\"source\",namespace=\"kyma-integration\",response_code_class=\"4xx\",event_source=\"$app\"}[5m])", "hide": false, "legendFormat": "4XX", "refId": "B" }, { - "expr": "rate(revision_app_request_count{configuration_name=\"$app\",container_name=\"queue-proxy\",namespace_name=\"kyma-integration\",response_code_class=\"5xx\",revision_name=~\"$app-.*\",service_name=~\"$app\"}[5m])", + "expr": "rate(httpsource_event_count{container=\"source\",namespace=\"kyma-integration\",response_code_class=\"5xx\",event_source=\"$app\"}[5m])", "hide": false, "legendFormat": "5XX", "refId": "C" @@ -484,8 +484,9 @@ data: { "allValue": null, "current": { - "text": "mocks", - "value": "mocks" + "selected": true, + "text": "test", + "value": "test" }, "datasource": "Prometheus", "definition": "query_result(kube_pod_info{pod=~\"default-broker-ingress.*\"} or kube_pod_info{pod=~\"application-broker.*\"})", @@ -539,7 +540,6 @@ data: }, "timepicker": { "refresh_intervals": [ - "5s", "10s", "30s", "1m", diff --git a/resources/knative-eventing/charts/event-mesh-dashboard/templates/event-mesh-latency-dashboard.yaml b/resources/knative-eventing/charts/event-mesh-dashboard/templates/event-mesh-latency-dashboard.yaml index fd63ce72435e..3e540d3875d8 100644 --- a/resources/knative-eventing/charts/event-mesh-dashboard/templates/event-mesh-latency-dashboard.yaml +++ b/resources/knative-eventing/charts/event-mesh-dashboard/templates/event-mesh-latency-dashboard.yaml @@ -25,6 +25,7 @@ data: "editable": false, "gnetId": null, "graphTooltip": 0, + "id": 396, "links": [], "panels": [ { @@ -47,6 +48,13 @@ data: "dashLength": 10, "dashes": false, "datasource": null, + "description": "Data-plane entrypoint inside the cluster for legacy events.", + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { @@ -82,7 +90,7 @@ data: "steppedLine": false, "targets": [ { - "expr": "histogram_quantile(0.99, sum(rate(istio_request_duration_seconds_bucket{source_workload_namespace=\"kyma-integration\",source_workload=~\".*-connectivity-validator\",destination_workload_namespace=\"knative-serving\",destination_workload=\"activator\"}[5m])) by (le,source_workload_namespace,source_workload,destination_workload_namespace,destination_workload))", + "expr": "histogram_quantile(0.99, sum(rate(istio_request_duration_seconds_bucket{source_workload_namespace=\"kyma-integration\",source_workload=~\".*-connectivity-validator\",destination_workload_namespace=\"kyma-integration\",destination_workload=~\".*-event-service\"}[5m])) by (le,source_workload_namespace,source_workload,destination_workload_namespace,destination_workload))", "legendFormat": "{{`{{source_workload_namespace}}/{{source_workload}} -> {{destination_workload_namespace}}/{{destination_workload}} (p99)`}}", "refId": "A" } @@ -91,7 +99,7 @@ data: "timeFrom": null, "timeRegions": [], "timeShift": null, - "title": "Connectivity Validator -> Knative Service Activator", + "title": "Connectivity Validator -> Event Service", "tooltip": { "shared": true, "sort": 0, @@ -134,6 +142,12 @@ data: "dashLength": 10, "dashes": false, "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { @@ -169,7 +183,7 @@ data: "steppedLine": false, "targets": [ { - "expr": "histogram_quantile(0.99, sum(rate(istio_request_duration_seconds_bucket{source_workload_namespace=\"knative-serving\",source_workload=\"activator\",destination_workload_namespace=\"kyma-integration\",destination_workload=~\".*-deployment\"}[5m])) by (le,source_workload_namespace,source_workload,destination_workload_namespace,destination_workload))", + "expr": "histogram_quantile(0.99, sum(rate(istio_request_duration_seconds_bucket{source_workload_namespace=\"kyma-integration\",source_workload=~\".*-event-service\",destination_workload_namespace=\"kyma-integration\",destination_workload=~\".*\"}[5m])) by (le,source_workload_namespace,source_workload,destination_workload_namespace,destination_workload))", "legendFormat": "{{`{{source_workload_namespace}}/{{source_workload}} -> {{destination_workload_namespace}}/{{destination_workload}} (p99)`}}", "refId": "A" } @@ -178,7 +192,7 @@ data: "timeFrom": null, "timeRegions": [], "timeShift": null, - "title": "Knative Service Activator -> HTTP Event Source", + "title": "Event Service -> HTTP Event Source", "tooltip": { "shared": true, "sort": 0, @@ -221,6 +235,13 @@ data: "dashLength": 10, "dashes": false, "datasource": null, + "description": "Data-plane entrypoint inside the cluster for non-legacy events. Event-service is not required in this eventing flow.", + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { @@ -230,9 +251,8 @@ data: "y": 9 }, "hiddenSeries": false, - "id": 4, + "id": 18, "legend": { - "alignAsTable": false, "avg": false, "current": false, "max": false, @@ -257,7 +277,7 @@ data: "steppedLine": false, "targets": [ { - "expr": "histogram_quantile(0.99, sum(rate(istio_request_duration_seconds_bucket{source_workload_namespace=\"kyma-integration\",source_workload=~\".*-deployment\",destination_workload_namespace=\"knative-eventing\",destination_workload=~\".*-dispatcher|knative-kafka-channel\"}[5m])) by (le,source_workload_namespace,source_workload,destination_workload_namespace,destination_workload))", + "expr": "histogram_quantile(0.99, sum(rate(istio_request_duration_seconds_bucket{source_workload_namespace=\"kyma-integration\",source_workload=~\".*-connectivity-validator\",destination_workload_namespace=\"kyma-integration\",destination_workload!~\".*-event-service\",destination_workload!=\"application-registry\"}[5m])) by (le,source_workload_namespace,source_workload,destination_workload_namespace,destination_workload))", "hide": false, "legendFormat": "{{`{{source_workload_namespace}}/{{source_workload}} -> {{destination_workload_namespace}}/{{destination_workload}} (p99)`}}", "refId": "A" @@ -267,7 +287,7 @@ data: "timeFrom": null, "timeRegions": [], "timeShift": null, - "title": "HTTP Event Source -> Source Channel", + "title": "Connectivity Validator -> HTTP Event Source", "tooltip": { "shared": true, "sort": 0, @@ -310,6 +330,12 @@ data: "dashLength": 10, "dashes": false, "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { @@ -319,6 +345,99 @@ data: "y": 9 }, "hiddenSeries": false, + "id": 4, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "histogram_quantile(0.99, sum(rate(istio_request_duration_seconds_bucket{source_workload_namespace=\"kyma-integration\",source_workload=~\".*\",destination_workload_namespace=\"knative-eventing\",destination_workload=~\".*-dispatcher|knative-kafka-channel\"}[5m])) by (le,source_workload_namespace,source_workload,destination_workload_namespace,destination_workload))", + "legendFormat": "{{`{{source_workload_namespace}}/{{source_workload}} -> {{destination_workload_namespace}}/{{destination_workload}} (p99)`}}", + "refId": "A" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "HTTP Event Source -> Source Channel", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "s", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 17 + }, + "hiddenSeries": false, "id": 6, "legend": { "avg": false, @@ -346,7 +465,6 @@ data: "targets": [ { "expr": "histogram_quantile(0.99, sum(rate(istio_request_duration_seconds_bucket{source_workload=~\"[a-z0-9-]+-dispatcher\",destination_workload=\"default-broker-ingress\"}[5m])) by (le,source_workload_namespace,source_workload,destination_workload_namespace,destination_workload))", - "hide": false, "legendFormat": "{{`{{source_workload_namespace}}/{{source_workload}} -> {{destination_workload_namespace}}/{{destination_workload}} (p99)`}}", "refId": "A" } @@ -398,12 +516,18 @@ data: "dashLength": 10, "dashes": false, "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 8, "w": 12, - "x": 0, + "x": 12, "y": 17 }, "hiddenSeries": false, @@ -485,13 +609,19 @@ data: "dashLength": 10, "dashes": false, "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 8, "w": 12, - "x": 12, - "y": 17 + "x": 0, + "y": 25 }, "hiddenSeries": false, "id": 8, @@ -572,12 +702,18 @@ data: "dashLength": 10, "dashes": false, "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 8, "w": 12, - "x": 0, + "x": 12, "y": 25 }, "hiddenSeries": false, @@ -656,7 +792,7 @@ data: } ], "refresh": "10s", - "schemaVersion": 21, + "schemaVersion": 25, "style": "dark", "tags": [ "kyma", @@ -685,6 +821,6 @@ data: }, "timezone": "", "title": "Kyma / Event Mesh / Latency", - "uid": "ycULeS8Zz", - "version": 1 + "uid": "jUfN-ESMk", + "version": 3 } diff --git a/resources/knative-eventing/charts/event-mesh-dashboard/templates/pod-monitor.yaml b/resources/knative-eventing/charts/event-mesh-dashboard/templates/pod-monitor.yaml index 593e04ee136a..6f75e9d0c2a7 100644 --- a/resources/knative-eventing/charts/event-mesh-dashboard/templates/pod-monitor.yaml +++ b/resources/knative-eventing/charts/event-mesh-dashboard/templates/pod-monitor.yaml @@ -32,7 +32,7 @@ spec: - port: http-usermetric selector: matchExpressions: - - key: serving.knative.dev/service + - key: kyma-project.io/eventsource operator: Exists matchLabels: kyma-project.io/dashboard: event-mesh diff --git a/tests/end-to-end/upgrade/Gopkg.lock b/tests/end-to-end/upgrade/Gopkg.lock index b9536e8f765c..dac8ae66f91b 100644 --- a/tests/end-to-end/upgrade/Gopkg.lock +++ b/tests/end-to-end/upgrade/Gopkg.lock @@ -181,11 +181,14 @@ version = "v3.2.0" [[projects]] - digest = "1:582e25eccee928dc12416ea4c23b6dae8f3b5687730632aa1473ebebe80a2359" + digest = "1:85a9bc2805bd82a7d717447eb83015d881855fee0c8201de6d2ca1df1b9ef931" name = "github.com/gogo/protobuf" packages = [ + "jsonpb", "proto", + "protoc-gen-gogo/descriptor", "sortkeys", + "types", ] pruneopts = "UT" revision = "5628607bb4c51c3157aacc3a50f0ab707582b805" @@ -366,7 +369,7 @@ version = "v1.0.0" [[projects]] - digest = "1:65654f7d7ee7491f75738c96a0973515f9e7917c8d9fc1e5c158ee3e9904b93a" + digest = "1:6e994f4f591eee9a0a093a72c1aa0eeb17b7dd45677f5103a9eb005ac9709607" name = "github.com/kyma-project/kyma" packages = [ "common/microfrontend-client/pkg/apis/ui", @@ -382,6 +385,10 @@ "components/application-operator/pkg/client/clientset/versioned", "components/application-operator/pkg/client/clientset/versioned/scheme", "components/application-operator/pkg/client/clientset/versioned/typed/applicationconnector/v1alpha1", + "components/event-sources/apis/sources", + "components/event-sources/apis/sources/v1alpha1", + "components/event-sources/client/generated/clientset/internalclientset/scheme", + "components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1", "components/function-controller/pkg/apis/serverless/v1alpha1", "components/kyma-operator/pkg/overrides", "components/service-binding-usage-controller/pkg/apis/servicecatalog/v1alpha1", @@ -910,6 +917,30 @@ revision = "afd67930eec2a9ed3e9b19f684d17a062285f16a" version = "2019.2.3" +[[projects]] + digest = "1:8ebab926f874611c31e1ea62fc34ec4b31ee224eca8530db175b30ac62c1086a" + name = "istio.io/api" + packages = ["authentication/v1alpha1"] + pruneopts = "UT" + revision = "34e474846e0d348c39ee16a268a71a3104cb6f9e" + version = "1.6.7" + +[[projects]] + digest = "1:3f0537a8015004b5fe8bba6fb6d41193a767a478a91cdbdc16666a0e6c34003d" + name = "istio.io/client-go" + packages = ["pkg/apis/authentication/v1alpha1"] + pruneopts = "UT" + revision = "f8d9d8ff84e6e3753cdfcbb82c03f495269e29dc" + version = "1.5.8" + +[[projects]] + digest = "1:c49d54c5c21522692aff4ff2664622b412f78b6b7e397b1681930d60ff8aa3ea" + name = "istio.io/gogo-genproto" + packages = ["googleapis/google/api"] + pruneopts = "UT" + revision = "8607e17318e8a875c2e9e75ab576a6f55ffa964d" + version = "1.6.7" + [[projects]] digest = "1:d89afbf3588e87d2c9e6efdd5528d249b32d23a12fbd7ec324f3cb373c6fb76c" name = "k8s.io/api" @@ -1260,7 +1291,7 @@ revision = "5e3431e56176359316416c5952dcb7797299248f" [[projects]] - digest = "1:457cb733d811cb3840996e2c69a9cf9c6526aa3e2580fb7052108c920dd29905" + digest = "1:fc0c5d0f7d8cd02183a789133637d810c41fd245f801a5d0e9f9910f129db5aa" name = "knative.dev/serving" packages = [ "pkg/apis/autoscaling", @@ -1272,13 +1303,6 @@ "pkg/apis/serving/v1", "pkg/apis/serving/v1alpha1", "pkg/apis/serving/v1beta1", - "pkg/client/clientset/versioned", - "pkg/client/clientset/versioned/scheme", - "pkg/client/clientset/versioned/typed/autoscaling/v1alpha1", - "pkg/client/clientset/versioned/typed/networking/v1alpha1", - "pkg/client/clientset/versioned/typed/serving/v1", - "pkg/client/clientset/versioned/typed/serving/v1alpha1", - "pkg/client/clientset/versioned/typed/serving/v1beta1", "pkg/gc", "pkg/network", "pkg/reconciler/route/config", @@ -1329,6 +1353,7 @@ "github.com/kyma-project/kyma/components/application-broker/pkg/client/clientset/versioned", "github.com/kyma-project/kyma/components/application-operator/pkg/apis/applicationconnector/v1alpha1", "github.com/kyma-project/kyma/components/application-operator/pkg/client/clientset/versioned", + "github.com/kyma-project/kyma/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1", "github.com/kyma-project/kyma/components/function-controller/pkg/apis/serverless/v1alpha1", "github.com/kyma-project/kyma/components/kyma-operator/pkg/overrides", "github.com/kyma-project/kyma/components/service-binding-usage-controller/pkg/apis/servicecatalog/v1alpha1", @@ -1372,7 +1397,6 @@ "knative.dev/eventing/pkg/client/clientset/versioned/typed/messaging/v1alpha1", "knative.dev/pkg/apis", "knative.dev/pkg/apis/duck/v1", - "knative.dev/serving/pkg/client/clientset/versioned", "sigs.k8s.io/controller-runtime/pkg/client", "sigs.k8s.io/controller-runtime/pkg/client/config", ] diff --git a/tests/end-to-end/upgrade/Gopkg.toml b/tests/end-to-end/upgrade/Gopkg.toml index 9169eb173b43..f6b6b258e666 100644 --- a/tests/end-to-end/upgrade/Gopkg.toml +++ b/tests/end-to-end/upgrade/Gopkg.toml @@ -59,10 +59,6 @@ required = [ name = "knative.dev/eventing" version = "0.12.0" -[[constraint]] - name = "knative.dev/serving" - version = "0.12.0" - # Transitive dependencies of knative.dev/pkg [[override]] name = "k8s.io/api" diff --git a/tests/end-to-end/upgrade/chart/upgrade/templates/rbac.yaml b/tests/end-to-end/upgrade/chart/upgrade/templates/rbac.yaml index d48035b165d9..f49a93359cfc 100644 --- a/tests/end-to-end/upgrade/chart/upgrade/templates/rbac.yaml +++ b/tests/end-to-end/upgrade/chart/upgrade/templates/rbac.yaml @@ -54,8 +54,8 @@ rules: - apiGroups: ["applicationconnector.kyma-project.io"] resources: ["applications", "applicationmappings","eventactivations"] verbs: ["create", "delete", "list", "get"] -- apiGroups: ["serving.knative.dev"] - resources: ["services", "services/status"] +- apiGroups: ["sources.kyma-project.io"] + resources: ["httpsources", "httpsources/status"] verbs: ["get","list"] - apiGroups: [""] resources: ["pods", "pods/log", "pods/status", "secrets", "configmaps"] diff --git a/tests/end-to-end/upgrade/chart/upgrade/values.yaml b/tests/end-to-end/upgrade/chart/upgrade/values.yaml index 6d4716080bb6..72a0346ae964 100644 --- a/tests/end-to-end/upgrade/chart/upgrade/values.yaml +++ b/tests/end-to-end/upgrade/chart/upgrade/values.yaml @@ -7,7 +7,7 @@ subscriberimage: image: dir: - version: PR-9155 + version: PR-9186 pullPolicy: "IfNotPresent" dex: diff --git a/tests/end-to-end/upgrade/main.go b/tests/end-to-end/upgrade/main.go index 84eb6c5832b0..9b11fcb159bd 100644 --- a/tests/end-to-end/upgrade/main.go +++ b/tests/end-to-end/upgrade/main.go @@ -9,7 +9,6 @@ import ( eventingclientv1alpha1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/eventing/v1alpha1" messagingclientv1alpha1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/messaging/v1alpha1" - servingclientset "knative.dev/serving/pkg/client/clientset/versioned" "github.com/sirupsen/logrus" "github.com/vrischmann/envconfig" @@ -25,6 +24,7 @@ import ( mfClient "github.com/kyma-project/kyma/common/microfrontend-client/pkg/client/clientset/versioned" ab "github.com/kyma-project/kyma/components/application-broker/pkg/client/clientset/versioned" ao "github.com/kyma-project/kyma/components/application-operator/pkg/client/clientset/versioned" + sourcesv1alpha1 "github.com/kyma-project/kyma/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1" "github.com/kyma-project/kyma/components/kyma-operator/pkg/overrides" bu "github.com/kyma-project/kyma/components/service-binding-usage-controller/pkg/client/clientset/versioned" "github.com/kyma-project/kyma/tests/end-to-end/upgrade/internal/platform/logger" @@ -116,8 +116,8 @@ func main() { dexConfig, err := getDexConfigFromCluster(k8sCli, cfg.DexUserSecret, cfg.DexNamespace, domainName) fatalOnError(err, "while reading dex config from cluster") - servingCli, err := servingclientset.NewForConfig(k8sConfig) - fatalOnError(err, "while generating knative serving client") + sourcesCli, err := sourcesv1alpha1.NewForConfig(k8sConfig) + fatalOnError(err, "while generating sources client") eventingCli, err := eventingclientv1alpha1.NewForConfig(k8sConfig) fatalOnError(err, "while generating knative eventing client") @@ -147,7 +147,7 @@ func main() { "ApiGatewayUpgradeTest": apigateway.NewApiGatewayTest(k8sCli, dynamicCli, domainName, dexConfig.IdProviderConfig()), "ApplicationOperatorUpgradeTest": applicationoperator.NewApplicationOperatorUpgradeTest(appConnectorCli, *k8sCli), "RafterUpgradeTest": rafter.NewRafterUpgradeTest(dynamicCli), - "EventMeshUpgradeTest": eventmesh.NewEventMeshUpgradeTest(appConnectorCli, k8sCli, messagingCli, servingCli, appBrokerCli, scCli, eventingCli, cfg.EventSubscriberImage), + "EventMeshUpgradeTest": eventmesh.NewEventMeshUpgradeTest(appConnectorCli, k8sCli, messagingCli, sourcesCli, appBrokerCli, scCli, eventingCli, cfg.EventSubscriberImage), "ServerlessUpgradeTest": serverless.New(dynamicCli), //"LoggingUpgradeTest": logging.NewLoggingTest(k8sCli, domainName, dexConfig.IdProviderConfig()), } diff --git a/tests/end-to-end/upgrade/pkg/tests/eventmesh/eventmesh.go b/tests/end-to-end/upgrade/pkg/tests/eventmesh/eventmesh.go index 98f0ed576333..94f861a9d8cd 100644 --- a/tests/end-to-end/upgrade/pkg/tests/eventmesh/eventmesh.go +++ b/tests/end-to-end/upgrade/pkg/tests/eventmesh/eventmesh.go @@ -10,11 +10,12 @@ import ( appbrokerclientset "github.com/kyma-project/kyma/components/application-broker/pkg/client/clientset/versioned" appconnectorclientset "github.com/kyma-project/kyma/components/application-operator/pkg/client/clientset/versioned" + sourcesv1alpha1 "github.com/kyma-project/kyma/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1" + "github.com/kyma-project/kyma/tests/end-to-end/upgrade/internal/runner" eventingv1alpha1clientset "knative.dev/eventing/pkg/client/clientset/versioned/typed/eventing/v1alpha1" messagingv1alpha1clientset "knative.dev/eventing/pkg/client/clientset/versioned/typed/messaging/v1alpha1" - servingclientset "knative.dev/serving/pkg/client/clientset/versioned" ) type EventMeshUpgradeTest struct { @@ -22,7 +23,7 @@ type EventMeshUpgradeTest struct { appConnectorInterface appconnectorclientset.Interface messagingClient messagingv1alpha1clientset.MessagingV1alpha1Interface - servingClient servingclientset.Interface + sourcesClient sourcesv1alpha1.SourcesV1alpha1Interface appBrokerCli appbrokerclientset.Interface scCli scclientset.Interface eventingCli eventingv1alpha1clientset.EventingV1alpha1Interface @@ -36,7 +37,7 @@ func NewEventMeshUpgradeTest( appConnectorCli appconnectorclientset.Interface, k8sCli kubernetes.Interface, messagingCli messagingv1alpha1clientset.MessagingV1alpha1Interface, - servingCli servingclientset.Interface, + sourcesCli sourcesv1alpha1.SourcesV1alpha1Interface, appBrokerCli appbrokerclientset.Interface, scCli scclientset.Interface, eventingCli eventingv1alpha1clientset.EventingV1alpha1Interface, @@ -45,7 +46,7 @@ func NewEventMeshUpgradeTest( k8sInterface: k8sCli, messagingClient: messagingCli, appConnectorInterface: appConnectorCli, - servingClient: servingCli, + sourcesClient: sourcesCli, appBrokerCli: appBrokerCli, scCli: scCli, eventingCli: eventingCli, diff --git a/tests/end-to-end/upgrade/pkg/tests/eventmesh/helpers/application.go b/tests/end-to-end/upgrade/pkg/tests/eventmesh/helpers/application.go index 156fe76c3232..c5f01e42bf49 100644 --- a/tests/end-to-end/upgrade/pkg/tests/eventmesh/helpers/application.go +++ b/tests/end-to-end/upgrade/pkg/tests/eventmesh/helpers/application.go @@ -3,21 +3,17 @@ package helpers import ( "fmt" - appbrokerclientset "github.com/kyma-project/kyma/components/application-broker/pkg/client/clientset/versioned" - "github.com/avast/retry-go" - scv1beta1 "github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1" servicecatalogclientset "github.com/kubernetes-incubator/service-catalog/pkg/client/clientset_generated/clientset" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + messagingv1alpha1clientset "knative.dev/eventing/pkg/client/clientset/versioned/typed/messaging/v1alpha1" appbrokerv1alpha1 "github.com/kyma-project/kyma/components/application-broker/pkg/apis/applicationconnector/v1alpha1" + appbrokerclientset "github.com/kyma-project/kyma/components/application-broker/pkg/client/clientset/versioned" appconnectorv1alpha1 "github.com/kyma-project/kyma/components/application-operator/pkg/apis/applicationconnector/v1alpha1" appconnectorclientset "github.com/kyma-project/kyma/components/application-operator/pkg/client/clientset/versioned" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - messagingv1alpha1clientset "knative.dev/eventing/pkg/client/clientset/versioned/typed/messaging/v1alpha1" - servingclientset "knative.dev/serving/pkg/client/clientset/versioned" + sourcesv1alpha1 "github.com/kyma-project/kyma/components/event-sources/client/generated/clientset/internalclientset/typed/sources/v1alpha1" ) const ( @@ -74,7 +70,7 @@ func WithEventService(id string) ApplicationOption { } } -func WaitForApplication(appConnector appconnectorclientset.Interface, messaging messagingv1alpha1clientset.MessagingV1alpha1Interface, serving servingclientset.Interface, name string, retryOptions ...retry.Option) error { +func WaitForApplication(appConnector appconnectorclientset.Interface, messaging messagingv1alpha1clientset.MessagingV1alpha1Interface, sources sourcesv1alpha1.SourcesV1alpha1Interface, name string, retryOptions ...retry.Option) error { application, err := appConnector.ApplicationconnectorV1alpha1().Applications().Get(name, metav1.GetOptions{}) if err != nil { return fmt.Errorf("cannot get application: %v", err) @@ -83,7 +79,7 @@ func WaitForApplication(appConnector appconnectorclientset.Interface, messaging if err := WaitForChannel(messaging, name, integrationNamespace, retryOptions...); err != nil { return fmt.Errorf("waiting for application failed: %v, application: %+v", err, application) } - if err := WaitForHttpSource(serving, name, integrationNamespace, retryOptions...); err != nil { + if err := WaitForHttpSource(sources, name, integrationNamespace, retryOptions...); err != nil { return fmt.Errorf("waiting for application failed: %v, application: %+v", err, application) } } @@ -118,15 +114,15 @@ func WaitForChannel(messaging messagingv1alpha1clientset.MessagingV1alpha1Interf }, retryOptions...) } -func WaitForHttpSource(serving servingclientset.Interface, name, namespace string, retryOptions ...retry.Option) error { +func WaitForHttpSource(sources sourcesv1alpha1.SourcesV1alpha1Interface, name, namespace string, retryOptions ...retry.Option) error { return retry.Do( func() error { - ksvc, err := serving.ServingV1alpha1().Services(namespace).Get(name, metav1.GetOptions{}) + src, err := sources.HTTPSources(namespace).Get(name, metav1.GetOptions{}) if err != nil { return fmt.Errorf("cannot get HttpSource: %v", err) } - if !ksvc.Status.IsReady() { - return fmt.Errorf("knative-service %v for HTTPSource not ready, ksvc: %+v", ksvc.Name, ksvc) + if !src.Status.IsReady() { + return fmt.Errorf("httpsource %v for HTTPSource not ready, src: %+v", src.Name, src) } return nil }, retryOptions...) diff --git a/tests/end-to-end/upgrade/pkg/tests/eventmesh/setup.go b/tests/end-to-end/upgrade/pkg/tests/eventmesh/setup.go index cb694826d659..589e86a79c5f 100644 --- a/tests/end-to-end/upgrade/pkg/tests/eventmesh/setup.go +++ b/tests/end-to-end/upgrade/pkg/tests/eventmesh/setup.go @@ -67,7 +67,7 @@ func (f *eventMeshFlow) WaitForSubscriber() error { } func (f *eventMeshFlow) WaitForApplication() error { - return helpers.WaitForApplication(f.appConnectorInterface, f.messagingClient, f.servingClient, f.applicationName) + return helpers.WaitForApplication(f.appConnectorInterface, f.messagingClient, f.sourcesClient, f.applicationName) } func (f *eventMeshFlow) CreateApplicationMapping() error {