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

--kubeconfig flag not honored #5732

Closed
rm3l opened this issue May 11, 2022 · 2 comments · Fixed by #7017
Closed

--kubeconfig flag not honored #5732

rm3l opened this issue May 11, 2022 · 2 comments · Fixed by #7017
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug.
Milestone

Comments

@rm3l
Copy link
Member

rm3l commented May 11, 2022

/kind bug

What versions of software are you using?

Operating System:
Fedora release 36 (Thirty Six)

Output of odo version:
odo v3.0.0-alpha1 (b7e45da)

How did you run odo exactly?

❯ odo dev --kubeconfig /path/to/a/kubeconfig/other/than/the/default

This always uses the default config, not the one specified by the user. As such, it uses the wrong cluster.

Actually, this affects all commands that expose this flag, like odo deploy or odo list, e.g.:

❯ odo list --kubeconfig /path/to/a/kubeconfig/other/than/the/default -v 4                                                                                                                                                                                         
I0511 16:41:56.599645 1765751 implem.go:103] The path for preference file is /home/asoro/.config/odo/preferences.yaml                                                                                                                                                            
I0511 16:41:56.599700 1765751 util.go:733] HTTPGetRequest: https://raw.githubusercontent.com/redhat-developer/odo/main/build/VERSION                                                                                                                                             
I0511 16:41:56.599724 1765751 segment.go:254] Checking telemetry enable status                                                                                                                                                                                                   
I0511 16:41:56.599767 1765751 util.go:754] Response will be cached in /tmp/odohttpcache for 1h0m0s
                                                                                                                                                                               
I0511 16:41:56.602227 1765751 util.go:1077] using default kubeconfig path /home/asoro/.kube/config

--- truncated ---

Actual behavior

Almost all commands currently expose this --kubeconfig flag in their help message (under the "Additional Flags" section):

For example, with odo help dev:

Additional Flags:
      --kubeconfig string    Paths to a kubeconfig. Only required if out-of-cluster.
  -v, --v Level              Number for the log level verbosity. Level varies from 0 to 9 (default 0).
      --vmodule moduleSpec   Comma-separated list of pattern=N settings for file-filtered logging

Maybe I missed something, but I was expecting this --kubeconfig option to allow me to target a different cluster. Instead, it seems like odo always reads the default ${HOME}/.kube/config file.

After a quick look, it looks like:

  • we always initialize a kclient with the defaults:
    // New creates a new client
    func New() (*Client, error) {
    return NewForConfig(nil)
    }
  • in odo list, we always check either the KUBECONFIG env var is set or the default ~/.kube/config does exist :
    // Check to see if KUBECONFIG exists, and if not, error the user that we would not be able to get cluster information
    // Do this before anything else, or else we will just error out with the:
    // invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
    // instead
    if !dfutil.CheckKubeConfigExist() {
    return errors.New("KUBECONFIG not found. Unable to retrieve cluster information. Please set your Kubernetes configuration via KUBECONFIG env variable or ~/.kube/config")
    }

Expected behavior

Make odo honor the user-defined kubeconfig file(s) defined via this flag, for all interactions with a cluster.

Workaround: Set the KUBECONFIG environment variable instead, but it would be nice to make this --kubeconfig option work (taking precedence over the environment variable).

Or if this is not something expected, we should probably remove this flag from the Help messages.

@openshift-ci openshift-ci bot added the kind/bug Categorizes issue or PR as related to a bug. label May 11, 2022
@rm3l rm3l mentioned this issue May 11, 2022
3 tasks
@feloy
Copy link
Contributor

feloy commented Aug 31, 2022

I think that CheckKubeConfigExist should not be used as is, as it does not support KUBECONFIG values with several kubeconfig paths:

KUBECONFIG=/path/to/config:/other/path/to/config

Also, we should rely on genericlioptions.New to do this work, and not do it in the operation specific functions.

@rm3l rm3l added this to odo Project Oct 3, 2022
@rm3l rm3l moved this to To Do 📝 in odo Project Oct 3, 2022
@rm3l rm3l removed the status in odo Project Oct 3, 2022
@kadel
Copy link
Member

kadel commented Feb 20, 2023

That flag is coming from controller-runtime

// TODO: Fix this to allow double vendoring this library but still register flags on behalf of users
flag.StringVar(&kubeconfig, "kubeconfig", "",
"Paths to a kubeconfig. Only required if out-of-cluster.")

It was not my intention to have it there.

We should figure out a way how to remove it from odo. And then, as a separate issue, have it properly implemented.

@feloy feloy mentioned this issue Aug 3, 2023
3 tasks
@feloy feloy self-assigned this Aug 3, 2023
@rm3l rm3l added this to the v3.14.0 🚀 milestone Aug 3, 2023
@rm3l rm3l removed the needs-triage Indicates an issue or PR lacks a `triage/*` and requires one. label Aug 3, 2023
@feloy feloy moved this to In Review 👀 in odo Project Aug 3, 2023
@github-project-automation github-project-automation bot moved this from In Review 👀 to Done ✅ in odo Project Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants