Skip to content
Open
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
6 changes: 5 additions & 1 deletion charts/kube-ovn-v2/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ Create the name of the service account to use


{{/*
Get IP-addresses of master nodes
Get IP-addresses of master nodes. If no nodes are returned, we assume this is
a dry-run/template call and return nothing.
*/}}
{{- define "kubeovn.nodeIPs" -}}
{{- $nodes := lookup "v1" "Node" "" "" -}}
{{- if eq (len $nodes) 0 -}}
{{- else -}}
Comment on lines +63 to +64
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For better readability and to follow idiomatic Helm/Go template practices, this conditional can be simplified. Instead of checking eq (len $nodes) 0 and having an empty if block, you can directly check if $nodes contains any items. An empty dictionary (which lookup returns on failure or when no items are found) is treated as false in conditionals.

The current if-else-end structure can be simplified to a more concise if-end block:

{{- if $nodes -}}
  // ... existing logic to find IPs
{{- end -}}

{{- $ips := list -}}
{{- range $node := $nodes.items -}}
{{- range $label, $value := $.Values.masterNodesLabels }}
Expand All @@ -77,6 +80,7 @@ Get IP-addresses of master nodes
{{- end -}}
{{ join "," $ips }}
{{- end -}}
{{- end -}}

{{/*
Number of master nodes
Expand Down
6 changes: 5 additions & 1 deletion charts/kube-ovn/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{{/*
Get IP-addresses of master nodes
Get IP-addresses of master nodes. If no nodes are returned, we assume this is
a dry-run/template call and return nothing.
*/}}
{{- define "kubeovn.nodeIPs" -}}
{{- $nodes := lookup "v1" "Node" "" "" -}}
{{- if eq (len $nodes) 0 -}}
{{- else -}}
Comment on lines +7 to +8
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For better readability and to follow idiomatic Helm/Go template practices, this conditional can be simplified. Instead of checking eq (len $nodes) 0 and having an empty if block, you can directly check if $nodes contains any items. An empty dictionary (which lookup returns on failure or when no items are found) is treated as false in conditionals.

The current if-else-end structure can be simplified to a more concise if-end block:

{{- if $nodes -}}
  // ... existing logic to find IPs
{{- end -}}

{{- $ips := list -}}
{{- range $node := $nodes.items -}}
{{- $label := splitList "=" $.Values.MASTER_NODES_LABEL }}
Expand All @@ -25,6 +28,7 @@ Get IP-addresses of master nodes
{{- end -}}
{{ join "," $ips }}
{{- end -}}
{{- end -}}

{{/*
Number of master nodes
Expand Down