From cca6776c408551a3a511220884ded12a058acfd3 Mon Sep 17 00:00:00 2001 From: Ahmed Abdalla Date: Mon, 22 Jun 2020 12:32:26 +0200 Subject: [PATCH 1/7] Add Sources flag for e2e flags --- test/e2e_flags.go | 4 +++ test/flags/eventing_environment.go | 1 + test/flags/sources.go | 42 ++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 test/flags/sources.go diff --git a/test/e2e_flags.go b/test/e2e_flags.go index d67925fc2d6..83ac9440d66 100644 --- a/test/e2e_flags.go +++ b/test/e2e_flags.go @@ -35,6 +35,9 @@ const ( BrokerUsage = "Which brokerclass to test, requires the proper Broker " + "implementation to have been installed, and only one value. brokerclass " + "must be (for now) 'MTChannelBasedBroker'." + SourceUsage = "The names of the source type metas, separated by comma. " + + "Example: \"sources.knative.dev/v1alpha1:ApiServerSource," + + "sources.knative.dev/v1alpha1:PingSource\"." ) // EventingFlags holds the command line flags specific to knative/eventing. @@ -46,6 +49,7 @@ func InitializeEventingFlags() { flag.Var(&EventingFlags.Channels, "channels", ChannelUsage) flag.StringVar(&EventingFlags.BrokerClass, "brokerclass", "MTChannelBasedBroker", BrokerUsage) + flag.Var(&EventingFlags.Sources, "sources", SourceUsage) flag.Parse() // If no channel is passed through the flag, initialize it as the DefaultChannel. diff --git a/test/flags/eventing_environment.go b/test/flags/eventing_environment.go index b53d3738a05..65a05dd7ac4 100644 --- a/test/flags/eventing_environment.go +++ b/test/flags/eventing_environment.go @@ -20,4 +20,5 @@ package flags type EventingEnvironmentFlags struct { BrokerClass string Channels + Sources } diff --git a/test/flags/sources.go b/test/flags/sources.go new file mode 100644 index 00000000000..633b7a6ba38 --- /dev/null +++ b/test/flags/sources.go @@ -0,0 +1,42 @@ +package flags + +import ( + "fmt" + "log" + "strings" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// Sources holds the Sourcess we want to run test against. +type Sources []metav1.TypeMeta + +func (sources *Sources) String() string { + return fmt.Sprint(*sources) +} + +// Set converts the input string to Sources. +func (sources *Sources) Set(value string) error { + for _, source := range strings.Split(value, ",") { + source := strings.TrimSpace(source) + split := strings.Split(source, ":") + if len(split) != 2 { + log.Fatalf("The given Source name %q is invalid, it needs to be in the form \"apiVersion:Kind\".", source) + } + tm := metav1.TypeMeta{ + APIVersion: split[0], + Kind: split[1], + } + if !isValidSource(tm.Kind) { + log.Fatalf("The given source name %q is invalid, tests cannot be run.\n", source) + } + + *sources = append(*sources, tm) + } + return nil +} + +// Check if the Source name is valid. +func isValidSource(source string) bool { + return strings.HasSuffix(source, "Source") +} From 456b92b1df4572850046230979e570757e951a63 Mon Sep 17 00:00:00 2001 From: Ahmed Abdalla Date: Mon, 22 Jun 2020 12:58:37 +0200 Subject: [PATCH 2/7] Add Sources CRD labels conformance test --- .../source_crd_metadata_test_helper.go | 48 +++++++++++++++++++ test/conformance/main_test.go | 4 ++ test/conformance/source_crd_metadata_test.go | 28 +++++++++++ test/flags/sources.go | 20 +++++++- 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 test/conformance/helpers/source_crd_metadata_test_helper.go create mode 100644 test/conformance/source_crd_metadata_test.go diff --git a/test/conformance/helpers/source_crd_metadata_test_helper.go b/test/conformance/helpers/source_crd_metadata_test_helper.go new file mode 100644 index 00000000000..5cde699acbc --- /dev/null +++ b/test/conformance/helpers/source_crd_metadata_test_helper.go @@ -0,0 +1,48 @@ +/* +Copyright 2020 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + 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 helpers + +import ( + "testing" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + testlib "knative.dev/eventing/test/lib" +) + +var sourceLabels = map[string]string{ + "duck.knative.dev/source": "true", +} + +func SourceCRDMetadataTestHelperWithChannelTestRunner( + t *testing.T, + sourceTestRunner testlib.ComponentsTestRunner, + options ...testlib.SetupClientOption, +) { + + sourceTestRunner.RunTests(t, testlib.FeatureBasic, func(st *testing.T, source metav1.TypeMeta) { + client := testlib.Setup(st, true, options...) + defer testlib.TearDown(client) + + // From spec: + // Each source MUST have the following: + // label of duck.knative.dev/source: "true" + t.Run("Source CRD has required label", func(t *testing.T) { + validateRequiredLabels(client, source, sourceLabels) + }) + + }) +} diff --git a/test/conformance/main_test.go b/test/conformance/main_test.go index fcb1780afb9..ee6f100f53f 100644 --- a/test/conformance/main_test.go +++ b/test/conformance/main_test.go @@ -27,6 +27,7 @@ import ( ) var channelTestRunner testlib.ComponentsTestRunner +var sourcesTestRunner testlib.ComponentsTestRunner var brokerClass string func TestMain(m *testing.M) { @@ -36,6 +37,9 @@ func TestMain(m *testing.M) { ComponentFeatureMap: testlib.ChannelFeatureMap, ComponentsToTest: test.EventingFlags.Channels, } + sourcesTestRunner = testlib.ComponentsTestRunner{ + ComponentsToTest: test.EventingFlags.Sources, + } brokerClass = test.EventingFlags.BrokerClass // Any tests may SetupZipkinTracing, it will only actually be done once. This should be the ONLY diff --git a/test/conformance/source_crd_metadata_test.go b/test/conformance/source_crd_metadata_test.go new file mode 100644 index 00000000000..871baa37339 --- /dev/null +++ b/test/conformance/source_crd_metadata_test.go @@ -0,0 +1,28 @@ +/* +Copyright 2020 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + 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 conformance + +import ( + "testing" + + "knative.dev/eventing/test/conformance/helpers" + testlib "knative.dev/eventing/test/lib" +) + +func TestSourceCRDMetadata(t *testing.T) { + helpers.SourceCRDMetadataTestHelperWithChannelTestRunner(t, sourcesTestRunner, testlib.SetupClientOptionNoop) +} diff --git a/test/flags/sources.go b/test/flags/sources.go index 633b7a6ba38..cc3e016b4db 100644 --- a/test/flags/sources.go +++ b/test/flags/sources.go @@ -1,3 +1,19 @@ +/* +Copyright 2020 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + 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 flags import ( @@ -15,7 +31,7 @@ func (sources *Sources) String() string { return fmt.Sprint(*sources) } -// Set converts the input string to Sources. +// Set appends the input string to Sources. func (sources *Sources) Set(value string) error { for _, source := range strings.Split(value, ",") { source := strings.TrimSpace(source) @@ -28,7 +44,7 @@ func (sources *Sources) Set(value string) error { Kind: split[1], } if !isValidSource(tm.Kind) { - log.Fatalf("The given source name %q is invalid, tests cannot be run.\n", source) + log.Fatalf("The given Source name %q is invalid, tests cannot be run.\n", source) } *sources = append(*sources, tm) From 13b41c9c9697e47a36510d9f2c30e8d8ed1d259f Mon Sep 17 00:00:00 2001 From: Ahmed Abdalla Date: Mon, 22 Jun 2020 14:32:02 +0200 Subject: [PATCH 3/7] Extract e2e test flags parsing of objects --- test/e2e_flags.go | 2 +- test/flags/channels.go | 20 +++--------------- test/flags/parsing.go | 47 ++++++++++++++++++++++++++++++++++++++++++ test/flags/sources.go | 18 +--------------- 4 files changed, 52 insertions(+), 35 deletions(-) create mode 100644 test/flags/parsing.go diff --git a/test/e2e_flags.go b/test/e2e_flags.go index 83ac9440d66..af7b552ffae 100644 --- a/test/e2e_flags.go +++ b/test/e2e_flags.go @@ -35,7 +35,7 @@ const ( BrokerUsage = "Which brokerclass to test, requires the proper Broker " + "implementation to have been installed, and only one value. brokerclass " + "must be (for now) 'MTChannelBasedBroker'." - SourceUsage = "The names of the source type metas, separated by comma. " + + SourceUsage = "The names of the source type metas, separated by comma. " + "Example: \"sources.knative.dev/v1alpha1:ApiServerSource," + "sources.knative.dev/v1alpha1:PingSource\"." ) diff --git a/test/flags/channels.go b/test/flags/channels.go index d4ff2cc22b5..45abe33620b 100644 --- a/test/flags/channels.go +++ b/test/flags/channels.go @@ -18,7 +18,6 @@ package flags import ( "fmt" - "log" "strings" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,28 +26,15 @@ import ( // Channels holds the Channels we want to run test against. type Channels []metav1.TypeMeta +var objs []metav1.TypeMeta + func (channels *Channels) String() string { return fmt.Sprint(*channels) } // Set appends the input string to Channels. func (channels *Channels) Set(value string) error { - for _, channel := range strings.Split(value, ",") { - channel := strings.TrimSpace(channel) - split := strings.Split(channel, ":") - if len(split) != 2 { - log.Fatalf("The given Channel name %q is invalid, it needs to be in the form \"apiVersion:Kind\".", channel) - } - tm := metav1.TypeMeta{ - APIVersion: split[0], - Kind: split[1], - } - if !isValidChannel(tm.Kind) { - log.Fatalf("The given Channel name %q is invalid, tests cannot be run.\n", channel) - } - - *channels = append(*channels, tm) - } + *channels = csvToObjects(value, isValidChannel) return nil } diff --git a/test/flags/parsing.go b/test/flags/parsing.go new file mode 100644 index 00000000000..6fba018767a --- /dev/null +++ b/test/flags/parsing.go @@ -0,0 +1,47 @@ +/* +Copyright 2020 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + 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 flags + +import ( + "log" + "strings" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type Validator func(string) bool + +func csvToObjects(csvObjects string, validator Validator) []metav1.TypeMeta { + result := make([]metav1.TypeMeta, 0, 5) + for _, object := range strings.Split(csvObjects, ",") { + object := strings.TrimSpace(object) + split := strings.Split(object, ":") + if len(split) != 2 { + log.Fatalf("The given object name %q is invalid, it needs to be in the form \"apiVersion:Kind\".", object) + } + tm := metav1.TypeMeta{ + APIVersion: split[0], + Kind: split[1], + } + if !validator(tm.Kind) { + log.Fatalf("The given object name %q is invalid, tests cannot be run.\n", object) + } + + result = append(result, tm) + } + return result +} diff --git a/test/flags/sources.go b/test/flags/sources.go index cc3e016b4db..00473d79330 100644 --- a/test/flags/sources.go +++ b/test/flags/sources.go @@ -18,7 +18,6 @@ package flags import ( "fmt" - "log" "strings" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -33,22 +32,7 @@ func (sources *Sources) String() string { // Set appends the input string to Sources. func (sources *Sources) Set(value string) error { - for _, source := range strings.Split(value, ",") { - source := strings.TrimSpace(source) - split := strings.Split(source, ":") - if len(split) != 2 { - log.Fatalf("The given Source name %q is invalid, it needs to be in the form \"apiVersion:Kind\".", source) - } - tm := metav1.TypeMeta{ - APIVersion: split[0], - Kind: split[1], - } - if !isValidSource(tm.Kind) { - log.Fatalf("The given Source name %q is invalid, tests cannot be run.\n", source) - } - - *sources = append(*sources, tm) - } + *sources = csvToObjects(value, isValidSource) return nil } From 4f88bff37611c2348fd8634ec8f60ccd29a86574 Mon Sep 17 00:00:00 2001 From: Ahmed Abdalla Date: Mon, 22 Jun 2020 14:41:14 +0200 Subject: [PATCH 4/7] Run sources conformance tests by default in e2e-test runner --- test/e2e-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e-tests.sh b/test/e2e-tests.sh index adb66e808ff..3b377ac9c4b 100755 --- a/test/e2e-tests.sh +++ b/test/e2e-tests.sh @@ -35,6 +35,6 @@ initialize $@ --skip-istio-addon install_mt_broker || fail_test "Could not install MT Channel Based Broker" echo "Running tests with Multi Tenant Channel Based Broker" -go_test_e2e -timeout=20m -parallel=12 ./test/e2e ./test/conformance -brokerclass=MTChannelBasedBroker -channels=messaging.knative.dev/v1beta1:Channel,messaging.knative.dev/v1beta1:InMemoryChannel || fail_test +go_test_e2e -timeout=20m -parallel=12 ./test/e2e ./test/conformance -brokerclass=MTChannelBasedBroker -channels=messaging.knative.dev/v1beta1:Channel,messaging.knative.dev/v1beta1:InMemoryChannel -sources=sources.knative.dev/v1alpha2:ApiServerSource,sources.knative.dev/v1alpha2:ContainerSource,sources.knative.dev/v1alpha2:PingSource || fail_test success From c9124171eb6f01e5c108266546d6b91accd09ea5 Mon Sep 17 00:00:00 2001 From: Ahmed Abdalla Date: Mon, 22 Jun 2020 14:43:02 +0200 Subject: [PATCH 5/7] Remove leftover var in test flags package --- test/flags/channels.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/flags/channels.go b/test/flags/channels.go index 45abe33620b..ae5af45c22c 100644 --- a/test/flags/channels.go +++ b/test/flags/channels.go @@ -26,8 +26,6 @@ import ( // Channels holds the Channels we want to run test against. type Channels []metav1.TypeMeta -var objs []metav1.TypeMeta - func (channels *Channels) String() string { return fmt.Sprint(*channels) } From 16fcdcd49dbffda3c239d1c7aa6481e1c4fc15dc Mon Sep 17 00:00:00 2001 From: Ahmed Abdalla Date: Mon, 22 Jun 2020 14:44:26 +0200 Subject: [PATCH 6/7] Fix flags function comments --- test/flags/channels.go | 2 +- test/flags/sources.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/flags/channels.go b/test/flags/channels.go index ae5af45c22c..3cb7a2928f5 100644 --- a/test/flags/channels.go +++ b/test/flags/channels.go @@ -36,7 +36,7 @@ func (channels *Channels) Set(value string) error { return nil } -// Check if the channel name is valid. +// Check if the channel kind is valid. func isValidChannel(channel string) bool { return strings.HasSuffix(channel, "Channel") } diff --git a/test/flags/sources.go b/test/flags/sources.go index 00473d79330..44c4fb0d7dc 100644 --- a/test/flags/sources.go +++ b/test/flags/sources.go @@ -36,7 +36,7 @@ func (sources *Sources) Set(value string) error { return nil } -// Check if the Source name is valid. +// Check if the Source kind is valid. func isValidSource(source string) bool { return strings.HasSuffix(source, "Source") } From 59e589115cf668cdf44bf567e76afb7b955712ed Mon Sep 17 00:00:00 2001 From: Ahmed Abdalla Date: Mon, 22 Jun 2020 15:07:28 +0200 Subject: [PATCH 7/7] Fix a typo --- test/flags/sources.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/flags/sources.go b/test/flags/sources.go index 44c4fb0d7dc..9add5e7b8ce 100644 --- a/test/flags/sources.go +++ b/test/flags/sources.go @@ -23,7 +23,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// Sources holds the Sourcess we want to run test against. +// Sources holds the Sources we want to run test against. type Sources []metav1.TypeMeta func (sources *Sources) String() string {