From f0eaa993b939e700e73af19ac8696245d8afb025 Mon Sep 17 00:00:00 2001 From: Leopold Schabel Date: Wed, 30 Jun 2021 22:48:20 +0200 Subject: [PATCH] kvm: only check libvirt membership if we failed to connect to it Test Plan: - Ran `go run k8s.io/minikube/cmd/minikube start --driver=kvm2` on a machine with polkit-based libvirt permission. This previously failed and now works. - Re-ran the same command after shutting down libvirt. This fails with PR_KVM_USER_PERMISSION as expected. --- pkg/minikube/registry/drvs/kvm2/kvm2.go | 52 +++++++++++++------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/pkg/minikube/registry/drvs/kvm2/kvm2.go b/pkg/minikube/registry/drvs/kvm2/kvm2.go index 0f76409b68..619873b4d0 100644 --- a/pkg/minikube/registry/drvs/kvm2/kvm2.go +++ b/pkg/minikube/registry/drvs/kvm2/kvm2.go @@ -122,34 +122,38 @@ func status() registry.State { return registry.State{Error: err, Fix: "Install libvirt", Doc: docURL} } - member, err := isCurrentUserLibvirtGroupMember() - if err != nil { - return registry.State{ - Installed: true, - Running: true, - // keep the error messsage in sync with reason.providerIssues(Kind.ID: "PR_KVM_USER_PERMISSION") regexp - Error: fmt.Errorf("libvirt group membership check failed:\n%v", err.Error()), - Reason: "PR_KVM_USER_PERMISSION", - Fix: "Check that libvirtd is properly installed and that you are a member of the appropriate libvirt group (remember to relogin for group changes to take effect!)", - Doc: docURL, - } - } - if !member { - return registry.State{ - Installed: true, - Running: true, - // keep the error messsage in sync with reason.providerIssues(Kind.ID: "PR_KVM_USER_PERMISSION") regexp - Error: fmt.Errorf("libvirt group membership check failed:\nuser is not a member of the appropriate libvirt group"), - Reason: "PR_KVM_USER_PERMISSION", - Fix: "Check that libvirtd is properly installed and that you are a member of the appropriate libvirt group (remember to relogin for group changes to take effect!)", - Doc: docURL, - } - } - // On Ubuntu 19.10 (libvirt 5.4), this fails if LIBVIRT_DEFAULT_URI is unset cmd := exec.CommandContext(ctx, path, "domcapabilities", "--virttype", "kvm") cmd.Env = append(os.Environ(), fmt.Sprintf("LIBVIRT_DEFAULT_URI=%s", defaultURI())) out, err := cmd.CombinedOutput() + + // If we fail to connect to libvirt, first check whether we're member of the libvirt group. + if err != nil { + member, err := isCurrentUserLibvirtGroupMember() + if err != nil { + return registry.State{ + Installed: true, + Running: true, + // keep the error messsage in sync with reason.providerIssues(Kind.ID: "PR_KVM_USER_PERMISSION") regexp + Error: fmt.Errorf("libvirt group membership check failed:\n%v", err.Error()), + Reason: "PR_KVM_USER_PERMISSION", + Fix: "Check that libvirtd is properly installed and that you are a member of the appropriate libvirt group (remember to relogin for group changes to take effect!)", + Doc: docURL, + } + } + if !member { + return registry.State{ + Installed: true, + Running: true, + // keep the error messsage in sync with reason.providerIssues(Kind.ID: "PR_KVM_USER_PERMISSION") regexp + Error: fmt.Errorf("libvirt group membership check failed:\nuser is not a member of the appropriate libvirt group"), + Reason: "PR_KVM_USER_PERMISSION", + Fix: "Check that libvirtd is properly installed and that you are a member of the appropriate libvirt group (remember to relogin for group changes to take effect!)", + Doc: docURL, + } + } + } + if ctx.Err() == context.DeadlineExceeded { return registry.State{ Installed: true,