Skip to content

feat: expose client kube context to accessCommand templates#459

Open
corydolphin wants to merge 1 commit intodiranged:mainfrom
corydolphin:feature/client-kube-context
Open

feat: expose client kube context to accessCommand templates#459
corydolphin wants to merge 1 commit intodiranged:mainfrom
corydolphin:feature/client-kube-context

Conversation

@corydolphin
Copy link
Copy Markdown

Problem:

In environments with multiple clusters and or kubernetes contexts, it is common to be able to pass --context XXX to execute a command within that environment. While Oz respects that, it is impossible for a PodAccessTemplate's accessCommand to include that context, making it impossible for the templated command to always be executable by a user.

This change adds a clientKubeContext field to PodAccessRequestSpec and ExecAccessRequestSpec, populated automatically by ozctl from the effective kubeconfig context (the standard --context flag if set, otherwise the kubeconfig's current-context). The renderer surfaces this value as {{ .ClientKubeContext }} so an accessCommand can include --context <name> and produce a kubectl invocation that targets the same cluster the request was created in.

The field is optional. The default accessCommand does not reference it, so behavior is unchanged for existing templates. Templates that opt into using it should gate the reference with a conditional so they remain safe when the field is empty (e.g. when the request is applied as raw YAML or by an older ozctl).

Add a `clientKubeContext` field to PodAccessRequestSpec and
ExecAccessRequestSpec, populated automatically by `ozctl` from the
effective kubeconfig context (the standard `--context` flag if set,
otherwise the kubeconfig's `current-context`). The renderer surfaces
this value as `{{ .ClientKubeContext }}` so an `accessCommand` can
include `--context <name>` and produce a kubectl invocation that
targets the same cluster the request was created in.

The field is optional. The default `accessCommand` does not reference
it, so behavior is unchanged for existing templates. Templates that
opt into using it should gate the reference with a conditional so they
remain safe when the field is empty (e.g. when the request is applied
as raw YAML or by an older `ozctl`).
@corydolphin corydolphin requested a review from diranged as a code owner April 30, 2026 04:46
@github-actions github-actions Bot added the go Pull requests that update Go code label Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant