Skip to content

feat: support inline kubeconfig in config_path#354

Open
Abhi011999 wants to merge 2 commits intoturbot:mainfrom
Abhi011999:feat/inline-kubeconfig
Open

feat: support inline kubeconfig in config_path#354
Abhi011999 wants to merge 2 commits intoturbot:mainfrom
Abhi011999:feat/inline-kubeconfig

Conversation

@Abhi011999
Copy link

@Abhi011999 Abhi011999 commented Mar 5, 2026

Issue: #353

Changes

kubernetes/utils.go

  • Added pathOrContents(poc string) — mirrors GCP plugin's helper. Returns isInline=true if the value is not a path that exists on disk and doesn't look like an absolute path.
  • Added tryInlineKubeconfig(configPath string, configContext *string) — if config_path is inline YAML, parses it directly via clientcmd.NewClientConfigFromBytes with optional context override. Returns ok=false to let the caller fall through to the standard file-loader path.
  • Hooked both getK8Config and getK8ConfigRaw to call tryInlineKubeconfig before the existing ClientConfigLoadingRules loader, so file-path usage is fully backwards-compatible.

Behaviour

config_path value Behaviour
/home/user/.kube/config (exists) unchanged — loaded from file
apiVersion: v1\nkind: Config\n... (YAML string) parsed inline, no disk I/O
/tmp/missing (absolute, missing) error: no such file or directory

Testing

Verified end-to-end with EKS kubeconfig passed inline. Ran 10 concurrent queries across 2 EKS clusters, all of them passing correctly.

(Code written by Opus 4.6)

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for providing an inline kubeconfig (YAML) directly via the config_path connection argument, avoiding disk I/O and file-watcher timing issues.

Changes:

  • Added pathOrContents to classify config_path as either an on-disk path or inline content.
  • Added tryInlineKubeconfig to parse inline kubeconfig YAML via clientcmd.NewClientConfigFromBytes, with optional context override.
  • Updated getK8Config and getK8ConfigRaw to attempt inline parsing before falling back to the standard file-based loader.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Use positive YAML check (newlines + apiVersion key) to identify inline
  content instead of "everything that isn't a path" heuristic, preventing
  relative filenames from being misclassified as inline YAML
- Surface real os.Stat errors (e.g., permission denied) instead of
  silently falling through to inline classification
- Let missing file paths fall through to the standard loader for proper
  error messages and in-cluster config fallback, fixing a backwards-compat
  break where ~/.kube/config (missing) would hard-error instead of
  allowing fallback
- Move overrides allocation inside configContext block where it's used

Made-with: Cursor
@Abhi011999
Copy link
Author

@rajlearner17 made the updates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants