diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 8cc1ff09ab..9a93ffc29e 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -349,6 +349,7 @@ jobs: (New-Object Net.WebClient).DownloadFile("https://github.com/medyagh/gopogh/releases/download/v0.2.4/gopogh.exe", "C:\ProgramData\chocolatey\bin\gopogh.exe") choco install -y kubernetes-cli choco install -y jq + choco install -y caffeine if (Test-Path 'C:\Program Files\Docker\Docker\resources\bin\kubectl.exe') { Remove-Item 'C:\Program Files\Docker\Docker\resources\bin\kubectl.exe' }; - name: Run Integration Test in powershell continue-on-error: true @@ -485,6 +486,7 @@ jobs: (New-Object Net.WebClient).DownloadFile("https://github.com/medyagh/gopogh/releases/download/v0.2.4/gopogh.exe", "C:\ProgramData\chocolatey\bin\gopogh.exe") choco install -y kubernetes-cli choco install -y jq + choco install -y caffeine if (Test-Path 'C:\Program Files\Docker\Docker\resources\bin\kubectl.exe') { Remove-Item 'C:\Program Files\Docker\Docker\resources\bin\kubectl.exe' }; - name: Run Integration Test in powershell continue-on-error: true diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 8b9f86d83f..0f67bafe87 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -347,6 +347,7 @@ jobs: (New-Object Net.WebClient).DownloadFile("https://github.com/medyagh/gopogh/releases/download/v0.2.4/gopogh.exe", "C:\ProgramData\chocolatey\bin\gopogh.exe") choco install -y kubernetes-cli choco install -y jq + choco install -y caffeine if (Test-Path 'C:\Program Files\Docker\Docker\resources\bin\kubectl.exe') { Remove-Item 'C:\Program Files\Docker\Docker\resources\bin\kubectl.exe' }; - name: Run Integration Test in powershell continue-on-error: true @@ -483,6 +484,7 @@ jobs: (New-Object Net.WebClient).DownloadFile("https://github.com/medyagh/gopogh/releases/download/v0.2.4/gopogh.exe", "C:\ProgramData\chocolatey\bin\gopogh.exe") choco install -y kubernetes-cli choco install -y jq + choco install -y caffeine if (Test-Path 'C:\Program Files\Docker\Docker\resources\bin\kubectl.exe') { Remove-Item 'C:\Program Files\Docker\Docker\resources\bin\kubectl.exe' }; - name: Run Integration Test in powershell continue-on-error: true diff --git a/go.mod b/go.mod index 51b5d12766..78f91ae7da 100644 --- a/go.mod +++ b/go.mod @@ -72,7 +72,6 @@ require ( github.com/zchee/go-vmnet v0.0.0-20161021174912-97ebf9174097 golang.org/x/build v0.0.0-20190927031335-2835ba2e683f golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 - golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6 // indirect golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a golang.org/x/sys v0.0.0-20200523222454-059865788121 diff --git a/pkg/drivers/kic/types.go b/pkg/drivers/kic/types.go index 87c51ad915..a374da2a13 100644 --- a/pkg/drivers/kic/types.go +++ b/pkg/drivers/kic/types.go @@ -24,9 +24,9 @@ import ( const ( // Version is the current version of kic - Version = "v0.0.11" + Version = "v0.0.12-snapshot" // SHA of the kic base image - baseImageSHA = "6fee59db7d67ed8ae6835e4bcb02f32056dc95f11cb369c51e352b62dd198aa0" + baseImageSHA = "7be40a42fdfec56fbf7bc9de07ea2ed4a931cbb70dccb8612b2ba13763bf4568" ) var ( diff --git a/pkg/minikube/kubeconfig/kubeconfig.go b/pkg/minikube/kubeconfig/kubeconfig.go index 566353eb32..5cda239f2c 100644 --- a/pkg/minikube/kubeconfig/kubeconfig.go +++ b/pkg/minikube/kubeconfig/kubeconfig.go @@ -123,8 +123,8 @@ func UpdateEndpoint(contextName string, hostname string, port int, confpath stri address := "https://" + hostname + ":" + strconv.Itoa(port) - // if the kubeconfig is missed, create new one - if len(cfg.Clusters) == 0 { + // if the cluster setting is missed in the kubeconfig, create new one + if _, ok := cfg.Clusters[contextName]; !ok { lp := localpath.Profile(contextName) gp := localpath.MiniPath() kcs := &Settings{ @@ -139,8 +139,10 @@ func UpdateEndpoint(contextName string, hostname string, port int, confpath stri if err != nil { return false, errors.Wrap(err, "populating kubeconfig") } + } else { + cfg.Clusters[contextName].Server = address } - cfg.Clusters[contextName].Server = address + err = writeToFile(cfg, confpath) if err != nil { return false, errors.Wrap(err, "write") diff --git a/pkg/minikube/kubeconfig/kubeconfig_test.go b/pkg/minikube/kubeconfig/kubeconfig_test.go index 6eb05cdcff..5507f8142b 100644 --- a/pkg/minikube/kubeconfig/kubeconfig_test.go +++ b/pkg/minikube/kubeconfig/kubeconfig_test.go @@ -25,6 +25,7 @@ import ( "k8s.io/client-go/tools/clientcmd/api" "k8s.io/minikube/pkg/minikube/constants" + "k8s.io/minikube/pkg/minikube/localpath" "k8s.io/client-go/tools/clientcmd" ) @@ -51,6 +52,40 @@ users: client-key: /home/la-croix/apiserver.key `) +var kubeConfigWithoutHTTPSUpdated = []byte(` +apiVersion: v1 +clusters: +- cluster: + certificate-authority: /home/la-croix/apiserver.crt + server: 192.168.1.1:8080 + name: la-croix +- cluster: + certificate-authority: /home/la-croix/.minikube/ca.crt + server: https://192.168.10.100:8080 + name: minikube +contexts: +- context: + cluster: la-croix + user: la-croix + name: la-croix +- context: + cluster: minikube + user: minikube + name: minikube +current-context: minikube +kind: Config +preferences: {} +users: +- name: la-croix + user: + client-certificate: /home/la-croix/apiserver.crt + client-key: /home/la-croix/apiserver.key +- name: minikube + user: + client-certificate: /home/la-croix/.minikube/profiles/minikube/client.crt + client-key: /home/la-croix/.minikube/profiles/minikube/client.key +`) + var kubeConfig192 = []byte(` apiVersion: v1 clusters: @@ -117,6 +152,37 @@ users: client-key: /home/la-croix/apiserver.key `) +var kubeConfigNoClusters = []byte(` +apiVersion: v1 +clusters: +contexts: +kind: Config +preferences: {} +users: +`) + +var kubeConfigNoClustersUpdated = []byte(` +apiVersion: v1 +clusters: +- cluster: + certificate-authority: /home/la-croix/.minikube/ca.crt + server: https://192.168.10.100:8080 + name: minikube +contexts: +- context: + cluster: minikube + user: minikube + name: minikube +current-context: minikube +kind: Config +preferences: {} +users: +- name: minikube + user: + client-certificate: /home/la-croix/.minikube/profiles/minikube/client.crt + client-key: /home/la-croix/.minikube/profiles/minikube/client.key +`) + func TestUpdate(t *testing.T) { setupCfg := &Settings{ ClusterName: "test", @@ -300,8 +366,8 @@ func TestUpdateIP(t *testing.T) { hostname: "192.168.10.100", port: 8080, existing: kubeConfigWithoutHTTPS, - err: true, - expCfg: kubeConfigWithoutHTTPS, + status: true, + expCfg: kubeConfigWithoutHTTPSUpdated, }, { description: "same IP", @@ -326,8 +392,20 @@ func TestUpdateIP(t *testing.T) { status: true, expCfg: kubeConfigLocalhost12345, }, + { + description: "no clusters", + hostname: "192.168.10.100", + port: 8080, + existing: kubeConfigNoClusters, + status: true, + expCfg: kubeConfigNoClustersUpdated, + }, } + + os.Setenv(localpath.MinikubeHome, "/home/la-croix") + for _, test := range tests { + test := test t.Run(test.description, func(t *testing.T) { t.Parallel() configFilename := tempFile(t, test.existing) @@ -342,6 +420,18 @@ func TestUpdateIP(t *testing.T) { if test.status != statusActual { t.Errorf("Expected status %t, but got %t", test.status, statusActual) } + + actual, err := readOrNew(configFilename) + if err != nil { + t.Fatal(err) + } + expected, err := decode(test.expCfg) + if err != nil { + t.Fatal(err) + } + if !configEquals(actual, expected) { + t.Fatal("configs did not match") + } }) } diff --git a/site/content/en/docs/commands/start.md b/site/content/en/docs/commands/start.md index 22aae361d2..6fc33a0a18 100644 --- a/site/content/en/docs/commands/start.md +++ b/site/content/en/docs/commands/start.md @@ -27,7 +27,7 @@ minikube start [flags] --apiserver-names stringArray A set of apiserver names which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine --apiserver-port int The apiserver listening port (default 8443) --auto-update-drivers If set, automatically updates drivers to the latest version. Defaults to true. (default true) - --base-image string The base image to use for docker/podman drivers. Intended for local development. (default "gcr.io/k8s-minikube/kicbase:v0.0.11@sha256:6fee59db7d67ed8ae6835e4bcb02f32056dc95f11cb369c51e352b62dd198aa0") + --base-image string The base image to use for docker/podman drivers. Intended for local development. (default "gcr.io/k8s-minikube/kicbase:v0.0.12-snapshot@sha256:7be40a42fdfec56fbf7bc9de07ea2ed4a931cbb70dccb8612b2ba13763bf4568") --cache-images If true, cache docker images for the current bootstrapper and load them into the machine. Always false with --driver=none. (default true) --cni string CNI plug-in to use. Valid options: auto, bridge, calico, cilium, flannel, kindnet, or path to a CNI manifest (default: auto) --container-runtime string The container runtime to be used (docker, cri-o, containerd). (default "docker") diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index e2a82a726a..c9b6abb4b3 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -1007,14 +1007,86 @@ func validateCertSync(ctx context.Context, t *testing.T, profile string) { func validateUpdateContextCmd(ctx context.Context, t *testing.T, profile string) { defer PostMortemLogs(t, profile) - rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "update-context", "--alsologtostderr", "-v=2")) - if err != nil { - t.Errorf("failed to run minikube update-context: args %q: %v", rr.Command(), err) + tests := []struct { + name string + kubeconfig []byte + want []byte + }{ + { + name: "no changes", + kubeconfig: nil, + want: []byte("No changes"), + }, + { + name: "no minikube cluster", + kubeconfig: []byte(` +apiVersion: v1 +clusters: +- cluster: + certificate-authority: /home/la-croix/apiserver.crt + server: 192.168.1.1:8080 + name: la-croix +contexts: +- context: + cluster: la-croix + user: la-croix + name: la-croix +current-context: la-croix +kind: Config +preferences: {} +users: +- name: la-croix + user: + client-certificate: /home/la-croix/apiserver.crt + client-key: /home/la-croix/apiserver.key +`), + want: []byte("context has been updated"), + }, + { + name: "no clusters", + kubeconfig: []byte(` +apiVersion: v1 +clusters: +contexts: +kind: Config +preferences: {} +users: +`), + want: []byte("context has been updated"), + }, } - want := []byte("No changes") - if !bytes.Contains(rr.Stdout.Bytes(), want) { - t.Errorf("update-context: got=%q, want=*%q*", rr.Stdout.Bytes(), want) + for _, tc := range tests { + tc := tc + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + c := exec.CommandContext(ctx, Target(), "-p", profile, "update-context", "--alsologtostderr", "-v=2") + if tc.kubeconfig != nil { + tf, err := ioutil.TempFile("", "kubeconfig") + if err != nil { + t.Fatal(err) + } + + if err := ioutil.WriteFile(tf.Name(), tc.kubeconfig, 0644); err != nil { + t.Fatal(err) + } + + t.Cleanup(func() { + os.Remove(tf.Name()) + }) + + c.Env = append(os.Environ(), fmt.Sprintf("KUBECONFIG=%s", tf.Name())) + } + + rr, err := Run(t, c) + if err != nil { + t.Errorf("failed to run minikube update-context: args %q: %v", rr.Command(), err) + } + + if !bytes.Contains(rr.Stdout.Bytes(), tc.want) { + t.Errorf("update-context: got=%q, want=*%q*", rr.Stdout.Bytes(), tc.want) + } + }) } }