diff --git a/plugin/kubernetes/README.md b/plugin/kubernetes/README.md index 570090d9..3a3d9589 100644 --- a/plugin/kubernetes/README.md +++ b/plugin/kubernetes/README.md @@ -8,6 +8,8 @@ this plugin is inpsired by the [first version kubernetes plugin](https://github. Start plugin with flag `--all-namespaces` or environment variable `SSHPIPERD_KUBERNETES_ALL_NAMESPACES=true` for cluster-wide usage, or it will listen to the namespace where it is in by default. +Start plugin with flag `--kubeconfig` or environment variable `SSHPIPERD_KUBERNETES_KUBECONFIG=/path/to/kubeconfig` to specify the kubeconfig file. + ### Helm [![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/sshpiper)](https://artifacthub.io/packages/helm/sshpiper/sshpiper) diff --git a/plugin/kubernetes/kubernetes.go b/plugin/kubernetes/kubernetes.go index 7a7a4e5f..9273c6ab 100644 --- a/plugin/kubernetes/kubernetes.go +++ b/plugin/kubernetes/kubernetes.go @@ -33,9 +33,11 @@ type plugin struct { cache *gocache.Cache } -func newKubernetesPlugin(allNamespaces bool) (*plugin, error) { +func newKubernetesPlugin(allNamespaces bool, kubeConfigPath string) (*plugin, error) { + loader := clientcmd.NewDefaultClientConfigLoadingRules() + loader.ExplicitPath = kubeConfigPath kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig( - clientcmd.NewDefaultClientConfigLoadingRules(), + loader, &clientcmd.ConfigOverrides{}, ) diff --git a/plugin/kubernetes/main.go b/plugin/kubernetes/main.go index 63ee44db..39c415bb 100644 --- a/plugin/kubernetes/main.go +++ b/plugin/kubernetes/main.go @@ -16,9 +16,15 @@ func main() { EnvVars: []string{"SSHPIPERD_KUBERNETES_ALL_NAMESPACES"}, Required: false, }, + &cli.StringFlag{ + Name: "kubeconfig", + Usage: "Path to kubeconfig file", + EnvVars: []string{"SSHPIPERD_KUBERNETES_KUBECONFIG", "KUBECONFIG"}, + Required: false, + }, }, CreateConfig: func(c *cli.Context) (*libplugin.SshPiperPluginConfig, error) { - plugin, err := newKubernetesPlugin(c.Bool("all-namespaces")) + plugin, err := newKubernetesPlugin(c.Bool("all-namespaces"), c.String("kubeconfig")) if err != nil { return nil, err }