-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
k8s-tester/metrics-server: initial commit
Signed-off-by: Gyuho Lee <[email protected]>
- Loading branch information
Showing
11 changed files
with
1,265 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
k8s-tester/metrics-server/cmd/k8s-tester-metrics-server/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// k8s-tester-metrics-server installs Kubernetes metrics-server tester. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/aws/aws-k8s-tester/client" | ||
metrics_server "github.com/aws/aws-k8s-tester/k8s-tester/metrics-server" | ||
"github.com/aws/aws-k8s-tester/utils/log" | ||
"github.com/spf13/cobra" | ||
"go.uber.org/zap" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "k8s-tester-metrics-server", | ||
Short: "Kubernetes metrics-server tester", | ||
SuggestFor: []string{"metrics-server"}, | ||
} | ||
|
||
func init() { | ||
cobra.EnablePrefixMatching = true | ||
} | ||
|
||
var ( | ||
enablePrompt bool | ||
logLevel string | ||
logOutputs []string | ||
namespace string | ||
kubectlPath string | ||
kubeConfigPath string | ||
) | ||
|
||
func init() { | ||
rootCmd.PersistentFlags().BoolVar(&enablePrompt, "enable-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().StringVar(&namespace, "namespace", "test-namespace", "'true' to auto-generate path for create config/cluster, overwrites existing --path value") | ||
rootCmd.PersistentFlags().StringVar(&kubectlPath, "kubectl-path", "", "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-metrics-server failed %v\n", err) | ||
os.Exit(1) | ||
} | ||
os.Exit(0) | ||
} | ||
|
||
func newApply() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "apply", | ||
Short: "Apply tests", | ||
Run: createApplyFunc, | ||
} | ||
return cmd | ||
} | ||
|
||
func createApplyFunc(cmd *cobra.Command, args []string) { | ||
lg, logWriter, _, err := log.NewWithStderrWriter(logLevel, logOutputs) | ||
if err != nil { | ||
panic(err) | ||
} | ||
_ = zap.ReplaceGlobals(lg) | ||
|
||
cfg := metrics_server.Config{ | ||
EnablePrompt: enablePrompt, | ||
Logger: lg, | ||
LogWriter: logWriter, | ||
Namespace: namespace, | ||
ClientConfig: &client.Config{ | ||
Logger: lg, | ||
KubectlPath: kubectlPath, | ||
KubeConfigPath: kubeConfigPath, | ||
}, | ||
} | ||
|
||
ts := metrics_server.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-metrics-server 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) | ||
|
||
cfg := metrics_server.Config{ | ||
EnablePrompt: enablePrompt, | ||
Logger: lg, | ||
LogWriter: logWriter, | ||
Namespace: namespace, | ||
ClientConfig: &client.Config{ | ||
Logger: lg, | ||
KubectlPath: kubectlPath, | ||
KubeConfigPath: kubeConfigPath, | ||
}, | ||
} | ||
|
||
ts := metrics_server.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-metrics-server delete' success\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module github.com/aws/aws-k8s-tester/k8s-tester/metrics-server | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/aws/aws-k8s-tester/client v0.0.0-00010101000000-000000000000 | ||
github.com/aws/aws-k8s-tester/k8s-tester/tester v0.0.0-00010101000000-000000000000 | ||
github.com/aws/aws-k8s-tester/utils v0.0.0-00010101000000-000000000000 | ||
github.com/aws/aws-sdk-go v1.38.50 | ||
github.com/manifoldco/promptui v0.8.0 | ||
github.com/spf13/cobra v1.1.3 | ||
go.uber.org/zap v1.17.0 | ||
k8s.io/apimachinery v0.21.1 | ||
k8s.io/client-go v0.21.1 | ||
k8s.io/utils v0.0.0-20210305010621-2afb4311ab10 | ||
) | ||
|
||
replace ( | ||
github.com/aws/aws-k8s-tester/client => ../../client | ||
github.com/aws/aws-k8s-tester/k8s-tester/tester => ../tester | ||
github.com/aws/aws-k8s-tester/utils => ../../utils | ||
) |
Oops, something went wrong.