Skip to content

Commit

Permalink
k8s-tester/stress: initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <[email protected]>
  • Loading branch information
gyuho committed Jun 8, 2021
1 parent 298c17a commit 310f44b
Show file tree
Hide file tree
Showing 39 changed files with 3,399 additions and 84 deletions.
8 changes: 4 additions & 4 deletions client/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
k8s_client "k8s.io/client-go/kubernetes"
)

// WaitForDeploymentCompletes waits till target replicas are ready in the Deployment.
func WaitForDeploymentCompletes(
// WaitForDeploymentAvailables waits till target replicas are ready in the Deployment.
func WaitForDeploymentAvailables(
ctx context.Context,
lg *zap.Logger,
logWriter io.Writer,
Expand All @@ -36,8 +36,8 @@ func WaitForDeploymentCompletes(
pollInterval = DefaultNamespacePollInterval
}

sp := newSpinner(logWriter, "Waiting for Deployment completes "+deploymentName)
lg.Info("waiting Deployment completes",
sp := newSpinner(logWriter, "Waiting for Deployment availables "+deploymentName)
lg.Info("waiting Deployment availables",
zap.String("namespace", namespace),
zap.String("job-name", deploymentName),
zap.String("initial-wait", initialWait.String()),
Expand Down
30 changes: 30 additions & 0 deletions k8s-tester/README.config.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,34 @@
*----------------------------------------------------------------------------------*----------------------*-------------------------------------------------------------*---------*
*-----------------------------------------------------*----------------------*----------------------------------------*-----------------*
| ENVIRONMENTAL VARIABLE | FIELD TYPE | TYPE | GO TYPE |
*-----------------------------------------------------*----------------------*----------------------------------------*-----------------*
| K8S_TESTER_ADD_ON_STRESS_ENABLE | SETTABLE VIA ENV VAR | *stress.Config.Enable | bool |
| K8S_TESTER_ADD_ON_STRESS_MINIMUM_NODES | SETTABLE VIA ENV VAR | *stress.Config.MinimumNodes | int |
| K8S_TESTER_ADD_ON_STRESS_NAMESPACE | SETTABLE VIA ENV VAR | *stress.Config.Namespace | string |
| K8S_TESTER_ADD_ON_STRESS_RUN_TIMEOUT | SETTABLE VIA ENV VAR | *stress.Config.RunTimeout | time.Duration |
| K8S_TESTER_ADD_ON_STRESS_RUN_TIMEOUT_STRING | READ-ONLY | *stress.Config.RunTimeoutString | string |
| K8S_TESTER_ADD_ON_STRESS_OBJECT_KEY_PREFIX | SETTABLE VIA ENV VAR | *stress.Config.ObjectKeyPrefix | string |
| K8S_TESTER_ADD_ON_STRESS_OBJECTS | SETTABLE VIA ENV VAR | *stress.Config.Objects | int |
| K8S_TESTER_ADD_ON_STRESS_OBJECT_SIZE | SETTABLE VIA ENV VAR | *stress.Config.ObjectSize | int |
| K8S_TESTER_ADD_ON_STRESS_UPDATE_CONCURRENCY | SETTABLE VIA ENV VAR | *stress.Config.UpdateConcurrency | int |
| K8S_TESTER_ADD_ON_STRESS_LIST_LIMIT | SETTABLE VIA ENV VAR | *stress.Config.ListLimit | int64 |
| K8S_TESTER_ADD_ON_STRESS_LATENCY_SUMMARY_WRITES | READ-ONLY | *stress.Config.LatencySummaryWrites | latency.Summary |
| K8S_TESTER_ADD_ON_STRESS_LATENCY_SUMMARY_GETS | READ-ONLY | *stress.Config.LatencySummaryGets | latency.Summary |
| K8S_TESTER_ADD_ON_STRESS_LATENCY_SUMMARY_RANGE_GETS | READ-ONLY | *stress.Config.LatencySummaryRangeGets | latency.Summary |
*-----------------------------------------------------*----------------------*----------------------------------------*-----------------*
*------------------------------------------------*----------------------*---------------------------*---------*
| ENVIRONMENTAL VARIABLE | FIELD TYPE | TYPE | GO TYPE |
*------------------------------------------------*----------------------*---------------------------*---------*
| K8S_TESTER_ADD_ON_STRESS_REPOSITORY_PARTITION | SETTABLE VIA ENV VAR | *ecr.Repository.Partition | string |
| K8S_TESTER_ADD_ON_STRESS_REPOSITORY_ACCOUNT_ID | SETTABLE VIA ENV VAR | *ecr.Repository.AccountID | string |
| K8S_TESTER_ADD_ON_STRESS_REPOSITORY_REGION | SETTABLE VIA ENV VAR | *ecr.Repository.Region | string |
| K8S_TESTER_ADD_ON_STRESS_REPOSITORY_NAME | SETTABLE VIA ENV VAR | *ecr.Repository.Name | string |
| K8S_TESTER_ADD_ON_STRESS_REPOSITORY_IMAGE_TAG | SETTABLE VIA ENV VAR | *ecr.Repository.ImageTag | string |
*------------------------------------------------*----------------------*---------------------------*---------*
```
130 changes: 128 additions & 2 deletions k8s-tester/cloudwatch-agent/go.sum

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions k8s-tester/cloudwatch-agent/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ type Config struct {
}

func (cfg *Config) ValidateAndSetDefaults(clusterName string) error {
if cfg.MinimumNodes == 0 {
cfg.MinimumNodes = DefaultMinimumNodes
}
if cfg.Namespace == "" {
return errors.New("empty Namespace")
}

cfg.ClusterName = clusterName

return nil
}

Expand Down
1 change: 1 addition & 0 deletions k8s-tester/cmd/k8s-tester/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ replace (
github.com/aws/aws-k8s-tester/k8s-tester/nlb-hello-world => ../../nlb-hello-world
github.com/aws/aws-k8s-tester/k8s-tester/php-apache => ../../php-apache
github.com/aws/aws-k8s-tester/k8s-tester/secrets => ../../secrets
github.com/aws/aws-k8s-tester/k8s-tester/stress => ../../stress
github.com/aws/aws-k8s-tester/k8s-tester/tester => ../../tester
github.com/aws/aws-k8s-tester/utils => ../../../utils
)
2 changes: 2 additions & 0 deletions k8s-tester/cmd/readme-gen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
github.com/aws/aws-k8s-tester/k8s-tester/nlb-hello-world v0.0.0-00010101000000-000000000000
github.com/aws/aws-k8s-tester/k8s-tester/php-apache v0.0.0-00010101000000-000000000000
github.com/aws/aws-k8s-tester/k8s-tester/secrets v0.0.0-00010101000000-000000000000
github.com/aws/aws-k8s-tester/k8s-tester/stress v0.0.0-00010101000000-000000000000
github.com/aws/aws-k8s-tester/utils v0.0.0-00010101000000-000000000000
github.com/olekukonko/tablewriter v0.0.5
)
Expand All @@ -41,6 +42,7 @@ replace (
github.com/aws/aws-k8s-tester/k8s-tester/nlb-hello-world => ../../nlb-hello-world
github.com/aws/aws-k8s-tester/k8s-tester/php-apache => ../../php-apache
github.com/aws/aws-k8s-tester/k8s-tester/secrets => ../../secrets
github.com/aws/aws-k8s-tester/k8s-tester/stress => ../../stress
github.com/aws/aws-k8s-tester/k8s-tester/tester => ../../tester
github.com/aws/aws-k8s-tester/utils => ../../../utils
)
8 changes: 8 additions & 0 deletions k8s-tester/cmd/readme-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
nlb_hello_world "github.com/aws/aws-k8s-tester/k8s-tester/nlb-hello-world"
php_apache "github.com/aws/aws-k8s-tester/k8s-tester/php-apache"
"github.com/aws/aws-k8s-tester/k8s-tester/secrets"
"github.com/aws/aws-k8s-tester/k8s-tester/stress"
aws_v1_ecr "github.com/aws/aws-k8s-tester/utils/aws/v1/ecr"
"github.com/olekukonko/tablewriter"
)
Expand Down Expand Up @@ -116,6 +117,13 @@ func createDoc() string {
b.WriteByte('\n')
b.WriteString(es.writeDoc(k8s_tester.ENV_PREFIX+clusterloader.EnvTestOverride()+"_", &clusterloader.TestOverride{}))

b.WriteByte('\n')
b.WriteByte('\n')
b.WriteString(es.writeDoc(k8s_tester.ENV_PREFIX+stress.Env()+"_", &stress.Config{}))
b.WriteByte('\n')
b.WriteByte('\n')
b.WriteString(es.writeDoc(k8s_tester.ENV_PREFIX+stress.EnvRepository()+"_", &aws_v1_ecr.Repository{}))

b.WriteByte('\n')
b.WriteByte('\n')

Expand Down
84 changes: 84 additions & 0 deletions k8s-tester/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
nlb_hello_world "github.com/aws/aws-k8s-tester/k8s-tester/nlb-hello-world"
php_apache "github.com/aws/aws-k8s-tester/k8s-tester/php-apache"
"github.com/aws/aws-k8s-tester/k8s-tester/secrets"
"github.com/aws/aws-k8s-tester/k8s-tester/stress"
aws_v1_ecr "github.com/aws/aws-k8s-tester/utils/aws/v1/ecr"
"github.com/aws/aws-k8s-tester/utils/file"
"github.com/aws/aws-k8s-tester/utils/log"
Expand Down Expand Up @@ -136,6 +137,7 @@ type Config struct {
AddOnConfigmaps *configmaps.Config `json:"add_on_configmaps"`
AddOnSecrets *secrets.Config `json:"add_on_secrets"`
AddOnClusterloader *clusterloader.Config `json:"add_on_clusterloader"`
AddOnStress *stress.Config `json:"add_on_stress"`
}

const (
Expand Down Expand Up @@ -204,6 +206,7 @@ func NewDefault() *Config {
AddOnConfigmaps: configmaps.NewDefault(),
AddOnSecrets: secrets.NewDefault(),
AddOnClusterloader: clusterloader.NewDefault(),
AddOnStress: stress.NewDefault(),
}
}

Expand Down Expand Up @@ -232,21 +235,81 @@ func (cfg *Config) ValidateAndSetDefaults() error {
return err
}
}
if cfg.AddOnFluentBit != nil && cfg.AddOnFluentBit.Enable {
if err := cfg.AddOnFluentBit.ValidateAndSetDefaults(); err != nil {
return err
}
}
if cfg.AddOnMetricsServer != nil && cfg.AddOnMetricsServer.Enable {
if err := cfg.AddOnMetricsServer.ValidateAndSetDefaults(); err != nil {
return err
}
}
if cfg.AddOnConformance != nil && cfg.AddOnConformance.Enable {
if err := cfg.AddOnConformance.ValidateAndSetDefaults(); err != nil {
return err
}
}
if cfg.AddOnCSIEBS != nil && cfg.AddOnCSIEBS.Enable {
if err := cfg.AddOnCSIEBS.ValidateAndSetDefaults(); err != nil {
return err
}
}
if cfg.AddOnKubernetesDashboard != nil && cfg.AddOnKubernetesDashboard.Enable {
if err := cfg.AddOnKubernetesDashboard.ValidateAndSetDefaults(); err != nil {
return err
}
}
if cfg.AddOnPHPApache != nil && cfg.AddOnPHPApache.Enable {
if err := cfg.AddOnPHPApache.ValidateAndSetDefaults(); err != nil {
return err
}
}
if cfg.AddOnNLBHelloWorld != nil && cfg.AddOnNLBHelloWorld.Enable {
if err := cfg.AddOnNLBHelloWorld.ValidateAndSetDefaults(); err != nil {
return err
}
}
if cfg.AddOnJobsPi != nil && cfg.AddOnJobsPi.Enable {
if err := cfg.AddOnJobsPi.ValidateAndSetDefaults(); err != nil {
return err
}
}
if cfg.AddOnJobsEcho != nil && cfg.AddOnJobsEcho.Enable {
if err := cfg.AddOnJobsEcho.ValidateAndSetDefaults(); err != nil {
return err
}
}
if cfg.AddOnCronJobsEcho != nil && cfg.AddOnCronJobsEcho.Enable {
if err := cfg.AddOnCronJobsEcho.ValidateAndSetDefaults(); err != nil {
return err
}
}
if cfg.AddOnCSRs != nil && cfg.AddOnCSRs.Enable {
if err := cfg.AddOnCSRs.ValidateAndSetDefaults(); err != nil {
return err
}
}
if cfg.AddOnConfigmaps != nil && cfg.AddOnConfigmaps.Enable {
if err := cfg.AddOnConfigmaps.ValidateAndSetDefaults(); err != nil {
return err
}
}
if cfg.AddOnSecrets != nil && cfg.AddOnSecrets.Enable {
if err := cfg.AddOnSecrets.ValidateAndSetDefaults(); err != nil {
return err
}
}
if cfg.AddOnClusterloader != nil && cfg.AddOnClusterloader.Enable {
if err := cfg.AddOnClusterloader.ValidateAndSetDefaults(); err != nil {
return err
}
}
if cfg.AddOnStress != nil && cfg.AddOnStress.Enable {
if err := cfg.AddOnStress.ValidateAndSetDefaults(); err != nil {
return err
}
}

return nil
}
Expand Down Expand Up @@ -596,6 +659,27 @@ func (cfg *Config) UpdateFromEnvs() (err error) {
}
}

vv, err = parseEnvs(ENV_PREFIX+stress.Env()+"_", cfg.AddOnStress)
if err != nil {
return err
}
if av, ok := vv.(*stress.Config); ok {
cfg.AddOnStress = av
} else {
return fmt.Errorf("expected *stress.Config, got %T", vv)
}
if cfg.AddOnStress != nil {
vv, err = parseEnvs(ENV_PREFIX+stress.EnvRepository()+"_", cfg.AddOnStress.Repository)
if err != nil {
return err
}
if av, ok := vv.(*aws_v1_ecr.Repository); ok {
cfg.AddOnStress.Repository = av
} else {
return fmt.Errorf("expected *aws_v1_ecr.Repository, got %T", vv)
}
}

return err
}

Expand Down
55 changes: 55 additions & 0 deletions k8s-tester/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,3 +719,58 @@ func TestEnvAddOnClusterloader(t *testing.T) {
t.Fatalf("unexpected cfg.AddOnClusterloader.TestOverride.EnableSystemPodMetrics %v", cfg.AddOnClusterloader.TestOverride.EnableSystemPodMetrics)
}
}

func TestEnvAddOnStress(t *testing.T) {
cfg := NewDefault()

os.Setenv("K8S_TESTER_ADD_ON_STRESS_ENABLE", "true")
defer os.Unsetenv("K8S_TESTER_ADD_ON_STRESS_ENABLE")
os.Setenv("K8S_TESTER_ADD_ON_STRESS_NAMESPACE", "hello")
defer os.Unsetenv("K8S_TESTER_ADD_ON_STRESS_NAMESPACE")
os.Setenv("K8S_TESTER_ADD_ON_STRESS_RUN_TIMEOUT", "11h")
defer os.Unsetenv("K8S_TESTER_ADD_ON_STRESS_RUN_TIMEOUT")
os.Setenv("K8S_TESTER_ADD_ON_STRESS_REPOSITORY_PARTITION", "aws")
defer os.Unsetenv("K8S_TESTER_ADD_ON_STRESS_REPOSITORY_PARTITION")
os.Setenv("K8S_TESTER_ADD_ON_STRESS_REPOSITORY_ACCOUNT_ID", "123")
defer os.Unsetenv("K8S_TESTER_ADD_ON_STRESS_REPOSITORY_ACCOUNT_ID")
os.Setenv("K8S_TESTER_ADD_ON_STRESS_REPOSITORY_REGION", "hello")
defer os.Unsetenv("K8S_TESTER_ADD_ON_STRESS_REPOSITORY_REGION")
os.Setenv("K8S_TESTER_ADD_ON_STRESS_REPOSITORY_NAME", "hello")
defer os.Unsetenv("K8S_TESTER_ADD_ON_STRESS_REPOSITORY_NAME")
os.Setenv("K8S_TESTER_ADD_ON_STRESS_REPOSITORY_IMAGE_TAG", "hello")
defer os.Unsetenv("K8S_TESTER_ADD_ON_STRESS_REPOSITORY_IMAGE_TAG")
os.Setenv("K8S_TESTER_ADD_ON_STRESS_UPDATE_CONCURRENCY", "1000")
defer os.Unsetenv("K8S_TESTER_ADD_ON_STRESS_UPDATE_CONCURRENCY")

if err := cfg.UpdateFromEnvs(); err != nil {
t.Fatal(err)
}

if !cfg.AddOnStress.Enable {
t.Fatalf("unexpected cfg.AddOnStress.Enable %v", cfg.AddOnStress.Enable)
}
if cfg.AddOnStress.Namespace != "hello" {
t.Fatalf("unexpected cfg.AddOnStress.Namespace %v", cfg.AddOnStress.Namespace)
}
if cfg.AddOnStress.RunTimeout != 11*time.Hour {
t.Fatalf("unexpected cfg.AddOnStress.RunTimeout %v", cfg.AddOnStress.RunTimeout)
}
if cfg.AddOnStress.Repository.Partition != "aws" {
t.Fatalf("unexpected cfg.AddOnStress.Repository.Partition %v", cfg.AddOnStress.Repository.Partition)
}
if cfg.AddOnStress.Repository.AccountID != "123" {
t.Fatalf("unexpected cfg.AddOnStress.Repository.AccountID %v", cfg.AddOnStress.Repository.AccountID)
}
if cfg.AddOnStress.Repository.Region != "hello" {
t.Fatalf("unexpected cfg.AddOnStress.Repository.Region %v", cfg.AddOnStress.Repository.Region)
}
if cfg.AddOnStress.Repository.Name != "hello" {
t.Fatalf("unexpected cfg.AddOnStress.Repository.Name %v", cfg.AddOnStress.Repository.Name)
}
if cfg.AddOnStress.Repository.ImageTag != "hello" {
t.Fatalf("unexpected cfg.AddOnStress.Repository.ImageTag %v", cfg.AddOnStress.Repository.ImageTag)
}
if cfg.AddOnStress.UpdateConcurrency != 1000 {
t.Fatalf("unexpected cfg.AddOnStress.UpdateConcurrency %v", cfg.AddOnStress.UpdateConcurrency)
}
}
13 changes: 12 additions & 1 deletion k8s-tester/configmaps/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ type Config struct {
LatencySummary latency.Summary `json:"latency_summary" read-only:"true"`
}

func (cfg *Config) ValidateAndSetDefaults() error {
if cfg.MinimumNodes == 0 {
cfg.MinimumNodes = DefaultMinimumNodes
}
if cfg.Namespace == "" {
return errors.New("empty Namespace")
}

return nil
}

const (
DefaultMinimumNodes int = 1
DefaultObjects int = 10
Expand Down Expand Up @@ -181,8 +192,8 @@ func (ts *tester) Apply() error {
}
}
}
fmt.Fprintf(ts.cfg.LogWriter, "\n\nLatencySummary:\n%s\n", ts.cfg.LatencySummary.Table())

fmt.Fprintf(ts.cfg.LogWriter, "\n\nLatencySummary:\n%s\n", ts.cfg.LatencySummary.Table())
return nil
}

Expand Down
1 change: 1 addition & 0 deletions k8s-tester/conformance/sonobuoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
)

var (
// ref. https://github.com/vmware-tanzu/sonobuoy/releases
defaultSonobuoyVersion = "0.50.0"
defaultSonobuoyPath = fmt.Sprintf("/tmp/sonobuoy-%s", defaultSonobuoyVersion)
// ref. https://github.com/vmware-tanzu/sonobuoy/releases
Expand Down
4 changes: 4 additions & 0 deletions k8s-tester/conformance/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ type Config struct {
}

func (cfg *Config) ValidateAndSetDefaults() error {
if cfg.MinimumNodes == 0 {
cfg.MinimumNodes = DefaultMinimumNodes
}

if cfg.SonobuoyPath == "" {
cfg.SonobuoyPath = DefaultSonobuoyPath()
}
Expand Down
Loading

0 comments on commit 310f44b

Please sign in to comment.