Repository navigation
refactor(k8s): KubernetesService is the Kubernetes API seam, with a shared fake cluster and its contract suite - #2527
Merged
Conversation
…hared fake cluster and its contract suite `k8s/api.py` holds the seam. The Protocols `CoreApi`, `CustomObjectsApi` and `VersionApi` name the 18 calls that devops-cli makes on the SDK's API objects, and `KubernetesApiSource` names where the objects come from. `KubernetesClientSource` is the one real source. It uses the kubeconfig when the kubeconfig names the context, else the pod's service account, reads every `KUBECONFIG` entry when it connects, and builds each `ApiClient` with its own `Configuration`. `KubernetesService` takes a source. `install(source)` replaces the process's service until `reset_instance`, and `core_api` and `custom_objects_api` are its public accessors, so the informer and the service proxy no longer read `_core_v1`. `switch_context` checks the context and points the clients at it; it no longer writes the kubeconfig after `kubectl config use-context`. The unused `AppsV1Api` client is deleted. `tests/support/fakes/kubernetes.py` promotes `tests/k8s_fakes.py`: `FakeCluster` over `FakeCoreV1`, `FakeCustomObjects` and `FakeVersion`, behind the `cluster` fixture. `tests/k8s/test_kubernetes_contract.py` runs each case over the fake and over the real client against recorded API responses that a loopback server replays. The tests that reached the service through `_core_v1`, `load_config` patches or patched SDK modules now use the fake.
Owner
Author
|
Test evidence:
Pending a person:
|
dan-petty
marked this pull request as ready for review
October 28, 2026 20:15
dan-petty
pushed a commit
that referenced
this pull request
Oct 28, 2026
🤖 I have created a release *beep* *boop* --- ## [0.11.1](v0.11.0...v0.11.1) (2026-10-28) ### Bug Fixes * **config:** devops config audit-keys scans each config file that the settings merge ([#2516](#2516)) ([57541df](57541df)) * **security:** the osv, internetdb, radar and cloudflare api clients dial through the egress-checked factory at the public level ([#2509](#2509)) ([0379f21](0379f21)) ### Code Refactoring * **k8s:** KubernetesService is the Kubernetes API seam, with a shared fake cluster and its contract suite ([#2527](#2527)) ([0f6b9af](0f6b9af)), closes [#1315](#1315) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
devops-cli reached the Kubernetes API through
KubernetesServiceand four other loaders, and its tests reached the API by patching the SDK. This change makes the service the one seam of the Kubernetes API edge, with a shared fake and a contract suite that holds the fake to the real client.src/devops_cli/k8s/api.pyis the seam. The ProtocolsCoreApi,CustomObjectsApiandVersionApiname the 18 calls that devops-cli makes on the SDK's API objects, andKubernetesApiSourcenames where the objects come from:contexts()andconnect(context).KubernetesClientSourceis the one real source, with one configuration rule: the kubeconfig when the kubeconfig names the context, else the pod's service account. Before, the service tried the service account first, so inside a pod it ignored the configured context. The source reads everyKUBECONFIGentry when it connects, and it builds eachApiClientwith its ownConfiguration, so it never writes the client's global default.KubernetesServicetakes a source.KubernetesService.install(source)replaces the process's service untilreset_instance.core_apiandcustom_objects_apiare its public accessors, and the informer and the service proxy usecore_apiinstead of the private_core_v1.switch_contextchecks that the kubeconfig names the context and points the in-process clients at it. It no longer writes the kubeconfig afterkubectl config use-context, so the comments of the file stay. The unusedAppsV1Apiclient and_get_kubeconfig_pathare deleted.tests/support/fakes/kubernetes.pypromotestests/k8s_fakes.py:FakeCluster, a source overFakeCoreV1,FakeCustomObjectsandFakeVersion, behind theclusterfixture. A missing object is the SDK'sApiExceptionwith its status,unreachable()refuses every call as an API server that does not listen, and each fake records its calls.tests/k8s/test_kubernetes_contract.pyruns each case through the service over the fake and over the real client, whose kubeconfig intmp_pathpoints at a loopback server that replaystests/fixtures/kubernetes/recorded_responses.json._core_v1, patchedload_config, or patchedkubernetesmodules now use the fake.tests/test_k8s_service.pypatches nokubernetesname and no method of the service.k8s/service_proxy.py,k8s/doctor.py,commands/k8s/cluster_context.pyandui/data_providers.pykeep their own loaders until test(k8s): k8s/ is tested through its public interface over the Kubernetes API, process, HTTP and keyring fakes, with no internal patches or private imports #1322, test(k8s): devops k8s commands are thin adapters tested over edge fakes, and the _K8sModule patch forwarding is gone #1323 and test(telemetry): telemetry, server, ui, output and docs tests run on edge fakes, and the dashboard suite splits by behaviour #1334 route them through the seam.Closes #1315
Change:
openspec/changes/archive/2026-10-28-1315-kubernetes-api-seam/