Skip to content

Commit

Permalink
k8s-tester/nlb-guestbook: initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
  • Loading branch information
gyuho committed Jun 12, 2021
1 parent 3c19ec3 commit 6c985cf
Show file tree
Hide file tree
Showing 14 changed files with 2,254 additions and 4 deletions.
18 changes: 17 additions & 1 deletion k8s-tester/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ See example commits:

### Environmental variables

Total 18 test cases!
Total 19 test cases!

```
*----------------------------------*----------------------*----------------------------------------*---------------*
Expand Down Expand Up @@ -156,6 +156,22 @@ Total 18 test cases!
| K8S_TESTER_ADD_ON_PHP_APACHE_REPOSITORY_IMAGE_TAG | SETTABLE VIA ENV VAR | *ecr.Repository.ImageTag | string |
*----------------------------------------------------*----------------------*---------------------------*---------*
*----------------------------------------------------------*----------------------*----------------------------------------------*-------------------*
| ENVIRONMENTAL VARIABLE | FIELD TYPE | TYPE | GO TYPE |
*----------------------------------------------------------*----------------------*----------------------------------------------*-------------------*
| K8S_TESTER_ADD_ON_NLB_GUESTBOOK_ENABLE | SETTABLE VIA ENV VAR | *nlb_guestbook.Config.Enable | bool |
| K8S_TESTER_ADD_ON_NLB_GUESTBOOK_ACCOUNT_ID | READ-ONLY | *nlb_guestbook.Config.AccountID | string |
| K8S_TESTER_ADD_ON_NLB_GUESTBOOK_PARTITION | SETTABLE VIA ENV VAR | *nlb_guestbook.Config.Partition | string |
| K8S_TESTER_ADD_ON_NLB_GUESTBOOK_REGION | SETTABLE VIA ENV VAR | *nlb_guestbook.Config.Region | string |
| K8S_TESTER_ADD_ON_NLB_GUESTBOOK_MINIMUM_NODES | SETTABLE VIA ENV VAR | *nlb_guestbook.Config.MinimumNodes | int |
| K8S_TESTER_ADD_ON_NLB_GUESTBOOK_NAMESPACE | SETTABLE VIA ENV VAR | *nlb_guestbook.Config.Namespace | string |
| K8S_TESTER_ADD_ON_NLB_GUESTBOOK_DEPLOYMENT_NODE_SELECTOR | SETTABLE VIA ENV VAR | *nlb_guestbook.Config.DeploymentNodeSelector | map[string]string |
| K8S_TESTER_ADD_ON_NLB_GUESTBOOK_DEPLOYMENT_REPLICAS | SETTABLE VIA ENV VAR | *nlb_guestbook.Config.DeploymentReplicas | int32 |
| K8S_TESTER_ADD_ON_NLB_GUESTBOOK_ELB_ARN | READ-ONLY | *nlb_guestbook.Config.ELBARN | string |
| K8S_TESTER_ADD_ON_NLB_GUESTBOOK_ELB_NAME | READ-ONLY | *nlb_guestbook.Config.ELBName | string |
| K8S_TESTER_ADD_ON_NLB_GUESTBOOK_ELB_URL | READ-ONLY | *nlb_guestbook.Config.ELBURL | string |
*----------------------------------------------------------*----------------------*----------------------------------------------*-------------------*
*------------------------------------------------------------*----------------------*------------------------------------------------*-------------------*
| ENVIRONMENTAL VARIABLE | FIELD TYPE | TYPE | GO TYPE |
*------------------------------------------------------------*----------------------*------------------------------------------------*-------------------*
Expand Down
2 changes: 1 addition & 1 deletion k8s-tester/cmd/k8s-tester/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (

replace (
github.com/aws/aws-k8s-tester/client => ../../../client

github.com/aws/aws-k8s-tester/k8s-tester => ../..
github.com/aws/aws-k8s-tester/k8s-tester/cloudwatch-agent => ../../cloudwatch-agent
github.com/aws/aws-k8s-tester/k8s-tester/clusterloader => ../../clusterloader
Expand All @@ -25,6 +24,7 @@ replace (
github.com/aws/aws-k8s-tester/k8s-tester/jobs-pi => ../../jobs-pi
github.com/aws/aws-k8s-tester/k8s-tester/kubernetes-dashboard => ../../kubernetes-dashboard
github.com/aws/aws-k8s-tester/k8s-tester/metrics-server => ../../metrics-server
github.com/aws/aws-k8s-tester/k8s-tester/nlb-guestbook => ../../nlb-guestbook
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
Expand Down
2 changes: 1 addition & 1 deletion k8s-tester/cmd/readme-gen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ require (

replace (
github.com/aws/aws-k8s-tester/client => ../../../client

github.com/aws/aws-k8s-tester/k8s-tester => ../..
github.com/aws/aws-k8s-tester/k8s-tester/cloudwatch-agent => ../../cloudwatch-agent
github.com/aws/aws-k8s-tester/k8s-tester/clusterloader => ../../clusterloader
Expand All @@ -41,6 +40,7 @@ replace (
github.com/aws/aws-k8s-tester/k8s-tester/jobs-pi => ../../jobs-pi
github.com/aws/aws-k8s-tester/k8s-tester/kubernetes-dashboard => ../../kubernetes-dashboard
github.com/aws/aws-k8s-tester/k8s-tester/metrics-server => ../../metrics-server
github.com/aws/aws-k8s-tester/k8s-tester/nlb-guestbook => ../../nlb-guestbook
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
Expand Down
5 changes: 5 additions & 0 deletions k8s-tester/cmd/readme-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
jobs_pi "github.com/aws/aws-k8s-tester/k8s-tester/jobs-pi"
kubernetes_dashboard "github.com/aws/aws-k8s-tester/k8s-tester/kubernetes-dashboard"
metrics_server "github.com/aws/aws-k8s-tester/k8s-tester/metrics-server"
nlb_guestbook "github.com/aws/aws-k8s-tester/k8s-tester/nlb-guestbook"
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"
Expand Down Expand Up @@ -101,6 +102,10 @@ func createDoc() string {
b.WriteString(es.writeDoc(k8s_tester.ENV_PREFIX+php_apache.EnvRepository()+"_", &aws_v1_ecr.Repository{}))
totalTestCases++

b.WriteByte('\n')
b.WriteString(es.writeDoc(k8s_tester.ENV_PREFIX+nlb_guestbook.Env()+"_", &nlb_guestbook.Config{}))
totalTestCases++

b.WriteByte('\n')
b.WriteString(es.writeDoc(k8s_tester.ENV_PREFIX+nlb_hello_world.Env()+"_", &nlb_hello_world.Config{}))
totalTestCases++
Expand Down
18 changes: 18 additions & 0 deletions k8s-tester/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
jobs_pi "github.com/aws/aws-k8s-tester/k8s-tester/jobs-pi"
kubernetes_dashboard "github.com/aws/aws-k8s-tester/k8s-tester/kubernetes-dashboard"
metrics_server "github.com/aws/aws-k8s-tester/k8s-tester/metrics-server"
nlb_guestbook "github.com/aws/aws-k8s-tester/k8s-tester/nlb-guestbook"
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"
Expand Down Expand Up @@ -132,6 +133,7 @@ type Config struct {
AddOnKubernetesDashboard *kubernetes_dashboard.Config `json:"add_on_kubernetes_dashboard"`
AddOnFalco *falco.Config `json:"add_on_falco"`
AddOnPHPApache *php_apache.Config `json:"add_on_php_apache"`
AddOnNLBGuestbook *nlb_guestbook.Config `json:"add_on_nlb_guestbook"`
AddOnNLBHelloWorld *nlb_hello_world.Config `json:"add_on_nlb_hello_world"`
AddOnJobsPi *jobs_pi.Config `json:"add_on_jobs_pi"`
AddOnJobsEcho *jobs_echo.Config `json:"add_on_jobs_echo"`
Expand Down Expand Up @@ -204,6 +206,7 @@ func NewDefault() *Config {
AddOnKubernetesDashboard: kubernetes_dashboard.NewDefault(),
AddOnFalco: falco.NewDefault(),
AddOnPHPApache: php_apache.NewDefault(),
AddOnNLBGuestbook: nlb_guestbook.NewDefault(),
AddOnNLBHelloWorld: nlb_hello_world.NewDefault(),
AddOnJobsPi: jobs_pi.NewDefault(),
AddOnJobsEcho: jobs_echo.NewDefault("Job"),
Expand Down Expand Up @@ -277,6 +280,11 @@ func (cfg *Config) ValidateAndSetDefaults() error {
return err
}
}
if cfg.AddOnNLBGuestbook != nil && cfg.AddOnNLBGuestbook.Enable {
if err := cfg.AddOnNLBGuestbook.ValidateAndSetDefaults(); err != nil {
return err
}
}
if cfg.AddOnNLBHelloWorld != nil && cfg.AddOnNLBHelloWorld.Enable {
if err := cfg.AddOnNLBHelloWorld.ValidateAndSetDefaults(); err != nil {
return err
Expand Down Expand Up @@ -563,6 +571,16 @@ func (cfg *Config) UpdateFromEnvs() (err error) {
}
}

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

vv, err = parseEnvs(ENV_PREFIX+nlb_hello_world.Env()+"_", cfg.AddOnNLBHelloWorld)
if err != nil {
return err
Expand Down
35 changes: 35 additions & 0 deletions k8s-tester/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,41 @@ func TestEnvAddOnPHPApache(t *testing.T) {
}
}

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

os.Setenv("K8S_TESTER_CONFIG_PATH", "test.yaml")
defer os.Unsetenv("K8S_TESTER_CONFIG_PATH")
os.Setenv("K8S_TESTER_ADD_ON_NLB_GUESTBOOK_ENABLE", "true")
defer os.Unsetenv("K8S_TESTER_ADD_ON_NLB_GUESTBOOK_ENABLE")
os.Setenv("K8S_TESTER_ADD_ON_NLB_GUESTBOOK_MINIMUM_NODES", "100")
defer os.Unsetenv("K8S_TESTER_ADD_ON_NLB_GUESTBOOK_MINIMUM_NODES")
os.Setenv("K8S_TESTER_ADD_ON_NLB_GUESTBOOK_NAMESPACE", "hello")
defer os.Unsetenv("K8S_TESTER_ADD_ON_NLB_GUESTBOOK_NAMESPACE")
os.Setenv("K8S_TESTER_ADD_ON_NLB_GUESTBOOK_DEPLOYMENT_NODE_SELECTOR", `{"a":"b","c":"d"}`)
defer os.Unsetenv("K8S_TESTER_ADD_ON_NLB_GUESTBOOK_DEPLOYMENT_NODE_SELECTOR")

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

if cfg.ConfigPath != "test.yaml" {
t.Fatalf("unexpected cfg.ConfigPath %v", cfg.ConfigPath)
}
if !cfg.AddOnNLBGuestbook.Enable {
t.Fatalf("unexpected cfg.AddOnNLBGuestbook.Enable %v", cfg.AddOnNLBGuestbook.Enable)
}
if cfg.AddOnNLBGuestbook.MinimumNodes != 100 {
t.Fatalf("unexpected cfg.AddOnNLBGuestbook.MinimumNodes %v", cfg.AddOnNLBGuestbook.MinimumNodes)
}
if cfg.AddOnNLBGuestbook.Namespace != "hello" {
t.Fatalf("unexpected cfg.AddOnNLBGuestbook.Namespace %v", cfg.AddOnNLBGuestbook.Namespace)
}
if !reflect.DeepEqual(cfg.AddOnNLBGuestbook.DeploymentNodeSelector, map[string]string{"a": "b", "c": "d"}) {
t.Fatalf("unexpected cfg.AddOnNLBGuestbook.DeploymentNodeSelector %v", cfg.AddOnNLBGuestbook.DeploymentNodeSelector)
}
}

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

Expand Down
9 changes: 9 additions & 0 deletions k8s-tester/fmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ gofmt -s -w ./conformance
goimports -w ./csi-ebs
gofmt -s -w ./csi-ebs

goimports -w ./csrs
gofmt -s -w ./csrs

goimports -w ./falco
gofmt -s -w ./falco

goimports -w ./fluent-bit
gofmt -s -w ./fluent-bit

Expand All @@ -45,6 +51,9 @@ gofmt -s -w ./kubernetes-dashboard
goimports -w ./metrics-server
gofmt -s -w ./metrics-server

goimports -w ./nlb-guestbook
gofmt -s -w ./nlb-guestbook

goimports -w ./nlb-hello-world
gofmt -s -w ./nlb-hello-world

Expand Down
3 changes: 2 additions & 1 deletion k8s-tester/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/aws/aws-k8s-tester/k8s-tester/jobs-pi v0.0.0-00010101000000-000000000000
github.com/aws/aws-k8s-tester/k8s-tester/kubernetes-dashboard v0.0.0-00010101000000-000000000000
github.com/aws/aws-k8s-tester/k8s-tester/metrics-server v0.0.0-00010101000000-000000000000
github.com/aws/aws-k8s-tester/k8s-tester/nlb-guestbook v0.0.0-00010101000000-000000000000
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
Expand All @@ -34,7 +35,6 @@ require (

replace (
github.com/aws/aws-k8s-tester/client => ../client

github.com/aws/aws-k8s-tester/k8s-tester/cloudwatch-agent => ./cloudwatch-agent
github.com/aws/aws-k8s-tester/k8s-tester/clusterloader => ./clusterloader
github.com/aws/aws-k8s-tester/k8s-tester/configmaps => ./configmaps
Expand All @@ -48,6 +48,7 @@ replace (
github.com/aws/aws-k8s-tester/k8s-tester/jobs-pi => ./jobs-pi
github.com/aws/aws-k8s-tester/k8s-tester/kubernetes-dashboard => ./kubernetes-dashboard
github.com/aws/aws-k8s-tester/k8s-tester/metrics-server => ./metrics-server
github.com/aws/aws-k8s-tester/k8s-tester/nlb-guestbook => ./nlb-guestbook
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
Expand Down
Loading

0 comments on commit 6c985cf

Please sign in to comment.