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

minikube update-context: Fix nil pointer dereference #8989

Merged

Conversation

superbrothers
Copy link
Member

Fixes #8988

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 13, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: superbrothers
To complete the pull request process, please assign medyagh
You can assign the PR to them by writing /assign @medyagh in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Member

@medyagh medyagh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am glad you are doing a PR to improve this, could you please add a subtest to our exiting UpdateContext integration test?

https://github.com/medyagh/minikube/blob/5c73732d767154d168604dac8a45d5e534978a33/test/integration/functional_test.go#L1010

you could do a subtest, by passing a KUBECONFIG env to the command that points to a problamtic kubeconfig.

for example, you can add something like this
https://github.com/medyagh/minikube/blob/5c73732d767154d168604dac8a45d5e534978a33/test/integration/functional_test.go#L1010-L1014
cmd= exec.CommandContext(ctx, Target(), "-p", profile, "update-context", "--alsologtostderr", "-v=2")
cmd.Env =..... (add a KUBECONFIG env here...you can create a dummy temp file or add the probalmatic kubeconfig to the testdata folder.
rr, err := Run(t,cmd)
if err != nil {
t.Errorf("failed to run minikube update-context: args %q: %v", rr.Command(), err)
}

@superbrothers
Copy link
Member Author

@medyagh OK, I'll add a subtest for Update Context, but we need to decide update-context command's behavior first.

If there is no minikube cluster in the kubeconfig (including if no clusters), add cluster, user and context settings to the kubeconfig, and set minikube to the current-context. This is the current behavior, but according to TestUpdateIP in pkg/minikube/kubeconfig_test.go, update-context command is originally expected to result in an error.

func TestUpdateIP(t *testing.T) {

	var tests = []struct {
		description string
		hostname    string
		port        int
		existing    []byte
		err         bool
		status      bool
		expCfg      []byte
	}{
		{
			description: "no minikube cluster",
			hostname:    "192.168.10.100",
			port:        8080,
			existing:    kubeConfigWithoutHTTPS,
			err:         true,
			expCfg:      kubeConfigWithoutHTTPS,
		},

@tstromberg tstromberg changed the title minikube upate-cotext: Fix nil pointer dereference minikube upate-context: Fix nil pointer dereference Aug 14, 2020
@sharifelgamal sharifelgamal changed the title minikube upate-context: Fix nil pointer dereference minikube update-context: Fix nil pointer dereference Aug 14, 2020
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 16, 2020
@superbrothers
Copy link
Member Author

superbrothers commented Aug 16, 2020

@medyagh I updated a subtest to our exiting UpdateContext integration test at eb01a2e.

$ env TEST_ARGS="-test.run=TestFunctional/parallel/UpdateContextCmd --profile=minikube --cleanup=false" make integration
go test -ldflags="-X k8s.io/minikube/pkg/version.version=v1.12.3 -X k8s.io/minikube/pkg/version.isoVersion=v1.12.2 -X k8s.io/minikube/pkg/version.isoPath=minikube/iso -X k8s.io/minikube/pkg/version.gitCommitID="3ecf887959389a85a04f4b3ba34f83f12b88536f-dirty" -X k8s.io/minikube/pkg/version.storageProvisionerVersion=v2" -v -test.timeout=90m ./test/integration --tags="integration container_image_ostree_stub containers_image_openpgp go_getter_nos3 go_getter_nogcs" -test.run=TestFunctional/parallel/UpdateContextCmd --profile=minikube --cleanup=false
Found 16 cores, limiting parallelism with --test.parallel=9
=== RUN   TestFunctional
=== PAUSE TestFunctional
=== CONT  TestFunctional
=== RUN   TestFunctional/parallel
=== RUN   TestFunctional/parallel/UpdateContextCmd
=== PAUSE TestFunctional/parallel/UpdateContextCmd
=== CONT  TestFunctional/parallel/UpdateContextCmd
=== RUN   TestFunctional/parallel/UpdateContextCmd/no_changes
=== PAUSE TestFunctional/parallel/UpdateContextCmd/no_changes
=== RUN   TestFunctional/parallel/UpdateContextCmd/no_minikube_cluster
=== PAUSE TestFunctional/parallel/UpdateContextCmd/no_minikube_cluster
=== RUN   TestFunctional/parallel/UpdateContextCmd/no_clusters
=== PAUSE TestFunctional/parallel/UpdateContextCmd/no_clusters
=== CONT  TestFunctional/parallel/UpdateContextCmd/no_changes
=== CONT  TestFunctional/parallel/UpdateContextCmd/no_clusters
=== CONT  TestFunctional/parallel/UpdateContextCmd/no_minikube_cluster
=== CONT  TestFunctional/parallel/UpdateContextCmd/no_changes
    functional_test.go:1082: (dbg) Run:  out/minikube -p minikube update-context --alsologtostderr -v=2
=== CONT  TestFunctional/parallel/UpdateContextCmd/no_minikube_cluster
    functional_test.go:1082: (dbg) Run:  out/minikube -p minikube update-context --alsologtostderr -v=2
=== CONT  TestFunctional/parallel/UpdateContextCmd/no_clusters
    functional_test.go:1082: (dbg) Run:  out/minikube -p minikube update-context --alsologtostderr -v=2
--- PASS: TestFunctional (0.39s)
    --- PASS: TestFunctional/parallel (0.00s)
        --- PASS: TestFunctional/parallel/UpdateContextCmd (0.00s)
            --- PASS: TestFunctional/parallel/UpdateContextCmd/no_changes (0.39s)
            --- PASS: TestFunctional/parallel/UpdateContextCmd/no_minikube_cluster (0.39s)
            --- PASS: TestFunctional/parallel/UpdateContextCmd/no_clusters (0.39s)
PASS
Tests completed in 388.50175ms (result code 0)
ok      k8s.io/minikube/test/integration        1.312s

@superbrothers
Copy link
Member Author

I'll squash the commits after the changes are reviewed.

@tstromberg
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Aug 17, 2020
Copy link
Contributor

@tstromberg tstromberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending integration tests

@minikube-pr-bot
Copy link

kvm2 Driver
docker Driver

@superbrothers
Copy link
Member Author

Some tests seem to be failing on items not related to this PR.

@tstromberg
Copy link
Contributor

I tested this locally and it works great. Thank you!

@tstromberg tstromberg merged commit dd11ed8 into kubernetes:master Aug 19, 2020
@superbrothers superbrothers deleted the fix-nil-pointer-dereference branch August 20, 2020 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

minikube update-context: invalid memory address or nil pointer dereference
5 participants