Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
cli/cmd/health.go: remove check if kubeconfig exists
Browse files Browse the repository at this point in the history
The subcommand function will fail anyway while trying to read kubeconfig
file, so there is no need to check it twice.

Also part of #608.

Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
  • Loading branch information
invidian committed Jul 1, 2020
1 parent 47a64c1 commit d98d7d8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
7 changes: 3 additions & 4 deletions cli/cmd/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ import (
)

var healthCmd = &cobra.Command{
Use: "health",
Short: "Get the health of a cluster",
Run: runHealth,
PersistentPreRunE: doesKubeconfigExist,
Use: "health",
Short: "Get the health of a cluster",
Run: runHealth,
}

func init() {
Expand Down
14 changes: 0 additions & 14 deletions cli/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

"github.com/hashicorp/hcl/v2"
"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/kinvolk/lokomotive/pkg/backend"
Expand Down Expand Up @@ -161,19 +160,6 @@ func assetsKubeconfig(assetDir string) string {
return filepath.Join(assetDir, "cluster-assets", "auth", "kubeconfig")
}

// doesKubeconfigExist checks if the kubeconfig provided by user exists
func doesKubeconfigExist(*cobra.Command, []string) error {
var err error
kubeconfig, err := getKubeconfig()
if err != nil {
return err
}
if _, err = os.Stat(kubeconfig); os.IsNotExist(err) {
return fmt.Errorf("Kubeconfig %q not found", kubeconfig)
}
return err
}

func getLokoConfig() (*config.Config, hcl.Diagnostics) {
return config.LoadConfig(viper.GetString("lokocfg"), viper.GetString("lokocfg-vars"))
}
Expand Down

0 comments on commit d98d7d8

Please sign in to comment.