mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-09-11 05:19:11 +00:00
query namespace exists with GET Namespace
More efficient ns switches with kubens by querying only the namespace (instead of listing all namespaces). Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
@@ -54,15 +54,7 @@ func queryNamespaces(kc *kubeconfig.Kubeconfig) ([]string, error) {
|
||||
return []string{"ns1", "ns2"}, nil
|
||||
}
|
||||
|
||||
b, err := kc.Bytes()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to convert in-memory kubeconfig to yaml")
|
||||
}
|
||||
cfg, err := clientcmd.RESTConfigFromKubeConfig(b)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to initialize config")
|
||||
}
|
||||
clientset, err := kubernetes.NewForConfig(cfg)
|
||||
clientset, err := newKubernetesClientSet(kc)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to initialize k8s REST client")
|
||||
}
|
||||
@@ -87,3 +79,15 @@ func queryNamespaces(kc *kubeconfig.Kubeconfig) ([]string, error) {
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func newKubernetesClientSet(kc *kubeconfig.Kubeconfig) (*kubernetes.Clientset, error) {
|
||||
b, err := kc.Bytes()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to convert in-memory kubeconfig to yaml")
|
||||
}
|
||||
cfg, err := clientcmd.RESTConfigFromKubeConfig(b)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to initialize config")
|
||||
}
|
||||
return kubernetes.NewForConfig(cfg)
|
||||
}
|
||||
|
Reference in New Issue
Block a user