Skip to content

Commit fd1b4f9

Browse files
kvapsclaude
andcommitted
feat(helpers): add bond interface discovery helpers
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 <[email protected]> Signed-off-by: Andrei Kvapil <[email protected]>
1 parent da29320 commit fd1b4f9

3 files changed

Lines changed: 64 additions & 2 deletions

File tree

‎charts/cozystack/templates/_helpers.tpl‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ machine:
7575
{{- if $existingInterfacesConfiguration }}
7676
{{- $existingInterfacesConfiguration | nindent 4 }}
7777
{{- else }}
78-
- interface: {{ include "talm.discovered.default_link_name_by_gateway" . }}
78+
{{- $defaultLinkName := include "talm.discovered.default_link_name_by_gateway" . }}
79+
- interface: {{ $defaultLinkName }}
80+
{{- $bondConfig := include "talm.discovered.bond_config" $defaultLinkName }}
81+
{{- if $bondConfig }}
82+
{{- $bondConfig | nindent 6 }}
83+
{{- end }}
7984
addresses: {{ include "talm.discovered.default_addresses_by_gateway" . }}
8085
routes:
8186
- network: 0.0.0.0/0

‎charts/generic/templates/_helpers.tpl‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ machine:
2121
{{- if $existingInterfacesConfiguration }}
2222
{{- $existingInterfacesConfiguration | nindent 4 }}
2323
{{- else }}
24-
- interface: {{ include "talm.discovered.default_link_name_by_gateway" . }}
24+
{{- $defaultLinkName := include "talm.discovered.default_link_name_by_gateway" . }}
25+
- interface: {{ $defaultLinkName }}
26+
{{- $bondConfig := include "talm.discovered.bond_config" $defaultLinkName }}
27+
{{- if $bondConfig }}
28+
{{- $bondConfig | nindent 6 }}
29+
{{- end }}
2530
addresses: {{ include "talm.discovered.default_addresses_by_gateway" . }}
2631
routes:
2732
- network: 0.0.0.0/0

‎charts/talm/templates/_helpers.tpl‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,55 @@ busPath: {{ .spec.busPath }}
156156
{{- end }}
157157
{{- end }}
158158
{{- end }}
159+
160+
{{- /* Get bond slave interfaces for a given bond index */ -}}
161+
{{- define "talm.discovered.bond_slaves" -}}
162+
{{- $bondIndex := . -}}
163+
{{- $slaves := list -}}
164+
{{- range (lookup "links" "" "").items -}}
165+
{{- if and (eq .spec.slaveKind "bond") (eq (int .spec.masterIndex) (int $bondIndex)) -}}
166+
{{- $slaves = append $slaves .metadata.id -}}
167+
{{- end -}}
168+
{{- end -}}
169+
{{- toJson $slaves -}}
170+
{{- end -}}
171+
172+
{{- /* Generate bond configuration from bondMaster spec */ -}}
173+
{{- define "talm.discovered.bond_config" -}}
174+
{{- $linkName := . -}}
175+
{{- $link := lookup "links" "" $linkName -}}
176+
{{- if and $link (eq $link.spec.kind "bond") -}}
177+
{{- $bondMaster := $link.spec.bondMaster -}}
178+
{{- $slaves := fromJsonArray (include "talm.discovered.bond_slaves" $link.spec.index) -}}
179+
bond:
180+
interfaces:
181+
{{- range $slaves }}
182+
- {{ . }}
183+
{{- end }}
184+
mode: {{ $bondMaster.mode }}
185+
{{- if $bondMaster.xmitHashPolicy }}
186+
xmitHashPolicy: {{ $bondMaster.xmitHashPolicy }}
187+
{{- end }}
188+
{{- if $bondMaster.lacpRate }}
189+
lacpRate: {{ $bondMaster.lacpRate }}
190+
{{- end }}
191+
{{- if $bondMaster.miimon }}
192+
miimon: {{ $bondMaster.miimon }}
193+
{{- end }}
194+
{{- if $bondMaster.updelay }}
195+
updelay: {{ $bondMaster.updelay }}
196+
{{- end }}
197+
{{- if $bondMaster.downdelay }}
198+
downdelay: {{ $bondMaster.downdelay }}
199+
{{- end }}
200+
{{- end -}}
201+
{{- end -}}
202+
203+
{{- /* Check if a link is a bond interface */ -}}
204+
{{- define "talm.discovered.is_bond" -}}
205+
{{- $linkName := . -}}
206+
{{- $link := lookup "links" "" $linkName -}}
207+
{{- if and $link (eq $link.spec.kind "bond") -}}
208+
true
209+
{{- end -}}
210+
{{- end -}}

0 commit comments

Comments
 (0)