Skip to content

minikube kubectl --profile does not switch context #10143

Closed
@owenthereal

Description

@owenthereal

Steps to reproduce the issue:

  1. Provision multiple minikube clusters, e.g. cluster-a & cluster-b
  2. Change context to cluster-a with kubectl config use-context cluster-a
  3. Get namespaces in cluster-b with minikube kubectl --profile cluster-b -- get ns, context isn't switched from cluster-a to cluster-b and cluster-a namespaces are shown.

The reason is that

var kubectlCmd = &cobra.Command{
Use: "kubectl",
Short: "Run a kubectl binary matching the cluster version",
Long: `Run the Kubernetes client, download it if necessary. Remember -- after kubectl!
Examples:
minikube kubectl -- --help
minikube kubectl -- get pods --namespace kube-system`,
Run: func(cmd *cobra.Command, args []string) {
co := mustload.Healthy(ClusterFlagValue())
version := co.Config.KubernetesConfig.KubernetesVersion
c, err := KubectlCommand(version, args...)
if err != nil {
out.ErrLn("Error caching kubectl: %v", err)
}
klog.Infof("Running %s %v", c.Path, args)
c.Stdin = os.Stdin
c.Stdout = os.Stdout
c.Stderr = os.Stderr
if err := c.Run(); err != nil {
var rc int
if exitError, ok := err.(*exec.ExitError); ok {
waitStatus := exitError.Sys().(syscall.WaitStatus)
rc = waitStatus.ExitStatus()
} else {
fmt.Fprintf(os.Stderr, "Error running %s: %v\n", path, err)
rc = 1
}
os.Exit(rc)
}
},
}
// KubectlCommand will return kubectl command with a version matching the cluster
func KubectlCommand(version string, args ...string) (*exec.Cmd, error) {
if version == "" {
version = constants.DefaultKubernetesVersion
}
path, err := node.CacheKubectlBinary(version)
if err != nil {
return nil, err
}
return exec.Command(path, args...), nil
}
doesn't consider --profile.

Full output of failed command:

N/A

Full output of minikube start command used, if not already included:

N/A

Optional: Full output of minikube logs command:

Metadata

Metadata

Assignees

Labels

good first issueDenotes an issue ready for a new contributor, according to the "help wanted" guidelines.help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.kind/bugCategorizes issue or PR as related to a bug.priority/important-soonMust be staffed and worked on either currently, or very soon, ideally in time for the next release.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions