Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kubeconfig flag for k8s plugin #296

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading