Skip to content

Commit

Permalink
Add kubeconfig flag for k8s plugin (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
haiker2011 authored Jan 4, 2024
1 parent f172d2b commit 22af927
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions plugin/kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions plugin/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
)

Expand Down
8 changes: 7 additions & 1 deletion plugin/kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 22af927

Please sign in to comment.