Skip to content

Commit

Permalink
clusterloader: enhance namespace configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanchen8911 committed Apr 20, 2020
1 parent d9bdf46 commit 3a19456
Show file tree
Hide file tree
Showing 18 changed files with 175 additions and 31 deletions.
53 changes: 53 additions & 0 deletions clusterloader2/api/default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2018 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 api

import (
"fmt"
"k8s.io/perf-tests/clusterloader2/pkg/util"
)

// SetDefaults set the default configuration parameters.
func (conf *Config) SetDefaults() {
conf.Namespace.SetDefaults()

// TODO: remove after deprecated automanagedNamespaces is disabled.
if conf.Namespace.Number == 1 && conf.AutomanagedNamespaces > 1 {
conf.Namespace.Number = conf.AutomanagedNamespaces
}
}

// SetDefaults specifies the default values for namespace parameters.
func (ns *NamespaceConfig) SetDefaults() {
if ns.Number == 0 {
ns.Number = 1
}

if ns.Prefix == "" {
ns.Prefix = fmt.Sprintf("test-%s", util.RandomDNS1123String(6))
}

defaultDeleteStaleNS := false
if ns.DeleteStaleNamespaces == nil {
ns.DeleteStaleNamespaces = &defaultDeleteStaleNS
}

defaultDeleteAutoNS := true
if ns.DeleteAutomanagedNamespaces == nil {
ns.DeleteAutomanagedNamespaces = &defaultDeleteAutoNS
}
}
20 changes: 18 additions & 2 deletions clusterloader2/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ type TestScenario struct {
type Config struct {
// Name of the test case.
Name string `json: name`
// AutomanagedNamespaces is a number of automanaged namespaces.
AutomanagedNamespaces int32 `json: automanagedNamespaces`
// Deprecated: a number of automanaged namespaces.
// Use Namespace.Number instead.
AutomanagedNamespaces int32 `json: automanagedNamespaces,omitempty`
// Namespace is a structure for namespace configuration.
Namespace NamespaceConfig `json: namespace`
// Steps is a sequence of test steps executed in serial.
Steps []Step `json: steps`
// TuningSets is a collection of tuning sets that can be used by steps.
Expand Down Expand Up @@ -106,6 +109,19 @@ type ListUnknownObjectOptions struct {
LabelSelector *metav1.LabelSelector `json: labelSelector`
}

// NamespaceConfig defines namespace parameters.
type NamespaceConfig struct {
// Number is a number of automanaged namespaces.
Number int32 `json: number,omitempty`
// NamePrefix is the name prefix of automanaged namespaces.
// It's optional, if set CL will use it, otherwise generate one with random string.
Prefix string `json: prefix,omitempty`
// DeleteStaleNamespaces specifies whether or not delete stale namepaces
DeleteStaleNamespaces *bool `json: deleteStaleNamespaces,omitempty`
// DeleteAutomanangedNamespaces specifies whether or not delete namepaces after a test
DeleteAutomanagedNamespaces *bool `json: deleteAutomanagedNamespaces,omitempty`
}

// NamespaceRange specifies the range of namespaces [Min, Max].
type NamespaceRange struct {
// Min is the lower index of namespace range.
Expand Down
41 changes: 41 additions & 0 deletions clusterloader2/api/validation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright 2018 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 api

import (
"fmt"
"k8s.io/perf-tests/clusterloader2/pkg/errors"
)

// Validate checks and verifies the configuration parameters.
func (conf *Config) Validate() *errors.ErrorList {
return conf.Namespace.Validate()
}

// Validate checks and verifies the namespace parameters.
func (ns *NamespaceConfig) Validate() *errors.ErrorList {
errList := errors.NewErrorList()
if ns.Number <= 0 {
errList.Append(fmt.Errorf("number of namespaces: %d was less than 1", ns.Number))
}

if errList.IsEmpty() {
return nil
}

return errList
}
6 changes: 4 additions & 2 deletions clusterloader2/cmd/clusterloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ func initClusterFlags() {
flags.StringEnvVar(&clusterLoaderConfig.ClusterConfig.EtcdCertificatePath, "etcd-certificate", "ETCD_CERTIFICATE", "/etc/srv/kubernetes/pki/etcd-apiserver-server.crt", "Path to the etcd certificate on the master machine")
flags.StringEnvVar(&clusterLoaderConfig.ClusterConfig.EtcdKeyPath, "etcd-key", "ETCD_KEY", "/etc/srv/kubernetes/pki/etcd-apiserver-server.key", "Path to the etcd key on the master machine")
flags.IntEnvVar(&clusterLoaderConfig.ClusterConfig.EtcdInsecurePort, "etcd-insecure-port", "ETCD_INSECURE_PORT", 2382, "Inscure http port")
flags.BoolEnvVar(&clusterLoaderConfig.ClusterConfig.DeleteStaleNamespaces, "delete-stale-namespaces", "DELETE_STALE_NAMESPACES", false, "Whether to delete all stale namespaces before the test execution.")
flags.BoolEnvVar(&clusterLoaderConfig.ClusterConfig.DeleteAutomanagedNamespaces, "delete-automanaged-namespaces", "DELETE_AUTOMANAGED_NAMESPACES", true, "Whether to delete all automanaged namespaces after the test execution.")
flags.BoolEnvVar(&clusterLoaderConfig.ClusterConfig.DeleteStaleNamespaces, "delete-stale-namespaces", "DELETE_STALE_NAMESPACES", false, "DEPRECATED: Whether to delete all stale namespaces before the test execution.")
flags.MarkDeprecated("delete-stale-namespaces", "specify deleteStaleNamespaces in testconfig file instead.")
flags.BoolEnvVar(&clusterLoaderConfig.ClusterConfig.DeleteAutomanagedNamespaces, "delete-automanaged-namespaces", "DELETE_AUTOMANAGED_NAMESPACES", true, "DEPRECATED: Whether to delete all automanaged namespaces after the test execution.")
flags.MarkDeprecated("delete-automanaged-namespaces", "specify deleteAutomanagedNamespaces in testconfig file instead.")
flags.StringEnvVar(&clusterLoaderConfig.ClusterConfig.MasterName, "mastername", "MASTER_NAME", "", "Name of the masternode")
// TODO(#595): Change the name of the MASTER_IP and MASTER_INTERNAL_IP flags and vars to plural
flags.StringSliceEnvVar(&clusterLoaderConfig.ClusterConfig.MasterIPs, "masterip", "MASTER_IP", nil /*defaultValue*/, "Hostname/IP of the master node, supports multiple values when separated by commas")
Expand Down
24 changes: 13 additions & 11 deletions clusterloader2/pkg/config/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ type ClusterLoaderConfig struct {

// ClusterConfig is a structure that represents cluster description.
type ClusterConfig struct {
KubeConfigPath string
Nodes int
Provider string
EtcdCertificatePath string
EtcdKeyPath string
EtcdInsecurePort int
MasterIPs []string
MasterInternalIPs []string
MasterName string
KubemarkRootKubeConfigPath string
DeleteStaleNamespaces bool
KubeConfigPath string
Nodes int
Provider string
EtcdCertificatePath string
EtcdKeyPath string
EtcdInsecurePort int
MasterIPs []string
MasterInternalIPs []string
MasterName string
KubemarkRootKubeConfigPath string
// Deprecated: use NamespaceConfig.DeleteStaleNamespaces instead.
DeleteStaleNamespaces bool
// Deprecated: use NamespaceConfig.DeleteAutomanagedNamespaces instead.
DeleteAutomanagedNamespaces bool
// SSHToMasterSupported determines whether SSH access to master machines is possible.
// If false (impossible for many providers), ClusterLoader will skip operations requiring it.
Expand Down
5 changes: 5 additions & 0 deletions clusterloader2/pkg/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ func Parse() error {
return nil
}

// MarkDeprecated indicates that a flag is deprecated
func MarkDeprecated(name string, usageMessage string) error {
return pflag.CommandLine.MarkDeprecated(name, usageMessage)
}

func parseEnvString(s *string, envVariable, defaultValue string) error {
*s = defaultValue
if envVariable != "" {
Expand Down
13 changes: 7 additions & 6 deletions clusterloader2/pkg/test/simple_test_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ func createSimpleTestExecutor() TestExecutor {

// ExecuteTest executes test based on provided configuration.
func (ste *simpleTestExecutor) ExecuteTest(ctx Context, conf *api.Config) *errors.ErrorList {
ctx.GetClusterFramework().SetAutomanagedNamespacePrefix(fmt.Sprintf("test-%s", util.RandomDNS1123String(6)))
ctx.GetClusterFramework().SetAutomanagedNamespacePrefix(conf.Namespace.Prefix)
klog.Infof("AutomanagedNamespacePrefix: %s", ctx.GetClusterFramework().GetAutomanagedNamespacePrefix())
defer cleanupResources(ctx)

defer cleanupResources(ctx, conf)
ctx.GetTuningSetFactory().Init(conf.TuningSets)

stopCh := make(chan struct{})
Expand Down Expand Up @@ -103,15 +104,15 @@ func (ste *simpleTestExecutor) ExecuteTestSteps(ctx Context, conf *api.Config) *
if len(automanagedNamespacesList) > 0 {
return errors.NewErrorList(fmt.Errorf("pre-existing automanaged namespaces found"))
}
var deleteStaleNS = ctx.GetClusterFramework().GetClusterConfig().DeleteStaleNamespaces
var deleteStaleNS = *conf.Namespace.DeleteStaleNamespaces
if len(staleNamespaces) > 0 && deleteStaleNS {
klog.Warning("stale automanaged namespaces found")
if errList := ctx.GetClusterFramework().DeleteNamespaces(staleNamespaces); !errList.IsEmpty() {
klog.Errorf("stale automanaged namespaces cleanup error: %v", errList.String())
}
}

err = ctx.GetClusterFramework().CreateAutomanagedNamespaces(int(conf.AutomanagedNamespaces))
err = ctx.GetClusterFramework().CreateAutomanagedNamespaces(int(conf.Namespace.Number))
if err != nil {
return errors.NewErrorList(fmt.Errorf("automanaged namespaces creation failed: %v", err))
}
Expand Down Expand Up @@ -371,10 +372,10 @@ func isErrsCritical(*errors.ErrorList) bool {
return false
}

func cleanupResources(ctx Context) {
func cleanupResources(ctx Context, conf *api.Config) {
cleanupStartTime := time.Now()
ctx.GetMeasurementManager().Dispose()
if ctx.GetClusterFramework().GetClusterConfig().DeleteAutomanagedNamespaces {
if *conf.Namespace.DeleteAutomanagedNamespaces {
if errList := ctx.GetClusterFramework().DeleteAutomanagedNamespaces(); !errList.IsEmpty() {
klog.Errorf("Resource cleanup error: %v", errList.String())
return
Expand Down
14 changes: 14 additions & 0 deletions clusterloader2/pkg/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,19 @@ func RunTest(clusterFramework, prometheusFramework *framework.Framework, cluster
if err != nil {
return errors.NewErrorList(fmt.Errorf("config reading error: %v", err))
}

// TODO: remove them after the deprecated command options are removed.
if testConfig.Namespace.DeleteStaleNamespaces == nil {
testConfig.Namespace.DeleteStaleNamespaces = &clusterFramework.GetClusterConfig().DeleteStaleNamespaces
}
if testConfig.Namespace.DeleteAutomanagedNamespaces == nil {
testConfig.Namespace.DeleteAutomanagedNamespaces = &clusterFramework.GetClusterConfig().DeleteAutomanagedNamespaces
}

testConfig.SetDefaults()
if err := testConfig.Validate(); err != nil {
return err
}

return Test.ExecuteTest(ctx, testConfig)
}
3 changes: 2 additions & 1 deletion clusterloader2/testing/access-tokens/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
{{$RESTART_COUNT_THRESHOLD_OVERRIDES:= DefaultParam .RESTART_COUNT_THRESHOLD_OVERRIDES ""}}

name: access-tokens
automanagedNamespaces: {{$namespaces}}
namespace:
number: {{$namespaces}}
tuningSets:
- name: Sequence
parallelismLimitedLoad:
Expand Down
3 changes: 2 additions & 1 deletion clusterloader2/testing/density/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
{{$saturationDeploymentHardTimeout := MaxInt $saturationDeploymentTimeout 1200}}

name: density
automanagedNamespaces: {{$namespaces}}
namespace:
number: {{$namespaces}}
tuningSets:
- name: Uniform5qps
qpsLoad:
Expand Down
3 changes: 2 additions & 1 deletion clusterloader2/testing/density/high-density-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
{{$saturationDeploymentHardTimeout := MaxInt $saturationDeploymentTimeout 1200}}

name: density
automanagedNamespaces: {{$namespaces}}
namespace:
number: {{$namespaces}}
tuningSets:
- name: Uniform5qps
qpsLoad:
Expand Down
3 changes: 2 additions & 1 deletion clusterloader2/testing/density/legacy/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
{{$saturationRCHardTimeout := MaxInt $saturationRCTimeout 1200}}

name: density
automanagedNamespaces: {{$namespaces}}
namespace:
number: {{$namespaces}}
tuningSets:
- name: Uniform5qps
qpsLoad:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@


name: storage
automanagedNamespaces: {{$namespaces}}
namespace:
number: {{$namespaces}}
tuningSets:
- name: UniformQPS
qpsLoad:
Expand Down
3 changes: 2 additions & 1 deletion clusterloader2/testing/l4ilb/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

#Test
name: ilbload
automanagedNamespaces: {{$namespaces}}
namespace:
number: {{$namespaces}}
tuningSets:
- name: ILBConstantQPS
qpsLoad:
Expand Down
3 changes: 2 additions & 1 deletion clusterloader2/testing/load/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
{{$bigDeploymentsPerNamespace := SubtractInt $bigDeploymentsPerNamespace 1}}

name: load
automanagedNamespaces: {{$namespaces}}
namespace:
number: {{$namespaces}}
tuningSets:
- name: Sequence
parallelismLimitedLoad:
Expand Down
3 changes: 2 additions & 1 deletion clusterloader2/testing/load/experimental-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
# END pod-startup-latency section

name: load
automanagedNamespaces: {{AddInt $namespaces $schedulerThroughputNamespaces}}
namespace:
number: {{AddInt $namespaces $schedulerThroughputNamespaces}}
tuningSets:
- name: Sequence
parallelismLimitedLoad:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@


name: load
automanagedNamespaces: {{$namespaces}}
namespace:
number: {{$namespaces}}
tuningSets:
- name: RandomizedSaturationTimeLimited
RandomizedTimeLimitedLoad:
Expand Down
3 changes: 2 additions & 1 deletion clusterloader2/testing/load/legacy/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@


name: load
automanagedNamespaces: {{$namespaces}}
namespace:
number: {{$namespaces}}
tuningSets:
- name: Sequence
parallelismLimitedLoad:
Expand Down

0 comments on commit 3a19456

Please sign in to comment.