Add support for multiple hosts in a daemonset

A daemonset overrides template generates a separate
daemonset and configuration secret for each host, even when
configurations are identical. This approach leads to unnecessary
resource consumption and complexity.

This adds support for specifying multiple hosts for a single daemonset
in conf.overrides.neutron_dhcp-agent.hosts[].name as shown below:

   overrides:
     neutron_dhcp-agent:
       hosts:
       - conf:
           plugins:
             openvswitch_agent:
               agent: {}
               ovs:
                 bridge_mappings: group0-data0:br-phy0,group0-data0b:br-phy0,group0-data1:br-phy0,group0-ext0:br-phy0,
                 datapath_type: system
                 integration_bridge: br-int
                 vhostuser_socket_dir: /var/run/openvswitch
             sriov_agent:
               agent:
                 root_helper: ''
               securitygroup:
                 firewall_driver: noop
               sriov_nic:
                 physical_device_mappings: ''
         name:
         - compute-0
         - compute-1
         - compute-2

In one of the tests, the size reduced from 383044 to 267788 bytes (~30%
less).

Before the change:

    [sysadmin@controller-0 ~(keystone_admin)]$ kubectl describe secret sh.helm.release.v1.osh-openstack-neutron.v1 -n openstack
    Name:         sh.helm.release.v1.osh-openstack-neutron.v1
    Namespace:    openstack
    Labels:       modifiedAt=1735071637
                  name=osh-openstack-neutron
                  owner=helm
                  status=deployed
                  version=1
    Annotations:  <none>Type:  helm.sh/release.v1Data
    ====
    release:  383044 byte

After the change:

    [sysadmin@controller-0 ~(keystone_admin)]$ kubectl describe secret sh.helm.release.v1.osh-openstack-neutron.v1 -n openstack
    Name:         sh.helm.release.v1.osh-openstack-neutron.v1
    Namespace:    openstack
    Labels:       modifiedAt=1735049803
                  name=osh-openstack-neutron
                  owner=helm
                  status=deployed
                  version=1
    Annotations:  <none>Type:  helm.sh/release.v1Data
    ====
    release:  267788 bytes

The reduction can be bigger as the number of hosts with the same
configurations increase.

Test Plan:
    PASS: build-pkg -c -l openstack
    PASS: build openstack tarball
    PASS: Upload and Apply openstack tarball on standard system
    PASS: Check grouping of Neutron overrides
    PASS: Check size reduction in Neutron release secret
    PASS: Launch 3x Guest instances (tis-centos-guest VMs)
    PASS: Access instances through a remote console
    PASS: Ping instances from remote console (all to all)
    PASS: Ping instances from external server in the management network

Task: 51436
Story: 2011304
Change-Id: Ib9f41d9c9578d9340299b6438309b24826fce805
Signed-off-by: Daniel Bolgheroni <Daniel.Bolgheroni@windriver.com>
This commit is contained in:
Daniel Bolgheroni 2024-12-16 16:43:45 -03:00
parent e40fe2d3c5
commit ecd2a968dd
2 changed files with 105 additions and 0 deletions
openstack-helm-infra/debian/deb_folder/patches

@ -0,0 +1,104 @@
From 214a1e4ea099f3dd99011d142cba0ca5715ef175 Mon Sep 17 00:00:00 2001
From: Daniel Bolgheroni <Daniel.Bolgheroni@windriver.com>
Date: Mon, 16 Dec 2024 16:31:34 -0300
Subject: [PATCH] Add support for multiple hosts in a daemonset
A daemonset overrides template generates a separate
daemonset and configuration secret for each host, even when
configurations are identical. This approach leads to unnecessary
resource consumption and complexity.
This adds support for specifying multiple hosts for a single daemonset
in conf.overrides.neutron_dhcp-agent.hosts[].name.
Change-Id: I80e87174addd26af12490c4f18cae8316c2bd670
Signed-off-by: Daniel Bolgheroni <Daniel.Bolgheroni@windriver.com>
---
.../templates/utils/_daemonset_overrides.tpl | 50 ++++++++++++++++---
1 file changed, 44 insertions(+), 6 deletions(-)
diff --git a/helm-toolkit/templates/utils/_daemonset_overrides.tpl b/helm-toolkit/templates/utils/_daemonset_overrides.tpl
index 40359f0f..7bf0dd23 100644
--- a/helm-toolkit/templates/utils/_daemonset_overrides.tpl
+++ b/helm-toolkit/templates/utils/_daemonset_overrides.tpl
@@ -35,9 +35,23 @@ limitations under the License.
{{- $current_dict := dict }}
{{/* set daemonset name */}}
- {{/* Note: long hostnames can cause the 63 char name limit to be
- exceeded. Truncate the hostname if hostname > 20 char */}}
- {{- if gt (len $host_data.name) 20 }}
+ {{/* There are cases where the name can be a list instead of a single
+ value. Since some metadata are defined using these names as the base
+ name, create a hostgroup. */}}
+ {{- $hostgroup_name := "" }}
+ {{- $host_data_names := list }}
+ {{- if eq (kindOf $host_data.name) "slice" }}
+ {{- range $host_data.name }}
+ {{- $host_data_names = append $host_data_names . }}
+ {{- end }}
+ {{- $host_data_names_all := join "-" $host_data_names }}
+ {{- $hostgroup_name = printf "hostgroup-%s" (sha256sum $host_data_names_all | trunc 7) }}
+ {{- end }}
+ {{- if $hostgroup_name }}
+ {{- $_ := set $current_dict "name" $hostgroup_name }}
+ {{- /* Note: long hostnames can cause the 63 char name limit to be
+ exceeded. Truncate the hostname if hostname > 20 char */}}
+ {{- else if gt (len $host_data.name) 20 }}
{{- $_ := set $current_dict "name" (substr 0 20 $host_data.name) }}
{{- else }}
{{- $_ := set $current_dict "name" $host_data.name }}
@@ -60,7 +74,14 @@ limitations under the License.
{{- $_ := set $nodeSelector_dict "key" "kubernetes.io/hostname" }}
{{- $_ := set $nodeSelector_dict "operator" "In" }}
- {{- $values_list := list $host_data.name }}
+ {{- $values_list := list }}
+ {{- if eq (kindOf $host_data.name) "slice" }}
+ {{- range $host_data.name }}
+ {{- $values_list = append $values_list . }}
+ {{- end }}
+ {{- else }}
+ {{- $values_list = list $host_data.name }}
+ {{- end }}
{{- $_ := set $nodeSelector_dict "values" $values_list }}
{{- $list_aggregate := list $nodeSelector_dict }}
@@ -123,7 +144,16 @@ limitations under the License.
{{- $_ := set $label_dict "key" "kubernetes.io/hostname" }}
{{- $_ := set $label_dict "operator" "NotIn" }}
- {{- $values_list := list $host_data.name }}
+ {{/* - $values_list := list $host_data.name */}}
+ {{- $values_list := list }}
+ {{- if eq (kindOf $host_data.name) "slice" }}
+ {{- range $host_data.name }}
+ {{ $values_list = append $values_list . }}
+ {{- end }}
+ {{- else }}
+ {{- $values_list = list $host_data.name }}
+ {{- end }}
+
{{- $_ := set $label_dict "values" $values_list }}
{{- $list_aggregate := append $context.Values.__current_label.matchExpressions $label_dict }}
@@ -164,7 +194,15 @@ limitations under the License.
{{- $_ := set $default_dict "key" "kubernetes.io/hostname" }}
{{- $_ := set $default_dict "operator" "NotIn" }}
- {{- $values_list := list $host_data.name }}
+ {{- $values_list := list }}
+ {{- if eq (kindOf $host_data.name) "slice" }}
+ {{- range $host_data.name }}
+ {{ $values_list = append $values_list . }}
+ {{- end }}
+ {{- else }}
+ {{- $values_list = list $host_data.name }}
+ {{- end }}
+
{{- $_ := set $default_dict "values" $values_list }}
{{- $list_aggregate := append $context.Values.__default.matchExpressions $default_dict }}
--
2.34.1

@ -18,3 +18,4 @@
0018-Remove-nginx-configuration-snippet.patch
0019-Add-pre-apply-cleanup-Job-to-STX-O-Helm-charts.patch
0020-Add-Kubernetes-name-label-to-helm-toolkit-template.patch
0021-Add-support-for-multiple-hosts-in-a-daemonset.patch