feat: allow overriding spiffe-helper health-check port via annotation#87
feat: allow overriding spiffe-helper health-check port via annotation#87ErvalhouS wants to merge 2 commits intocofide:mainfrom
Conversation
Add a new pod annotation `spiffe.cofide.io/helper-health-port` that lets
users override the port spiffe-helper binds its health-check server on.
The default remains 8081, but pods where that port is already taken by
another container (e.g. FreeSwitch JSON RPC API) can now set a different
port:
annotations:
spiffe.cofide.io/helper-health-port: "8088"
The annotation value is validated (must be a valid 1–65535 integer); an
invalid value is logged and the default is used instead.
Changes:
- internal/const/const.go: add SPIFFEHelperHealthPortAnnotation constant
- internal/helper/config.go: thread HealthCheckPort through
SPIFFEHelperConfigParams → SPIFFEHelper → GetSidecarContainer() so the
injected HCL config and all three probes use the overridden port
- internal/webhook/webhook.go: read and validate the annotation, pass
the value to SPIFFEHelperConfigParams
Summary of ChangesHello @ErvalhouS, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the spiffe-enable admission webhook by providing a mechanism to customize the health-check port used by the injected spiffe-helper sidecar. This change resolves potential port conflicts in environments where the default port 8081 is already occupied, improving the robustness and deployability of spiffe-enabled applications without altering existing configurations. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request effectively addresses the problem of port conflicts for the spiffe-helper health-check server by introducing a configurable port via a pod annotation. The implementation is robust, including proper validation of the annotation value and defaulting to the standard port if the annotation is invalid or not provided. The changes are well-integrated across the const, helper, and webhook packages, ensuring the new port is used consistently for both the spiffe-helper configuration and Kubernetes probes. This is a well-executed feature.
There was a problem hiding this comment.
Pull request overview
Adds support for overriding the SPIFFE helper sidecar’s health-check server port via a pod annotation to avoid port collisions (default remains 8081).
Changes:
- Introduces
spiffe.cofide.io/helper-health-portannotation constant. - Parses/validates the annotation in the mutating webhook and passes the resolved port into helper config generation.
- Threads the resolved health-check port through SPIFFE helper config generation so both HCL
bind_portand container probes use it.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| internal/webhook/webhook.go | Reads/validates new annotation and passes HealthCheckPort into helper config params. |
| internal/helper/config.go | Adds HealthCheckPort parameter/field and uses it for HCL bind_port and probe ports. |
| internal/const/const.go | Defines the new SPIFFEHelperHealthPortAnnotation constant and docs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| healthCheckPort := 0 | ||
| if portStr, ok := pod.Annotations[constants.SPIFFEHelperHealthPortAnnotation]; ok { | ||
| if p, err := strconv.Atoi(portStr); err != nil || p <= 0 || p > 65535 { | ||
| logger.Error(fmt.Errorf("invalid annotation value %q", portStr), | ||
| "Ignoring invalid helper-health-port annotation, using default", | ||
| "annotation", constants.SPIFFEHelperHealthPortAnnotation) | ||
| } else { | ||
| healthCheckPort = p | ||
| } | ||
| } |
There was a problem hiding this comment.
Consider trimming whitespace from the annotation value before parsing (e.g., users may accidentally set "8088 " in YAML). Also, when strconv.Atoi fails, logging the parsing error (or including it via %w) would make the log more actionable than a generic "invalid annotation value" error.
| // Resolve optional health-check port override | ||
| healthCheckPort := 0 | ||
| if portStr, ok := pod.Annotations[constants.SPIFFEHelperHealthPortAnnotation]; ok { | ||
| if p, err := strconv.Atoi(portStr); err != nil || p <= 0 || p > 65535 { | ||
| logger.Error(fmt.Errorf("invalid annotation value %q", portStr), | ||
| "Ignoring invalid helper-health-port annotation, using default", | ||
| "annotation", constants.SPIFFEHelperHealthPortAnnotation) | ||
| } else { | ||
| healthCheckPort = p | ||
| } | ||
| } | ||
|
|
||
| // Generate the spiffe-helper configuration | ||
| configParams := helper.SPIFFEHelperConfigParams{ | ||
| AgentAddress: constants.SPIFFEWLSocketPath, | ||
| CertPath: constants.SPIFFEEnableCertDirectory, | ||
| IncludeIntermediateBundle: incIntermediateBundle, | ||
| HealthCheckPort: healthCheckPort, | ||
| } |
There was a problem hiding this comment.
The new helper-health-port override logic isn't covered by tests. Please add webhook tests that (a) set the annotation to a valid port and assert the injected spiffe-helper container probes use that port, and (b) set an invalid value and assert the default port is used (and the pod mutation still succeeds).
| @@ -97,6 +105,7 @@ func NewSPIFFEHelper(params SPIFFEHelperConfigParams) (*SPIFFEHelper, error) { | |||
| SVIDBundleFilename: "ca.pem", | |||
| HealthCheck: SPIFFEHelperHealthConfig{ | |||
| ListenerEnabled: true, | |||
| BindPort: healthCheckPort, | |||
| }, | |||
| } | |||
|
|
|||
| @@ -106,7 +115,7 @@ func NewSPIFFEHelper(params SPIFFEHelperConfigParams) (*SPIFFEHelper, error) { | |||
| hclBytes := hclFile.Bytes() | |||
| hclString := string(hclBytes) | |||
|
|
|||
| return &SPIFFEHelper{Config: hclString}, nil | |||
| return &SPIFFEHelper{Config: hclString, HealthCheckPort: healthCheckPort}, nil | |||
| } | |||
There was a problem hiding this comment.
The health check port defaulting/override is newly introduced but isn't asserted in unit tests for NewSPIFFEHelper. Consider adding tests that verify (1) HealthCheck.BindPort defaults to 8081 when params.HealthCheckPort is zero, and (2) when a custom port is provided, both the generated HCL bind_port and the returned SPIFFEHelper.HealthCheckPort (used by probes) reflect that value.
Problem
When the spiffe-helper sidecar is injected into a pod that already has
another container binding port 8081, the health-check server fails
to start:
Because the health server never comes up, the startup probe always hits
the other process and receives a non-2xx response, causing an infinite
CrashLoopBackOff on the spiffe-helper container.
Solution
Add a new pod annotation
spiffe.cofide.io/helper-health-portthat letsusers override the port used for:
bind_portin the injected spiffe-helper HCL configstartupProbe,livenessProbe, andreadinessProbeon theinjected sidecar container
The default remains 8081 — no behaviour change for existing pods.
An invalid annotation value (non-integer, out of range) is logged and
the default is used as a fallback.
Changes
internal/const/const.goSPIFFEHelperHealthPortAnnotationconstantinternal/helper/config.goHealthCheckPortthroughSPIFFEHelperConfigParams→SPIFFEHelperstruct →GetSidecarContainer()probes and HCL configinternal/webhook/webhook.goSPIFFEHelperConfigParamsTesting
🤖 Generated with Claude Code