Skip to content

Commit

Permalink
Merge pull request #9 from herbygillot/kubeconf-name-config
Browse files Browse the repository at this point in the history
Allow for specifying kubeconfig-name in the config file
  • Loading branch information
danielfoehrKn authored Mar 4, 2021
2 parents a327f7e + 2f19d69 commit 1685a46
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cmd/switcher/switcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ import (
"github.com/spf13/cobra"
)

const vaultTokenFileName = ".vault-token"
const (
vaultTokenFileName = ".vault-token"
defaultKubeconfigName = "config"
)

var (
// root command
Expand Down Expand Up @@ -278,7 +281,7 @@ func setCommonFlags(command *cobra.Command) {
command.Flags().StringVar(
&kubeconfigName,
"kubeconfig-name",
"config",
defaultKubeconfigName,
"only shows kubeconfig files with this name. Accepts wilcard arguments '*' and '?'. Defaults to 'config'.")
command.Flags().StringVar(
&vaultAPIAddressFromFlag,
Expand Down Expand Up @@ -314,6 +317,12 @@ func initialize() ([]store.KubeconfigStore, *types.Config, error) {
config = &types.Config{}
}

if kubeconfigName == defaultKubeconfigName {
if config.KubeconfigName != "" {
kubeconfigName = config.KubeconfigName
}
}

if len(kubeconfigPath) > 0 {
config.KubeconfigPaths = append(config.KubeconfigPaths, types.KubeconfigPath{
Path: kubeconfigPath,
Expand Down
13 changes: 13 additions & 0 deletions docs/kubeconfig_stores.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ kubeconfigPaths:
store: filesystem
```

## Specify the Kubeconfig name/pattern

The name or pattern to use when searching for kubeconfig files within a store is specified via the command line flag `--kubeconfig-name`. This can also be defined in config:

```
$ cat ~/.kube/switch-config.yaml
kind: SwitchConfig
kubeconfigName: "*.myconfig"
kubeconfigPaths:
- path: "~/.kube/local-kubeconfigs/"
store: filesystem
```

## Using both CLI and `SwitchConfig` file

- The flag `--vault-api-address` takes presendence over the config field `vaultAPIAddress`.
Expand Down
1 change: 1 addition & 0 deletions types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (

type Config struct {
Kind string `yaml:"kind"`
KubeconfigName string `yaml:"kubeconfigName"`
KubeconfigRediscoveryInterval *time.Duration `yaml:"kubeconfigRediscoveryInterval"`
VaultAPIAddress string `yaml:"vaultAPIAddress"`
Hooks []Hook `yaml:"hooks"`
Expand Down

0 comments on commit 1685a46

Please sign in to comment.