From b769895a60f2c68c48732a0a4b7fc8d047d9ee62 Mon Sep 17 00:00:00 2001 From: "SPEARS, DUSTIN (ds443n)" Date: Mon, 30 Oct 2023 16:24:41 -0400 Subject: [PATCH] Update openvswitch to support cgroups v2 Adds check and if cgroups v2 is active use cgroups v2 file structure for setting cpus Change-Id: I603271a1b043d192988694c50ea7411a567b16ca --- openvswitch/Chart.yaml | 2 +- .../bin/_openvswitch-vswitchd.sh.tpl | 41 ++++++++++++++----- releasenotes/notes/openvswitch.yaml | 1 + 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/openvswitch/Chart.yaml b/openvswitch/Chart.yaml index 9b85ed7e4..93a655174 100644 --- a/openvswitch/Chart.yaml +++ b/openvswitch/Chart.yaml @@ -15,7 +15,7 @@ apiVersion: v1 appVersion: v1.0.0 description: OpenStack-Helm OpenVSwitch name: openvswitch -version: 0.1.18 +version: 0.1.19 home: http://openvswitch.org icon: https://www.openstack.org/themes/openstack/images/project-mascots/Neutron/OpenStack_Project_Neutron_vertical.png sources: diff --git a/openvswitch/templates/bin/_openvswitch-vswitchd.sh.tpl b/openvswitch/templates/bin/_openvswitch-vswitchd.sh.tpl index f3776b4ab..dad613c31 100644 --- a/openvswitch/templates/bin/_openvswitch-vswitchd.sh.tpl +++ b/openvswitch/templates/bin/_openvswitch-vswitchd.sh.tpl @@ -77,19 +77,38 @@ function start () { # No need to create the cgroup if lcore_mask or pmd_cpu_mask is not set. if [[ -n ${PMD_CPU_MASK} || -n ${LCORE_MASK} ]]; then - # Setup Cgroups to use when breaking out of Kubernetes defined groups - mkdir -p /sys/fs/cgroup/cpuset/osh-openvswitch - target_mems="/sys/fs/cgroup/cpuset/osh-openvswitch/cpuset.mems" - target_cpus="/sys/fs/cgroup/cpuset/osh-openvswitch/cpuset.cpus" + if [ "$(stat -fc %T /sys/fs/cgroup/)" = "cgroup2fs" ]; then + # Setup Cgroups to use when breaking out of Kubernetes defined groups + mkdir -p /sys/fs/cgroup/osh-openvswitch + target_mems="/sys/fs/cgroup/osh-openvswitch/cpuset.mems" + target_cpus="/sys/fs/cgroup/osh-openvswitch/cpuset.cpus" + touch $target_mems + touch $target_cpus - # Ensure the write target for the for cpuset.mem for the pod exists - if [[ -f "$target_mems" && -f "$target_cpus" ]]; then - # Write cpuset.mem and cpuset.cpus for new cgroup and add current task to new cgroup - cat /sys/fs/cgroup/cpuset/cpuset.mems > "$target_mems" - cat /sys/fs/cgroup/cpuset/cpuset.cpus > "$target_cpus" - echo $$ > /sys/fs/cgroup/cpuset/osh-openvswitch/tasks + # Ensure the write target for the for cpuset.mem for the pod exists + if [[ -f "$target_mems" && -f "$target_cpus" ]]; then + # Write cpuset.mem and cpuset.cpus for new cgroup and add current task to new cgroup + cat /sys/fs/cgroup/cpuset.mems.effective > "$target_mems" + cat /sys/fs/cgroup/cpuset.cpus.effective > "$target_cpus" + echo $$ > /sys/fs/cgroup/osh-openvswitch/cgroup.procs + else + echo "ERROR: Could not find write target for either cpuset.mems: $target_mems or cpuset.cpus: $target_cpus" + fi else - echo "ERROR: Could not find write target for either cpuset.mems: $target_mems or cpuset.cpus: $target_cpus" + # Setup Cgroups to use when breaking out of Kubernetes defined groups + mkdir -p /sys/fs/cgroup/cpuset/osh-openvswitch + target_mems="/sys/fs/cgroup/cpuset/osh-openvswitch/cpuset.mems" + target_cpus="/sys/fs/cgroup/cpuset/osh-openvswitch/cpuset.cpus" + + # Ensure the write target for the for cpuset.mem for the pod exists + if [[ -f "$target_mems" && -f "$target_cpus" ]]; then + # Write cpuset.mem and cpuset.cpus for new cgroup and add current task to new cgroup + cat /sys/fs/cgroup/cpuset/cpuset.mems > "$target_mems" + cat /sys/fs/cgroup/cpuset/cpuset.cpus > "$target_cpus" + echo $$ > /sys/fs/cgroup/cpuset/osh-openvswitch/tasks + else + echo "ERROR: Could not find write target for either cpuset.mems: $target_mems or cpuset.cpus: $target_cpus" + fi fi fi {{- end }} diff --git a/releasenotes/notes/openvswitch.yaml b/releasenotes/notes/openvswitch.yaml index 93a7113f4..5d6d24511 100644 --- a/releasenotes/notes/openvswitch.yaml +++ b/releasenotes/notes/openvswitch.yaml @@ -19,4 +19,5 @@ openvswitch: - 0.1.16 Restore ServiceAccount to openvswitch pod - 0.1.17 Add buffer to wait for potential new CTL file before running chown - 0.1.18 Add value for extra poststart command + - 0.1.19 Add check for cgroups v2 file structure ...