Add kubeconfig flag for k8s plugin (#296)

This commit is contained in:
Haiker Sun 2024-01-04 08:51:44 -06:00 committed by GitHub
parent f172d2b155
commit 22af927e77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View file

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

View file

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

View file

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