Skip to content

feat: add extraContainers to SharedDeploymentSpec for sidecar support#1724

Merged
EItanya merged 6 commits intokagent-dev:mainfrom
mesutoezdil:feat/extra-containers-sidecar
May 1, 2026
Merged

feat: add extraContainers to SharedDeploymentSpec for sidecar support#1724
EItanya merged 6 commits intokagent-dev:mainfrom
mesutoezdil:feat/extra-containers-sidecar

Conversation

@mesutoezdil
Copy link
Copy Markdown
Contributor

@mesutoezdil mesutoezdil commented Apr 21, 2026

Closes #1646.

There's currently no way to run a sidecar container alongside the main agent pod. This adds an optional extraContainers field to SharedDeploymentSpec so users can inject things like token proxies, log shippers, or any other helper container.

The field is optional and defaults to empty, so existing agents are unaffected. When set, the extra containers are appended after the primary kagent container in the pod spec.

Changes:

  • Added ExtraContainers []corev1.Container to SharedDeploymentSpec in agent_types.go
  • Wired it through the internal resolvedDeployment struct in deployments.go for both inline and BYO paths
  • Updated manifest_builder.go to append the extra containers to the pod spec
  • Added a golden test with an Envoy sidecar

Example:

spec:
  type: Declarative
  declarative:
    deployment:
      extraContainers:
        - name: token-proxy
          image: envoyproxy/envoy:v1.30.0
          ports:
            - containerPort: 9901

Copilot AI review requested due to automatic review settings April 21, 2026 11:53
@mesutoezdil mesutoezdil force-pushed the feat/extra-containers-sidecar branch from 12f6a30 to 8adc35b Compare April 21, 2026 11:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for running sidecar containers alongside the main kagent container by introducing an optional extraContainers field on SharedDeploymentSpec, wiring it through deployment resolution, and emitting it into the generated Pod spec.

Changes:

  • Extend SharedDeploymentSpec with extraContainers to allow user-defined sidecars.
  • Propagate extraContainers through both inline and BYO deployment resolution paths.
  • Update manifest building and golden test fixtures to include appended sidecar containers.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
go/api/v1alpha2/agent_types.go Adds ExtraContainers to the public CRD API type.
go/core/internal/controller/translator/agent/deployments.go Threads ExtraContainers into the resolved deployment model.
go/core/internal/controller/translator/agent/manifest_builder.go Appends ExtraContainers after the primary kagent container in the Pod spec.
go/core/internal/controller/translator/agent/testdata/inputs/agent_with_extra_containers.yaml Adds a new golden input covering sidecar configuration.
go/core/internal/controller/translator/agent/testdata/outputs/agent_with_extra_containers.json Adds the expected rendered manifests including the sidecar container.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

PodSecurityContext: spec.PodSecurityContext,
ServiceAccountName: spec.ServiceAccountName,
ServiceAccountConfig: spec.ServiceAccountConfig,
ExtraContainers: slices.Clone(spec.ExtraContainers),
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

There is no validation preventing extraContainers from using the reserved name kagent (or causing duplicate container names). If a user sets a sidecar name that duplicates the primary container (or another sidecar), the generated PodSpec will be rejected by Kubernetes and reconciliation will fail. Consider adding validation during resolve (or API validation) to reject ExtraContainers entries with Name == \"kagent\" and to enforce uniqueness across all container names.

Copilot uses AI. Check for mistakes.
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.

@mesutoezdil this needs to be solved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a71c636. Added validateExtraContainers which returns an error if any extra container uses the reserved name "kagent" or if two extra containers share the same name. The check runs in both resolveInlineDeployment and resolveByoDeployment before the slice is cloned. Five unit tests cover the cases: empty list, normal names, reserved name, duplicates, and mixed.

// +optional
ServiceAccountConfig *ServiceAccountConfig `json:"serviceAccountConfig,omitempty"`
// ExtraContainers is a list of additional containers to run alongside the main agent container.
// Useful for sidecars such as token proxies, log shippers, or security agents.
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

Exposing []corev1.Container directly in a CRD can significantly bloat the generated OpenAPI schema and can also prune unknown/newer container fields (apiserver schema-pruning) as Kubernetes evolves. To avoid CRD size/compatibility issues, consider marking this field as schemaless / preserve-unknown-fields (kubebuilder marker) or switching to a slimmer custom sidecar spec / raw JSON representation, depending on how strictly you want to validate user input.

Suggested change
// Useful for sidecars such as token proxies, log shippers, or security agents.
// Useful for sidecars such as token proxies, log shippers, or security agents.
// Preserve unknown/newer container fields in the CRD schema to avoid pruning as Kubernetes evolves.
// +kubebuilder:validation:Schemaless
// +kubebuilder:pruning:PreserveUnknownFields

Copilot uses AI. Check for mistakes.
Adds an optional extraContainers field to SharedDeploymentSpec so users
can inject sidecar containers (token proxies, log shippers, etc.) alongside
the main agent container. The extra containers are appended after the
primary kagent container in the pod spec.

Closes kagent-dev#1646

Signed-off-by: mesutoezdil <mesudozdil@gmail.com>
Signed-off-by: mesutoezdil <mesudozdil@gmail.com>
mesutoezdil and others added 3 commits April 29, 2026 20:07
Without this check a user could set an extra container named "kagent",
which would produce a pod with two containers sharing the same name.
Kubernetes rejects such pods, leaving the agent stuck in a reconcile loop.

validateExtraContainers now returns an error early in both
resolveInlineDeployment and resolveByoDeployment when any extra container
uses the reserved name "kagent" or when two extra containers share a name.

Signed-off-by: mesutoezdil <mesudozdil@gmail.com>
Signed-off-by: mesutoezdil <mesudozdil@gmail.com>
@EItanya EItanya merged commit 318b19b into kagent-dev:main May 1, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add ExtraContainers to SharedDeploymentSpec

3 participants