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

loads kubeconfig only once #71117

Merged
merged 1 commit into from
Jan 19, 2019
Merged

Conversation

dixudx
Copy link
Member

@dixudx 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

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. area/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Nov 16, 2018
Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 16, 2018
@soltysh
Copy link
Contributor

soltysh commented Nov 16, 2018

/milestone v1.13
/priority important-longterm

@k8s-ci-robot k8s-ci-robot added this to the v1.13 milestone Nov 16, 2018
@k8s-ci-robot k8s-ci-robot added priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Nov 16, 2018
@liggitt
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 added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 16, 2018
@liggitt liggitt removed this from the v1.13 milestone Nov 17, 2018
@dixudx
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
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
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 read_kubeconfig_once branch from 6820c9d to bf54d21 Compare November 20, 2018 06:51
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 20, 2018
@dixudx dixudx force-pushed the read_kubeconfig_once branch from bf54d21 to f630648 Compare November 20, 2018 06:52
@dixudx
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.

pkg/kubectl/cmd/cmd.go Outdated Show resolved Hide resolved
@dixudx dixudx force-pushed the read_kubeconfig_once branch 2 times, most recently from 23f63c8 to 9d4e6f9 Compare November 22, 2018 11:52
Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@dixudx dixudx force-pushed the read_kubeconfig_once branch from 9d4e6f9 to 34fda1b Compare November 23, 2018 12:13
@dixudx dixudx force-pushed the read_kubeconfig_once branch from 34fda1b to 4b524ef Compare December 7, 2018 07:42
@dixudx
Copy link
Member Author

dixudx commented Jan 2, 2019

Kindly ping @soltysh to get this merged.

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve
Thanks for the patience

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 18, 2019
@soltysh
Copy link
Contributor

soltysh commented Jan 18, 2019

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 18, 2019
@k8s-ci-robot
Copy link
Contributor

[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
Copy link

/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
Copy link
Member Author

dixudx commented Jan 19, 2019

/retest

@fejta-bot
Copy link

/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
@dixudx dixudx deleted the read_kubeconfig_once branch January 21, 2019 02:56
@KnVerey
Copy link
Contributor

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
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.

@totahuanocotl
Copy link

@soltysh this issue did not exist in kubectl 1.10, and it has affected production systems where we rely on kubectl. I would call that a bug. We are using 1.11 because of the recent cve patch, so it would be good to have it in 1.11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kubectl get loads kubeconfig once per resource
9 participants