Skip to content

OLS-3274: inject audit env vars into sandbox pods from AgenticOLSConfig#232

Open
vimalk78 wants to merge 1 commit into
openshift:mainfrom
vimalk78:ols-3274-sandbox-audit-env
Open

OLS-3274: inject audit env vars into sandbox pods from AgenticOLSConfig#232
vimalk78 wants to merge 1 commit into
openshift:mainfrom
vimalk78:ols-3274-sandbox-audit-env

Conversation

@vimalk78

Copy link
Copy Markdown
Contributor

Read the AgenticOLSConfig CR's audit config and set LIGHTSPEED_AUDIT_ENABLED and OTEL_EXPORTER_OTLP_ENDPOINT on sandbox containers in both bare-pod and sandbox-template paths. Include audit config in the template hash so config changes trigger new templates.

@openshift-ci-robot

openshift-ci-robot commented Jun 25, 2026

Copy link
Copy Markdown

@vimalk78: This pull request references OLS-3274 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Read the AgenticOLSConfig CR's audit config and set LIGHTSPEED_AUDIT_ENABLED and OTEL_EXPORTER_OTLP_ENDPOINT on sandbox containers in both bare-pod and sandbox-template paths. Include audit config in the template hash so config changes trigger new templates.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jun 25, 2026
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@vimalk78, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 45 minutes and 31 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 4f7a3ad0-2e2a-4863-bf68-3bf9df2fce72

📥 Commits

Reviewing files that changed from the base of the PR and between 02a3248 and 1155906.

📒 Files selected for processing (7)
  • controller/proposal/bare_pod_manager.go
  • controller/proposal/bare_pod_manager_test.go
  • controller/proposal/helpers.go
  • controller/proposal/podspec_builder.go
  • controller/proposal/sandbox_templates.go
  • controller/proposal/sandbox_templates_test.go
  • controller/proposal/sandbox_test.go
📝 Walkthrough

Walkthrough

The controller now reads audit settings from AgenticOLSConfig and uses them when building bare pods and sandbox templates. Audit logging and OTEL endpoint values are added to container environment variables, and template hashes now include audit config fields.

Changes

Audit config propagation

Layer / File(s) Summary
Audit config reader and env helper
controller/proposal/helpers.go, controller/proposal/podspec_builder.go
readAuditConfig fetches the cluster audit config, and appendAuditEnvVars appends LIGHTSPEED_AUDIT_ENABLED and OTEL_EXPORTER_OTLP_ENDPOINT to a container when configured.
Bare pod audit env injection
controller/proposal/bare_pod_manager.go, controller/proposal/bare_pod_manager_test.go
BarePodManager.Claim calls appendAuditEnvVars before pod creation; tests cover default-enabled, OTEL-enabled, and disabled audit configs on the created container.
Sandbox template audit handling
controller/proposal/sandbox_templates.go, controller/proposal/sandbox_templates_test.go
templateHashInput and computeTemplateHash include audit fields, EnsureAgentTemplate passes audit config into hashing and patches audit env vars onto the template, and tests cover the new signature and hash changes.

Sequence Diagram(s)

sequenceDiagram
  participant EnsureAgentTemplate
  participant readAuditConfig
  participant computeTemplateHash
  participant patchAuditEnvVars
  participant "client.Client" as clientClient

  EnsureAgentTemplate->>readAuditConfig: load cluster audit config
  readAuditConfig->>clientClient: Get AgenticOLSConfig "cluster"
  clientClient-->>readAuditConfig: *AuditConfig or nil
  readAuditConfig-->>EnsureAgentTemplate: audit config
  EnsureAgentTemplate->>computeTemplateHash: include audit logging and OTEL endpoint
  EnsureAgentTemplate->>patchAuditEnvVars: patch template env vars
  patchAuditEnvVars->>readAuditConfig: load cluster audit config
  readAuditConfig->>clientClient: Get AgenticOLSConfig "cluster"
  clientClient-->>patchAuditEnvVars: *AuditConfig or nil
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: injecting audit env vars from AgenticOLSConfig into sandbox pods.
Description check ✅ Passed The description is directly aligned with the changes, covering audit env vars and template hash updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@openshift-ci

openshift-ci Bot commented Jun 25, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign xrajesh for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
controller/proposal/sandbox_templates.go (1)

231-233: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Audit config is read twice; the hash and the patched env vars can diverge.

EnsureAgentTemplate reads audit config at Line 176 to compute the template name/hash, then patchAuditEnvVars (Line 749) calls readAuditConfig again. Besides the redundant API Get, if the CR changes between the two reads, the template name reflects the first read while its env vars reflect the second — the name no longer describes its contents. Reuse the already-fetched value.

Proposed fix: pass audit into the patch helper
-	if err := patchAuditEnvVars(ctx, c, derived); err != nil {
+	if err := patchAuditEnvVars(derived, audit); err != nil {
 		return "", fmt.Errorf("patch audit env vars: %w", err)
 	}
-func patchAuditEnvVars(ctx context.Context, c client.Client, tmpl *unstructured.Unstructured) error {
-	audit := readAuditConfig(ctx, c)
+func patchAuditEnvVars(tmpl *unstructured.Unstructured, audit *agenticv1alpha1.AuditConfig) error {
 	if audit.LoggingEnabled() {

Also applies to: 748-761

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@controller/proposal/sandbox_templates.go` around lines 231 - 233, Ensure
EnsureAgentTemplate and patchAuditEnvVars use the same audit config snapshot
instead of calling readAuditConfig twice. Pass the already-fetched audit value
from EnsureAgentTemplate into patchAuditEnvVars (and any helper it uses) so the
template name/hash and the patched env vars are derived from the same data,
avoiding divergence if the CR changes between reads.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@controller/proposal/helpers.go`:
- Around line 75-81: readAuditConfig currently swallows every c.Get error by
returning nil, which lets computeTemplateHash and appendAuditEnvVars later
dereference a nil AuditConfig and panic. Update readAuditConfig in
controller/proposal/helpers.go to follow the isSuspended pattern: return nil
only when the AgenticOLSConfig object is NotFound, and surface all other
client.Get errors to the caller so upstream code can handle transient failures
safely.

---

Nitpick comments:
In `@controller/proposal/sandbox_templates.go`:
- Around line 231-233: Ensure EnsureAgentTemplate and patchAuditEnvVars use the
same audit config snapshot instead of calling readAuditConfig twice. Pass the
already-fetched audit value from EnsureAgentTemplate into patchAuditEnvVars (and
any helper it uses) so the template name/hash and the patched env vars are
derived from the same data, avoiding divergence if the CR changes between reads.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 6276b424-5c8c-445b-9566-148232766645

📥 Commits

Reviewing files that changed from the base of the PR and between 5e8e27d and 02a3248.

📒 Files selected for processing (6)
  • controller/proposal/bare_pod_manager.go
  • controller/proposal/bare_pod_manager_test.go
  • controller/proposal/helpers.go
  • controller/proposal/podspec_builder.go
  • controller/proposal/sandbox_templates.go
  • controller/proposal/sandbox_templates_test.go
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • openshift/lightspeed-agentic-sandbox (manual)

Comment thread controller/proposal/helpers.go Outdated
Read the AgenticOLSConfig CR's audit config and set
LIGHTSPEED_AUDIT_ENABLED and OTEL_EXPORTER_OTLP_ENDPOINT on sandbox
containers in both bare-pod and sandbox-template paths. Include audit
config in the template hash so config changes trigger new templates.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Vimal Kumar <vimal78@gmail.com>
@vimalk78 vimalk78 force-pushed the ols-3274-sandbox-audit-env branch from 02a3248 to 1155906 Compare June 25, 2026 09:33
@openshift-ci

openshift-ci Bot commented Jun 25, 2026

Copy link
Copy Markdown

@vimalk78: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@blublinsky blublinsky left a comment

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.

nice-to-have: Redundant AgenticOLSConfig read on every Claim()

Location: controller/proposal/podspec_builder.go:appendAuditEnvVars and controller/proposal/sandbox_templates.go:EnsureAgentTemplate

Observation:

A single reconcile reads AgenticOLSConfig/cluster twice:

  1. isSuspended() at the top of Reconcile()
  2. readAuditConfig() inside Claim() (via appendAuditEnvVars or EnsureAgentTemplate)

Since controller-runtime's client uses the informer cache for Get, read #2 is a cache lookup, not a real API round-trip — so there's zero performance impact.

Still, if this ever moves to a direct/uncached client (e.g., for freshness), it would be a real extra read. Could be avoided by reading the config once at the top of Reconcile and passing *AuditConfig through the call chain. Low priority — current pattern is consistent with isSuspended.

@vimalk78

Copy link
Copy Markdown
Contributor Author

nice-to-have: Redundant AgenticOLSConfig read on every Claim()

Location: controller/proposal/podspec_builder.go:appendAuditEnvVars and controller/proposal/sandbox_templates.go:EnsureAgentTemplate

Observation:

A single reconcile reads AgenticOLSConfig/cluster twice:

  1. isSuspended() at the top of Reconcile()
  2. readAuditConfig() inside Claim() (via appendAuditEnvVars or EnsureAgentTemplate)

Since controller-runtime's client uses the informer cache for Get, read #2 is a cache lookup, not a real API round-trip — so there's zero performance impact.

Still, if this ever moves to a direct/uncached client (e.g., for freshness), it would be a real extra read. Could be avoided by reading the config once at the top of Reconcile and passing *AuditConfig through the call chain. Low priority — current pattern is consistent with isSuspended.

This comment was also posted by CodeRabbit, and has been resolved.

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

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants