Skip to content

fix: ignore kubeconfig parse errors when listing profiles#23300

Open
immanuwell wants to merge 1 commit into
kubernetes:masterfrom
immanuwell:fix-list-profiles-invalid-kubeconfig
Open

fix: ignore kubeconfig parse errors when listing profiles#23300
immanuwell wants to merge 1 commit into
kubernetes:masterfrom
immanuwell:fix-list-profiles-invalid-kubeconfig

Conversation

@immanuwell

Copy link
Copy Markdown

minikube profile list should not faceplant when KUBECONFIG is malformed.

We only read kubeconfig here to mark the active kubecontext column. This keeps profile discovery working and just leaves ActiveKubeContext unset if kubeconfig parsing blows up. small bug, pretty user visible.

Repro:

tmp=$(mktemp)
printf 'not: [valid\n' > "$tmp"
KUBECONFIG="$tmp" minikube profile list

Before this, profile discovery could fail and no profiles were returned.
After this, profiles still show up, just no active kubecontext marker. all good.

Tests:

KUBECONFIG="$tmp" go test ./pkg/minikube/config -run TestListProfiles -count=1
go test ./pkg/minikube/config -count=1

@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: immanuwell
Once this PR has been reviewed and has the lgtm label, please assign comradeprogrammer for approval. For more information see the Code Review Process.

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

Details 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

@kubernetes-prow kubernetes-prow Bot requested review from nirs and prezha July 4, 2026 10:48
@kubernetes-prow kubernetes-prow Bot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 4, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @immanuwell!

It looks like this is your first PR to kubernetes/minikube 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/minikube has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@kubernetes-prow kubernetes-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 4, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Hi @immanuwell. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kubernetes-prow kubernetes-prow Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 4, 2026
@minikube-bot

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@nirs

nirs commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

@immanuwell Thanks of the change. I could reproduce the issue and created #23301. Let's discuss the wanted behavior first in the issue.

@nirs nirs left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@immanuwell Thanks!, see suggestion improving the warning.

Comment thread pkg/minikube/config/profile_test.go Outdated
Comment thread pkg/minikube/config/profile.go Outdated
Comment thread pkg/minikube/config/profile_test.go Outdated
@immanuwell immanuwell force-pushed the fix-list-profiles-invalid-kubeconfig branch from 4f8e482 to ef12374 Compare July 11, 2026 10:45
@immanuwell

Copy link
Copy Markdown
Author

@nirs addressed all your suggestions, PTAL

@immanuwell immanuwell requested a review from nirs July 11, 2026 11:00
@nirs

nirs commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Testing with the fix:

minikube profile list

% minikube profile list
❗  Unable to determine the current kubeconfig context: Error getting kubeconfig status: decode kubeconfig from "/Users/nir/.kube/config": decode data: not: [valid
: yaml: line 1: did not find expected ',' or ']'
E0711 22:44:15.321842   28706 status.go:457] kubeconfig endpoint: get endpoint: read kubeconfig: decode kubeconfig from "/Users/nir/.kube/config": decode data: not: [valid
: yaml: line 1: did not find expected ',' or ']'
┌──────────┬────────┬─────────┬──────────────┬─────────┬────────┬───────┬────────────────┬────────────────────┐
│ PROFILE  │ DRIVER │ RUNTIME │      IP      │ VERSION │ STATUS │ NODES │ ACTIVE PROFILE │ ACTIVE KUBECONTEXT │
├──────────┼────────┼─────────┼──────────────┼─────────┼────────┼───────┼────────────────┼────────────────────┤
│ minikube │ vfkit  │ docker  │ 192.168.64.3 │ v1.36.2 │ OK     │ 1     │ *              │                    │
└──────────┴────────┴─────────┴──────────────┴─────────┴────────┴───────┴────────────────┴────────────────────┘

Works - we get the profiles now.

Issues:

  • We log the same issue twice with different location and facilities (out.WarningT, klog.Errorf).
  • Warning is too verbose and includes details which do not belong to user message.
    We need to log a cleaner warning and log the full error using klog.Warningf()
❗  Kubeconfig '/Users/nir/.kube/config' is invalid, unable to determine active context

minikube delete --all

% minikube delete --all 
❗  Unable to determine the current kubeconfig context: Error getting kubeconfig status: decode kubeconfig from "/Users/nir/.kube/config": decode data: not: [valid
: yaml: line 1: did not find expected ',' or ']'
🔥  Deleting "minikube" in vfkit ...
🔥  Trying to delete invalid profile minikube
🔥  Successfully deleted all profiles

Works - profile was deleted.

Issues:

  • Warning is too verbose
  • Profile is treated as invalid, maybe related to the broken kubeconfig?

minikube stop --all

% minikube stop --all
❗  Unable to determine the current kubeconfig context: Error getting kubeconfig status: decode kubeconfig from "/Users/nir/.kube/config": decode data: not: [valid
: yaml: line 1: did not find expected ',' or ']'
✋  Stopping node "minikube"  ...

❌  Exiting due to HOST_KUBECONFIG_DELETE_CTX: delete ctx: Error getting kubeconfig status: decode kubeconfig from "/Users/nir/.kube/config": decode data: not: [valid
: yaml: line 1: did not find expected ',' or ']'

╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                       │
│    😿  If the above advice does not help, please let us know:                                                         │
│    👉  https://github.com/kubernetes/minikube/issues/new/choose                                                       │
│                                                                                                                       │
│    Please run `minikube logs --file=logs.txt` and attach logs.txt to the GitHub issue.                                │
│    Please also attach the following file to the GitHub issue:                                                         │
│    - /var/folders/v1/lcvpk6v567x43cfsjqg_97t40000gn/T/minikube_stop_5644b90c1b481b75163323bcf8cd2eecc0b02f39_0.log    │
│                                                                                                                       │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Works - profile was stopped

Issues:

  • We failed to change the active context. The failure cannot be avoided since the kubeconfig is broken.
  • Reporting the same issue twice (warning, exit error)
  • Warnings and errors are too verbose

minikube addons list

% minikube addons list
┌─────────────────────────────┬──────────┬────────────┬────────────────────────────────────────┐
│         ADDON NAME          │ PROFILE  │   STATUS   │               MAINTAINER               │
├─────────────────────────────┼──────────┼────────────┼────────────────────────────────────────┤
│ ambassador                  │ minikube │ disabled   │ 3rd party (Ambassador)                 │
│ amd-gpu-device-plugin       │ minikube │ disabled   │ 3rd party (AMD)                        │
│ auto-pause                  │ minikube │ disabled   │ minikube                               │
│ cloud-spanner               │ minikube │ disabled   │ Google                                 │
│ csi-hostpath-driver         │ minikube │ disabled   │ Kubernetes                             │
│ dashboard                   │ minikube │ disabled   │ Kubernetes                             │
│ default-storageclass        │ minikube │ enabled ✅ │ Kubernetes                             │
│ efk                         │ minikube │ disabled   │ 3rd party (Elastic)                    │
│ freshpod                    │ minikube │ disabled   │ Google                                 │
│ gcp-auth                    │ minikube │ disabled   │ Google                                 │
│ gvisor                      │ minikube │ disabled   │ minikube                               │
│ headlamp                    │ minikube │ disabled   │ 3rd party (kinvolk.io)                 │
│ inaccel                     │ minikube │ disabled   │ 3rd party (InAccel [info@inaccel.com]) │
│ ingress                     │ minikube │ disabled   │ Kubernetes                             │
│ ingress-dns                 │ minikube │ disabled   │ minikube                               │
│ inspektor-gadget            │ minikube │ disabled   │ 3rd party (inspektor-gadget.io)        │
│ istio                       │ minikube │ disabled   │ 3rd party (Istio)                      │
│ istio-provisioner           │ minikube │ disabled   │ 3rd party (Istio)                      │
│ kong                        │ minikube │ disabled   │ 3rd party (Kong HQ)                    │
│ kubeflow                    │ minikube │ disabled   │ 3rd party                              │
│ kubetail                    │ minikube │ disabled   │ 3rd party (kubetail.com)               │
│ kubevirt                    │ minikube │ disabled   │ 3rd party (KubeVirt)                   │
│ logviewer                   │ minikube │ disabled   │ 3rd party (unknown)                    │
│ metallb                     │ minikube │ disabled   │ 3rd party (MetalLB)                    │
│ metrics-server              │ minikube │ disabled   │ Kubernetes                             │
│ nvidia-device-plugin        │ minikube │ disabled   │ 3rd party (NVIDIA)                     │
│ nvidia-driver-installer     │ minikube │ disabled   │ 3rd party (NVIDIA)                     │
│ nvidia-gpu-device-plugin    │ minikube │ disabled   │ 3rd party (NVIDIA)                     │
│ olm                         │ minikube │ disabled   │ 3rd party (Operator Framework)         │
│ pod-security-policy         │ minikube │ disabled   │ 3rd party (unknown)                    │
│ portainer                   │ minikube │ disabled   │ 3rd party (Portainer.io)               │
│ registry                    │ minikube │ disabled   │ minikube                               │
│ registry-aliases            │ minikube │ disabled   │ 3rd party (unknown)                    │
│ registry-creds              │ minikube │ disabled   │ 3rd party (UPMC Enterprises)           │
│ storage-provisioner         │ minikube │ enabled ✅ │ minikube                               │
│ storage-provisioner-rancher │ minikube │ disabled   │ 3rd party (Rancher)                    │
│ volcano                     │ minikube │ disabled   │ third-party (volcano)                  │
│ volumesnapshots             │ minikube │ disabled   │ Kubernetes                             │
│ yakd                        │ minikube │ disabled   │ 3rd party (marcnuri.com)               │
└─────────────────────────────┴──────────┴────────────┴────────────────────────────────────────┘
❗  Unable to determine the current kubeconfig context: Error getting kubeconfig status: decode kubeconfig from "/Users/nir/.kube/config": decode data: not: [valid
: yaml: line 1: did not find expected ',' or ']'

Works.

Issues:

  • Warning is too verbose

minikube profile

% minikube profile minikube
❗  Unable to determine the current kubeconfig context: Error getting kubeconfig status: decode kubeconfig from "/Users/nir/.kube/config": decode data: not: [valid
: yaml: line 1: did not find expected ',' or ']'
😿  Error while setting kubectl current context :  Error getting kubeconfig status: decode kubeconfig from "/Users/nir/.kube/config": decode data: not: [valid
: yaml: line 1: did not find expected ',' or ']'
✅  minikube profile was successfully set to minikube

Better - 2 errors replaced with one warning.

Issues:

  • Reporting the same error twice (warning, error about setting kubectl current context)

@nirs nirs left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This change is a great improvement, but we still have issues.

I tested with diff:

diff --git a/pkg/minikube/config/profile_test.go b/pkg/minikube/config/profile_test.go
index 59df40341..2db823d18 100644
--- a/pkg/minikube/config/profile_test.go
+++ b/pkg/minikube/config/profile_test.go
@@ -86,7 +86,7 @@ func TestListProfiles(t *testing.T) {
nir@space-gray minikube (fix-list-profiles-invalid-kubeconfig)% git show | cat
commit a7af78f8fcaa24139aaf4b7c2ffb06ff5a58777c
Author: Nir Soffer <nirsof@gmail.com>
Date:   Sat Jul 11 19:48:43 2026 +0300

    review suggestions

diff --git a/pkg/minikube/config/profile.go b/pkg/minikube/config/profile.go
index e54d80dd3..6c6fe6dba 100644
--- a/pkg/minikube/config/profile.go
+++ b/pkg/minikube/config/profile.go
@@ -191,21 +191,18 @@ var DockerContainers = func() ([]string, error) {
 // invalidPs are the profiles that have a directory or config file but not usable
 // invalidPs would be suggested to be deleted
 func ListProfiles(miniHome ...string) (validPs []*Profile, inValidPs []*Profile, err error) {
-	return listProfiles(kubeconfig.PathFromEnv(), DockerContainers, miniHome...)
+	containers, _ := DockerContainers()
+	return listProfiles(kubeconfig.PathFromEnv(), containers, miniHome...)
 }
 
-func listProfiles(kubeconfigPath string, dockerContainers func() ([]string, error), miniHome ...string) (validPs []*Profile, inValidPs []*Profile, err error) {
+func listProfiles(kubeconfigPath string, containers []string, miniHome ...string) (validPs []*Profile, inValidPs []*Profile, err error) {
 	activeP := viper.GetString(ProfileName)
 	// try to get profiles list based on left over evidences such as directory
 	pDirs, err := profileDirs(miniHome...)
 	if err != nil {
 		return nil, nil, err
 	}
-	// try to get profiles list based on all containers created by docker driver
-	cs, err := dockerContainers()
-	if err == nil {
-		pDirs = append(pDirs, cs...)
-	}
+	pDirs = append(pDirs, containers...)
 
 	activeKubeContext := ""
 	if ctx, err := kubeconfig.GetCurrentContext(kubeconfigPath); err != nil {
diff --git a/pkg/minikube/config/profile_test.go b/pkg/minikube/config/profile_test.go
index 59df40341..2db823d18 100644
--- a/pkg/minikube/config/profile_test.go
+++ b/pkg/minikube/config/profile_test.go
@@ -86,7 +86,7 @@ func TestListProfiles(t *testing.T) {
 func TestListProfilesWithInvalidKubeconfig(t *testing.T) {
 	miniDir, err := filepath.Abs("./testdata/profile/.minikube")
 	if err != nil {
-		t.Errorf("error getting dir path for ./testdata/.minikube : %v", err)
+		t.Fatalf("error getting dir path for ./testdata/.minikube : %v", err)
 	}
 
 	tmpDir := t.TempDir()
@@ -94,9 +94,7 @@ func TestListProfilesWithInvalidKubeconfig(t *testing.T) {
 	if err := os.WriteFile(kubeconfig, []byte("not: [valid\n"), 0600); err != nil {
 		t.Fatalf("failed to write invalid kubeconfig: %v", err)
 	}
-	val, inv, err := listProfiles(kubeconfig, func() ([]string, error) {
-		return []string{}, nil
-	}, miniDir)
+	val, inv, err := listProfiles(kubeconfig, nil, miniDir)
 	if err != nil {
 		t.Fatalf("ListProfiles returned unexpected error: %v", err)
 	}

func TestListProfilesWithInvalidKubeconfig(t *testing.T) {
miniDir, err := filepath.Abs("./testdata/profile/.minikube")
if err != nil {
t.Errorf("error getting dir path for ./testdata/.minikube : %v", err)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

t.Fatalf

return listProfiles(kubeconfig.PathFromEnv(), DockerContainers, miniHome...)
}

func listProfiles(kubeconfigPath string, dockerContainers func() ([]string, error), miniHome ...string) (validPs []*Profile, inValidPs []*Profile, err error) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Accepting function returning profiles makes the code harder to follow and testing harder. We need to create functions returning lists.

Accept list of containers instead.

// try to get profiles list based on all containers created by docker driver
cs, err := DockerContainers()
cs, err := dockerContainers()
if err == nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can be removed if we accept list of containers.

}
val, inv, err := listProfiles(kubeconfig, func() ([]string, error) {
return []string{}, nil
}, miniDir)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Will be much simpler if we pass nil list of containers.

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. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

minikube profile list shows no profiles if it fails to parse the kubeconfig

3 participants