Skip to content

refactor(ops): depend on kubernetesjs and reuse its APIClient - #40

Merged
pyramation merged 1 commit into
mainfrom
feat/ops-reuse-kubernetesjs-client
Aug 23, 2026
Merged

refactor(ops): depend on kubernetesjs and reuse its APIClient#40
pyramation merged 1 commit into
mainfrom
feat/ops-reuse-kubernetesjs-client

Conversation

@pyramation

Copy link
Copy Markdown
Collaborator

Summary

Makes kubernetesjs a real (published) dependency of @kubernetesjs/ops and drops ops's duplicated HTTP transport in favor of the core one — no schema-sdk changes needed, since npmApiClient already accepts an arbitrary import specifier:

 // packages/ops/scripts/codegen.ts
-npmApiClient: './client',
+npmApiClient: 'kubernetesjs/client',
  • packages/ops/src/client.ts deleted; the regenerated src/index.ts now imports APIClient/APIClientOptions/APIClientRequestOpts from kubernetesjs/client (only the import line changed in the generated output).
  • packages/ops/package.json gains "kubernetesjs": "workspace:^", so on publish kubernetesjs becomes a subdep of @kubernetesjs/ops.
  • Side effect: ops now gets the richer core client for free (in-cluster SA token support, token/headers/timeout options, getInClusterConfig()), instead of the older stale copy.
  • @kubernetesjs/client's Client stopped passing kubeconfig/namespace/context to new KubernetesClient(...) — those fields existed only in ops's old APIClientOptions and were never read by the transport (dead options); the core APIClientOptions doesn't declare them.

Not done here (would require a schema-sdk feature): importing the core k8s types (ObjectMeta, Pod, …) from kubernetesjs instead of re-emitting them into ops's generated index.ts — schema-sdk currently has no "external types" option, so the generated type surface is unchanged.

Verified with pnpm build and pnpm lint across the workspace (what CI runs).

Link to Devin session: https://app.devin.ai/sessions/95f4ed628067485ebab80535c50d6e88
Requested by: @pyramation

@devin-ai-integration

Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@tenki-reviewer

tenki-reviewer Bot commented Aug 23, 2026

Copy link
Copy Markdown

Review complete. 🟡 2 medium

💬 Inline comments (1)

  • 🟡 kubeconfig/context silently ignored by Clientclient.ts:46
📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to

🟡 Medium — Dashboard passes removed kubeconfig/context to KubernetesClient · apps/ops-dashboard/services/kubernetes-client.ts

The @kubernetesjs/ops KubernetesClient constructor now takes APIClientOptions re-exported from kubernetesjs/client (packages/ops/src/index.ts:1), which no longer contains kubeconfig, namespace, or context. In-repo consumers still pass those fields: apps/ops-dashboard/services/kubernetes-client.ts:16-18 and apps/ops-dashboard/k8s/context.tsx:59-61 call new KubernetesClient({ ... kubeconfig: '', namespace, context: 'default' }).

These become excess-property type errors and the values are silently discarded at runtime. Because the dashboard is excluded from pnpm build, CI will not surface the break.


This PR consolidates the duplicated APIClient in @kubernetesjs/ops onto the shared kubernetesjs client: it deletes packages/ops/src/client.ts, rewires the ops codegen and src/index.ts to import from kubernetesjs/client, and adds kubernetesjs as a workspace dependency. The Client constructor now forwards only restEndpoint, and the ops APIClientOptions no longer carries kubeconfig/namespace/context.

Files Change
packages/client/src/client.ts Constructor forwards only restEndpoint; kubeconfig/context on KubernetesContext are now silently ignored.
packages/ops/src/client.ts, packages/ops/src/index.ts, packages/ops/scripts/codegen.ts, packages/ops/package.json Deletes the local APIClient, imports kubernetesjs/client, and adds the kubernetesjs dependency.
apps/ops-dashboard/services/kubernetes-client.ts, apps/ops-dashboard/k8s/context.tsx Downstream consumers still pass removed kubeconfig/namespace/context to KubernetesClient (not in this diff; broken by it).

Reviewed commit: 8f0fcad

@tenki-reviewer tenki-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Refactors @kubernetesjs/ops to reuse the kubernetesjs APIClient, deleting the local APIClient and switching imports to the kubernetesjs/client package, but leaves kubeconfig/context options silently ignored and in-repo dashboard consumers passing removed constructor fields.

Key findings

  • 🟡 Dashboard passes removed kubeconfig/context to KubernetesClientkubernetes-client.ts
  • 🟡 kubeconfig/context silently ignored by Clientclient.ts:46

Comment on lines 46 to 48
this.kubeClient = new KubernetesClient({
kubeconfig: ctx.kubeconfig,
namespace: ctx.namespace,
context: ctx.context,
restEndpoint: ctx.restEndpoint || 'http://127.0.0.1:8001'
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 bug · medium

kubeconfig/context silently ignored by Client

The Client constructor now forwards only restEndpoint to KubernetesClient, so the kubeconfig and context fields on the public KubernetesContext interface are silently discarded and every request targets restEndpoint (default http://127.0.0.1:8001) (packages/client/src/client.ts:46-48).

The --kubeconfig and --context CLI flags in packages/ops-cli/src/index.ts at lines 28-29 still pass these values through, so a user selecting a non-default cluster gets a client silently wired to the proxy instead. The PR removed the forwarding without reconciling the interface, leaving a misleading contract.

📋 Prompt for AI Agents

In packages/client/src/client.ts, the Client constructor (lines 44-48) no longer forwards kubeconfig/context to KubernetesClient, yet KubernetesContext (lines 28-35) still declares kubeconfig and context, and packages/ops-cli commands (setup.ts:180-186, deploy.ts:111-117, delete.ts, status.ts, teardown.ts) pass --kubeconfig/--context expecting cluster selection. Either (a) remove kubeconfig and context from KubernetesContext and stop passing them from the ops-cli commands and index.ts flags, or (b) implement real kubeconfig/context loading in the KubernetesClient. Do not leave public options that are silently ignored.

@pyramation
pyramation merged commit 1f2153e into main Aug 23, 2026
14 checks passed
@pyramation
pyramation deleted the feat/ops-reuse-kubernetesjs-client branch August 23, 2026 09:44
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