Skip to content

[TASK] Refactor drop the full Kubernetes clientset to shrink the binary by ~26MB #1649

Closed

Description

@edenreich

Summary

The release binaries grew from about 50MB to about 105MB. The release pipeline is not the cause. release.yml builds with the same flags as task build (CGO_ENABLED=0 -tags purego -ldflags "-w -s"), and a local task build at HEAD is also about 105MB.

The size grew with two features:

Release linux-amd64 Cause
<= v0.230.3 50MB
v0.231.0 71MB (+21) The daemon's A2A server imports adk/server, which pulls in gin, sonic, minio, redis v9, mongo-driver, quic-go, cloudevents and mcp-golang
v0.239.0-rc.1 105MB (+34) The teleport Kubernetes executor imports the full k8s.io/client-go/kubernetes clientset

The clientset links 55 typed API-group clients. Through kubernetes/scheme, which discovery and every typed client import, it also links all 56 k8s.io/api groups. internal/agent/infrastructure/kubernetes needs it for only three things:

  • Secret CRUD in ensureSecret, ownSecret and Delete
  • the pod portforward URL in portforward.go
  • Discovery().ServerVersion() in Probe

client-go/dynamic, rest, tools/clientcmd, tools/portforward and transport/spdy do not import the scheme. self.go already uses only the dynamic client.

Proposed change

All changes stay in internal/agent/infrastructure/kubernetes/:

  • Drop the typed k8sclient.Interface field and the k8s.io/client-go/kubernetes import.

  • Add a core/v1 REST client that carries no scheme:

    coreConfig := k8sdynamic.ConfigFor(restConfig)
    coreConfig.APIPath = "/api"
    coreConfig.GroupVersion = &k8sschema.GroupVersion{Version: "v1"}
    return k8srest.RESTClientFor(coreConfig)
  • Route Secrets through the dynamic client:

    • Add secretGVR = {Version: "v1", Resource: "secrets"}.
    • On Get and Create, convert between corev1.Secret and unstructured with k8sruntime.DefaultUnstructuredConverter, which the file already uses for the pod spec.
    • On Create, set TypeMeta{APIVersion: "v1", Kind: "Secret"}.
  • portforward.go: change e.typed.CoreV1().RESTClient().Post() to e.core.Post(). It builds the same URL.

  • Probe: replace e.typed.Discovery().ServerVersion() with e.core.Get().AbsPath("/version").DoRaw(ctx) decoded into k8s.io/apimachinery/pkg/version.Info.

  • environment_test.go: drop k8s.io/client-go/kubernetes/fake.

    • Add secretGVR: "SecretList" to the dynamic fake's list kinds, and seed Secrets as unstructured objects.
    • Assert on dynamic.Actions() only.

Measured impact

A go build -overlay prototype of the change above compiles and passes go vet:

  • Stripped linux/amd64 drops from 110.4MB to 83.7MB, a saving of 26.7MB (-24%).
  • Linked k8s.io/api packages drop from 56 to 1.

Out of scope

The +21MB from adk/server needs an upstream change in inference-gateway/adk:

  • Make the redis and minio storage backends opt-in subpackages.
  • Avoid gin, whose binding and render packages pull in ugorji, mongo bson and quic-go.

The CLI cannot trim that locally without dropping the daemon's A2A server.

Acceptance Criteria

  • go list -tags purego -deps ./cmd/infer lists no k8s.io/client-go/kubernetes package and exactly one k8s.io/api/ package (core/v1)
  • task build produces a binary roughly 25MB smaller than before
  • go test ./internal/agent/infrastructure/kubernetes/ ./cmd/daemon/... passes
  • task precommit:run passes
  • A teleport to a kubernetes environment still works:
    • its Secret is created and owned by the Sandbox
    • the port-forward connects
    • the environment probe reports the kubernetes version

Activity

  1. added
    refactor
    on Oct 30, 2026
  2. added theissue type on Oct 30, 2026
  3. moved this from Todo to Done in 2026on Nov 3, 2026
  4. inference-gateway-releaser commented on Nov 3, 2026

    @inference-gateway-releaser
    Contributor

    🎉 This issue has been resolved in version 0.241.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorreleased

    Type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions