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 kubectl --profile does not switch context #10143

Closed
owenthereal opened this issue Jan 14, 2021 · 4 comments · Fixed by #10535
Closed

minikube kubectl --profile does not switch context #10143

owenthereal opened this issue Jan 14, 2021 · 4 comments · Fixed by #10535
Assignees
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release.

Comments

@owenthereal
Copy link

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:

@priyawadhwa priyawadhwa added good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug. labels Jan 25, 2021
@priyawadhwa
Copy link

Hey @owenthereal thank you for reporting this bug. We should be taking profile into account for the kubectl command.

It should be on the easier end to fix. If you, or anyone else, would be interested in taking this issue on, please comment /assign.

@priyawadhwa priyawadhwa added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Jan 25, 2021
@BLasan
Copy link
Contributor

BLasan commented Feb 2, 2021

/assign

@BLasan
Copy link
Contributor

BLasan commented Feb 11, 2021

@priyawadhwa Ma'am could you please verify this issue?

@BLasan
Copy link
Contributor

BLasan commented Feb 16, 2021

@priyawadhwa Ma'am could you please verify this issue?

Starting the implementations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants