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

Support multi config files #222

Merged
merged 3 commits into from
Jul 17, 2019

Conversation

edwardstudy
Copy link
Contributor

@edwardstudy edwardstudy commented Jul 2, 2019

Fixed: #196

./kn service list --kubeconfig=$KUBECONFIG
the server could not find the requested resource (get services.serving.knative.dev)

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Jul 2, 2019
@knative-prow-robot knative-prow-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jul 2, 2019
@knative-prow-robot
Copy link
Contributor

Hi @edwardstudy. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@rhuss
Copy link
Contributor

rhuss commented Jul 2, 2019

/ok-to-test

@knative-prow-robot knative-prow-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 2, 2019
Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

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

Thanks for the PR !

Do you think it would be possible to write a test for this, too ? We should do this if the test setup is not so involved that it does not justify the benefit.

pkg/kn/commands/types.go Outdated Show resolved Hide resolved
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jul 2, 2019
@knative-prow-robot knative-prow-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 2, 2019
Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

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

Tanks a lot. Funny thing is that the coverage report fails now after you added a test (and we didn't have a test before that for types.go). So I'm not sure how this check is supposed to work, as it seems like having 0% coverage is ok, but if you have a coverage >0% then you do need to have more than 50%.

Not sure how we can resolve that (except by writing more test code unrelated to this PR).

@sixolet @adrcunha Is there a way to "overrule" the code coverage check ? Or what is the recommendation for this kind of situation ?

@adrcunha
Copy link
Contributor

adrcunha commented Jul 2, 2019

@sixolet @adrcunha Is there a way to "overrule" the code coverage check ? Or what is the recommendation for this kind of situation ?

I think the coverage check was marked as required by mistake, based on the numbers in https://testgrid.knative.dev/client#coverage

Unless you feel very confident that, at this point that no PR with coverage below 50% should get merged, I suggest that an admin simply uncheck the go coverage job as required to merge.

@cppforlife
Copy link

i dont think kubectl supports following (someone verify:

./kn service list --kubeconfig=$KUBECONFIG

it does support KUBECONFIG having multiple paths set though which we support as well via kubectl's library.

original issue mentioned in this pr is fixed via #172.

@rhuss
Copy link
Contributor

rhuss commented Jul 2, 2019

good catch, @cppforlife

someone verify:

correct, I get an error with a --kubeconfig=$PATH_LIKE_VAR :

error: stat /Users/roland/.kube/config:/Users/roland/Development/openshift/ocp4/dev/auth/kubeconfig: no such file or directory

@edwardstudy sorry for bugging you with the test and change (really good work, thx again), but what was actually your use case ? Does setting KUBECONFIG as env var to a path does not work as expected ? Or why would you like to have a path like arg for --kubeconfig ?

explicitPath string
}

func TestGetClientConfig(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice work @edwardstudy. Consider also using the new gotest.tools which should make your tests cleaner, especially assertions and dividing into multiple parts. We agreed during yesterday's WG meeting to move all tests using this small addition to gotest.tools. See #134's tests for examples or let's chat today in Beijing, I am working on some. Cheers 🍻

@edwardstudy
Copy link
Contributor Author

@rhuss My case is simple, specify multi configs over --kubeconfig flag. When you specify --kubeconfig, you should make sure that kn works no matter what values passed. It should work: get current kube context or return a proper error message. What do you think? 😃

@rhuss
Copy link
Contributor

rhuss commented Jul 3, 2019

@rhuss My case is simple, specify multi configs over --kubeconfig flag. When you specify --kubeconfig, you should make sure that kn works no matter what values passed. It should work: get current kube context or return a proper error message. What do you think? 😃

For multiple configs, I think that kubectl settle on using an env variable KUBECONFIG for this, so the kubectl is like this (in this order) :

  • Setting a very specific configuration via --kubeconfig
  • Setting the location of the configuration files in a path like manner via KUBECONFIG
  • Fallback to `~/.kube/config

I think your use case can be simply be done with

KUBECONFIG=dir1:dir2 kn service create ....

instead of using one --kubeconfig with a path or multiple kubeconfigs.

We should mimic the behaviour of kubectl here as I think it makes sense, too (no one expects a path with --kubeconfig).

I totally agree thought that the error message should be better, maybe even suggesting that KUBECONFIG env var should be used for multiple configs.

The current kubectl behaviour is:

kubectl get pods --kubeconfig=/Users/roland/.kube/config --kubeconfig=/Users/roland/Development/openshift/ocp4/dev/auth/kubeconfig

---> Take only the last --kubeconfig given

kubectl get pods --kubeconfig=/Users/roland/.kube/config:/Users/roland/Development/openshift/ocp4/dev/auth/kubeconfig

---> error: stat /Users/roland/.kube/config:/Users/roland/Development/openshift/ocp4/dev/auth/kubeconfig: no such file or directory

For the last case, I suggest an error message like

Configuration file "/Users/roland/.kube/config:/Users/roland/Development/openshift/ocp4/dev/auth/kubeconfig" could not be found. For configuration lookup path please use the environment variable KUBECONFIG.

The last sentence I would add when the path contains a : (this might be a valid filename part, too (egg on Windows), but printing out that extra error message wouldn't harm either then. Important is that it should be checked if the provided argument exists as a file first.

@edwardstudy does this make sense ?

@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 3, 2019
@edwardstudy
Copy link
Contributor Author

/retest

@edwardstudy
Copy link
Contributor Author

edwardstudy commented Jul 3, 2019

@rhuss Hi, I recoded and let os.PathListSeparator to handle OS-specific path separator.

@rhuss
Copy link
Contributor

rhuss commented Jul 3, 2019

Let me jump on the PR later (probably tomorrow, its already late here). Thanks for doing the rework !

@rhuss
Copy link
Contributor

rhuss commented Jul 3, 2019

/retest

(sorry, test failure is again because of a too short timeout in the it test. We will address this soonish).

@rhuss
Copy link
Contributor

rhuss commented Jul 8, 2019

/retest

Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

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

direction looks very good. Some minor nits, mostly around testing.

pkg/kn/commands/types.go Outdated Show resolved Hide resolved
pkg/kn/commands/types.go Outdated Show resolved Hide resolved
pkg/kn/commands/types.go Outdated Show resolved Hide resolved
pkg/kn/commands/types_test.go Outdated Show resolved Hide resolved
pkg/kn/commands/types_test.go Outdated Show resolved Hide resolved
pkg/kn/commands/types_test.go Outdated Show resolved Hide resolved
@maximilien
Copy link
Contributor

@edwardstudy you also need to rebase to resolve pkg/kn/commands/types.go conflict


paths := filepath.SplitList(params.KubeCfgPath)
if len(paths) > 1 {
return nil, errors.New(fmt.Sprintf("Can not find config file. '%s' looks like a combine path. "+
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nil, errors.New(fmt.Sprintf("Can not find config file. '%s' looks like a combine path. "+
return nil, errors.New(fmt.Sprintf("Can not find config file. '%s' looks like a path. "+

Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

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

Thanks a lot ! Except for one super-mini correction (where I provide a suggestion) at https://github.com/knative/client/pull/222/files#r304285543 we are good to merge.

@edwardstudy
Copy link
Contributor Author

Done. Sorry for the delay in getting a chance to respond to this PR.

@knative-metrics-robot
Copy link

The following is the coverage report on pkg/.
Say /test pull-knative-client-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/kn/commands/namespaced.go 72.7% 68.0% -4.7
pkg/kn/commands/types.go 0.0% 53.6% 53.6

@rhuss
Copy link
Contributor

rhuss commented Jul 17, 2019

/approve
/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 17, 2019
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: edwardstudy, rhuss

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

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 17, 2019
@knative-prow-robot knative-prow-robot merged commit 0b348d7 into knative:master Jul 17, 2019
@edwardstudy edwardstudy deleted the ed/multi-configs branch July 17, 2019 09:25
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. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

kn fails when KUBECONFIG multi config files
9 participants