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

Check for EmptyConfig errors when trying to use in-cluster config #31947

Merged

Conversation

smarterclayton
Copy link
Contributor

@smarterclayton smarterclayton commented Sep 2, 2016

By removing the default "localhost:8080" behavior several paths in
client config began returning err == ErrEmptyConfig rather than err ==
nil. The code checking for in cluster config was wrong - the logic
should be:

  1. If loading the underlying config returns a non-empty error, fail
  2. If the underlying config is not equal to the default config,
    return that config (it has user input)
  3. If it is possible to use in-cluster config, do so
  4. Otherwise return the default config (and or default EmptyConfig
    error).

Fixes #31910 @thockin @lavalamp @deads2k. We introduced EmptyConfig a very long time ago, but until I removed the "localhost:8080" Kubernetes was not actually exposing it (OpenShift relies on it since we don't set an insecure default). This properly falls through to in-cluster config in the described conditions.


This change is Reviewable

Some components like kube-dns and kube-proxy could fail to load the service account token when started within a pod. Properly handle empty configurations to try loading the service account config.

@smarterclayton smarterclayton added this to the v1.4 milestone Sep 2, 2016
@smarterclayton
Copy link
Contributor Author

smarterclayton commented Sep 2, 2016

Note the controller and scheduler were not affected because they don't use a DeferredNonInteractiveConfig. Kubectl was not affected because it uses a Deferred*Config with defaulting. OpenShift would not have been broken since we use a wrapper (which basically was there to fix this particular bug).

@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-label-needed labels Sep 2, 2016
@smarterclayton
Copy link
Contributor Author

I don't think this needs a release note because the issue never actually manifested in any code (kube-dns was not built).

@smarterclayton
Copy link
Contributor Author

@deads2k can you review?

@smarterclayton smarterclayton added priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. cherrypick-candidate labels Sep 2, 2016
@@ -358,21 +358,21 @@ func (inClusterClientConfig) ClientConfig() (*restclient.Config, error) {
return restclient.InClusterConfig()
}

func (inClusterClientConfig) Namespace() (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

this function never actually returns an error. Remove the error parameter or use it instead of the bool.

Copy link
Contributor

Choose a reason for hiding this comment

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

this function never actually returns an error. Remove the error parameter or use it instead of the bool.

It's implementing an interface. Other implementors do return errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

Add a couple type assertions. this dropped out of the ClientConfig interface at some point.

Copy link
Member

Choose a reason for hiding this comment

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

If it's part of an interface, then change the interface, too-- (string, bool, error) is a confusing return set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The interface is correct - this implementation just happens not to return an error. The bool is "was this specified" by the user. The string is the value. We use the bool all over the code to determine between user passed "--namespace" on the CLI vs getting the "default" namespace.

@lavalamp
Copy link
Member

lavalamp commented Sep 2, 2016

I still can't understand this loader code. lgtm but maybe @jlowdermilk wants to take a look?

return icc.ClientConfig()

// check for in-cluster configuration and use it
if config.icc.Possible() {
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is going to have priority, why don't we do it first?

Copy link
Contributor

Choose a reason for hiding this comment

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

hrm, I see. It doesn't have priority. And it can't go into the switch above because of the error handling down the non-nil patch. What sticky little bit of code.

@smarterclayton
Copy link
Contributor Author

@deads2k any other comments?

@deads2k
Copy link
Contributor

deads2k commented Sep 6, 2016

@smarterclayton no more comments from me.

lgtm, could use a squash.

By removing the default "localhost:8080" behavior several paths in
client config began returning err == ErrEmptyConfig rather than err ==
nil.  The code checking for in cluster config was wrong - the logic
should be:

1. If loading the underlying config returns a non-empty error, fail
2. If the underlying config is not equal to the default config,
   return that config (it's got user input)
3. If it is possible to use in cluster config, do so
4. Otherwise return the default config (and or default EmptyConfig
   error).
@k8s-bot
Copy link

k8s-bot commented Sep 6, 2016

GCE e2e build/test passed for commit 48b4d6d.

@smarterclayton
Copy link
Contributor Author

Squashed

@smarterclayton smarterclayton added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 7, 2016
@k8s-github-robot k8s-github-robot added the do-not-merge DEPRECATED. Indicates that a PR should not merge. Label can only be manually applied/removed. label Sep 7, 2016
@smarterclayton smarterclayton added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-label-needed do-not-merge DEPRECATED. Indicates that a PR should not merge. Label can only be manually applied/removed. labels Sep 7, 2016
@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-bot
Copy link

k8s-bot commented Sep 7, 2016

GCE e2e build/test passed for commit 48b4d6d.

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit 9dce773 into kubernetes:master Sep 7, 2016
@pwittrock pwittrock added the cherry-pick-approved Indicates a cherry-pick PR into a release branch has been approved by the release branch manager. label Sep 7, 2016
foxish added a commit that referenced this pull request Sep 8, 2016
errordeveloper added a commit to errordeveloper/kubernetes that referenced this pull request Sep 10, 2016
Changes made in kubernetes#31947 cause kube-proxy to ignore `--kubeconfig`
and `--master` flags and use in-cluster configuration, which is
unusable due to the fact that VIP hasn't been created yet.
errordeveloper added a commit to errordeveloper/kubernetes that referenced this pull request Sep 10, 2016
Changes made in kubernetes#31947 cause kube-proxy to ignore `--kubeconfig`
and `--master` flags and use in-cluster configuration, which is
unusable due to the fact that VIP hasn't been created yet.
pwittrock pushed a commit that referenced this pull request Sep 10, 2016
k8s-github-robot pushed a commit that referenced this pull request Sep 12, 2016
Automatic merge from submit-queue

Automated cherry pick of #31947

By removing the default "localhost:8080" behavior several paths in
client config began returning err == ErrEmptyConfig rather than err ==
nil.  The code checking for in cluster config was wrong - the logic
should be:

1. If loading the underlying config returns a non-empty error, fail
2. If the underlying config is not equal to the default config,
   return that config (it's got user input)
3. If it is possible to use in cluster config, do so
4. Otherwise return the default config (and or default EmptyConfig
   error).

Cherry-pick of #31947
@eparis
Copy link
Contributor

eparis commented Sep 13, 2016

removing cherrypick-candidate as this was previously merged in release-1.4

errordeveloper added a commit to errordeveloper/kubernetes that referenced this pull request Sep 14, 2016
Changes made in kubernetes#31947 cause kube-proxy to ignore `--kubeconfig`
and `--master` flags and use in-cluster configuration, which is
unusable due to the fact that VIP hasn't been created yet.
aaronlevy pushed a commit to aaronlevy/kubernetes that referenced this pull request Sep 15, 2016
Check if default config is invalid before comparing it

Changes made in kubernetes#31947 cause kube-proxy to ignore `--kubeconfig`
and `--master` flags and use in-cluster configuration, which is
unusable due to the fact that VIP hasn't been created yet.
aaronlevy pushed a commit to coreos/kubernetes that referenced this pull request Sep 15, 2016
Check if default config is invalid before comparing it

Changes made in kubernetes#31947 cause kube-proxy to ignore `--kubeconfig`
and `--master` flags and use in-cluster configuration, which is
unusable due to the fact that VIP hasn't been created yet.
shyamjvs pushed a commit to shyamjvs/kubernetes that referenced this pull request Dec 1, 2016
…onfig_14

Automatic merge from submit-queue

Automated cherry pick of kubernetes#31947

By removing the default "localhost:8080" behavior several paths in
client config began returning err == ErrEmptyConfig rather than err ==
nil.  The code checking for in cluster config was wrong - the logic
should be:

1. If loading the underlying config returns a non-empty error, fail
2. If the underlying config is not equal to the default config,
   return that config (it's got user input)
3. If it is possible to use in cluster config, do so
4. Otherwise return the default config (and or default EmptyConfig
   error).

Cherry-pick of kubernetes#31947
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick-approved Indicates a cherry-pick PR into a release branch has been approved by the release branch manager. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants