Skip to content

Commit

Permalink
Merge pull request #4761 from randomvariable/remove-kubetest-viper
Browse files Browse the repository at this point in the history
🌱 kubetest: Remove usage of Viper, converting config files to kubetest arguments
  • Loading branch information
k8s-ci-robot authored Jun 8, 2021
2 parents 2c7a4f3 + 8445e16 commit 19d791f
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 @@ -19,6 +19,7 @@ package kubetest

import (
"context"
"fmt"
"os"
"os/exec"
"os/user"
Expand All @@ -32,6 +33,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 @@ -111,12 +113,11 @@ func Run(ctx context.Context, 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 @@ -138,7 +139,6 @@ func Run(ctx context.Context, 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 @@ -147,15 +147,14 @@ func Run(ctx context.Context, 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"
networkArg := "--network=kind"
e2eCmd := exec.Command("docker", "run", "--user", userArg, entrypointArg, kubeConfigVolumeMount, outputVolumeMount, viperVolumeMount, "-t", networkArg)
e2eCmd := exec.Command("docker", "run", "--user", userArg, entrypointArg, kubeConfigVolumeMount, outputVolumeMount, "-t", networkArg)
if len(testRepoListVolumeArgs) > 0 {
e2eCmd.Args = append(e2eCmd.Args, testRepoListVolumeArgs...)
}
Expand All @@ -164,13 +163,32 @@ func Run(ctx context.Context, 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")
}
return framework.GatherJUnitReports(reportDir, input.ArtifactsDirectory)
}

type kubetestConfig map[string]string

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

func parseKubetestConfig(kubetestConfigFile string) (kubetestConfig, error) {
conf := make(kubetestConfig)
data, err := os.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 19d791f

Please sign in to comment.