Skip to content

feat(orchestrator): add generic k8s kubeconfig helpers, pinned kubectlIn, and air-gap telemetry guard - #6649

Open
Neelabh94 wants to merge 5 commits into
GoogleCloudPlatform:developfrom
Neelabh94:feat/k8s-kubeconfig-airgap-guard
Open

Neelabh94 wants to merge 5 commits into
GoogleCloudPlatform:developfrom
Neelabh94:feat/k8s-kubeconfig-airgap-guard

Conversation

@Neelabh94

@Neelabh94 Neelabh94 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Related PRs (2 of 3 — Standalone on develop):

Summary

Extracts provider-agnostic kubeconfig loading, context resolution, and --context pinning utilities into pkg/orchestrator/k8s, hardens kubectl probe pinning with kubectlIn, and guards CLI telemetry uploads in air-gapped environments via foundational pkg/shell state.

  • Provider-Agnostic Kubeconfig Helpers (pkg/orchestrator/k8s/types.go, pkg/orchestrator/k8s/kubeconfig.go):
    • Adds KubeconfigLoader, DefaultKubeconfigLoader, FindContextByCluster (preferring exact context name matches, then active current-context when its cluster matches, before deterministic sorted cluster-entry lookup), ResolveCurrentContext, ExecPluginBaseName (normalizing Windows \ paths and .exe suffixes on Unix/WSL), and WithContext.
  • Pinned kubectlIn & gke Kubeconfig Refactor (pkg/orchestrator/gke/types.go, pkg/orchestrator/gke/kube_auth.go, pkg/orchestrator/gke/inspector.go, pkg/orchestrator/gke/sps_client.go, pkg/orchestrator/gke/gke_job_orchestrator.go):
    • Moves kubeconfig endpoint/probe types into pkg/orchestrator/gke/types.go, wires pkg/orchestrator/gke onto pkg/orchestrator/k8s with shell.ExtractRegion zonal-to-regional GKE context fallback in resolveGKEContext, distinguishes missing current-context from unknown cluster names in GetCurrentNamespace, adds kubectlIn refusing empty contexts so connectivity probes never silently fall back to current-context, and extends TestNoUnpinnedKubectlCalls across pkg/orchestrator/....
  • Foundational Air-Gap Telemetry Guard (pkg/shell/airgap.go, pkg/telemetry/telemetry.go, pkg/telemetry/README.md):
    • Introduces lock-free GCLUSTER_AIR_GAPPED classification (IsKnownAirGapped, IsAirGappedEnv, SetDefaultAirGapped, SetDefaultAirGappedState) in pkg/shell (preserving strict Layer-1 separation without pkg/telemetry importing pkg/orchestrator), short-circuits telemetry.Collector.Execute when air-gapped so disconnected CLI runs never stall on Clearcut uploads at exit, and documents GCLUSTER_AIR_GAPPED in pkg/telemetry/README.md.

Cloud-Docs: none

Testing

  • KUBECONFIG=/dev/null GOOGLE_API_USE_CLIENT_CERTIFICATE=false go test -race -count=1 ./pkg/shell/... ./pkg/orchestrator/... ./pkg/telemetry/... ./cmd/job/...
  • Covers TestFindContextByCluster, TestResolveCurrentContext, TestExecPluginBaseName, TestWithContextAndDefaultLoader, TestNoUnpinnedKubectlCalls, TestKubectlIn_RefusesEmptyContextAndPinsNonEmpty, TestResolveGKEContext_ZonalFallbackAndCurrentContext, TestDefaultKubeClient_GetCurrentNamespaceErrors, TestAirGappedPrecedenceAndConcurrency, and TestExecute_AirGappedSkipsClearcut.

@Neelabh94 Neelabh94 added enhancement New feature or request go Pull requests that update Go code release-improvements Added to release notes under the "Improvements" heading. labels Nov 6, 2026
@Neelabh94 Neelabh94 self-assigned this Nov 6, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors Kubernetes orchestration logic to improve reliability and environment awareness. By centralizing kubeconfig management and enforcing pinned context execution, it eliminates common connectivity pitfalls. Additionally, it introduces robust support for air-gapped environments by allowing telemetry uploads to be disabled, ensuring the CLI remains performant in restricted network settings.

Highlights

  • Provider-Agnostic Kubeconfig Helpers: Introduced centralized utilities in pkg/orchestrator/k8s for loading kubeconfig, resolving contexts, and normalizing execution plugin paths, improving consistency across the orchestrator.
  • Pinned kubectlIn & GKE Refactor: Refactored GKE orchestration to use kubectlIn for pinned context execution, preventing silent fallbacks to the current-context and adding zonal-to-regional GKE context resolution.
  • Air-Gap Telemetry Guard: Added an Environment classifier and GCLUSTER_AIR_GAPPED support to short-circuit telemetry uploads in disconnected environments, preventing CLI stalls.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for air-gapped environments via the GCLUSTER_AIR_GAPPED environment variable, which disables telemetry uploads and external probes. It also refactors kubeconfig loading and context resolution into a shared pkg/orchestrator/k8s package. The reviewer suggested using the existing shell.ExtractRegion helper in kube_auth.go to simplify the zonal-to-regional fallback logic instead of manually splitting the location string.

Comment thread pkg/orchestrator/gke/kube_auth.go Resolved
…lIn, and air-gap telemetry guard

- Add provider-agnostic kubeconfig loading, deterministic context resolution, cross-OS exec-plugin basename normalization, and --context pinning helpers in pkg/orchestrator/k8s.
- Refactor pkg/orchestrator/gke kube_auth, inspector, and namespace resolution onto pkg/orchestrator/k8s, move kube_auth type declarations into types.go, add empty-context-safe kubectlIn, and extend TestNoUnpinnedKubectlCalls across pkg/orchestrator/...
- Add non-probing GCLUSTER_AIR_GAPPED Environment state classification and skip Clearcut CLI telemetry uploads when air-gapped so disconnected runs exit immediately.
…onor current-context, and reuse ExtractRegion
…tighten doc comments, and defer ResolveContext
@Neelabh94
Neelabh94 force-pushed the feat/k8s-kubeconfig-airgap-guard branch from ebf11d8 to feec9c3 Compare November 6, 2026 13:38
@Neelabh94
Neelabh94 marked this pull request as ready for review November 6, 2026 17:31
@Neelabh94
Neelabh94 requested a review from a team as a code owner November 6, 2026 17:31
@Neelabh94
Neelabh94 force-pushed the feat/k8s-kubeconfig-airgap-guard branch from c9d0258 to dd49a69 Compare November 7, 2026 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update Go code release-improvements Added to release notes under the "Improvements" heading.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants