feat(helpers): add bond interface discovery helpers#94
Conversation
Add three new template helpers for bond interface configuration: - talm.discovered.bond_slaves: finds slave interfaces by masterIndex - talm.discovered.bond_config: generates bond section from bondMaster spec - talm.discovered.is_bond: checks if interface is a bond These helpers read bond information directly from Talos links resource, enabling bond configuration discovery in insecure/maintenance mode. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughThis pull request introduces bond interface configuration management to three Helm chart templates. Three new template helpers are added to discover bond relationships and generate corresponding configuration, while two existing templates are refactored to use these helpers to conditionally inject bond settings into interface blocks. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
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 |
Summary of ChangesHello Andrei Kvapil (@kvaps), 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 network configuration capabilities by introducing new Helm template helpers for automated discovery and configuration of bonded network interfaces. These helpers leverage Talos links resources to dynamically generate bond configurations, making it easier to set up complex network interfaces, particularly in scenarios where direct machine configuration access is restricted. 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. 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 (@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
This pull request introduces valuable new Helm template helpers for discovering and configuring bond interfaces in Talos, which is a great feature for automating network setup. The changes in the cozystack and generic charts correctly utilize these new helpers. My review focuses on improving the robustness of the new helpers in charts/talm/templates/_helpers.tpl to prevent potential template rendering errors when encountering unexpected or malformed input data. I've suggested adding more checks for data existence before use and utilizing hasKey for optional parameters to correctly handle all valid values, including zero.
| {{- if $bondMaster.xmitHashPolicy }} | ||
| xmitHashPolicy: {{ $bondMaster.xmitHashPolicy }} | ||
| {{- end }} | ||
| {{- if $bondMaster.lacpRate }} | ||
| lacpRate: {{ $bondMaster.lacpRate }} | ||
| {{- end }} | ||
| {{- if $bondMaster.miimon }} | ||
| miimon: {{ $bondMaster.miimon }} | ||
| {{- end }} | ||
| {{- if $bondMaster.updelay }} | ||
| updelay: {{ $bondMaster.updelay }} | ||
| {{- end }} | ||
| {{- if $bondMaster.downdelay }} | ||
| downdelay: {{ $bondMaster.downdelay }} | ||
| {{- end }} |
There was a problem hiding this comment.
The current implementation uses if $bondMaster.someKey to check for optional parameters. This can cause issues for numeric parameters like miimon, updelay, and downdelay if their value is 0, as if 0 evaluates to false in Go templates, causing the parameter to be omitted. Using hasKey $bondMaster "someKey" is a more robust way to check for a key's presence, regardless of its value.
{{- if hasKey $bondMaster "xmitHashPolicy" }}
xmitHashPolicy: {{ $bondMaster.xmitHashPolicy }}
{{- end }}
{{- if hasKey $bondMaster "lacpRate" }}
lacpRate: {{ $bondMaster.lacpRate }}
{{- end }}
{{- if hasKey $bondMaster "miimon" }}
miimon: {{ $bondMaster.miimon }}
{{- end }}
{{- if hasKey $bondMaster "updelay" }}
updelay: {{ $bondMaster.updelay }}
{{- end }}
{{- if hasKey $bondMaster "downdelay" }}
downdelay: {{ $bondMaster.downdelay }}
{{- end }}
| {{- $bondIndex := . -}} | ||
| {{- $slaves := list -}} | ||
| {{- range (lookup "links" "" "").items -}} | ||
| {{- if and (eq .spec.slaveKind "bond") (eq (int .spec.masterIndex) (int $bondIndex)) -}} |
There was a problem hiding this comment.
To improve robustness, it's safer to check for the existence of .spec.masterIndex before attempting to use it in the int function. This will prevent potential template rendering errors if a link item in the loop is missing the masterIndex field.
{{- if and .spec.masterIndex (eq .spec.slaveKind "bond") (eq (int .spec.masterIndex) (int $bondIndex)) -}}
| {{- define "talm.discovered.bond_config" -}} | ||
| {{- $linkName := . -}} | ||
| {{- $link := lookup "links" "" $linkName -}} | ||
| {{- if and $link (eq $link.spec.kind "bond") -}} |
There was a problem hiding this comment.
To make the helper more robust, it's good practice to also check for the existence of bondMaster and index on the link spec before trying to access them. This prevents potential template rendering errors if a link of kind "bond" is missing these fields for some reason.
{{- if and $link (eq $link.spec.kind "bond") $link.spec.bondMaster $link.spec.index -}}
Summary
New helpers
talm.discovered.bond_slaves- finds slave interfaces by masterIndextalm.discovered.bond_config- generates bond section from bondMaster spectalm.discovered.is_bond- checks if interface is a bondChanges
charts/talm/templates/_helpers.tpl- add bond discovery helperscharts/generic/templates/_helpers.tpl- use bond_config in interface generationcharts/cozystack/templates/_helpers.tpl- use bond_config in interface generationExample output
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.