Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions charts/cozystack/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,32 @@ machine:
{{- $existingInterfacesConfiguration | nindent 4 }}
{{- else }}
{{- $defaultLinkName := include "talm.discovered.default_link_name_by_gateway" . }}
- interface: {{ $defaultLinkName }}
{{- $bondConfig := include "talm.discovered.bond_config" $defaultLinkName }}
{{- $isVlan := include "talm.discovered.is_vlan" $defaultLinkName }}
{{- $parentLinkName := "" }}
{{- if $isVlan }}
{{- $parentLinkName = include "talm.discovered.parent_link_name" $defaultLinkName }}
{{- end }}
{{- $interfaceName := $defaultLinkName }}
{{- if and $isVlan $parentLinkName }}
{{- $interfaceName = $parentLinkName }}
{{- end }}
- interface: {{ $interfaceName }}
{{- $bondConfig := include "talm.discovered.bond_config" $interfaceName }}
{{- if $bondConfig }}
{{- $bondConfig | nindent 6 }}
{{- end }}
{{- if $isVlan }}
vlans:
- vlanId: {{ include "talm.discovered.vlan_id" $defaultLinkName }}
addresses: {{ include "talm.discovered.default_addresses_by_gateway" . }}
routes:
- network: 0.0.0.0/0
gateway: {{ include "talm.discovered.default_gateway" . }}
{{- if and .Values.floatingIP (eq .MachineType "controlplane") }}
vip:
ip: {{ .Values.floatingIP }}
{{- end }}
{{- else }}
addresses: {{ include "talm.discovered.default_addresses_by_gateway" . }}
routes:
- network: 0.0.0.0/0
Expand All @@ -89,6 +110,7 @@ machine:
vip:
ip: {{ .Values.floatingIP }}
{{- end }}
{{- end }}
{{- end }}

cluster:
Expand Down
26 changes: 24 additions & 2 deletions charts/generic/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,32 @@ machine:
{{- $existingInterfacesConfiguration | nindent 4 }}
{{- else }}
{{- $defaultLinkName := include "talm.discovered.default_link_name_by_gateway" . }}
- interface: {{ $defaultLinkName }}
{{- $bondConfig := include "talm.discovered.bond_config" $defaultLinkName }}
{{- $isVlan := include "talm.discovered.is_vlan" $defaultLinkName }}
{{- $parentLinkName := "" }}
{{- if $isVlan }}
{{- $parentLinkName = include "talm.discovered.parent_link_name" $defaultLinkName }}
{{- end }}
{{- $interfaceName := $defaultLinkName }}
{{- if and $isVlan $parentLinkName }}
{{- $interfaceName = $parentLinkName }}
{{- end }}
- interface: {{ $interfaceName }}
{{- $bondConfig := include "talm.discovered.bond_config" $interfaceName }}
{{- if $bondConfig }}
{{- $bondConfig | nindent 6 }}
{{- end }}
{{- if $isVlan }}
vlans:
- vlanId: {{ include "talm.discovered.vlan_id" $defaultLinkName }}
addresses: {{ include "talm.discovered.default_addresses_by_gateway" . }}
routes:
- network: 0.0.0.0/0
gateway: {{ include "talm.discovered.default_gateway" . }}
{{- if and .Values.floatingIP (eq .MachineType "controlplane") }}
vip:
ip: {{ .Values.floatingIP }}
{{- end }}
{{- else }}
addresses: {{ include "talm.discovered.default_addresses_by_gateway" . }}
routes:
- network: 0.0.0.0/0
Expand All @@ -35,6 +56,7 @@ machine:
vip:
ip: {{ .Values.floatingIP }}
{{- end }}
{{- end }}
{{- end }}

cluster:
Expand Down
42 changes: 42 additions & 0 deletions charts/talm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,45 @@ bond:
true
{{- end -}}
{{- end -}}

{{- /* Check if a link is a vlan interface */ -}}
{{- define "talm.discovered.is_vlan" -}}
{{- $linkName := . -}}
{{- $link := lookup "links" "" $linkName -}}
{{- if and $link (eq $link.spec.kind "vlan") -}}
true
{{- end -}}
{{- end -}}

{{- /* Get parent link name by linkIndex */ -}}
{{- define "talm.discovered.parent_link_name" -}}
{{- $linkName := . -}}
{{- $link := lookup "links" "" $linkName -}}
{{- if and $link $link.spec.linkIndex -}}
{{- $parentIndex := $link.spec.linkIndex -}}
{{- range (lookup "links" "" "").items -}}
{{- if eq (int .spec.index) (int $parentIndex) -}}
{{- .metadata.id -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
Comment on lines +237 to +249
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The talm.discovered.parent_link_name helper iterates through all discovered links (range (lookup "links" "" "").items) to find the parent link by linkIndex. While functional, this approach could become inefficient if the number of discovered links grows very large. For typical network configurations, this might not be an issue, but it's worth considering if a more direct lookup mechanism or an indexed map could be employed for better performance in environments with many interfaces.


{{- /* Get vlan ID from link */ -}}
{{- define "talm.discovered.vlan_id" -}}
{{- $linkName := . -}}
{{- $link := lookup "links" "" $linkName -}}
{{- if and $link $link.spec.vlan -}}
{{- $link.spec.vlan.vlanID -}}
{{- end -}}
{{- end -}}

{{- /* Generate vlan configuration */ -}}
{{- define "talm.discovered.vlan_config" -}}
{{- $linkName := . -}}
{{- $link := lookup "links" "" $linkName -}}
{{- if and $link (eq $link.spec.kind "vlan") -}}
vlans:
- vlanId: {{ $link.spec.vlan.vlanID }}
{{- end -}}
{{- end -}}
Comment on lines +260 to +268
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The talm.discovered.vlan_config helper is introduced but currently only generates the vlanId portion of a VLAN configuration. The actual VLAN configuration blocks used in cozystack and generic templates are more comprehensive, including addresses, routes, and vip. This helper is either incomplete for its implied purpose or its name is too broad for its current functionality. Consider either expanding this helper to generate the full VLAN configuration block so it can be used consistently, or renaming it to better reflect its limited scope (e.g., talm.discovered.vlan_id_block) if it's only meant to generate the vlanId part. If this helper is not intended to be used in the current context, it might be better to remove it to avoid confusion.