Skip to content

Commit

Permalink
Allow 'pinniped get kubeconfig' to override the client-go credential …
Browse files Browse the repository at this point in the history
…plugin command
  • Loading branch information
joshuatcasey committed Sep 21, 2023
1 parent 19177fd commit 4dee60e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cmd/pinniped/cmd/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type getKubeconfigParams struct {
credentialCachePath string
credentialCachePathSet bool
installHint string
commandExePath string
}

type discoveryResponseScopesSupported struct {
Expand Down Expand Up @@ -152,6 +153,7 @@ func kubeconfigCommand(deps kubeconfigDeps) *cobra.Command {
f.StringVarP(&flags.outputPath, "output", "o", "", "Output file path (default: stdout)")
f.StringVar(&flags.generatedNameSuffix, "generated-name-suffix", "-pinniped", "Suffix to append to generated cluster, context, user kubeconfig entries")
f.StringVar(&flags.credentialCachePath, "credential-cache", "", "Path to cluster-specific credentials cache")
f.StringVar(&flags.commandExePath, "command-exe-path", "", "Path to use as the command for the client-go credential plugin, usually the pinniped CLI")
f.StringVar(&flags.installHint, "install-hint", "The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli for more details", "This text is shown to the user when the pinniped CLI is not installed.")
mustMarkHidden(cmd, "oidc-debug-session-cache")

Expand Down Expand Up @@ -270,6 +272,9 @@ func newExecConfig(deps kubeconfigDeps, flags getKubeconfigParams) (*clientcmdap
execConfig.InstallHint = flags.installHint
var err error
execConfig.Command, err = func() (string, error) {
if flags.commandExePath != "" {
return flags.commandExePath, nil
}
command, err := deps.getPathToSelf()
return filepath.Base(command), err
}()
Expand Down
5 changes: 3 additions & 2 deletions cmd/pinniped/cmd/kubeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func TestGetKubeconfig(t *testing.T) {
kubeconfig [flags]
Flags:
--command-exe-path string Path to use as the command for the client-go credential plugin, usually the pinniped CLI
--concierge-api-group-suffix string Concierge API group suffix (default "pinniped.dev")
--concierge-authenticator-name string Concierge authenticator name (default: autodiscover)
--concierge-authenticator-type string Concierge authenticator type (e.g., 'webhook', 'jwt') (default: autodiscover)
Expand Down Expand Up @@ -1585,7 +1586,6 @@ func TestGetKubeconfig(t *testing.T) {
},
},
{

name: "autodetect nothing, set a bunch of options",
args: func(issuerCABundle string, issuerURL string) []string {
f := testutil.WriteStringToTempFile(t, "testca-*.pem", issuerCABundle)
Expand All @@ -1609,6 +1609,7 @@ func TestGetKubeconfig(t *testing.T) {
"--skip-validation",
"--generated-name-suffix", "-sso",
"--credential-cache", "/path/to/cache/dir/credentials.yaml",
"--command-exe-path", "/some/path/to/command-exe",
}
},
conciergeObjects: func(issuerCABundle string, issuerURL string) []runtime.Object {
Expand Down Expand Up @@ -1660,7 +1661,7 @@ func TestGetKubeconfig(t *testing.T) {
- --session-cache=/path/to/cache/dir/sessions.yaml
- --debug-session-cache
- --request-audience=test-audience
command: pinniped
command: /some/path/to/command-exe
env: []
installHint: The pinniped CLI does not appear to be installed. See https://get.pinniped.dev/cli
for more details
Expand Down

0 comments on commit 4dee60e

Please sign in to comment.