Skip to content

Commit

Permalink
kubetest: Remove usage of Viper, converting config files
Browse files Browse the repository at this point in the history
to kubetest arguments

Signed-off-by: Naadir Jeewa <[email protected]>
  • Loading branch information
Naadir Jeewa committed Jun 8, 2021
1 parent e203a3d commit 091b709
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions test/framework/kubetest/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package kubetest

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
Expand All @@ -31,6 +32,7 @@ import (
"k8s.io/client-go/discovery"
"k8s.io/client-go/tools/clientcmd"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/yaml"
)

const (
Expand Down Expand Up @@ -109,12 +111,11 @@ func Run(input RunInput) error {
"slowSpecThreshold": strconv.Itoa(input.GinkgoSlowSpecThreshold),
}

// Copy configuration files for kubetest into the artifacts directory
// to avoid issues with volume mounts on MacOS
tmpConfigFilePath := path.Join(kubetestConfigDir, "viper-config.yaml")
if err := copyFile(input.ConfigFilePath, tmpConfigFilePath); err != nil {
config, err := parseKubetestConfig(input.ConfigFilePath)
if err != nil {
return err
}

tmpKubeConfigPath, err := dockeriseKubeconfig(kubetestConfigDir, input.ClusterProxy.GetKubeconfigPath())
if err != nil {
return err
Expand All @@ -136,7 +137,6 @@ func Run(input RunInput) error {
"dump-logs-on-failure": "false",
"report-prefix": "kubetest.",
"num-nodes": strconv.FormatInt(int64(input.NumberOfNodes), 10),
"viper-config": "/tmp/viper-config.yaml",
}
ginkgoArgs := buildArgs(ginkgoVars, "-")
e2eArgs := buildArgs(e2eVars, "--")
Expand All @@ -145,14 +145,13 @@ func Run(input RunInput) error {
}
kubeConfigVolumeMount := volumeArg(tmpKubeConfigPath, "/tmp/kubeconfig")
outputVolumeMount := volumeArg(reportDir, "/output")
viperVolumeMount := volumeArg(tmpConfigFilePath, "/tmp/viper-config.yaml")
user, err := user.Current()
if err != nil {
return errors.Wrap(err, "unable to determine current user")
}
userArg := user.Uid + ":" + user.Gid
entrypointArg := "--entrypoint=/usr/local/bin/ginkgo"
e2eCmd := exec.Command("docker", "run", "--user", userArg, entrypointArg, kubeConfigVolumeMount, outputVolumeMount, viperVolumeMount, "-t")
e2eCmd := exec.Command("docker", "run", "--user", userArg, entrypointArg, kubeConfigVolumeMount, outputVolumeMount, "-t")
if len(testRepoListVolumeArgs) > 0 {
e2eCmd.Args = append(e2eCmd.Args, testRepoListVolumeArgs...)
}
Expand All @@ -161,6 +160,7 @@ func Run(input RunInput) error {
e2eCmd.Args = append(e2eCmd.Args, "/usr/local/bin/e2e.test")
e2eCmd.Args = append(e2eCmd.Args, "--")
e2eCmd.Args = append(e2eCmd.Args, e2eArgs...)
e2eCmd.Args = append(e2eCmd.Args, config.toFlags()...)
e2eCmd = framework.CompleteCommand(e2eCmd, "Running e2e test", false)
if err := e2eCmd.Run(); err != nil {
return errors.Wrap(err, "Unable to run conformance tests")
Expand All @@ -171,6 +171,24 @@ func Run(input RunInput) error {
return nil
}

type kubetestConfig map[string]string

func (c kubetestConfig) toFlags() []string {
return buildArgs(c, "-")
}

func parseKubetestConfig(kubetestConfigFile string) (kubetestConfig, error) {
conf := make(kubetestConfig)
data, err := ioutil.ReadFile(kubetestConfigFile)
if err != nil {
return nil, fmt.Errorf("unable to read kubetest config file %s: %w", kubetestConfigFile, err)
}
if err := yaml.Unmarshal(data, conf); err != nil {
return nil, fmt.Errorf("unable to parse kubetest config file %s as valid, non-nested YAML: %w", kubetestConfigFile, err)
}
return conf, nil
}

func isUsingCIArtifactsVersion(k8sVersion string) bool {
return strings.Contains(k8sVersion, "-")
}
Expand Down

0 comments on commit 091b709

Please sign in to comment.