From 241983d2f7873eca18e91fa80218eb0025f45a31 Mon Sep 17 00:00:00 2001 From: soharab-ic <156293296+soharab-ic@users.noreply.github.com> Date: Tue, 7 May 2024 11:18:22 +0530 Subject: [PATCH] Fix `fission check` command doesnt work for namespace other than `fission` (#2932) * Fix `fission check` command which does not work outside of `fission` namespace If user provide namespace then use it for running `fission check` command. If user does not provide namespace then use `fission` as default namespace. * Update go version to 1.22.2 --------- Signed-off-by: Md Soharab Ansari --- go.mod | 2 +- pkg/fission-cli/cmd/check/check.go | 9 ++++++++- pkg/fission-cli/util/constants.go | 11 ++++++----- pkg/healthcheck/healthcheck.go | 8 ++++++-- test/e2e/cli/cli_test.go | 5 +++++ 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 5d2a5006..d904a817 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/fission/fission -go 1.22 +go 1.22.2 require ( dario.cat/mergo v1.0.0 diff --git a/pkg/fission-cli/cmd/check/check.go b/pkg/fission-cli/cmd/check/check.go index 43717577..0c5a0655 100644 --- a/pkg/fission-cli/cmd/check/check.go +++ b/pkg/fission-cli/cmd/check/check.go @@ -14,6 +14,8 @@ limitations under the License. package check import ( + "fmt" + "github.com/fission/fission/pkg/fission-cli/cliwrapper/cli" "github.com/fission/fission/pkg/fission-cli/cmd" flagkey "github.com/fission/fission/pkg/fission-cli/flag/key" @@ -32,13 +34,18 @@ func (opts *CheckSubCommand) do(input cli.Input) error { checks := []healthcheck.CategoryID{} + userProvidedNS, _, err := opts.GetResourceNamespace(input, flagkey.Namespace) + if err != nil { + return fmt.Errorf("error retrieving user provided namespace information: %w", err) + } + if input.IsSet(flagkey.PreCheckOnly) { checks = append(checks, healthcheck.Kubernetes) } else { checks = append(checks, healthcheck.FissionServices, healthcheck.FissionVersion) } - hc := healthcheck.NewHealthChecker(opts.Client(), checks) + hc := healthcheck.NewHealthChecker(opts.Client(), checks, userProvidedNS) healthcheck.RunChecks(input.Context(), input, opts.Client(), hc) return nil diff --git a/pkg/fission-cli/util/constants.go b/pkg/fission-cli/util/constants.go index bafdec87..e9f56770 100644 --- a/pkg/fission-cli/util/constants.go +++ b/pkg/fission-cli/util/constants.go @@ -18,11 +18,12 @@ package util // fission-cli options const ( - SPEC_IGNORE_FILE = ".specignore" - COMMIT_LABEL = "commit" - FISSION_AUTH_URI = "/auth/login" - FISSION_AUTH_TOKEN = "FISSION_AUTH_TOKEN" - FISSION_STORAGE_URI = "/v1/archive" + SPEC_IGNORE_FILE = ".specignore" + COMMIT_LABEL = "commit" + FISSION_AUTH_URI = "/auth/login" + FISSION_AUTH_TOKEN = "FISSION_AUTH_TOKEN" + FISSION_STORAGE_URI = "/v1/archive" + FISSION_DEFAULT_NAMESPACE = "fission" ) const ( diff --git a/pkg/healthcheck/healthcheck.go b/pkg/healthcheck/healthcheck.go index cbcd9828..7b22e07c 100644 --- a/pkg/healthcheck/healthcheck.go +++ b/pkg/healthcheck/healthcheck.go @@ -203,10 +203,14 @@ func (hc *HealthChecker) allCategories() []*Category { } } -func NewHealthChecker(cmd cmd.Client, categoryIDs []CategoryID) *HealthChecker { +func NewHealthChecker(cmd cmd.Client, categoryIDs []CategoryID, fissionNamespace string) *HealthChecker { + if fissionNamespace == "" { + fissionNamespace = util.FISSION_DEFAULT_NAMESPACE + } + hc := &HealthChecker{ kubeAPI: cmd.KubernetesClient, - fissionNamespace: "fission", + fissionNamespace: fissionNamespace, } hc.categories = hc.allCategories() diff --git a/test/e2e/cli/cli_test.go b/test/e2e/cli/cli_test.go index 5c5a81f2..5a965b52 100644 --- a/test/e2e/cli/cli_test.go +++ b/test/e2e/cli/cli_test.go @@ -366,6 +366,11 @@ func TestFissionCLI(t *testing.T) { require.NoError(t, err) }) + t.Run("check --namespace", func(t *testing.T) { + _, err := cli.ExecCommand(f, ctx, "check", "--namespace", "default") + require.NoError(t, err) + }) + t.Run("version", func(t *testing.T) { _, err := cli.ExecCommand(f, ctx, "version") require.NoError(t, err)