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 Jun 16, 2020
1 parent a120f93 commit c8ac2a7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 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
15 changes: 0 additions & 15 deletions cli/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ package cmd

import (
"fmt"
"os"
"path/filepath"

"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 @@ -127,19 +125,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 c8ac2a7

Please sign in to comment.