Accept probe port exposed via container args or command#1197
Accept probe port exposed via container args or command#1197arpitjain099 wants to merge 1 commit into
Conversation
The liveness-port, readiness-port and startup-port checks resolved a probe port only against the declared containerPort list. A declared containerPort is informational, so a process can listen on a port that is wired up only through a flag. Charts such as opentelemetry-operator pass the health-probe address purely through args (--health-probe-addr=:8081) and declare only the metrics port, which made the checks report a false positive for a port that is in fact served. CheckProbePort now also looks for a numeric probe port as a standalone integer token in the container args and command before flagging it. Named (string) ports still resolve against the declared containerPort list as before, and a port that only appears as a substring of a larger number is still flagged. Fixes stackrox#1086 Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Enterprise Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1197 +/- ##
===========================================
- Coverage 62.36% 31.17% -31.19%
===========================================
Files 197 239 +42
Lines 4854 6562 +1708
===========================================
- Hits 3027 2046 -981
- Misses 1439 4336 +2897
+ Partials 388 180 -208
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Fixes #1086
Problem
The
liveness-port,readiness-portandstartup-portchecks resolve the probe port only against the container's declaredcontainerPortlist. AcontainerPortentry is informational: a process can listen on any port regardless of whether it is declared. When the probe port is wired up through a flag instead of a declared port, the checks report a false positive for a port that is actually being served.The opentelemetry-operator chart (0.100.0) hits this. The manager container passes its health-probe address purely through args and only declares the metrics port:
Before
8081is not in the declared ports, so the check fires even though the process listens on it:After
CheckProbePortnow also looks for a numeric probe port as a standalone integer token in the containerargsandcommandbefore flagging it. With the change above the container no longer fires, which matches the expected behavior in the issue.Because all three checks share
CheckProbePort, the fix coversliveness-port,readiness-portandstartup-portat once.Scope and limitations
containerPortexactly as before.8081does not match18081,80818, or a port that only appears as a substring of an image tag or version. Those cases still fire.--health-probe-addr=:8081,--addr=0.0.0.0:8081,--port 8081). It does not attempt to confirm which flag the port belongs to.Tests
pkg/templates/util/check_probe_port_test.go(new): direct unit tests forCheckProbePortandargContainsPort, including the issue [BUG] - Liveness probe port exposed in args is being ignored #1086 args case, the command case, the string-port no-match, and the substring regression guards (18081,80818still fire).pkg/templates/livenessport/template_test.go: added aPortExposedViaArgscase to the existing suite.tests/checks/liveness-port.yml: added adont-fire-deployment-port-in-argscontainer reproducing the chart scenario end to end. The existing four fire-cases and their assertions are unchanged.go build ./...,go vet, andgo test ./pkg/templates/... ./pkg/lintcontext/...all pass.