fix(controller): add container ports so workloads can be targeted by name - #4382
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: openchoreo/openchoreo/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (5)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 SummarySummary
Changed files
API and CRD surface
TestsUpdated or added tests for:
The supplied changes do not show tests for rendered Deployment or Pod output, rollout behavior, or integration with Linkerd, NetworkPolicy, CiliumNetworkPolicy, admission policies, or Prometheus pod-role scraping. No test execution results were provided. Risk hotspots
WalkthroughThe pipeline derives named container ports from workload endpoints and uses their names as service ChangesNamed container port rendering
Priority: ⚪ Not assessed Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix · Severity of issue fixed: Medium Sequence Diagram(s)sequenceDiagram
participant DeploymentTemplate
participant toContainerPortsMacro
participant DerivedContext
participant ServiceTemplate
participant toServicePortsMacro
DeploymentTemplate->>toContainerPortsMacro: evaluate workload.toContainerPorts()
toContainerPortsMacro->>DerivedContext: select containerPorts
DerivedContext-->>DeploymentTemplate: container port entries
ServiceTemplate->>toServicePortsMacro: evaluate workload.toServicePorts()
toServicePortsMacro->>DerivedContext: select servicePorts
DerivedContext-->>ServiceTemplate: service ports with named targetPort
Merge Risk: ⚪ Minimal · up to The change adds named container ports to sample Deployments and points Service target ports at those names. No concrete merge-blocking issue was found. As the PR notes, existing workloads need a rolling restart when they pick up the new pod template. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to The updated examples render matching ports, but existing workloads may temporarily or permanently lack the declarations required by the new Service targets. That could interrupt traffic during upgrades or when older templates remain in use. No security bypass was established. Retained concerns
Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. (3 skipped: 3 unsupported.)
✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/pipeline/component/context/cel_extensions_test.go (1)
600-694: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick winAdd container-port edge-case coverage.
The new coverage checks only the default case where
TargetPortequalsPort. Add cases whereTargetPortdiffers fromPort, where the protocol is UDP, and where sanitized endpoint names collide. These cases verify that each ServicetargetPortnames a declared container port.As per path instructions, "Add tests for critical logic or regressions."
🤖 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 `@internal/pipeline/component/context/cel_extensions_test.go` around lines 600 - 694, Add edge-case table entries to TestWorkloadEndpointsToServicePortsMacro for endpoints whose TargetPort differs from Port, a UDP endpoint with a distinct target port, and multiple endpoint names that sanitize to the same value. Assert each generated Service targetPort references the declared container-port name and verify the expected collision-handling behavior.Source: Path instructions
🤖 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 `@internal/pipeline/component/context/cel_return_types.go`:
- Line 95: Run gofmt on the file containing the TargetPort field to remove
trailing whitespace and apply standard Go formatting, including any required
import grouping.
---
Outside diff comments:
In `@internal/pipeline/component/context/cel_extensions_test.go`:
- Around line 600-694: Add edge-case table entries to
TestWorkloadEndpointsToServicePortsMacro for endpoints whose TargetPort differs
from Port, a UDP endpoint with a distinct target port, and multiple endpoint
names that sanitize to the same value. Assert each generated Service targetPort
references the declared container-port name and verify the expected
collision-handling behavior.
🪄 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: Pro Plus
Run ID: ff845436-fa8c-4818-9ff5-917e8cb74652
📒 Files selected for processing (12)
internal/pipeline/component/context/cel_extensions.gointernal/pipeline/component/context/cel_extensions_test.gointernal/pipeline/component/context/cel_integration_test.gointernal/pipeline/component/context/cel_return_types.gointernal/pipeline/component/context/derived.gosamples/component-types/component-grpc-service/grpc-service-component.yamlsamples/component-types/component-http-openapi-service/http-openapi-service-component.yamlsamples/component-types/component-tls-service/tls-service-component.yamlsamples/component-types/component-with-configs/component-with-configs.yamlsamples/component-types/component-with-embedded-traits/component-with-embedded-traits.yamlsamples/getting-started/component-types/service.yamlsamples/getting-started/component-types/webapp.yaml
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
bdb5ae2 to
6510567
Compare
…name - openchoreo#4382 Signed-off-by: kavix <[email protected]>
e2440c9 to
13feae2
Compare
…name - openchoreo#4382 Signed-off-by: kavix <[email protected]>
…name - openchoreo#4382 Signed-off-by: kavix <[email protected]>
2c47426 to
3fd644f
Compare
…name - openchoreo#4382 Signed-off-by: kavix <[email protected]>
Signed-off-by: chathuranga95 <[email protected]>
3fd644f to
85967f4
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
Purpose
Workload endpoints currently render into a Service with a named port and a numeric
targetPort, but the generated container spec does not include aports:block.This means the pod does not explicitly declare the port, causing features that resolve ports by name against the pod spec to fail silently. For example:
Serverresources cannot bind to the port.NetworkPolicy/CiliumNetworkPolicyport rules resolve to zero ports and may be denied under a default-deny baseline.This PR adds container port definitions derived from workload endpoints and ensures Service
targetPortreferences resolve correctly.Fixes #4329
Approach
Added
buildContainerPorts()ininternal/pipeline/component/context/derived.go.buildServicePorts()to ensure generated Kubernetes port names are valid and unique.Added a new
workload.toContainerPorts()CEL macro incel_extensions.go.toServicePorts()macro.Updated
ServicePortEntry.TargetPort.Added
ports: ${workload.toContainerPorts()}to container specifications in built-inClusterComponentTypetemplates undersamples/:servicewebappgrpc-servicetls-servicehttp-openapi-servicecomponent-with-configscomponent-with-embedded-traitscontainerPortis informational only and does not affect application bindings or traffic routing.Related Issues
Fixes #4329
Checklist
backport/<release-branch>label if this should be backported (e.g.,backport/release-v1.0)Remarks
Container ports are named after endpoint keys so that workloads with multiple endpoints on the same port number but different visibility settings receive separate container port entries.
Kubernetes allows multiple named container ports with the same port number, so container ports are not deduplicated by
port + protocollike Service ports.Each endpoint requires its own unique name because the Service
targetPortmust resolve to the corresponding container port name.