Skip to content

Commit 3929611

Browse files
anencore94sophalHongwoohhan
authored andcommitted
Fix to kubeConfigPath could be set from env (kubernetes#6568)
* Fix to kubeConfigPath could be set from env Fix to use kubeConfigPath by using kubeconfig.PathFromEnv function not from just $HOME/.kube/config Co-authored-by: sopahlHong <[email protected]> Co-authored-by: woohhan <[email protected]> Signed-off-by: anencore94 <[email protected]> * Delete redundant logic to get kubeConfigPath - change to use already present util function to set up kubeConfigPath Co-authored-by: sopahlHong <[email protected]> Co-authored-by: woohhan <[email protected]> Signed-off-by: anencore94 <[email protected]> Co-authored-by: SOPHAL HONG <[email protected]> Co-authored-by: Woohyung Han <[email protected]>
1 parent 8659b29 commit 3929611

File tree

3 files changed

+3
-14
lines changed

3 files changed

+3
-14
lines changed

cmd/minikube/cmd/config/profile.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/spf13/viper"
2424
pkgConfig "k8s.io/minikube/pkg/minikube/config"
2525
pkg_config "k8s.io/minikube/pkg/minikube/config"
26-
"k8s.io/minikube/pkg/minikube/constants"
2726
"k8s.io/minikube/pkg/minikube/exit"
2827
"k8s.io/minikube/pkg/minikube/kubeconfig"
2928
"k8s.io/minikube/pkg/minikube/out"
@@ -87,7 +86,7 @@ var ProfileCmd = &cobra.Command{
8786
out.SuccessT("Skipped switching kubectl context for {{.profile_name}} because --keep-context was set.", out.V{"profile_name": profile})
8887
out.SuccessT("To connect to this cluster, use: kubectl --context={{.profile_name}}", out.V{"profile_name": profile})
8988
} else {
90-
err := kubeconfig.SetCurrentContext(profile, constants.KubeconfigPath)
89+
err := kubeconfig.SetCurrentContext(profile, kubeconfig.PathFromEnv())
9190
if err != nil {
9291
out.ErrT(out.Sad, `Error while setting kubectl current context : {{.error}}`, out.V{"error": err})
9392
}

cmd/minikube/cmd/stop.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/spf13/viper"
2727
"k8s.io/minikube/pkg/minikube/cluster"
2828
pkg_config "k8s.io/minikube/pkg/minikube/config"
29-
"k8s.io/minikube/pkg/minikube/constants"
3029
"k8s.io/minikube/pkg/minikube/exit"
3130
"k8s.io/minikube/pkg/minikube/kubeconfig"
3231
"k8s.io/minikube/pkg/minikube/machine"
@@ -82,7 +81,7 @@ func runStop(cmd *cobra.Command, args []string) {
8281
out.T(out.WarningType, "Unable to kill mount process: {{.error}}", out.V{"error": err})
8382
}
8483

85-
err = kubeconfig.UnsetCurrentContext(profile, constants.KubeconfigPath)
84+
err = kubeconfig.UnsetCurrentContext(profile, kubeconfig.PathFromEnv())
8685
if err != nil {
8786
exit.WithError("update config", err)
8887
}

cmd/minikube/cmd/update-context.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ limitations under the License.
1717
package cmd
1818

1919
import (
20-
"os"
21-
2220
"github.com/spf13/cobra"
2321
"github.com/spf13/viper"
2422
"k8s.io/minikube/pkg/minikube/cluster"
2523
"k8s.io/minikube/pkg/minikube/config"
26-
"k8s.io/minikube/pkg/minikube/constants"
2724
"k8s.io/minikube/pkg/minikube/exit"
2825
"k8s.io/minikube/pkg/minikube/kubeconfig"
2926
"k8s.io/minikube/pkg/minikube/machine"
@@ -47,13 +44,7 @@ var updateContextCmd = &cobra.Command{
4744
if err != nil {
4845
exit.WithError("Error host driver ip status", err)
4946
}
50-
var updated bool
51-
kubeConfigPath := os.Getenv("KUBECONFIG")
52-
if kubeConfigPath == "" {
53-
updated, err = kubeconfig.UpdateIP(ip, machineName, constants.KubeconfigPath)
54-
} else {
55-
updated, err = kubeconfig.UpdateIP(ip, machineName, kubeConfigPath)
56-
}
47+
updated, err := kubeconfig.UpdateIP(ip, machineName, kubeconfig.PathFromEnv())
5748
if err != nil {
5849
exit.WithError("update config", err)
5950
}

0 commit comments

Comments
 (0)