Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #403 from wwitzel3/issue-150
Browse files Browse the repository at this point in the history
fix issue with kubeconfig not being fetched correctly from envvar
  • Loading branch information
wwitzel3 authored Nov 5, 2019
2 parents b7a648f + da2f5fa commit ea9a130
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
14 changes: 6 additions & 8 deletions internal/commands/dash.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
)

func newOctantCmd(version string) *cobra.Command {
var kubeConfig string
var verboseLevel int

octantCmd := &cobra.Command{
Expand Down Expand Up @@ -69,11 +68,15 @@ func newOctantCmd(version string) *cobra.Command {

logger.Debugf("disable-open-browser: %s", viper.Get("disable-open-browser"))

if viper.GetString("kubeconfig") == "" {
viper.Set("kubeconfig", clientcmd.NewDefaultClientConfigLoadingRules().GetDefaultFilename())
}

go func() {
options := dash.Options{
DisableClusterOverview: viper.GetBool("disable-cluster-overview"),
EnableOpenCensus: viper.GetBool("enable-opencensus"),
KubeConfig: kubeConfig,
KubeConfig: viper.GetString("kubeconfig"),
Namespace: viper.GetString("namespace"),
FrontendURL: viper.GetString("ui-url"),
Context: viper.GetString("context"),
Expand Down Expand Up @@ -134,12 +137,7 @@ func newOctantCmd(version string) *cobra.Command {
octantCmd.Flags().BoolP("disable-cluster-overview", "", false, "disable cluster overview")
octantCmd.Flags().BoolP("disable-open-browser", "", false, "disable automatic launching of the browser")

kubeConfig = viper.GetString("kubeconfig")
if kubeConfig == "" {
kubeConfig = clientcmd.NewDefaultClientConfigLoadingRules().GetDefaultFilename()
}

octantCmd.Flags().StringVar(&kubeConfig, "kubeconfig", kubeConfig, "absolute path to kubeConfig file")
octantCmd.Flags().String("kubeconfig", "", "absolute path to kubeConfig file")

return octantCmd
}
Expand Down
35 changes: 35 additions & 0 deletions internal/commands/dash_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright (c) 2019 the Octant contributors. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package commands

import (
"os"
"testing"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test_bindViper_KUBECONFIG(t *testing.T) {
cmd := &cobra.Command{}

expected := "/testdata/kubeconfig.yml"
os.Setenv("KUBECONFIG", expected)
defer os.Unsetenv("KUBECONFIG")

// Before bindViper
actual := viper.GetString("kubeconfig")
assert.Equal(t, "", actual)

err := bindViper(cmd)
require.NoError(t, err)

// After bindViper
actual = viper.GetString("kubeconfig")
assert.Equal(t, expected, actual)
}

0 comments on commit ea9a130

Please sign in to comment.