Skip to content

fix(controller): keep user env vars over controller defaults - #2327

Open
mesutoezdil wants to merge 19 commits into
kagent-dev:mainfrom
mesutoezdil:fix/agent-env-precedence
Open

fix(controller): keep user env vars over controller defaults#2327
mesutoezdil wants to merge 19 commits into
kagent-dev:mainfrom
mesutoezdil:fix/agent-env-precedence

Conversation

@mesutoezdil

Copy link
Copy Markdown
Contributor

Agent env was built as user env then shared env appended after it. Same name in both means the shared value wins on the pod, since k8s takes the last entry for duplicate names. A user setting OTEL_SERVICE_NAME or KAGENT_NAME on their own agent got silently overwritten by the controller default, no error or warning.

Now shared entries are only added if the user did not already set that name, so the user's own value always wins.

Added a unit test covering the collision case.

Agent env was built as user env then shared env appended after it.
Same name in both means the shared value wins on the pod, since k8s
takes the last entry. A user setting OTEL_SERVICE_NAME or similar on
their own agent got silently overwritten by the controller default.

Now shared entries are only added if the user did not already set
that name.

Signed-off-by: mesutoezdil <mesudozdil@gmail.com>
@mesutoezdil
mesutoezdil requested a review from a team as a code owner July 25, 2026 10:06
@github-actions github-actions Bot added the bug Something isn't working label Jul 25, 2026

@0809android 0809android 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.

Please keep the controller-owned identity variables authoritative. sharedEnv also contains KAGENT_NAME, KAGENT_NAMESPACE, and KAGENT_URL, so this merge lets spec.deployment.env replace them. KAgentConfig.app_name uses the first two as agent_ref; HandleCreateSession then requires that ref to match a registered Agent. For example, KAGENT_NAME=custom on kagent/my-agent produces kagent__NS__custom and session creation fails as an invalid agent ref. I reproduced that merge on this head with a focused Go test. Could overrides be limited to propagated OTEL_* values while preserving controller-owned values?

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants