From 68b334d02bf7da8ef72a55741de3b4428c4fbb2d Mon Sep 17 00:00:00 2001 From: Nabarun Pal Date: Tue, 1 Jun 2021 17:15:18 +0530 Subject: [PATCH] test: setup embedded file sources for manifests Signed-off-by: Nabarun Pal --- test/conformance/testdata/embed.go | 33 ++++++++++++++++++++++++ test/e2e/e2e_test.go | 10 +++++++ test/e2e/testing-manifests/embed.go | 33 ++++++++++++++++++++++++ test/e2e_node/e2e_node_suite_test.go | 18 ++++++++----- test/e2e_node/testing-manifests/embed.go | 33 ++++++++++++++++++++++++ test/fixtures/embed.go | 33 ++++++++++++++++++++++++ 6 files changed, 153 insertions(+), 7 deletions(-) create mode 100644 test/conformance/testdata/embed.go create mode 100644 test/e2e/testing-manifests/embed.go create mode 100644 test/e2e_node/testing-manifests/embed.go create mode 100644 test/fixtures/embed.go diff --git a/test/conformance/testdata/embed.go b/test/conformance/testdata/embed.go new file mode 100644 index 00000000000..7a595650188 --- /dev/null +++ b/test/conformance/testdata/embed.go @@ -0,0 +1,33 @@ +/* +Copyright 2021 The Kubernetes 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 testdata + +import ( + "embed" + + "k8s.io/kubernetes/test/e2e/framework/testfiles" +) + +//go:embed conformance.yaml ineligible_endpoints.yaml +var conformanceTestdataFS embed.FS + +func GetConformanceTestdataFS() testfiles.EmbeddedFileSource { + return testfiles.EmbeddedFileSource{ + EmbeddedFS: conformanceTestdataFS, + Root: "test/conformance/testdata", + } +} diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index ae7146c47a0..88cc6f58c63 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -33,10 +33,13 @@ import ( // "github.com/onsi/ginkgo" "k8s.io/component-base/version" + conformancetestdata "k8s.io/kubernetes/test/conformance/testdata" "k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework/config" "k8s.io/kubernetes/test/e2e/framework/testfiles" "k8s.io/kubernetes/test/e2e/generated" + e2etestingmanifests "k8s.io/kubernetes/test/e2e/testing-manifests" + testfixtures "k8s.io/kubernetes/test/fixtures" "k8s.io/kubernetes/test/utils/image" // test sources @@ -86,10 +89,17 @@ func TestMain(m *testing.M) { } // Enable bindata file lookup as fallback. + // TODO: To be removed once all data sources have been moved to embeds. testfiles.AddFileSource(testfiles.BindataFileSource{ Asset: generated.Asset, AssetNames: generated.AssetNames, }) + + // Enable embedded FS file lookup as fallback + testfiles.AddFileSource(e2etestingmanifests.GetE2ETestingManifestsFS()) + testfiles.AddFileSource(testfixtures.GetTestFixturesFS()) + testfiles.AddFileSource(conformancetestdata.GetConformanceTestdataFS()) + if framework.TestContext.ListConformanceTests { var tests []struct { Testname string `yaml:"testname"` diff --git a/test/e2e/testing-manifests/embed.go b/test/e2e/testing-manifests/embed.go new file mode 100644 index 00000000000..1b91b46aa51 --- /dev/null +++ b/test/e2e/testing-manifests/embed.go @@ -0,0 +1,33 @@ +/* +Copyright 2021 The Kubernetes 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_manifests + +import ( + "embed" + + e2etestfiles "k8s.io/kubernetes/test/e2e/framework/testfiles" +) + +//go:embed flexvolume guestbook kubectl sample-device-plugin.yaml scheduling/nvidia-driver-installer.yaml statefulset storage-csi +var e2eTestingManifestsFS embed.FS + +func GetE2ETestingManifestsFS() e2etestfiles.EmbeddedFileSource { + return e2etestfiles.EmbeddedFileSource{ + EmbeddedFS: e2eTestingManifestsFS, + Root: "test/e2e/testing-manifests", + } +} diff --git a/test/e2e_node/e2e_node_suite_test.go b/test/e2e_node/e2e_node_suite_test.go index 5206167129c..0a9b30b1a24 100644 --- a/test/e2e_node/e2e_node_suite_test.go +++ b/test/e2e_node/e2e_node_suite_test.go @@ -44,8 +44,11 @@ import ( "k8s.io/kubernetes/test/e2e/framework" e2econfig "k8s.io/kubernetes/test/e2e/framework/config" e2etestfiles "k8s.io/kubernetes/test/e2e/framework/testfiles" - "k8s.io/kubernetes/test/e2e/generated" + e2etestingmanifests "k8s.io/kubernetes/test/e2e/testing-manifests" "k8s.io/kubernetes/test/e2e_node/services" + e2enodetestingmanifests "k8s.io/kubernetes/test/e2e_node/testing-manifests" + testfixtures "k8s.io/kubernetes/test/fixtures" + testimages "k8s.io/kubernetes/test/images" system "k8s.io/system-validators/validators" "github.com/onsi/ginkgo" @@ -90,12 +93,13 @@ func registerNodeFlags(flags *flag.FlagSet) { } func init() { - // Enable bindata file lookup as fallback. - e2etestfiles.AddFileSource(e2etestfiles.BindataFileSource{ - Asset: generated.Asset, - AssetNames: generated.AssetNames, - }) - + // Enable embedded FS file lookup as fallback + // TODO: This needs to be cleaned up later to include only file sources which are necessary. + e2etestfiles.AddFileSource(e2etestingmanifests.GetE2ETestingManifestsFS()) + e2etestfiles.AddFileSource(e2enodetestingmanifests.GetE2ENodeTestingManifestsFS()) + e2etestfiles.AddFileSource(testimages.GetTestImagesFS()) + e2etestfiles.AddFileSource(testfixtures.GetTestFixturesFS()) + e2etestfiles.AddFileSource(conformancetestdata.GetConformanceTestdataFS()) } func TestMain(m *testing.M) { diff --git a/test/e2e_node/testing-manifests/embed.go b/test/e2e_node/testing-manifests/embed.go new file mode 100644 index 00000000000..a0721e8ce27 --- /dev/null +++ b/test/e2e_node/testing-manifests/embed.go @@ -0,0 +1,33 @@ +/* +Copyright 2021 The Kubernetes 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_manifests + +import ( + "embed" + + e2etestfiles "k8s.io/kubernetes/test/e2e/framework/testfiles" +) + +//go:embed *.yaml +var e2eNodeTestingManifestsFS embed.FS + +func GetE2ENodeTestingManifestsFS() e2etestfiles.EmbeddedFileSource { + return e2etestfiles.EmbeddedFileSource{ + EmbeddedFS: e2eNodeTestingManifestsFS, + Root: "test/e2e_node/testing-manifests", + } +} diff --git a/test/fixtures/embed.go b/test/fixtures/embed.go new file mode 100644 index 00000000000..78fa5d100f0 --- /dev/null +++ b/test/fixtures/embed.go @@ -0,0 +1,33 @@ +/* +Copyright 2021 The Kubernetes 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 fixtures + +import ( + "embed" + + "k8s.io/kubernetes/test/e2e/framework/testfiles" +) + +//go:embed doc-yaml/user-guide/liveness doc-yaml/user-guide/secrets doc-yaml/user-guide/downward-api doc-yaml/user-guide/update-demo +var testFixturesFS embed.FS + +func GetTestFixturesFS() testfiles.EmbeddedFileSource { + return testfiles.EmbeddedFileSource{ + EmbeddedFS: testFixturesFS, + Root: "test/fixtures", + } +}