Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix update-context to use KUBECONFIG when the env is set #6090

Merged
merged 1 commit into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion cmd/minikube/cmd/update-context.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package cmd

import (
"os"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"k8s.io/minikube/pkg/minikube/cluster"
Expand Down Expand Up @@ -45,7 +47,13 @@ var updateContextCmd = &cobra.Command{
if err != nil {
exit.WithError("Error host driver ip status", err)
}
updated, err := kubeconfig.UpdateIP(ip, machineName, constants.KubeconfigPath)
updated := false
kubeConfigPath := os.Getenv("KUBECONFIG")
if kubeConfigPath == "" {
updated, err = kubeconfig.UpdateIP(ip, machineName, constants.KubeconfigPath)
} else {
updated, err = kubeconfig.UpdateIP(ip, machineName, kubeConfigPath)
}
if err != nil {
exit.WithError("update config", err)
}
Expand Down
14 changes: 14 additions & 0 deletions test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func TestFunctional(t *testing.T) {
{"SSHCmd", validateSSHCmd},
{"MySQL", validateMySQL},
{"FileSync", validateFileSync},
{"UpdateContextCmd", validateUpdateContextCmd},
}
for _, tc := range tests {
tc := tc
Expand Down Expand Up @@ -645,6 +646,19 @@ func validateFileSync(ctx context.Context, t *testing.T, profile string) {
}
}

// validateUpdateContextCmd asserts basic "update-context" command functionality
func validateUpdateContextCmd(ctx context.Context, t *testing.T, profile string) {
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "update-context", "--alsologtostderr", "-v=2"))
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}

want := []byte("IP was already correctly configured")
if !bytes.Contains(rr.Stdout.Bytes(), want) {
t.Errorf("update-context: got=%q, want=*%q*", rr.Stdout.Bytes(), want)
}
}

// startHTTPProxy runs a local http proxy and sets the env vars for it.
func startHTTPProxy(t *testing.T) (*http.Server, error) {
port, err := freeport.GetFreePort()
Expand Down