Search index
Search Index
Section titled “Search Index”The search index is a file in the state directory (default: ~/.kube/switch-state/switch.<store>.<id>.index)
that contains all the discovered kubecontext names over all kubeconfig stores mapped to their kubeconfig file (only the path).
This index is then used instead of querying the kubeconfig store.
This could lead to outdated search results until the index is refreshed again (kubeconfigs might have been deleted or added in the meanwhile).
Using the search index is especially useful when
- dealing with large amounts of Kubeconfigs and querying the Kubeconfig store is slow (e.g. searching a large directory)
- to save request when using a kubeconfig store that queries an API (Vault & Gardener).
Compared to the example in the hot reload feature, see that all the Kubeconfig contexts are available almost instantly.

Per default, the search index is not used.
Enable search index
Section titled “Enable search index”Enable the search index in the SwitchConfig file (per default located in ~/.kube/switch-config.yaml
or configured via flag --config-path.
The flag has to point to the file, not the directory).
You can disable using a configured search index for the current request by using the flag --no-index.
Enable index for all stores
Section titled “Enable index for all stores”The field refreshIndexAfter determines the time after which the tool should
refresh the index of every configured store.
$ cat ~/.kube/switch-config.yaml
kind: SwitchConfigrefreshIndexAfter: 1hkubeconfigStores: [...many-stores...]Enable search index for a specific kubeconfig store
Section titled “Enable search index for a specific kubeconfig store”The field refreshIndexAfter can also be set for only a specific store.
$ cat ~/.kube/switch-config.yaml
kind: SwitchConfigkubeconfigStores: - kind: filesystem id: unique-1 refreshIndexAfter: 3h paths: - "~/.kube/static-kubeconfigs/"Overwrite global refreshIndexAfter
Section titled “Overwrite global refreshIndexAfter”In the example below, the first store overwrites the global refreshIndexAfter of one hour and
sets the refreshIndexAfter to three hours instead.
Store two uses the default.
$ cat ~/.kube/switch-config.yaml
kind: SwitchConfigrefreshIndexAfter: 1hkubeconfigStores: - kind: filesystem id: unique-1 refreshIndexAfter: 3h paths: - "~/.kube/static-kubeconfigs/" - kind: filesystem id: unique-2 paths: - "~/.kube/next-kubeconfigs/"