Skip to content

feat(config): support multi-file KUBECONFIG and honor --context#171

Merged
Joibel merged 1 commit intomainfrom
feat/multi-kubeconfig-context
May 5, 2026
Merged

feat(config): support multi-file KUBECONFIG and honor --context#171
Joibel merged 1 commit intomainfrom
feat/multi-kubeconfig-context

Conversation

@Joibel
Copy link
Copy Markdown
Collaborator

@Joibel Joibel commented May 5, 2026

Summary

  • --context was defined but never plumbed into the Argo client — the kubeconfig's current-context always won. It now flows through internal/configargo.Configclientcmd.ConfigOverrides{CurrentContext: ...}.
  • KUBECONFIG containing multiple files joined by the OS path-list separator (the kubectl convention, e.g. eks.yaml:k3d.yaml:home.yaml) was being treated as a single literal path. The loader now uses Precedence: filepath.SplitList(kubeconfig) so each file is merged.
  • The resolved context and cluster are logged at startup so operators can confirm which cluster the server is bound to before running tools.

Test plan

  • go test ./... passes (new TestBuildLoadingRules covers empty / single / multi-path)
  • make lint passes
  • Smoke-tested locally with a 9-file KUBECONFIG:
    • default startup picks up current-context (e.g. k3d-pipeline-mono)
    • --context=eks-internal overrides and resolves to the correct cluster
    • all 9 source files appear in the startup log

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added support for specifying Kubernetes contexts in configuration
    • Enhanced kubeconfig handling to support multiple path lists in KUBECONFIG format
    • Improved context resolution with enhanced logging
  • Tests

    • Added tests for kubeconfig path loading behavior

The --context flag was defined but never plumbed into the Argo client, and
a KUBECONFIG containing multiple files joined by the OS path-list
separator (kubectl convention) was treated as a single literal path.

Switch the kubeconfig loader to use Precedence with filepath.SplitList,
copy Context from internal config into argo.Config, and apply it via
clientcmd.ConfigOverrides{CurrentContext: ...}. Log the resolved context
and cluster at startup so operators can confirm the bound cluster before
running tools.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 26684dc8-1377-4d0a-80ab-20fdbeb3ee24

📥 Commits

Reviewing files that changed from the base of the PR and between a9180d7 and cef948c.

⛔ Files ignored due to path filters (1)
  • README.md is excluded by !**/*.md
📒 Files selected for processing (4)
  • internal/config/config.go
  • pkg/argo/client.go
  • pkg/argo/client_test.go
  • pkg/argo/config.go

Walkthrough

The PR adds kubeconfig context selection and KUBECONFIG environment variable support to the Argo configuration. The Config struct gains a Context field for context selection and improved Kubeconfig documentation. Kubeconfig path loading is refactored to handle path lists via a new buildLoadingRules helper, with context/cluster resolution and logging added via logResolvedContext. Configuration propagation includes the new context field.

Changes

Kubeconfig Context and Path Selection

Layer / File(s) Summary
Data Shape
pkg/argo/config.go
Config struct adds exported Context field to select a kubeconfig context; Kubeconfig field is documented to accept single path or KUBECONFIG-style path list.
Environment Loading
pkg/argo/config.go
NewConfigFromEnv initializes Kubeconfig from the KUBECONFIG environment variable.
Path and Context Resolution
pkg/argo/client.go
New buildLoadingRules helper parses kubeconfig paths using filepath.SplitList or defaults to standard discovery. New logResolvedContext helper resolves the kubeconfig and logs selected context/cluster, with fallback to current-context.
Client Initialization
pkg/argo/client.go
Direct Kubernetes API mode now builds loading rules via buildLoadingRules, applies context override via clientcmd.ConfigOverrides{CurrentContext: config.Context}, and logs resolved context.
Configuration Propagation
internal/config/config.go
(*Config).ToArgoConfig() now sets the Context field in the returned argo.Config.
Tests
pkg/argo/client_test.go
New TestBuildLoadingRules validates path parsing for empty, single, and multiple kubeconfig paths.

Sequence Diagram

sequenceDiagram
    participant Env as Environment/<br/>Config
    participant Config as argo.Config<br/>Structure
    participant Rules as buildLoadingRules<br/>Helper
    participant Resolver as logResolvedContext<br/>Helper
    participant KubeAPI as Kubernetes<br/>Client

    Env->>Config: Read KUBECONFIG env var<br/>and Context field
    Config->>Rules: Pass Kubeconfig paths
    Rules->>Rules: Split paths (KUBECONFIG style)<br/>or use defaults
    Config->>Resolver: Provide loading rules<br/>and context override
    Resolver->>Resolver: Resolve kubeconfig<br/>Select context
    Resolver->>Resolver: Extract cluster info<br/>and log metadata
    Config->>KubeAPI: Build client config<br/>with context override
    KubeAPI->>KubeAPI: Initialize API client
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A kubeconfig rabbit hops with glee,
Context-aware paths, wild and free!
Split those lists like lettuce leaves so fine,
Logging clusters—every hop's divine!
From env to client, the journey's clear,
Configuration blooms, oh what good cheer! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main changes: multi-file KUBECONFIG support and --context flag handling, matching the primary objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/multi-kubeconfig-context

Comment @coderabbitai help to get the list of available commands and usage tips.

@Joibel Joibel merged commit 34dd079 into main May 5, 2026
6 checks passed
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.

1 participant