-
Notifications
You must be signed in to change notification settings - Fork 119
[platform] Autodetect RobotLB #1271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughA new Helm template helper for network configuration is introduced, allowing conditional disabling of load balancer node ports based on the presence of the "robotlb" component in the configuration. Multiple service templates, including PostgreSQL, FerretDB, HAProxy, Redis, TCP Balancer, Virtual Machine, and VM Instance, are updated to use this helper, setting Changes
Sequence Diagram(s)sequenceDiagram
participant Helm Chart
participant cozy-lib.network.disableLoadBalancerNodePorts
participant cozyConfig
Helm Chart->>cozy-lib.network.disableLoadBalancerNodePorts: Evaluate helper
cozy-lib.network.disableLoadBalancerNodePorts->>cozyConfig: Load cozyConfig
alt cozyConfig exists
cozy-lib.network.disableLoadBalancerNodePorts->>cozyConfig: Read "bundle-enable"
cozy-lib.network.disableLoadBalancerNodePorts-->>Helm Chart: Return true if "robotlb" not enabled
else cozyConfig missing
cozy-lib.network.disableLoadBalancerNodePorts-->>Helm Chart: Return default (true)
end
Helm Chart->>Helm Chart: Conditionally set allocateLoadBalancerNodePorts: false in service specs
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @lllamnyp, 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 implements an automatic detection mechanism to manage the allocation of node ports for Kubernetes LoadBalancer services. The primary goal is to ensure that node ports are correctly assigned or unassigned based on the presence of the RobotLB
component, which is crucial for proper load balancer functionality in specific cloud environments like Hetzner.
Highlights
- Conditional Node Port Allocation: Modified the
external-svc.yaml
template for PostgreSQL services to conditionally setallocateLoadBalancerNodePorts: false
. This ensures node ports are only disabled when appropriate for the environment. - New Helm Library Template for Network Logic: Introduced a new Helm template file
_network.tpl
within thecozy-lib
library. This file centralizes the logic for determining whether load balancer node ports should be allocated. - RobotLB Autodetection: The new network template includes logic to detect if the
robotlb
component is enabled viacozyConfig
. Ifrobotlb
is not enabled, or ifcozyConfig
is unavailable, node ports for LoadBalancer services will be explicitly disabled. Conversely, ifrobotlb
is enabled, node ports will be allocated (by not applying theallocateLoadBalancerNodePorts: false
setting).
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
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 .gemini/
folder in the base of the repository. Detailed instructions can be found here.
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 or fill out our survey to provide feedback.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
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)
packages/library/cozy-lib/templates/_network.tpl (1)
5-14
: Verify the logic implementation matches PR objectives.The function correctly implements the autodetection logic: when
robotlb
is NOT present in the enabled components, it returnstrue
to disable load balancer node ports. This aligns with the PR objective of allocating node ports only when RobotLB is enabled.However, consider adding error handling for edge cases:
{{- define "cozy-lib.network.disableLoadBalancerNodePorts" }} {{- include "cozy-lib.loadCozyConfig" (list "" .) }} {{- $cozyConfig := index . 1 "cozyConfig" }} {{- if not $cozyConfig }} {{- include "cozy-lib.network.defaultDisableLoadBalancerNodePorts" . }} {{- else }} -{{- $enabledComponents := splitList "," ((index $cozyConfig.data "bundle-enable") | default "") }} +{{- $bundleEnable := index $cozyConfig.data "bundle-enable" | default "" }} +{{- $enabledComponents := splitList "," $bundleEnable }} {{- not (has "robotlb" $enabledComponents) }} {{- end }} {{- end }}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/apps/postgres/templates/external-svc.yaml
(1 hunks)packages/library/cozy-lib/templates/_network.tpl
(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: lllamnyp
PR: cozystack/cozystack#1233
File: packages/system/hetzner-robotlb/charts/robotlb/templates/deployment.yaml:33-35
Timestamp: 2025-07-23T09:15:09.624Z
Learning: The `./charts/robotlb/` directory in the hetzner-robotlb package contains vendored code, and the team generally avoids modifying vendored code to maintain clean separation from upstream dependencies.
packages/library/cozy-lib/templates/_network.tpl (1)
Learnt from: NickVolynkin
PR: #1120
File: packages/apps/clickhouse/README.md:60-67
Timestamp: 2025-07-03T05:54:51.264Z
Learning: The cozy-lib.resources.sanitize
function in packages/library/cozy-lib/templates/_resources.tpl supports both standard Kubernetes resource format (with limits:/requests: sections) and flat format (direct resource specifications). The flat format takes priority over nested values. CozyStack apps include cozy-lib as a chart dependency through symlinks in packages/apps/*/charts/cozy-lib directories.
🔇 Additional comments (1)
packages/apps/postgres/templates/external-svc.yaml (1)
10-12
: Integration is correct; no changes needed.The helper name
cozy-lib.network.disableLoadBalancerNodePorts
matches its definition, andfromYaml
is required to turn the"false"
string into a boolean false for theif
check. Indentation and YAML structure are valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces logic to automatically detect if node ports should be assigned to load balancer services, specifically when running in Hetzner and using Hetzner's cloud load balancers. The changes involve adding a new template to determine whether to disable LoadBalancer node ports based on the presence of "robotlb" in the enabled components, and adjusting the external service template to conditionally disable node ports.
{{- if (include "cozy-lib.network.disableLoadBalancerNodePorts" $ | fromYaml) }} | ||
allocateLoadBalancerNodePorts: false | ||
{{- end }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,14 @@ | |||
{{- define "cozy-lib.resources.defaultDisableLoadBalancerNodePorts" }} | |||
{{- `true` }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{{- include "cozy-lib.network.defaultDisableLoadBalancerNodePorts" . }} | ||
{{- else }} | ||
{{- $enabledComponents := splitList "," ((index $cozyConfig.data "bundle-enable") | default "") }} | ||
{{- not (has "robotlb" $enabledComponents) }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic determines whether to disable LoadBalancer node ports based on the presence of "robotlb" in the enabled components. It might be beneficial to add a comment explaining the rationale behind this check, especially linking it to the Hetzner RobotLB context mentioned in the PR description.
{{- not (has "robotlb" $enabledComponents) }} {{/* Disable node ports if robotlb is NOT enabled */}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
If running in Hetzner and using Hetzner's cloud load balancers, node ports need to be allocated for the load balancer to function correctly. Therefore if RobotLB is enabled, we probably need to assign node ports. Release note: [platform] Autodetect if node ports should be assigned to load balancer services. Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
7e6e1bd
to
917a6f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (3)
packages/apps/virtual-machine/templates/service.yaml (1)
16-18
: Same whitespace-trim caveat as noted in tcp-balancer template – consider dropping the-
after{{
for safer, explicit indentation.packages/apps/redis/templates/service.yaml (1)
14-16
: Whitespace-trim note duplicated from earlier comment – consider{{ if …}}
instead of{{- if …}}
.packages/apps/vm-instance/templates/service.yaml (1)
16-18
: Whitespace-trim note duplicated from earlier comment – consider{{ if …}}
instead of{{- if …}}
.
🧹 Nitpick comments (3)
packages/apps/tcp-balancer/templates/service.yaml (1)
13-15
: Whitespace-trim in{{- if …}}
may accidentally drop YAML indentation
Because the opening tag uses{{-
, Helm trims the four leading spaces, so the rendered block becomes:externalTrafficPolicy: Local allocateLoadBalancerNodePorts: falseIndentation is still valid in this template (the
allocate…
line keeps the required 2-space indent), but a future copy-paste with a different indent level could silently break the YAML. Switching to a non-trimming opening tag keeps the guard‐indent explicit and safer:- {{- if (include "cozy-lib.network.disableLoadBalancerNodePorts" $ | fromYaml) }} + {{ if (include "cozy-lib.network.disableLoadBalancerNodePorts" $ | fromYaml) }}packages/apps/ferretdb/templates/external-svc.yaml (1)
11-13
: Repeated snippet suggests extracting a shared partial
The three-line conditional block disabling node-ports now appears in 7 service templates. A small helper partial (e.g.cozy-lib.service.allocateNodePorts
) would avoid duplication and guarantee future fixes land everywhere.No immediate action required for this PR, just a maintainability hint.
packages/apps/http-cache/templates/haproxy/service.yaml (1)
13-15
: Align indentation and switch totoBool
for a cleaner, safer boolean check
Indentation: the
if
/end
directives are indented by four spaces while their sibling keys (type
,externalTrafficPolicy
) use two. After the{{-
trim, Helm will emit a blank line that is purely cosmetic but keeps the template visually uneven across files. Using two-space indentation here maintains visual consistency and avoids the blank line.Boolean parsing:
fromYaml
works, but its intent is to convert documents to structured data. For single booleans,toBool
is more idiomatic and avoids edge-cases when the included helper ever returns an empty string.Suggested change:
- {{- if (include "cozy-lib.network.disableLoadBalancerNodePorts" $ | fromYaml) }} - allocateLoadBalancerNodePorts: false - {{- end }} + {{- if (include "cozy-lib.network.disableLoadBalancerNodePorts" $ | toBool) }} + allocateLoadBalancerNodePorts: false + {{- end }}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
packages/apps/ferretdb/templates/external-svc.yaml
(1 hunks)packages/apps/http-cache/templates/haproxy/service.yaml
(1 hunks)packages/apps/postgres/templates/external-svc.yaml
(1 hunks)packages/apps/redis/templates/service.yaml
(1 hunks)packages/apps/tcp-balancer/templates/service.yaml
(1 hunks)packages/apps/virtual-machine/templates/service.yaml
(1 hunks)packages/apps/vm-instance/templates/service.yaml
(1 hunks)packages/library/cozy-lib/templates/_network.tpl
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/apps/postgres/templates/external-svc.yaml
- packages/library/cozy-lib/templates/_network.tpl
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: lllamnyp
PR: cozystack/cozystack#1233
File: packages/system/hetzner-robotlb/charts/robotlb/templates/deployment.yaml:33-35
Timestamp: 2025-07-23T09:15:09.658Z
Learning: The `./charts/robotlb/` directory in the hetzner-robotlb package contains vendored code, and the team generally avoids modifying vendored code to maintain clean separation from upstream dependencies.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build
If running in Hetzner and using Hetzner's cloud load balancers, node ports need to be allocated for the load balancer to function correctly. Therefore if RobotLB is enabled, we probably need to assign node ports.
Release note:
[platform] Autodetect if node ports should be assigned to load balancer services.
What this PR does
Release note
Summary by CodeRabbit
Summary by CodeRabbit