feat: Add `--context` flag to choose specific context from kubeconfig (#1234)

* feat: Add  flag to choose specific context from kubeconfig

* chore: Generate docs

* chore: Add changelog entry

* fix: Review feedback

Co-authored-by: Roland Huß <rhuss@redhat.com>

* chore: Add --cluster flag to specify cluster from kubeconfig

* chore: Generate docs

* chore: Update changelog

Co-authored-by: Roland Huß <rhuss@redhat.com>
This commit is contained in:
David Simansky 2021-02-23 09:54:46 +01:00 committed by GitHub
parent dfdf62b1a0
commit 671ee229f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
77 changed files with 184 additions and 7 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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)
}

View File

@ -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)
}
}
}
}

View File

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

View File

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