Skip to content

Commit

Permalink
Merge pull request #53 from amwat/cl2
Browse files Browse the repository at this point in the history
[Clusterloader2] Implement a clusterloader2 tester
  • Loading branch information
k8s-ci-robot authored Sep 24, 2020
2 parents e0ffa6a + f4b5e39 commit 6e6ad4b
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 2 deletions.
15 changes: 13 additions & 2 deletions kubetest2-kind/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ type deployer struct {
verbosity int // --verbosity for kind
}

func (d *deployer) Kubeconfig() (string, error) {
if d.kubeconfigPath != "" {
return d.kubeconfigPath, nil
}
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
return filepath.Join(home, ".kube", "config"), nil
}

// helper used to create & bind a flagset to the deployer
func bindFlags(d *deployer) *pflag.FlagSet {
flags := pflag.NewFlagSet(Name, pflag.ContinueOnError)
Expand Down Expand Up @@ -90,8 +101,8 @@ func bindFlags(d *deployer) *pflag.FlagSet {
return flags
}

// assert that deployer implements types.Deployer
var _ types.Deployer = &deployer{}
// assert that deployer implements types.DeployerWithKubeconfig
var _ types.DeployerWithKubeconfig = &deployer{}

// Deployer implementation methods below

Expand Down
25 changes: 25 additions & 0 deletions kubetest2-tester-clusterloader2/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright 2020 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 main

import (
"sigs.k8s.io/kubetest2/pkg/testers/clusterloader2"
)

func main() {
clusterloader2.Main()
}
114 changes: 114 additions & 0 deletions pkg/testers/clusterloader2/cl2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package clusterloader2

import (
"flag"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/octago/sflags/gen/gpflag"
"k8s.io/klog"

"sigs.k8s.io/kubetest2/pkg/exec"
suite "sigs.k8s.io/kubetest2/pkg/testers/clusterloader2/suite"
)

type Tester struct {
Suites string `desc:"Comma separated list of standard scale testing suites e.g. load, density"`
TestOverrides string `desc:"Comma separated list of paths to the config override files. The latter overrides take precedence over changes in former files."`
TestConfigs string `desc:"Comma separated list of paths to test config files."`
Provider string `desc:"The type of cluster provider used (e.g gke, gce, skeleton)"`
KubeConfig string `desc:"Path to kubeconfig. If specified will override the path exposed by the kubetest2 deployer."`
RepoRoot string `desc:"Path to repository root of kubernetes/perf-tests"`
Nodes int `desc:"Number of nodes in the cluster. 0 will auto-detect schedulable nodes."`
}

func NewDefaultTester() *Tester {
return &Tester{
// TODO(amwat): pass kubetest2 deployer info here if possible
Provider: "skeleton",
KubeConfig: os.Getenv("KUBECONFIG"),
}
}

// Test runs the test
func (t *Tester) Test() error {
if t.RepoRoot == "" {
return fmt.Errorf("required path to kubernetes/perf-tests repository")
}

var testConfigs, testOverrides []string
testConfigs = append(testConfigs, strings.Split(t.TestConfigs, ",")...)
testOverrides = append(testOverrides, strings.Split(t.TestOverrides, ",")...)

sweets := strings.Split(t.Suites, ",")
for _, sweet := range sweets {
if s := suite.GetSuite(sweet); s != nil {
if s.TestConfigs != nil && len(s.TestConfigs) > 0 {
testConfigs = append(testConfigs, s.TestConfigs...)
}
if s.TestOverrides != nil && len(s.TestOverrides) > 0 {
testOverrides = append(testOverrides, s.TestOverrides...)
}
}
}

cmdArgs := []string{
"run",
"cmd/clusterloader.go",
}

args := []string{
"--provider=" + t.Provider,
"--kubeconfig=" + t.KubeConfig,
"--report-dir=" + filepath.Join(os.Getenv("ARTIFACTS"), "clusterloader2"),
}
for _, tc := range testConfigs {
if tc != "" {
args = append(args, "--testconfig="+tc)
}
}
for _, to := range testOverrides {
if to != "" {
args = append(args, "--testoverrides="+to)
}
}

// TODO(amwat): get prebuilt binaries
cmd := exec.Command("go", append(cmdArgs, args...)...)
exec.InheritOutput(cmd)
cmd.SetDir(filepath.Join(t.RepoRoot, "clusterloader2"))
klog.V(2).Infof("running clusterloader2 %s", args)
return cmd.Run()
}

func (t *Tester) Execute() error {
fs, err := gpflag.Parse(t)
if err != nil {
return fmt.Errorf("failed to initialize tester: %v", err)
}

klog.InitFlags(nil)
fs.AddGoFlagSet(flag.CommandLine)

help := fs.BoolP("help", "h", false, "")
if err := fs.Parse(os.Args); err != nil {
return fmt.Errorf("failed to parse flags: %v", err)
}

if *help {
fs.SetOutput(os.Stdout)
fs.PrintDefaults()
return nil
}

return t.Test()
}

func Main() {
t := NewDefaultTester()
if err := t.Execute(); err != nil {
klog.Fatalf("failed to run clusterloader2 tester: %v", err)
}
}
36 changes: 36 additions & 0 deletions pkg/testers/clusterloader2/suite/suite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package suite

type Suite struct {
TestConfigs []string
TestOverrides []string
}

// GetSuite returns the default configurations for well-known testing setups.
func GetSuite(suite string) *Suite {
const (
load = "load"
density = "density"
nodeThroughput = "node-throughput"
)

var supportedSuites = map[string]*Suite{
load: {
TestConfigs: []string{
"testing/load/config.yaml",
},
},

density: {
TestConfigs: []string{
"testing/density/config.yaml",
},
},

nodeThroughput: {
TestConfigs: []string{
"testing/node-throughput/config.yaml",
},
},
}
return supportedSuites[suite]
}

0 comments on commit 6e6ad4b

Please sign in to comment.