From b87d04e629de85dfcf382c2f26ffd41c396429ce Mon Sep 17 00:00:00 2001 From: Sunny Date: Fri, 10 May 2024 14:45:31 +0000 Subject: [PATCH] tests/int: Run flux check after installation Run flux check after installation to show the relevant cluster and resource configurations in the environment. Signed-off-by: Sunny --- tests/integration/suite_test.go | 10 ++++++++++ tests/integration/util_test.go | 13 ++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/tests/integration/suite_test.go b/tests/integration/suite_test.go index 7a016fb6..0b55c4c2 100644 --- a/tests/integration/suite_test.go +++ b/tests/integration/suite_test.go @@ -53,6 +53,9 @@ const ( // kubeconfigPath is the path of the file containing the kubeconfig kubeconfigPath = "./build/kubeconfig" + // fluxBin is the path to the flux binary. + fluxBin = "./build/flux" + // default branch to be used when cloning git repositories defaultBranch = "main" @@ -291,6 +294,13 @@ func TestMain(m *testing.M) { panic(fmt.Sprintf("error installing Flux: %v", err)) } + // On check failure, log and continue. Controllers may be ready by the time + // tests run. + log.Println("Running flux check") + if err := runFluxCheck(ctx); err != nil { + log.Printf("flux check failed: %v\n", err) + } + log.Println("Running e2e tests") exitCode = m.Run() } diff --git a/tests/integration/util_test.go b/tests/integration/util_test.go index 2f6b6a66..9d1c4637 100644 --- a/tests/integration/util_test.go +++ b/tests/integration/util_test.go @@ -92,17 +92,24 @@ func installFlux(ctx context.Context, tmpDir string, kubeconfigPath string) erro bootstrapArgs = fmt.Sprintf("--token-auth --password=%s", cfg.gitPat) } - bootstrapCmd := fmt.Sprintf("./build/flux bootstrap git --url=%s %s --kubeconfig=%s --path=clusters/e2e "+ + bootstrapCmd := fmt.Sprintf("%s bootstrap git --url=%s %s --kubeconfig=%s --path=clusters/e2e "+ " --components-extra image-reflector-controller,image-automation-controller", - repoURL, bootstrapArgs, kubeconfigPath) + fluxBin, repoURL, bootstrapArgs, kubeconfigPath) return tftestenv.RunCommand(ctx, "./", bootstrapCmd, tftestenv.RunCommandOptions{ Timeout: 15 * time.Minute, }) } +func runFluxCheck(ctx context.Context) error { + checkCmd := fmt.Sprintf("%s check --kubeconfig %s", fluxBin, kubeconfigPath) + return tftestenv.RunCommand(ctx, "./", checkCmd, tftestenv.RunCommandOptions{ + AttachConsole: true, + }) +} + func uninstallFlux(ctx context.Context) error { - uninstallCmd := fmt.Sprintf("./build/flux uninstall --kubeconfig %s -s", kubeconfigPath) + uninstallCmd := fmt.Sprintf("%s uninstall --kubeconfig %s -s", fluxBin, kubeconfigPath) if err := tftestenv.RunCommand(ctx, "./", uninstallCmd, tftestenv.RunCommandOptions{ Timeout: 15 * time.Minute, }); err != nil {