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

loads kubeconfig only once #71117

Merged
merged 1 commit into from Jan 19, 2019

Conversation

@dixudx
Copy link
Member

dixudx commented Nov 16, 2018

What type of PR is this?

/kind bug
/sig cli
/area kubectl

What this PR does / why we need it:

Currently a single kubeconfig file will be loaded several times, which should be parsed for only once.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #69856

Special notes for your reviewer:
/cc @kubernetes/sig-cli-bugs
/assign soltysh

Does this PR introduce a user-facing change?:

kubectl loads config file once and uses persistent client config
@soltysh
Copy link
Contributor

soltysh left a comment

/lgtm
/approve

@soltysh

This comment has been minimized.

Copy link
Contributor

soltysh commented Nov 16, 2018

/milestone v1.13
/priority important-longterm

@liggitt

This comment has been minimized.

Copy link
Member

liggitt commented Nov 16, 2018

/hold

is this method expected to be self mutating? previously, it was non-mutating and theadsafe

@liggitt liggitt removed this from the v1.13 milestone Nov 17, 2018

@dixudx

This comment has been minimized.

Copy link
Member Author

dixudx commented Nov 19, 2018

is this method expected to be self mutating? previously, it was non-mutating and theadsafe

it also freezes config at the point in time this method was first called. is that safe as well?

@liggitt @smarterclayton I don't think it is a good idea to load/parse the same config file again and again. That is time-consuming. And errors will occurr if we are changing the config file while the cli command is invoked.

This method is and will be only used by the command line. And only one such declaration is defined currently.

kubeConfigFlags := genericclioptions.NewConfigFlags()

I know your concern about thread safe. But kubectl only got one such declaration.

@liggitt

This comment has been minimized.

Copy link
Member

liggitt commented Nov 19, 2018

@liggitt @smarterclayton I don't think it is a good idea to load/parse the same config file again and again. That is time-consuming. And errors will occurr if we are changing the config file while the cli command is invoked.

To be clear, I'm fine with kubectl updating to use a method that explicitly loads only once (or with kubectl updating to load once itself and propagate the config to the places that need it, rather than calling this method multiple times)

This method is and will be only used by the command line. And only one such declaration is defined currently.

This method is in an exported repo intended to be used by arbitrary command line tools. Searching only in the kubernetes/kubernetes repo does not indicate all usage.

@dixudx

This comment has been minimized.

Copy link
Member Author

dixudx commented Nov 20, 2018

To be clear, I'm fine with kubectl updating to use a method that explicitly loads only once (or with kubectl updating to load once itself and propagate the config to the places that need it, rather than calling this method multiple times)

an acceptable alternative could be a second method that does something similar to this (though in a threadsafe manner) with a name that makes it clear the returned value is reusing a previously computed value if available, and switching callers that are ok with those semantics to that method

@liggitt Okay, I got it. I will have another alternative method to keep this peristent config.

This method is in an exported repo intended to be used by arbitrary command line tools. Searching only in the kubernetes/kubernetes repo does not indicate all usage.

Agree.

@dixudx dixudx force-pushed the dixudx:read_kubeconfig_once branch from 6820c9d to bf54d21 Nov 20, 2018

@k8s-ci-robot k8s-ci-robot added size/M and removed lgtm size/XS labels Nov 20, 2018

@dixudx dixudx force-pushed the dixudx:read_kubeconfig_once branch from bf54d21 to f630648 Nov 20, 2018

@dixudx

This comment has been minimized.

Copy link
Member Author

dixudx commented Nov 20, 2018

@liggitt @smarterclayton I've added a flag for persistent client config and made it thread safe. And this change won't break current behavoirs.

For kubectl, we are switching using persistent client config.

Show resolved Hide resolved pkg/kubectl/cmd/cmd.go Outdated

@dixudx dixudx force-pushed the dixudx:read_kubeconfig_once branch 2 times, most recently from 23f63c8 to 9d4e6f9 Nov 21, 2018

@soltysh
Copy link
Contributor

soltysh left a comment

Two more nits and you'll be good to go.

@dixudx dixudx force-pushed the dixudx:read_kubeconfig_once branch from 9d4e6f9 to 34fda1b Nov 23, 2018

@dixudx dixudx force-pushed the dixudx:read_kubeconfig_once branch from 34fda1b to 4b524ef Dec 7, 2018

@dixudx

This comment has been minimized.

Copy link
Member Author

dixudx commented Jan 2, 2019

Kindly ping @soltysh to get this merged.

@soltysh
Copy link
Contributor

soltysh left a comment

/lgtm
/approve
Thanks for the patience

@k8s-ci-robot k8s-ci-robot added the lgtm label Jan 18, 2019

@soltysh

This comment has been minimized.

Copy link
Contributor

soltysh commented Jan 18, 2019

/hold cancel

@k8s-ci-robot

This comment has been minimized.

Copy link
Contributor

k8s-ci-robot commented Jan 18, 2019

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dixudx, soltysh

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

The pull request process is described here

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

@fejta-bot

This comment has been minimized.

Copy link

fejta-bot commented Jan 19, 2019

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@dixudx

This comment has been minimized.

Copy link
Member Author

dixudx commented Jan 19, 2019

/retest

@fejta-bot

This comment has been minimized.

Copy link

fejta-bot commented Jan 19, 2019

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@k8s-ci-robot k8s-ci-robot merged commit 9d58c8f into kubernetes:master Jan 19, 2019

19 checks passed

cla/linuxfoundation dixudx authorized
Details
pull-kubernetes-bazel-build Job succeeded.
Details
pull-kubernetes-bazel-test Job succeeded.
Details
pull-kubernetes-cross Skipped
pull-kubernetes-e2e-gce Job succeeded.
Details
pull-kubernetes-e2e-gce-100-performance Job succeeded.
Details
pull-kubernetes-e2e-gce-device-plugin-gpu Job succeeded.
Details
pull-kubernetes-e2e-gke Skipped
pull-kubernetes-e2e-kops-aws Job succeeded.
Details
pull-kubernetes-e2e-kubeadm-gce Skipped
pull-kubernetes-godeps Job succeeded.
Details
pull-kubernetes-integration Job succeeded.
Details
pull-kubernetes-kubemark-e2e-gce-big Job succeeded.
Details
pull-kubernetes-local-e2e Skipped
pull-kubernetes-local-e2e-containerized Skipped
pull-kubernetes-node-e2e Job succeeded.
Details
pull-kubernetes-typecheck Job succeeded.
Details
pull-kubernetes-verify Job succeeded.
Details
tide In merge pool.
Details

@dixudx dixudx deleted the dixudx:read_kubeconfig_once branch Jan 21, 2019

@KnVerey

This comment has been minimized.

Copy link

KnVerey commented Feb 4, 2019

Would it be possible to get this fix cherry-picked to a released version? I've been experiencing performance problems using kubectl with a large kubeconfig + large resource counts, so I would love to have this before 1.14 (It'd be great to see it in 1.11.x in fact).

@soltysh

This comment has been minimized.

Copy link
Contributor

soltysh commented Feb 6, 2019

We prefer to cherry-pick only bug fixes, this is not quite that. It's more like a feature than a bug fix. Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment