Skip to content

Commit

Permalink
Add an explicit --cleanup from command line
Browse files Browse the repository at this point in the history
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
  • Loading branch information
dims committed Dec 24, 2023
1 parent 9562545 commit d636b8f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ $ bin/hydrophone --help
Usage of bin/hydrophone:
-busybox-image string
specify an alternate busybox container image. (default "registry.k8s.io/e2e-test-images/busybox:1.36.1-1")
-cleanup
cleanup resources (pods, namespaces etc).
-conformance
run conformance tests.
-conformance-image string
Expand Down
15 changes: 10 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ func main() {
config, clientSet := service.Init(cfg)
client.ClientSet = clientSet

common.ValidateArgs(client.ClientSet, config, cfg)
common.PrintInfo(client.ClientSet, config)

service.RunE2E(client.ClientSet, cfg)
client.PrintE2ELogs()
client.FetchFiles(config, clientSet, cfg.OutputDir)
service.Cleanup(client.ClientSet)
if cfg.Cleanup {
service.Cleanup(client.ClientSet)
} else {
common.ValidateArgs(client.ClientSet, config, cfg)

service.RunE2E(client.ClientSet, cfg)
client.PrintE2ELogs()
client.FetchFiles(config, clientSet, cfg.OutputDir)
service.Cleanup(client.ClientSet)
}
log.Println("Exiting with code: ", client.ExitCode)
os.Exit(client.ExitCode)
}
14 changes: 10 additions & 4 deletions pkg/common/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ type ArgConfig struct {

// DryRun to indicate whether to run ginkgo in dry run mode
DryRun bool

// Cleanup indicates we should just cleanup the resources
Cleanup bool
}

func InitArgs() (*ArgConfig, error) {
Expand All @@ -83,6 +86,7 @@ func InitArgs() (*ArgConfig, error) {
flag.StringVar(&cfg.OutputDir, "output-dir", outputDir, "directory for logs.")
flag.BoolVar(&cfg.ConformanceTests, "conformance", false, "run conformance tests.")
flag.BoolVar(&cfg.DryRun, "dry-run", false, "run in dry run mode.")
flag.BoolVar(&cfg.Cleanup, "cleanup", false, "cleanup resources (pods, namespaces etc).")

flag.Parse()

Expand All @@ -104,19 +108,21 @@ func InitArgs() (*ArgConfig, error) {
return &cfg, nil
}

func ValidateArgs(clientSet *kubernetes.Clientset, config *rest.Config, cfg *ArgConfig) {
func PrintInfo(clientSet *kubernetes.Clientset, config *rest.Config) {
serverVersion, err := clientSet.ServerVersion()
if err != nil {
log.Fatal("Error fetching server version: ", err)
}

log.Printf("API endpoint : %s", config.Host)
log.Printf("Server version : %#v", *serverVersion)
}

func ValidateArgs(clientSet *kubernetes.Clientset, config *rest.Config, cfg *ArgConfig) {
if cfg.ConformanceTests {
cfg.Focus = "\\[Conformance\\]"
}

log.Printf("API endpoint : %s", config.Host)
log.Printf("Server version : %#v", *serverVersion)
log.Printf("Running tests : '%s'", cfg.Focus)
if cfg.Skip != "" {
log.Printf("Skipping tests : '%s'", cfg.Skip)
}
Expand Down

0 comments on commit d636b8f

Please sign in to comment.