Skip to content

Commit

Permalink
k8s-tester/wordpress: 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 12, 2021
1 parent 3204f61 commit b5a8f3e
Show file tree
Hide file tree
Showing 16 changed files with 1,944 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG/CHANGELOG-1.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See [code changes](https://github.com/aws/aws-k8s-tester/compare/v1.6.0...v1.6.1
- Add [`k8s-tester/stress/in-cluster`](https://github.com/aws/aws-k8s-tester/commit/e0b5fa0b0fb97851d86d268d093f4754617c638b).
- Add [`k8s-tester/falco`](https://github.com/aws/aws-k8s-tester/pull/221).
- Add [`k8s-tester/nlb-guestbook`](https://github.com/aws/aws-k8s-tester/commit/6c985cfabff769c020d2f1f131c4106607fa5d95).
- Add [`k8s-tester/wordpress`](https://github.com/aws/aws-k8s-tester/commit/TODO).

### Go

Expand Down
19 changes: 18 additions & 1 deletion k8s-tester/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ See example commits:
- [`k8s-tester/csrs`](https://github.com/aws/aws-k8s-tester/commit/90ef22a2e6505189f998d1f6ed738fe05f73d56d).
- [`k8s-tester/falco`](https://github.com/aws/aws-k8s-tester/pull/221).
- [`k8s-tester/nlb-guestbook`](https://github.com/aws/aws-k8s-tester/commit/6c985cfabff769c020d2f1f131c4106607fa5d95).
- [`k8s-tester/wordpress`](https://github.com/aws/aws-k8s-tester/commit/TODO).

### Environmental variables

Total 19 test cases!
Total 20 test cases!

```
*----------------------------------*----------------------*----------------------------------------*---------------*
Expand Down Expand Up @@ -188,6 +189,22 @@ Total 19 test cases!
| K8S_TESTER_ADD_ON_NLB_HELLO_WORLD_ELB_URL | READ-ONLY | *nlb_hello_world.Config.ELBURL | string |
*------------------------------------------------------------*----------------------*------------------------------------------------*-------------------*
*-------------------------------------------*----------------------*--------------------------------*---------*
| ENVIRONMENTAL VARIABLE | FIELD TYPE | TYPE | GO TYPE |
*-------------------------------------------*----------------------*--------------------------------*---------*
| K8S_TESTER_ADD_ON_WORDPRESS_ENABLE | SETTABLE VIA ENV VAR | *wordpress.Config.Enable | bool |
| K8S_TESTER_ADD_ON_WORDPRESS_ACCOUNT_ID | READ-ONLY | *wordpress.Config.AccountID | string |
| K8S_TESTER_ADD_ON_WORDPRESS_PARTITION | SETTABLE VIA ENV VAR | *wordpress.Config.Partition | string |
| K8S_TESTER_ADD_ON_WORDPRESS_REGION | SETTABLE VIA ENV VAR | *wordpress.Config.Region | string |
| K8S_TESTER_ADD_ON_WORDPRESS_MINIMUM_NODES | SETTABLE VIA ENV VAR | *wordpress.Config.MinimumNodes | int |
| K8S_TESTER_ADD_ON_WORDPRESS_NAMESPACE | SETTABLE VIA ENV VAR | *wordpress.Config.Namespace | string |
| K8S_TESTER_ADD_ON_WORDPRESS_USER_NAME | SETTABLE VIA ENV VAR | *wordpress.Config.UserName | string |
| K8S_TESTER_ADD_ON_WORDPRESS_PASSWORD | SETTABLE VIA ENV VAR | *wordpress.Config.Password | string |
| K8S_TESTER_ADD_ON_WORDPRESS_ELB_ARN | READ-ONLY | *wordpress.Config.ELBARN | string |
| K8S_TESTER_ADD_ON_WORDPRESS_ELB_NAME | READ-ONLY | *wordpress.Config.ELBName | string |
| K8S_TESTER_ADD_ON_WORDPRESS_ELB_URL | READ-ONLY | *wordpress.Config.ELBURL | string |
*-------------------------------------------*----------------------*--------------------------------*---------*
*-----------------------------------------*----------------------*------------------------------*---------*
| ENVIRONMENTAL VARIABLE | FIELD TYPE | TYPE | GO TYPE |
*-----------------------------------------*----------------------*------------------------------*---------*
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 @@ -30,5 +30,6 @@ replace (
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/k8s-tester/wordpress => ../../wordpress
github.com/aws/aws-k8s-tester/utils => ../../../utils
)
3 changes: 3 additions & 0 deletions k8s-tester/cmd/readme-gen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ 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
github.com/aws/aws-k8s-tester/k8s-tester/stress v0.0.0-00010101000000-000000000000
github.com/aws/aws-k8s-tester/k8s-tester/wordpress v0.0.0-00010101000000-000000000000
github.com/aws/aws-k8s-tester/utils v0.0.0-20210610170531-2e5d31e5196c
github.com/olekukonko/tablewriter v0.0.5
)
Expand All @@ -46,5 +48,6 @@ replace (
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/k8s-tester/wordpress => ../../wordpress
github.com/aws/aws-k8s-tester/utils => ../../../utils
)
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 @@ -30,6 +30,7 @@ import (
"github.com/aws/aws-k8s-tester/k8s-tester/secrets"
"github.com/aws/aws-k8s-tester/k8s-tester/stress"
stress_in_cluster "github.com/aws/aws-k8s-tester/k8s-tester/stress/in-cluster"
"github.com/aws/aws-k8s-tester/k8s-tester/wordpress"
aws_v1_ecr "github.com/aws/aws-k8s-tester/utils/aws/v1/ecr"
"github.com/olekukonko/tablewriter"
)
Expand Down Expand Up @@ -110,6 +111,10 @@ func createDoc() string {
b.WriteString(es.writeDoc(k8s_tester.ENV_PREFIX+nlb_hello_world.Env()+"_", &nlb_hello_world.Config{}))
totalTestCases++

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

b.WriteByte('\n')
b.WriteString(es.writeDoc(k8s_tester.ENV_PREFIX+jobs_pi.Env()+"_", &jobs_pi.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 @@ -34,6 +34,7 @@ import (
"github.com/aws/aws-k8s-tester/k8s-tester/secrets"
"github.com/aws/aws-k8s-tester/k8s-tester/stress"
stress_in_cluster "github.com/aws/aws-k8s-tester/k8s-tester/stress/in-cluster"
"github.com/aws/aws-k8s-tester/k8s-tester/wordpress"
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 @@ -135,6 +136,7 @@ type Config struct {
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"`
AddOnWordpress *wordpress.Config `json:"add_on_wordpress"`
AddOnJobsPi *jobs_pi.Config `json:"add_on_jobs_pi"`
AddOnJobsEcho *jobs_echo.Config `json:"add_on_jobs_echo"`
AddOnCronJobsEcho *jobs_echo.Config `json:"add_on_cron_jobs_echo"`
Expand Down Expand Up @@ -208,6 +210,7 @@ func NewDefault() *Config {
AddOnPHPApache: php_apache.NewDefault(),
AddOnNLBGuestbook: nlb_guestbook.NewDefault(),
AddOnNLBHelloWorld: nlb_hello_world.NewDefault(),
AddOnWordpress: wordpress.NewDefault(),
AddOnJobsPi: jobs_pi.NewDefault(),
AddOnJobsEcho: jobs_echo.NewDefault("Job"),
AddOnCronJobsEcho: jobs_echo.NewDefault("CronJob"),
Expand Down Expand Up @@ -290,6 +293,11 @@ func (cfg *Config) ValidateAndSetDefaults() error {
return err
}
}
if cfg.AddOnWordpress != nil && cfg.AddOnWordpress.Enable {
if err := cfg.AddOnWordpress.ValidateAndSetDefaults(); err != nil {
return err
}
}
if cfg.AddOnJobsPi != nil && cfg.AddOnJobsPi.Enable {
if err := cfg.AddOnJobsPi.ValidateAndSetDefaults(); err != nil {
return err
Expand Down Expand Up @@ -591,6 +599,16 @@ func (cfg *Config) UpdateFromEnvs() (err error) {
return fmt.Errorf("expected *nlb_hello_world.Config, got %T", vv)
}

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

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

func TestEnvAddOnWordpress(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_WORDPRESS_ENABLE", "true")
defer os.Unsetenv("K8S_TESTER_ADD_ON_WORDPRESS_ENABLE")
os.Setenv("K8S_TESTER_ADD_ON_WORDPRESS_MINIMUM_NODES", "100")
defer os.Unsetenv("K8S_TESTER_ADD_ON_WORDPRESS_MINIMUM_NODES")
os.Setenv("K8S_TESTER_ADD_ON_WORDPRESS_NAMESPACE", "hello")
defer os.Unsetenv("K8S_TESTER_ADD_ON_WORDPRESS_NAMESPACE")

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

if cfg.ConfigPath != "test.yaml" {
t.Fatalf("unexpected cfg.ConfigPath %v", cfg.ConfigPath)
}
if !cfg.AddOnWordpress.Enable {
t.Fatalf("unexpected cfg.AddOnWordpress.Enable %v", cfg.AddOnWordpress.Enable)
}
if cfg.AddOnWordpress.MinimumNodes != 100 {
t.Fatalf("unexpected cfg.AddOnWordpress.MinimumNodes %v", cfg.AddOnWordpress.MinimumNodes)
}
if cfg.AddOnWordpress.Namespace != "hello" {
t.Fatalf("unexpected cfg.AddOnWordpress.Namespace %v", cfg.AddOnWordpress.Namespace)
}
}

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

Expand Down
2 changes: 1 addition & 1 deletion k8s-tester/csi-ebs/tester.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package csi_ebs a simple metrics server.
// Package csi_ebs installs CSI EBS driver.
// Replace https://github.com/aws/aws-k8s-tester/blob/v1.5.9/eks/csi-ebs/csi-ebs.go.
package csi_ebs

Expand Down
3 changes: 3 additions & 0 deletions k8s-tester/fmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@ gofmt -s -w ./tester

goimports -w ./version
gofmt -s -w ./version

goimports -w ./wordpress
gofmt -s -w ./wordpress
4 changes: 3 additions & 1 deletion k8s-tester/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
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/k8s-tester/tester v0.0.0-20210610170531-2e5d31e5196c
github.com/aws/aws-k8s-tester/k8s-tester/wordpress v0.0.0-00010101000000-000000000000
github.com/aws/aws-k8s-tester/utils v0.0.0-20210610170531-2e5d31e5196c
github.com/dustin/go-humanize v1.0.0
github.com/manifoldco/promptui v0.8.0
Expand Down Expand Up @@ -54,6 +55,7 @@ replace (
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/k8s-tester/version => ./tester
github.com/aws/aws-k8s-tester/k8s-tester/version => ./version
github.com/aws/aws-k8s-tester/k8s-tester/wordpress => ./wordpress
github.com/aws/aws-k8s-tester/utils => ../utils
)
8 changes: 8 additions & 0 deletions k8s-tester/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
stress_in_cluster "github.com/aws/aws-k8s-tester/k8s-tester/stress/in-cluster"
k8s_tester "github.com/aws/aws-k8s-tester/k8s-tester/tester"
"github.com/aws/aws-k8s-tester/k8s-tester/version"
"github.com/aws/aws-k8s-tester/k8s-tester/wordpress"
"github.com/aws/aws-k8s-tester/utils/log"
"github.com/dustin/go-humanize"
"github.com/manifoldco/promptui"
Expand Down Expand Up @@ -179,6 +180,13 @@ func (ts *tester) createTesters() {
ts.cfg.AddOnNLBHelloWorld.Client = ts.cli
ts.testers = append(ts.testers, nlb_hello_world.New(ts.cfg.AddOnNLBHelloWorld))
}
if ts.cfg.AddOnWordpress != nil && ts.cfg.AddOnWordpress.Enable {
ts.cfg.AddOnWordpress.Stopc = ts.stopCreationCh
ts.cfg.AddOnWordpress.Logger = ts.logger
ts.cfg.AddOnWordpress.LogWriter = ts.logWriter
ts.cfg.AddOnWordpress.Client = ts.cli
ts.testers = append(ts.testers, wordpress.New(ts.cfg.AddOnWordpress))
}
if ts.cfg.AddOnJobsPi != nil && ts.cfg.AddOnJobsPi.Enable {
ts.cfg.AddOnJobsPi.Stopc = ts.stopCreationCh
ts.cfg.AddOnJobsPi.Logger = ts.logger
Expand Down
155 changes: 155 additions & 0 deletions k8s-tester/wordpress/cmd/k8s-tester-wordpress/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
// k8s-tester-wordpress installs Kubernetes wordpress tester.
package main

import (
"fmt"
"os"

"github.com/aws/aws-k8s-tester/client"
"github.com/aws/aws-k8s-tester/k8s-tester/wordpress"
"github.com/aws/aws-k8s-tester/utils/log"
"github.com/spf13/cobra"
"go.uber.org/zap"
)

var rootCmd = &cobra.Command{
Use: "k8s-tester-wordpress",
Short: "Kubernetes wordpress tester",
SuggestFor: []string{"wordpress"},
}

func init() {
cobra.EnablePrefixMatching = true
}

var (
prompt bool
logLevel string
logOutputs []string
minimumNodes int
kubectlDownloadURL string
kubectlPath string
kubeconfigPath string
)

func init() {
rootCmd.PersistentFlags().BoolVar(&prompt, "prompt", true, "'true' to enable prompt mode")
rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", log.DefaultLogLevel, "Logging level")
rootCmd.PersistentFlags().StringSliceVar(&logOutputs, "log-outputs", []string{"stderr"}, "Additional logger outputs")
rootCmd.PersistentFlags().IntVar(&minimumNodes, "minimum-nodes", wordpress.DefaultMinimumNodes, "minimum number of Kubernetes nodes required for installing this addon")
rootCmd.PersistentFlags().StringVar(&kubectlDownloadURL, "kubectl-download-url", client.DefaultKubectlDownloadURL(), "kubectl download URL")
rootCmd.PersistentFlags().StringVar(&kubectlPath, "kubectl-path", client.DefaultKubectlPath(), "kubectl path")
rootCmd.PersistentFlags().StringVar(&kubeconfigPath, "kubeconfig-path", "", "KUBECONFIG path")

rootCmd.AddCommand(
newApply(),
newDelete(),
)
}

func main() {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "k8s-tester-wordpress failed %v\n", err)
os.Exit(1)
}
os.Exit(0)
}

var (
partition string
region string
)

func newApply() *cobra.Command {
cmd := &cobra.Command{
Use: "apply",
Short: "Apply tests",
Run: createApplyFunc,
}

cmd.PersistentFlags().StringVar(&partition, "partition", "aws", "partition for AWS region")
cmd.PersistentFlags().StringVar(&region, "region", "", "region for ELB resource")

return cmd
}

func createApplyFunc(cmd *cobra.Command, args []string) {
lg, logWriter, _, err := log.NewWithStderrWriter(logLevel, logOutputs)
if err != nil {
panic(err)
}
_ = zap.ReplaceGlobals(lg)

cli, err := client.New(&client.Config{
Logger: lg,
KubectlDownloadURL: kubectlDownloadURL,
KubectlPath: kubectlPath,
KubeconfigPath: kubeconfigPath,
})
if err != nil {
lg.Panic("failed to create client", zap.Error(err))
}

cfg := &wordpress.Config{
Prompt: prompt,
Logger: lg,
LogWriter: logWriter,
MinimumNodes: minimumNodes,
Client: cli,

Partition: partition,
Region: region,
}

ts := wordpress.New(cfg)
if err := ts.Apply(); err != nil {
fmt.Fprintf(os.Stderr, "failed to apply (%v)\n", err)
os.Exit(1)
}

fmt.Printf("\n*********************************\n")
fmt.Printf("'k8s-tester-wordpress apply' success\n")
}

func newDelete() *cobra.Command {
cmd := &cobra.Command{
Use: "delete",
Short: "Delete resources",
Run: createDeleteFunc,
}
return cmd
}

func createDeleteFunc(cmd *cobra.Command, args []string) {
lg, logWriter, _, err := log.NewWithStderrWriter(logLevel, logOutputs)
if err != nil {
panic(err)
}
_ = zap.ReplaceGlobals(lg)

cli, err := client.New(&client.Config{
Logger: lg,
KubectlDownloadURL: kubectlDownloadURL,
KubectlPath: kubectlPath,
KubeconfigPath: kubeconfigPath,
})
if err != nil {
lg.Panic("failed to create client", zap.Error(err))
}

cfg := &wordpress.Config{
Prompt: prompt,
Logger: lg,
LogWriter: logWriter,
Client: cli,
}

ts := wordpress.New(cfg)
if err := ts.Delete(); err != nil {
fmt.Fprintf(os.Stderr, "failed to delete (%v)\n", err)
os.Exit(1)
}

fmt.Printf("\n*********************************\n")
fmt.Printf("'k8s-tester-wordpress delete' success\n")
}
Loading

0 comments on commit b5a8f3e

Please sign in to comment.