From 671ee229f3871a2c6e9efce16bf79262a40b0407 Mon Sep 17 00:00:00 2001 From: David Simansky Date: Tue, 23 Feb 2021 09:54:46 +0100 Subject: [PATCH] feat: Add `--context` flag to choose specific context from kubeconfig (#1234) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Add flag to choose specific context from kubeconfig * chore: Generate docs * chore: Add changelog entry * fix: Review feedback Co-authored-by: Roland Huß * chore: Add --cluster flag to specify cluster from kubeconfig * chore: Generate docs * chore: Update changelog Co-authored-by: Roland Huß --- CHANGELOG.adoc | 5 +++++ docs/cmd/kn.md | 2 ++ docs/cmd/kn_broker.md | 2 ++ docs/cmd/kn_broker_create.md | 2 ++ docs/cmd/kn_broker_delete.md | 2 ++ docs/cmd/kn_broker_describe.md | 2 ++ docs/cmd/kn_broker_list.md | 2 ++ docs/cmd/kn_channel.md | 2 ++ docs/cmd/kn_channel_create.md | 2 ++ docs/cmd/kn_channel_delete.md | 2 ++ docs/cmd/kn_channel_describe.md | 2 ++ docs/cmd/kn_channel_list-types.md | 2 ++ docs/cmd/kn_channel_list.md | 2 ++ docs/cmd/kn_completion.md | 2 ++ docs/cmd/kn_options.md | 2 ++ docs/cmd/kn_plugin.md | 2 ++ docs/cmd/kn_plugin_list.md | 2 ++ docs/cmd/kn_revision.md | 2 ++ docs/cmd/kn_revision_delete.md | 2 ++ docs/cmd/kn_revision_describe.md | 2 ++ docs/cmd/kn_revision_list.md | 2 ++ docs/cmd/kn_route.md | 2 ++ docs/cmd/kn_route_describe.md | 2 ++ docs/cmd/kn_route_list.md | 2 ++ docs/cmd/kn_service.md | 2 ++ docs/cmd/kn_service_apply.md | 2 ++ docs/cmd/kn_service_create.md | 2 ++ docs/cmd/kn_service_delete.md | 2 ++ docs/cmd/kn_service_describe.md | 2 ++ docs/cmd/kn_service_export.md | 2 ++ docs/cmd/kn_service_import.md | 2 ++ docs/cmd/kn_service_list.md | 2 ++ docs/cmd/kn_service_update.md | 2 ++ docs/cmd/kn_source.md | 2 ++ docs/cmd/kn_source_apiserver.md | 2 ++ docs/cmd/kn_source_apiserver_create.md | 2 ++ docs/cmd/kn_source_apiserver_delete.md | 2 ++ docs/cmd/kn_source_apiserver_describe.md | 2 ++ docs/cmd/kn_source_apiserver_list.md | 2 ++ docs/cmd/kn_source_apiserver_update.md | 2 ++ docs/cmd/kn_source_binding.md | 2 ++ docs/cmd/kn_source_binding_create.md | 2 ++ docs/cmd/kn_source_binding_delete.md | 2 ++ docs/cmd/kn_source_binding_describe.md | 2 ++ docs/cmd/kn_source_binding_list.md | 2 ++ docs/cmd/kn_source_binding_update.md | 2 ++ docs/cmd/kn_source_container.md | 2 ++ docs/cmd/kn_source_container_create.md | 2 ++ docs/cmd/kn_source_container_delete.md | 2 ++ docs/cmd/kn_source_container_describe.md | 2 ++ docs/cmd/kn_source_container_list.md | 2 ++ docs/cmd/kn_source_container_update.md | 2 ++ docs/cmd/kn_source_list-types.md | 2 ++ docs/cmd/kn_source_list.md | 2 ++ docs/cmd/kn_source_ping.md | 2 ++ docs/cmd/kn_source_ping_create.md | 2 ++ docs/cmd/kn_source_ping_delete.md | 2 ++ docs/cmd/kn_source_ping_describe.md | 2 ++ docs/cmd/kn_source_ping_list.md | 2 ++ docs/cmd/kn_source_ping_update.md | 2 ++ docs/cmd/kn_subscription.md | 2 ++ docs/cmd/kn_subscription_create.md | 2 ++ docs/cmd/kn_subscription_delete.md | 2 ++ docs/cmd/kn_subscription_describe.md | 2 ++ docs/cmd/kn_subscription_list.md | 2 ++ docs/cmd/kn_subscription_update.md | 2 ++ docs/cmd/kn_trigger.md | 2 ++ docs/cmd/kn_trigger_create.md | 2 ++ docs/cmd/kn_trigger_delete.md | 2 ++ docs/cmd/kn_trigger_describe.md | 2 ++ docs/cmd/kn_trigger_list.md | 2 ++ docs/cmd/kn_trigger_update.md | 2 ++ docs/cmd/kn_version.md | 2 ++ pkg/kn/commands/types.go | 17 +++++++++++++---- pkg/kn/commands/types_test.go | 21 ++++++++++++++++++--- pkg/kn/root/root.go | 2 ++ pkg/kn/root/root_test.go | 2 ++ 77 files changed, 184 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index bd85bf198..c69abb26d 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -17,9 +17,14 @@ |=== | | Description | PR +| 🎁 +| Add `--context` and `--cluster` flags to choose specific context from kubeconfig +| https://github.com/knative/client/pull/1234[#1234] + | 🐣 | Making a toReference public to enable reuse from kn-plugins | https://github.com/knative/client/pull/1203[#1203] + | 🐣 | Do not print serviceUID and configUID labels in service export result | https://github.com/knative/client/pull/1194[#1194] diff --git a/docs/cmd/kn.md b/docs/cmd/kn.md index 1bae35100..ba6759edf 100644 --- a/docs/cmd/kn.md +++ b/docs/cmd/kn.md @@ -11,7 +11,9 @@ kn is the command line interface for managing Knative Serving and Eventing resou ### Options ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use -h, --help help for kn --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic diff --git a/docs/cmd/kn_broker.md b/docs/cmd/kn_broker.md index ae59ac3d8..c08b12348 100644 --- a/docs/cmd/kn_broker.md +++ b/docs/cmd/kn_broker.md @@ -15,7 +15,9 @@ kn broker ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_broker_create.md b/docs/cmd/kn_broker_create.md index c1cdc3569..ed1469b8d 100644 --- a/docs/cmd/kn_broker_create.md +++ b/docs/cmd/kn_broker_create.md @@ -27,7 +27,9 @@ kn broker create NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_broker_delete.md b/docs/cmd/kn_broker_delete.md index f98eab59a..3abd1d7f7 100644 --- a/docs/cmd/kn_broker_delete.md +++ b/docs/cmd/kn_broker_delete.md @@ -30,7 +30,9 @@ kn broker delete NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_broker_describe.md b/docs/cmd/kn_broker_describe.md index 69df2706c..ddaba7d0c 100644 --- a/docs/cmd/kn_broker_describe.md +++ b/docs/cmd/kn_broker_describe.md @@ -36,7 +36,9 @@ kn broker describe NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_broker_list.md b/docs/cmd/kn_broker_list.md index 4a7254d24..8bb485aec 100644 --- a/docs/cmd/kn_broker_list.md +++ b/docs/cmd/kn_broker_list.md @@ -32,7 +32,9 @@ kn broker list ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_channel.md b/docs/cmd/kn_channel.md index 3d345426d..192e5babc 100644 --- a/docs/cmd/kn_channel.md +++ b/docs/cmd/kn_channel.md @@ -15,7 +15,9 @@ kn channel COMMAND ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_channel_create.md b/docs/cmd/kn_channel_create.md index f7def2f7d..c947c738b 100644 --- a/docs/cmd/kn_channel_create.md +++ b/docs/cmd/kn_channel_create.md @@ -33,7 +33,9 @@ kn channel create NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_channel_delete.md b/docs/cmd/kn_channel_delete.md index a1b4351ec..da93f1b4c 100644 --- a/docs/cmd/kn_channel_delete.md +++ b/docs/cmd/kn_channel_delete.md @@ -24,7 +24,9 @@ kn channel delete NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_channel_describe.md b/docs/cmd/kn_channel_describe.md index 92f41b908..a3a6ce9c4 100644 --- a/docs/cmd/kn_channel_describe.md +++ b/docs/cmd/kn_channel_describe.md @@ -31,7 +31,9 @@ kn channel describe NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_channel_list-types.md b/docs/cmd/kn_channel_list-types.md index c098746d7..1892d065b 100644 --- a/docs/cmd/kn_channel_list-types.md +++ b/docs/cmd/kn_channel_list-types.md @@ -31,7 +31,9 @@ kn channel list-types ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_channel_list.md b/docs/cmd/kn_channel_list.md index f81b0ec02..d2504f0a1 100644 --- a/docs/cmd/kn_channel_list.md +++ b/docs/cmd/kn_channel_list.md @@ -32,7 +32,9 @@ kn channel list ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_completion.md b/docs/cmd/kn_completion.md index 5c40e568d..593178637 100644 --- a/docs/cmd/kn_completion.md +++ b/docs/cmd/kn_completion.md @@ -37,7 +37,9 @@ kn completion SHELL ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_options.md b/docs/cmd/kn_options.md index 2732acb3f..ca099cede 100644 --- a/docs/cmd/kn_options.md +++ b/docs/cmd/kn_options.md @@ -26,7 +26,9 @@ kn options ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_plugin.md b/docs/cmd/kn_plugin.md index ead701a00..de924e28b 100644 --- a/docs/cmd/kn_plugin.md +++ b/docs/cmd/kn_plugin.md @@ -22,7 +22,9 @@ kn plugin ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_plugin_list.md b/docs/cmd/kn_plugin_list.md index 28009fb52..0108ee1e8 100644 --- a/docs/cmd/kn_plugin_list.md +++ b/docs/cmd/kn_plugin_list.md @@ -26,7 +26,9 @@ kn plugin list ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_revision.md b/docs/cmd/kn_revision.md index db2e9e586..76c3cee60 100644 --- a/docs/cmd/kn_revision.md +++ b/docs/cmd/kn_revision.md @@ -15,7 +15,9 @@ kn revision ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_revision_delete.md b/docs/cmd/kn_revision_delete.md index bce75ab30..42db8ef81 100644 --- a/docs/cmd/kn_revision_delete.md +++ b/docs/cmd/kn_revision_delete.md @@ -27,7 +27,9 @@ kn revision delete NAME [NAME ...] ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_revision_describe.md b/docs/cmd/kn_revision_describe.md index c7e3f56b3..abee71279 100644 --- a/docs/cmd/kn_revision_describe.md +++ b/docs/cmd/kn_revision_describe.md @@ -20,7 +20,9 @@ kn revision describe NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_revision_list.md b/docs/cmd/kn_revision_list.md index ae813052e..bf1fa7439 100644 --- a/docs/cmd/kn_revision_list.md +++ b/docs/cmd/kn_revision_list.md @@ -43,7 +43,9 @@ kn revision list ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_route.md b/docs/cmd/kn_route.md index b5b4798a6..f4adcdff8 100644 --- a/docs/cmd/kn_route.md +++ b/docs/cmd/kn_route.md @@ -15,7 +15,9 @@ kn route ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_route_describe.md b/docs/cmd/kn_route_describe.md index aa11604e5..8fa390308 100644 --- a/docs/cmd/kn_route_describe.md +++ b/docs/cmd/kn_route_describe.md @@ -20,7 +20,9 @@ kn route describe NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_route_list.md b/docs/cmd/kn_route_list.md index 013e0bc80..c71e00737 100644 --- a/docs/cmd/kn_route_list.md +++ b/docs/cmd/kn_route_list.md @@ -35,7 +35,9 @@ kn route list NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_service.md b/docs/cmd/kn_service.md index ad319eaa4..c07d30f33 100644 --- a/docs/cmd/kn_service.md +++ b/docs/cmd/kn_service.md @@ -15,7 +15,9 @@ kn service ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_service_apply.md b/docs/cmd/kn_service_apply.md index ecdacdf18..b8456f3b3 100644 --- a/docs/cmd/kn_service_apply.md +++ b/docs/cmd/kn_service_apply.md @@ -73,7 +73,9 @@ kn service apply s0 --filename my-svc.yml ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_service_create.md b/docs/cmd/kn_service_create.md index 78ae63c82..7dd6f659b 100644 --- a/docs/cmd/kn_service_create.md +++ b/docs/cmd/kn_service_create.md @@ -99,7 +99,9 @@ kn service create NAME --image IMAGE ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_service_delete.md b/docs/cmd/kn_service_delete.md index 53de0252d..3c7cdc46a 100644 --- a/docs/cmd/kn_service_delete.md +++ b/docs/cmd/kn_service_delete.md @@ -40,7 +40,9 @@ kn service delete NAME [NAME ...] ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_service_describe.md b/docs/cmd/kn_service_describe.md index f15aac25f..0754431fd 100644 --- a/docs/cmd/kn_service_describe.md +++ b/docs/cmd/kn_service_describe.md @@ -40,7 +40,9 @@ kn service describe NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_service_export.md b/docs/cmd/kn_service_export.md index 001ddbc0e..c6924ffc7 100644 --- a/docs/cmd/kn_service_export.md +++ b/docs/cmd/kn_service_export.md @@ -38,7 +38,9 @@ kn service export NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_service_import.md b/docs/cmd/kn_service_import.md index 5ebaf02bf..2ea72d75b 100644 --- a/docs/cmd/kn_service_import.md +++ b/docs/cmd/kn_service_import.md @@ -30,7 +30,9 @@ kn service import FILENAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_service_list.md b/docs/cmd/kn_service_list.md index 8d86f9bd4..041bed2aa 100644 --- a/docs/cmd/kn_service_list.md +++ b/docs/cmd/kn_service_list.md @@ -42,7 +42,9 @@ kn service list ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_service_update.md b/docs/cmd/kn_service_update.md index f6f463621..8eeeae7c3 100644 --- a/docs/cmd/kn_service_update.md +++ b/docs/cmd/kn_service_update.md @@ -85,7 +85,9 @@ kn service update NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source.md b/docs/cmd/kn_source.md index e3c492372..c16f3e128 100644 --- a/docs/cmd/kn_source.md +++ b/docs/cmd/kn_source.md @@ -15,7 +15,9 @@ kn source SOURCE|COMMAND ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_apiserver.md b/docs/cmd/kn_source_apiserver.md index 16019910e..e94a2bf7f 100644 --- a/docs/cmd/kn_source_apiserver.md +++ b/docs/cmd/kn_source_apiserver.md @@ -15,7 +15,9 @@ kn source apiserver COMMAND ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_apiserver_create.md b/docs/cmd/kn_source_apiserver_create.md index 6033a1723..c3b676378 100644 --- a/docs/cmd/kn_source_apiserver_create.md +++ b/docs/cmd/kn_source_apiserver_create.md @@ -32,7 +32,9 @@ kn source apiserver create NAME --resource RESOURCE --sink SINK ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_apiserver_delete.md b/docs/cmd/kn_source_apiserver_delete.md index 30ef5ea98..76bbfa71c 100644 --- a/docs/cmd/kn_source_apiserver_delete.md +++ b/docs/cmd/kn_source_apiserver_delete.md @@ -24,7 +24,9 @@ kn source apiserver delete NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_apiserver_describe.md b/docs/cmd/kn_source_apiserver_describe.md index cfd2c949d..09af6697b 100644 --- a/docs/cmd/kn_source_apiserver_describe.md +++ b/docs/cmd/kn_source_apiserver_describe.md @@ -31,7 +31,9 @@ kn source apiserver describe NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_apiserver_list.md b/docs/cmd/kn_source_apiserver_list.md index c205cdfc9..dfb8e6cef 100644 --- a/docs/cmd/kn_source_apiserver_list.md +++ b/docs/cmd/kn_source_apiserver_list.md @@ -32,7 +32,9 @@ kn source apiserver list ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_apiserver_update.md b/docs/cmd/kn_source_apiserver_update.md index 7ae6ec0cd..3d8568ce5 100644 --- a/docs/cmd/kn_source_apiserver_update.md +++ b/docs/cmd/kn_source_apiserver_update.md @@ -32,7 +32,9 @@ kn source apiserver update NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_binding.md b/docs/cmd/kn_source_binding.md index 808a5cd8c..2e4473ebb 100644 --- a/docs/cmd/kn_source_binding.md +++ b/docs/cmd/kn_source_binding.md @@ -15,7 +15,9 @@ kn source binding COMMAND ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_binding_create.md b/docs/cmd/kn_source_binding_create.md index 0994c2d4d..d6eb50fee 100644 --- a/docs/cmd/kn_source_binding_create.md +++ b/docs/cmd/kn_source_binding_create.md @@ -27,7 +27,9 @@ kn source binding create NAME --subject SUBJECT --sink SINK ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_binding_delete.md b/docs/cmd/kn_source_binding_delete.md index 483e4633d..d625cef6f 100644 --- a/docs/cmd/kn_source_binding_delete.md +++ b/docs/cmd/kn_source_binding_delete.md @@ -24,7 +24,9 @@ kn source binding delete NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_binding_describe.md b/docs/cmd/kn_source_binding_describe.md index 5871a9d37..9fe9e0e01 100644 --- a/docs/cmd/kn_source_binding_describe.md +++ b/docs/cmd/kn_source_binding_describe.md @@ -31,7 +31,9 @@ kn source binding describe NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_binding_list.md b/docs/cmd/kn_source_binding_list.md index 204af0ed7..941cd9cd9 100644 --- a/docs/cmd/kn_source_binding_list.md +++ b/docs/cmd/kn_source_binding_list.md @@ -32,7 +32,9 @@ kn source binding list ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_binding_update.md b/docs/cmd/kn_source_binding_update.md index d266ca49a..8b22afa82 100644 --- a/docs/cmd/kn_source_binding_update.md +++ b/docs/cmd/kn_source_binding_update.md @@ -27,7 +27,9 @@ kn source binding update NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_container.md b/docs/cmd/kn_source_container.md index 6a09905fd..3d750ff4f 100644 --- a/docs/cmd/kn_source_container.md +++ b/docs/cmd/kn_source_container.md @@ -15,7 +15,9 @@ kn source container create|delete|update|list|describe ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_container_create.md b/docs/cmd/kn_source_container_create.md index eb84b423b..5e778f357 100644 --- a/docs/cmd/kn_source_container_create.md +++ b/docs/cmd/kn_source_container_create.md @@ -38,7 +38,9 @@ kn source container create NAME --image IMAGE --sink SINK ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_container_delete.md b/docs/cmd/kn_source_container_delete.md index 4877dc6d3..430b17bb3 100644 --- a/docs/cmd/kn_source_container_delete.md +++ b/docs/cmd/kn_source_container_delete.md @@ -24,7 +24,9 @@ kn source container delete NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_container_describe.md b/docs/cmd/kn_source_container_describe.md index 5328eb7b6..7a3f55904 100644 --- a/docs/cmd/kn_source_container_describe.md +++ b/docs/cmd/kn_source_container_describe.md @@ -25,7 +25,9 @@ kn source container describe NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_container_list.md b/docs/cmd/kn_source_container_list.md index a85727701..070b2ab51 100644 --- a/docs/cmd/kn_source_container_list.md +++ b/docs/cmd/kn_source_container_list.md @@ -32,7 +32,9 @@ kn source container list ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_container_update.md b/docs/cmd/kn_source_container_update.md index d7ee704fc..047136c0e 100644 --- a/docs/cmd/kn_source_container_update.md +++ b/docs/cmd/kn_source_container_update.md @@ -38,7 +38,9 @@ kn source container update NAME --image IMAGE ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_list-types.md b/docs/cmd/kn_source_list-types.md index be70497c0..8562308c1 100644 --- a/docs/cmd/kn_source_list-types.md +++ b/docs/cmd/kn_source_list-types.md @@ -31,7 +31,9 @@ kn source list-types ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_list.md b/docs/cmd/kn_source_list.md index 3ed1e83ee..fac82941d 100644 --- a/docs/cmd/kn_source_list.md +++ b/docs/cmd/kn_source_list.md @@ -36,7 +36,9 @@ kn source list ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_ping.md b/docs/cmd/kn_source_ping.md index e0b6a580c..5515bca3d 100644 --- a/docs/cmd/kn_source_ping.md +++ b/docs/cmd/kn_source_ping.md @@ -15,7 +15,9 @@ kn source ping COMMAND ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_ping_create.md b/docs/cmd/kn_source_ping_create.md index 7e1367896..5985455f1 100644 --- a/docs/cmd/kn_source_ping_create.md +++ b/docs/cmd/kn_source_ping_create.md @@ -28,7 +28,9 @@ kn source ping create NAME --sink SINK ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_ping_delete.md b/docs/cmd/kn_source_ping_delete.md index 2b01c9780..90f6f8c59 100644 --- a/docs/cmd/kn_source_ping_delete.md +++ b/docs/cmd/kn_source_ping_delete.md @@ -24,7 +24,9 @@ kn source ping delete NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_ping_describe.md b/docs/cmd/kn_source_ping_describe.md index 02986fc90..7aade71e3 100644 --- a/docs/cmd/kn_source_ping_describe.md +++ b/docs/cmd/kn_source_ping_describe.md @@ -31,7 +31,9 @@ kn source ping describe NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_ping_list.md b/docs/cmd/kn_source_ping_list.md index 15e5b7e06..56095435a 100644 --- a/docs/cmd/kn_source_ping_list.md +++ b/docs/cmd/kn_source_ping_list.md @@ -32,7 +32,9 @@ kn source ping list ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_source_ping_update.md b/docs/cmd/kn_source_ping_update.md index 1fbb3c66e..64c8e337b 100644 --- a/docs/cmd/kn_source_ping_update.md +++ b/docs/cmd/kn_source_ping_update.md @@ -28,7 +28,9 @@ kn source ping update NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_subscription.md b/docs/cmd/kn_subscription.md index 16d605861..dbd58732e 100644 --- a/docs/cmd/kn_subscription.md +++ b/docs/cmd/kn_subscription.md @@ -15,7 +15,9 @@ kn subscription COMMAND ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_subscription_create.md b/docs/cmd/kn_subscription_create.md index d88bd37c0..e49f40796 100644 --- a/docs/cmd/kn_subscription_create.md +++ b/docs/cmd/kn_subscription_create.md @@ -31,7 +31,9 @@ kn subscription create NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_subscription_delete.md b/docs/cmd/kn_subscription_delete.md index 59fdc23ac..4dee0a45a 100644 --- a/docs/cmd/kn_subscription_delete.md +++ b/docs/cmd/kn_subscription_delete.md @@ -24,7 +24,9 @@ kn subscription delete NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_subscription_describe.md b/docs/cmd/kn_subscription_describe.md index c266fda1b..7c6a0100c 100644 --- a/docs/cmd/kn_subscription_describe.md +++ b/docs/cmd/kn_subscription_describe.md @@ -28,7 +28,9 @@ kn subscription describe NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_subscription_list.md b/docs/cmd/kn_subscription_list.md index f5f4f795f..9f7330574 100644 --- a/docs/cmd/kn_subscription_list.md +++ b/docs/cmd/kn_subscription_list.md @@ -32,7 +32,9 @@ kn subscription list ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_subscription_update.md b/docs/cmd/kn_subscription_update.md index abc4fa27d..59cd20243 100644 --- a/docs/cmd/kn_subscription_update.md +++ b/docs/cmd/kn_subscription_update.md @@ -30,7 +30,9 @@ kn subscription update NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_trigger.md b/docs/cmd/kn_trigger.md index 0cd48d01e..012401bd5 100644 --- a/docs/cmd/kn_trigger.md +++ b/docs/cmd/kn_trigger.md @@ -15,7 +15,9 @@ kn trigger ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_trigger_create.md b/docs/cmd/kn_trigger_create.md index 13b8a841f..616506f2c 100644 --- a/docs/cmd/kn_trigger_create.md +++ b/docs/cmd/kn_trigger_create.md @@ -31,7 +31,9 @@ kn trigger create NAME --sink SINK ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_trigger_delete.md b/docs/cmd/kn_trigger_delete.md index d0029308f..37a631949 100644 --- a/docs/cmd/kn_trigger_delete.md +++ b/docs/cmd/kn_trigger_delete.md @@ -24,7 +24,9 @@ kn trigger delete NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_trigger_describe.md b/docs/cmd/kn_trigger_describe.md index a4028c6b2..2a4ac6332 100644 --- a/docs/cmd/kn_trigger_describe.md +++ b/docs/cmd/kn_trigger_describe.md @@ -31,7 +31,9 @@ kn trigger describe NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_trigger_list.md b/docs/cmd/kn_trigger_list.md index 3d0f1dde8..36748c9d8 100644 --- a/docs/cmd/kn_trigger_list.md +++ b/docs/cmd/kn_trigger_list.md @@ -32,7 +32,9 @@ kn trigger list ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_trigger_update.md b/docs/cmd/kn_trigger_update.md index 86e3012e5..2aad67a6e 100644 --- a/docs/cmd/kn_trigger_update.md +++ b/docs/cmd/kn_trigger_update.md @@ -35,7 +35,9 @@ kn trigger update NAME ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/docs/cmd/kn_version.md b/docs/cmd/kn_version.md index b88d8af2a..c583c9ad1 100644 --- a/docs/cmd/kn_version.md +++ b/docs/cmd/kn_version.md @@ -16,7 +16,9 @@ kn version ### Options inherited from parent commands ``` + --cluster string name of the kubeconfig cluster to use --config string kn configuration file (default: ~/.config/kn/config.yaml) + --context string name of the kubeconfig context to use --kubeconfig string kubectl configuration file (default: ~/.kube/config) --log-http log http traffic ``` diff --git a/pkg/kn/commands/types.go b/pkg/kn/commands/types.go index 7578a2584..524c521ef 100644 --- a/pkg/kn/commands/types.go +++ b/pkg/kn/commands/types.go @@ -42,6 +42,8 @@ import ( type KnParams struct { Output io.Writer KubeCfgPath string + KubeContext string + KubeCluster string ClientConfig clientcmd.ClientConfig NewServingClient func(namespace string) (clientservingv1.KnServingClient, error) NewGitopsServingClient func(namespace string, dir string) (clientservingv1.KnServingClient, error) @@ -167,14 +169,21 @@ func (params *KnParams) RestConfig() (*rest.Config, error) { // GetClientConfig gets ClientConfig from KubeCfgPath func (params *KnParams) GetClientConfig() (clientcmd.ClientConfig, error) { loadingRules := clientcmd.NewDefaultClientConfigLoadingRules() + configOverrides := &clientcmd.ConfigOverrides{} + if params.KubeContext != "" { + configOverrides.CurrentContext = params.KubeContext + } + if params.KubeCluster != "" { + configOverrides.Context.Cluster = params.KubeCluster + } if len(params.KubeCfgPath) == 0 { - return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &clientcmd.ConfigOverrides{}), nil + return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides), nil } _, err := os.Stat(params.KubeCfgPath) if err == nil { loadingRules.ExplicitPath = params.KubeCfgPath - return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &clientcmd.ConfigOverrides{}), nil + return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides), nil } if !os.IsNotExist(err) { @@ -183,8 +192,8 @@ func (params *KnParams) GetClientConfig() (clientcmd.ClientConfig, error) { paths := filepath.SplitList(params.KubeCfgPath) if len(paths) > 1 { - return nil, fmt.Errorf("Can not find config file. '%s' looks like a path. "+ + return nil, fmt.Errorf("can not find config file. '%s' looks like a path. "+ "Please use the env var KUBECONFIG if you want to check for multiple configuration files", params.KubeCfgPath) } - return nil, fmt.Errorf("Config file '%s' can not be found", params.KubeCfgPath) + return nil, fmt.Errorf("config file '%s' can not be found", params.KubeCfgPath) } diff --git a/pkg/kn/commands/types_test.go b/pkg/kn/commands/types_test.go index 0f51cc170..2c725e16b 100644 --- a/pkg/kn/commands/types_test.go +++ b/pkg/kn/commands/types_test.go @@ -100,6 +100,8 @@ func TestPrepareConfig(t *testing.T) { type typeTestCase struct { kubeCfgPath string + kubeContext string + kubeCluster string explicitPath string expectedError string } @@ -108,23 +110,30 @@ func TestGetClientConfig(t *testing.T) { multiConfigs := fmt.Sprintf("%s%s%s", "/testing/assets/kube-config-01.yml", string(os.PathListSeparator), "/testing/assets/kube-config-02.yml") for _, tc := range []typeTestCase{ { + "", + "", "", clientcmd.NewDefaultClientConfigLoadingRules().ExplicitPath, "", }, { "/testing/assets/kube-config-01.yml", + "foo", + "bar", "", - fmt.Sprintf("Config file '%s' can not be found", "/testing/assets/kube-config-01.yml"), + fmt.Sprintf("config file '%s' can not be found", "/testing/assets/kube-config-01.yml"), }, { multiConfigs, "", - fmt.Sprintf("Can not find config file. '%s' looks like a path. Please use the env var KUBECONFIG if you want to check for multiple configuration files", multiConfigs), + "", + "", + fmt.Sprintf("can not find config file. '%s' looks like a path. Please use the env var KUBECONFIG if you want to check for multiple configuration files", multiConfigs), }, } { p := &KnParams{ KubeCfgPath: tc.kubeCfgPath, + KubeContext: tc.kubeContext, } clientConfig, err := p.GetClientConfig() @@ -136,8 +145,14 @@ func TestGetClientConfig(t *testing.T) { if clientConfig != nil { configAccess := clientConfig.ConfigAccess() - assert.Assert(t, configAccess.GetExplicitFile() == tc.explicitPath) + + if tc.kubeContext != "" { + config, err := clientConfig.RawConfig() + assert.NilError(t, err) + assert.Assert(t, config.CurrentContext == tc.kubeContext) + assert.Assert(t, config.Contexts[tc.kubeContext].Cluster == tc.kubeCluster) + } } } } diff --git a/pkg/kn/root/root.go b/pkg/kn/root/root.go index 66410bb62..4d8a59f68 100644 --- a/pkg/kn/root/root.go +++ b/pkg/kn/root/root.go @@ -76,6 +76,8 @@ func NewRootCommand(helpFuncs *template.FuncMap) (*cobra.Command, error) { // Global flags rootCmd.PersistentFlags().StringVar(&p.KubeCfgPath, "kubeconfig", "", "kubectl configuration file (default: ~/.kube/config)") + rootCmd.PersistentFlags().StringVar(&p.KubeContext, "context", "", "name of the kubeconfig context to use") + rootCmd.PersistentFlags().StringVar(&p.KubeCluster, "cluster", "", "name of the kubeconfig cluster to use") flags.AddBothBoolFlags(rootCmd.PersistentFlags(), &p.LogHTTP, "log-http", "", false, "log http traffic") // Grouped commands diff --git a/pkg/kn/root/root_test.go b/pkg/kn/root/root_test.go index 47aba31c7..0ae262660 100644 --- a/pkg/kn/root/root_test.go +++ b/pkg/kn/root/root_test.go @@ -44,6 +44,8 @@ func TestNewRootCommand(t *testing.T) { assert.Assert(t, rootCmd.PersistentFlags().Lookup("config") != nil) assert.Assert(t, rootCmd.PersistentFlags().Lookup("kubeconfig") != nil) + assert.Assert(t, rootCmd.PersistentFlags().Lookup("context") != nil) + assert.Assert(t, rootCmd.PersistentFlags().Lookup("cluster") != nil) assert.Assert(t, rootCmd.RunE == nil)