Skip to content

Commit

Permalink
test: setup embedded file sources for manifests
Browse files Browse the repository at this point in the history
Signed-off-by: Nabarun Pal <[email protected]>
  • Loading branch information
palnabarun committed Jun 29, 2021
1 parent 3af6329 commit 68b334d
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 7 deletions.
33 changes: 33 additions & 0 deletions test/conformance/testdata/embed.go
Original file line number Diff line number Diff line change
@@ -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",
}
}
10 changes: 10 additions & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"`
Expand Down
33 changes: 33 additions & 0 deletions test/e2e/testing-manifests/embed.go
Original file line number Diff line number Diff line change
@@ -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",
}
}
18 changes: 11 additions & 7 deletions test/e2e_node/e2e_node_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
33 changes: 33 additions & 0 deletions test/e2e_node/testing-manifests/embed.go
Original file line number Diff line number Diff line change
@@ -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",
}
}
33 changes: 33 additions & 0 deletions test/fixtures/embed.go
Original file line number Diff line number Diff line change
@@ -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",
}
}

0 comments on commit 68b334d

Please sign in to comment.