Skip to content

feat(sensor): Add secrets to fake workloads#19479

Open
vikin91 wants to merge 3 commits intomasterfrom
piotr/fake-secret-workloads
Open

feat(sensor): Add secrets to fake workloads#19479
vikin91 wants to merge 3 commits intomasterfrom
piotr/fake-secret-workloads

Conversation

@vikin91
Copy link
Contributor

@vikin91 vikin91 commented Mar 18, 2026

Description

Add secret workloads to the fake workload generator so that local-sensor
can reproduce the ResolveAllDeployments() amplification that causes sensor
OOM at scale - see https://redhat.atlassian.net/browse/ROX-33638.

A cluster with high number of docker-config secrets and deployments
triggered O(secrets × deployments) resolver work on every secret informer
re-list wave, growing memory until OOM-kill.

This change lets us reproduce and measure that behavior locally:

  • New SecretWorkload config in the fake workload YAML controls the number
    of docker-config and opaque secrets, plus a periodic update interval.
  • manageSecrets goroutine sends waves of annotation-bumps to every
    docker-config secret on the configured interval, simulating informer
    re-lists.
  • Reproduction workload YAML configs is included:
    • secret-oom-repro.yaml — full-scale (3 k secrets × 1 k deployments)
  • A monitoring shell script (secret-oom-repro-monitor.sh) polls
    /metrics for heap, RSS, resolver queue, and secret/deployment event counts.

User-facing documentation

  • CHANGELOG.md is updated OR update is not needed
  • documentation PR is created and is linked above OR is not needed

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests
  • added e2e tests
  • added regression tests
  • added compatibility tests
  • modified existing tests

How I validated my change

⚠️ This change does not affect any production code!

Ran local-sensor with secret-oom-repro-light.yaml and confirmed that
resolver queue saturation and memory growth are visible via the monitoring
script.

go run ./tools/local-sensor \
    -with-fakeworkload scale/workloads/secret-oom-repro.yaml \
    -with-metrics \
    -with-pprof-server \
    -duration 30m \
    -skip-central-output

@vikin91
Copy link
Contributor Author

vikin91 commented Mar 18, 2026

This change is part of the following stack:

Change managed by git-spice.

@openshift-ci
Copy link

openshift-ci bot commented Mar 18, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@gitguardian
Copy link

gitguardian bot commented Mar 18, 2026

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
28930366 Triggered Generic High Entropy Secret 1c298ba sensor/kubernetes/fake/secret.go View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In getDockerConfigSecret, the json.Marshal error is ignored (data, _ := json.Marshal(cfg)); consider handling or logging the error so mis-serialization of the docker config doesn’t silently produce an invalid secret.
  • updateRandomSecret currently lists secrets with Limit: 1 and always updates the first item, which isn’t actually random and may repeatedly hit the same secret; consider either caching IDs from getSecrets or listing a broader set and selecting a random element to better simulate random churn and reduce repeated updates.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `getDockerConfigSecret`, the `json.Marshal` error is ignored (`data, _ := json.Marshal(cfg)`); consider handling or logging the error so mis-serialization of the docker config doesn’t silently produce an invalid secret.
- `updateRandomSecret` currently lists secrets with `Limit: 1` and always updates the first item, which isn’t actually random and may repeatedly hit the same secret; consider either caching IDs from `getSecrets` or listing a broader set and selecting a random element to better simulate random churn and reduce repeated updates.

## Individual Comments

### Comment 1
<location path="sensor/kubernetes/fake/secret.go" line_range="35" />
<code_context>
+			},
+		},
+	}
+	data, _ := json.Marshal(cfg)
+	return &corev1.Secret{
+		TypeMeta: metav1.TypeMeta{
</code_context>
<issue_to_address>
**issue (bug_risk):** Avoid discarding the json.Marshal error to surface malformed docker config generation issues

Ignoring the json.Marshal error can hide regressions if dockerConfigJSON or its tags change and secret generation starts failing silently. Even for test-only/fake workloads, handle the error explicitly: either return nil and log, or fail fast (panic/log.Fatalf) so such issues are immediately visible.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@rhacs-bot
Copy link
Contributor

rhacs-bot commented Mar 18, 2026

Images are ready for the commit at a1f9dce.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.11.x-363-ga1f9dce023.

@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 0% with 136 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.22%. Comparing base (2b34e97) to head (a1f9dce).
⚠️ Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
sensor/kubernetes/fake/secret.go 0.00% 123 Missing ⚠️
sensor/kubernetes/fake/fake.go 0.00% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #19479      +/-   ##
==========================================
- Coverage   49.25%   49.22%   -0.04%     
==========================================
  Files        2725     2726       +1     
  Lines      205582   205718     +136     
==========================================
- Hits       101268   101265       -3     
- Misses      96780    96917     +137     
- Partials     7534     7536       +2     
Flag Coverage Δ
go-unit-tests 49.22% <0.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vikin91 vikin91 force-pushed the piotr/fake-secret-workloads branch from a9a4125 to a0b51ea Compare March 18, 2026 10:38
@vikin91 vikin91 force-pushed the piotr/fake-secret-workloads branch from a0b51ea to fa21c31 Compare March 18, 2026 11:45
@vikin91 vikin91 marked this pull request as ready for review March 18, 2026 16:05
@vikin91 vikin91 requested a review from a team as a code owner March 18, 2026 16:05
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In updateAllDockerConfigSecrets, the List errors are silently ignored; consider at least debug-level logging (possibly rate-limited) so it's visible when a namespace’s secrets cannot be listed during an update wave.
  • The new SecretWorkload validation currently clamps negative counts to 0 and returns an error; if the intent is to auto-correct user input (as with the openPortReuseProbability rounding), consider downgrading this to a warning-style error or logging so callers don’t have to treat a fully-corrected workload as a hard failure.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `updateAllDockerConfigSecrets`, the `List` errors are silently ignored; consider at least debug-level logging (possibly rate-limited) so it's visible when a namespace’s secrets cannot be listed during an update wave.
- The new `SecretWorkload` validation currently clamps negative counts to 0 and returns an error; if the intent is to auto-correct user input (as with the openPortReuseProbability rounding), consider downgrading this to a warning-style error or logging so callers don’t have to treat a fully-corrected workload as a hard failure.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants