From f1deb0ba2e212212dc847ccf744ef1b6b0b1dd1c Mon Sep 17 00:00:00 2001 From: Danielle Lancashire Date: Thu, 7 Oct 2021 13:20:35 +0200 Subject: [PATCH] e2e_node: remote: add kubeletconfig to archive This commit enables the remote runner to provide a KubeletConfiguration file to the test suite when uploading it to a remote host, thet test runner will then use this configuration to run the Kubelet with the provided config. --- test/e2e_node/remote/remote.go | 43 ++++++++++++++++++++++- test/e2e_node/runner/remote/run_remote.go | 3 +- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/test/e2e_node/remote/remote.go b/test/e2e_node/remote/remote.go index fd2f509eeea..86bafbd14a7 100644 --- a/test/e2e_node/remote/remote.go +++ b/test/e2e_node/remote/remote.go @@ -19,6 +19,7 @@ package remote import ( "flag" "fmt" + "io" "io/ioutil" "os" "os/exec" @@ -36,8 +37,43 @@ var resultsDir = flag.String("results-dir", "/tmp/", "Directory to scp test resu const archiveName = "e2e_node_test.tar.gz" +func copyKubeletConfigIfExists(kubeletConfigFile, dstDir string) error { + srcStat, err := os.Stat(kubeletConfigFile) + if err != nil { + if os.IsNotExist(err) { + return nil + } else { + return err + } + } + + if !srcStat.Mode().IsRegular() { + return fmt.Errorf("%s is not a regular file", kubeletConfigFile) + } + + source, err := os.Open(kubeletConfigFile) + if err != nil { + return err + } + defer source.Close() + + dst := filepath.Join(dstDir, "kubeletconfig.yaml") + destination, err := os.Create(dst) + if err != nil { + return err + } + defer destination.Close() + + _, err = io.Copy(destination, source) + if err != nil { + return err + } + + return os.Chmod(dst, 0x644) +} + // CreateTestArchive creates the archive package for the node e2e test. -func CreateTestArchive(suite TestSuite, systemSpecName string) (string, error) { +func CreateTestArchive(suite TestSuite, systemSpecName, kubeletConfigFile string) (string, error) { klog.V(2).Infof("Building archive...") tardir, err := ioutil.TempDir("", "node-e2e-archive") if err != nil { @@ -45,6 +81,11 @@ func CreateTestArchive(suite TestSuite, systemSpecName string) (string, error) { } defer os.RemoveAll(tardir) + err = copyKubeletConfigIfExists(kubeletConfigFile, tardir) + if err != nil { + return "", fmt.Errorf("failed to copy kubelet config: %v", err) + } + // Call the suite function to setup the test package. err = suite.SetupTestPackage(tardir, systemSpecName) if err != nil { diff --git a/test/e2e_node/runner/remote/run_remote.go b/test/e2e_node/runner/remote/run_remote.go index c5ac93c651a..b13e0c18589 100644 --- a/test/e2e_node/runner/remote/run_remote.go +++ b/test/e2e_node/runner/remote/run_remote.go @@ -69,6 +69,7 @@ var ginkgoFlags = flag.String("ginkgo-flags", "", "Passed to ginkgo to specify a var systemSpecName = flag.String("system-spec-name", "", fmt.Sprintf("The name of the system spec used for validating the image in the node conformance test. The specs are at %s. If unspecified, the default built-in spec (system.DefaultSpec) will be used.", system.SystemSpecPath)) var extraEnvs = flag.String("extra-envs", "", "The extra environment variables needed for node e2e tests. Format: a list of key=value pairs, e.g., env1=val1,env2=val2") var runtimeConfig = flag.String("runtime-config", "", "The runtime configuration for the API server on the node e2e tests.. Format: a list of key=value pairs, e.g., env1=val1,env2=val2") +var kubeletConfigFile = flag.String("kubelet-config-file", "", "The KubeletConfiguration file that should be applied to the kubelet") // envs is the type used to collect all node envs. The key is the env name, // and the value is the env value @@ -218,7 +219,7 @@ func main() { rand.Seed(time.Now().UnixNano()) if *buildOnly { // Build the archive and exit - remote.CreateTestArchive(suite, *systemSpecName) + remote.CreateTestArchive(suite, *systemSpecName, *kubeletConfigFile) return }