From cab707c67dbae9be94cae67769c99a1bf0d2479c Mon Sep 17 00:00:00 2001 From: Yun Li Date: Fri, 21 Apr 2023 16:06:01 +0800 Subject: [PATCH 01/15] Move k8s script to config engine container for telemetry Signed-off-by: Yun Li --- dockers/docker-config-engine-bullseye/Dockerfile.j2 | 1 + dockers/docker-config-engine-buster/Dockerfile.j2 | 1 + rules/docker-telemetry.mk | 1 - rules/scripts.mk | 6 +++++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dockers/docker-config-engine-bullseye/Dockerfile.j2 b/dockers/docker-config-engine-bullseye/Dockerfile.j2 index f7e0de09b9f6..0fdfa08e3238 100644 --- a/dockers/docker-config-engine-bullseye/Dockerfile.j2 +++ b/dockers/docker-config-engine-bullseye/Dockerfile.j2 @@ -41,6 +41,7 @@ RUN pip3 uninstall -y enum34 # Copy files COPY ["files/swss_vars.j2", "/usr/share/sonic/templates/"] +COPY ["files/container_startup.py", "/usr/share/sonic/scripts/"] ## Clean up RUN apt-get purge -y \ diff --git a/dockers/docker-config-engine-buster/Dockerfile.j2 b/dockers/docker-config-engine-buster/Dockerfile.j2 index 77ea27e00ee3..bdd8fd74210d 100644 --- a/dockers/docker-config-engine-buster/Dockerfile.j2 +++ b/dockers/docker-config-engine-buster/Dockerfile.j2 @@ -41,6 +41,7 @@ RUN pip3 uninstall -y enum34 # Copy files COPY ["files/swss_vars.j2", "/usr/share/sonic/templates/"] +COPY ["files/container_startup.py", "/usr/share/sonic/scripts/"] ## Clean up RUN apt-get purge -y \ diff --git a/rules/docker-telemetry.mk b/rules/docker-telemetry.mk index 4a2d3fd64e28..a3db04d4f5df 100644 --- a/rules/docker-telemetry.mk +++ b/rules/docker-telemetry.mk @@ -30,7 +30,6 @@ endif $(DOCKER_TELEMETRY)_CONTAINER_NAME = telemetry $(DOCKER_TELEMETRY)_RUN_OPT += --privileged -t $(DOCKER_TELEMETRY)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro -$(DOCKER_TELEMETRY)_RUN_OPT += -v /usr/share/sonic/scripts:/usr/share/sonic/scripts:ro $(DOCKER_TELEMETRY)_RUN_OPT += -v /var/run/dbus:/var/run/dbus:rw $(DOCKER_TELEMETRY)_FILES += $(SUPERVISOR_PROC_EXIT_LISTENER_SCRIPT) diff --git a/rules/scripts.mk b/rules/scripts.mk index 12919d520b09..e55792563805 100644 --- a/rules/scripts.mk +++ b/rules/scripts.mk @@ -35,6 +35,9 @@ $(COPP_CONFIG_TEMPLATE)_PATH = files/image_config/copp RSYSLOG_PLUGIN_CONF_J2 = rsyslog_plugin.conf.j2 $(RSYSLOG_PLUGIN_CONF_J2)_PATH = files/build_templates +KUBERNETES_CONTAINER_STARTUP_SCRIPT = cotainer_startup.py +$(KUBERNETES_CONTAINER_STARTUP_SCRIPT)_PATH = src/sonic-ctrmgrd/ctrmgr + SONIC_COPY_FILES += $(CONFIGDB_LOAD_SCRIPT) \ $(ARP_UPDATE_SCRIPT) \ $(ARP_UPDATE_VARS_TEMPLATE) \ @@ -46,4 +49,5 @@ SONIC_COPY_FILES += $(CONFIGDB_LOAD_SCRIPT) \ $(UPDATE_CHASSISDB_CONFIG_SCRIPT) \ $(SWSS_VARS_TEMPLATE) \ $(RSYSLOG_PLUGIN_CONF_J2) \ - $(COPP_CONFIG_TEMPLATE) + $(COPP_CONFIG_TEMPLATE) \ + $(KUBERNETES_CONTAINER_STARTUP_SCRIPT) From 41405626a3444df3b6fcde5dcadd2f25d0ba644e Mon Sep 17 00:00:00 2001 From: Yun Li Date: Sun, 23 Apr 2023 19:04:31 +0800 Subject: [PATCH 02/15] Update --- rules/docker-config-engine-bullseye.mk | 1 + rules/docker-config-engine-buster.mk | 1 + rules/scripts.mk | 6 +----- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/rules/docker-config-engine-bullseye.mk b/rules/docker-config-engine-bullseye.mk index 9548391a6917..808905496e8f 100644 --- a/rules/docker-config-engine-bullseye.mk +++ b/rules/docker-config-engine-bullseye.mk @@ -19,6 +19,7 @@ $(DOCKER_CONFIG_ENGINE_BULLSEYE)_LOAD_DOCKERS += $(DOCKER_BASE_BULLSEYE) $(DOCKER_CONFIG_ENGINE_BULLSEYE)_FILES += $(SWSS_VARS_TEMPLATE) $(DOCKER_CONFIG_ENGINE_BULLSEYE)_FILES += $(RSYSLOG_PLUGIN_CONF_J2) $(DOCKER_CONFIG_ENGINE_BULLSEYE)_FILES += $($(SONIC_CTRMGRD)_CONTAINER_SCRIPT) +$(DOCKER_CONFIG_ENGINE_BULLSEYE)_FILES += $($(SONIC_CTRMGRD)_STARTUP_SCRIPT) $(DOCKER_CONFIG_ENGINE_BULLSEYE)_DBG_DEPENDS = $($(DOCKER_BASE_BULLSEYE)_DBG_DEPENDS) \ $(LIBSWSSCOMMON_DBG) \ diff --git a/rules/docker-config-engine-buster.mk b/rules/docker-config-engine-buster.mk index cd6d6f43b46d..474617bbbd94 100644 --- a/rules/docker-config-engine-buster.mk +++ b/rules/docker-config-engine-buster.mk @@ -18,6 +18,7 @@ $(DOCKER_CONFIG_ENGINE_BUSTER)_LOAD_DOCKERS += $(DOCKER_BASE_BUSTER) $(DOCKER_CONFIG_ENGINE_BUSTER)_FILES += $(SWSS_VARS_TEMPLATE) $(DOCKER_CONFIG_ENGINE_BUSTER)_FILES += $(RSYSLOG_PLUGIN_CONF_J2) $(DOCKER_CONFIG_ENGINE_BUSTER)_FILES += $($(SONIC_CTRMGRD)_CONTAINER_SCRIPT) +$(DOCKER_CONFIG_ENGINE_BUSTER)_FILES += $($(SONIC_CTRMGRD)_STARTUP_SCRIPT) $(DOCKER_CONFIG_ENGINE_BUSTER)_DBG_DEPENDS = $($(DOCKER_BASE_BUSTER)_DBG_DEPENDS) \ $(LIBSWSSCOMMON_DBG) \ diff --git a/rules/scripts.mk b/rules/scripts.mk index e55792563805..12919d520b09 100644 --- a/rules/scripts.mk +++ b/rules/scripts.mk @@ -35,9 +35,6 @@ $(COPP_CONFIG_TEMPLATE)_PATH = files/image_config/copp RSYSLOG_PLUGIN_CONF_J2 = rsyslog_plugin.conf.j2 $(RSYSLOG_PLUGIN_CONF_J2)_PATH = files/build_templates -KUBERNETES_CONTAINER_STARTUP_SCRIPT = cotainer_startup.py -$(KUBERNETES_CONTAINER_STARTUP_SCRIPT)_PATH = src/sonic-ctrmgrd/ctrmgr - SONIC_COPY_FILES += $(CONFIGDB_LOAD_SCRIPT) \ $(ARP_UPDATE_SCRIPT) \ $(ARP_UPDATE_VARS_TEMPLATE) \ @@ -49,5 +46,4 @@ SONIC_COPY_FILES += $(CONFIGDB_LOAD_SCRIPT) \ $(UPDATE_CHASSISDB_CONFIG_SCRIPT) \ $(SWSS_VARS_TEMPLATE) \ $(RSYSLOG_PLUGIN_CONF_J2) \ - $(COPP_CONFIG_TEMPLATE) \ - $(KUBERNETES_CONTAINER_STARTUP_SCRIPT) + $(COPP_CONFIG_TEMPLATE) From 5bd3cf3303f4505bb43cb05414389f23e6b78512 Mon Sep 17 00:00:00 2001 From: Yun Li Date: Mon, 24 Apr 2023 17:28:23 +0800 Subject: [PATCH 03/15] Enable k8s for the moment --- rules/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/config b/rules/config index 2f363ff279e8..d436e83364aa 100644 --- a/rules/config +++ b/rules/config @@ -178,7 +178,7 @@ INCLUDE_ROUTER_ADVERTISER ?= y # INCLUDE_KUBERNETES - if set to y kubernetes packages are installed to be able to # run as worker node in kubernetes cluster. -INCLUDE_KUBERNETES ?= n +INCLUDE_KUBERNETES ?= y KUBE_DOCKER_PROXY = http://172.16.1.1:3128/ From 1a08821b57f72cf128e1930ffa264efae80ab6f8 Mon Sep 17 00:00:00 2001 From: Yun Li Date: Thu, 27 Apr 2023 14:57:26 +0800 Subject: [PATCH 04/15] Check kube or local to decide execution of script --- dockers/docker-dhcp-relay/start.sh | 2 +- dockers/docker-lldp/start.sh | 2 +- dockers/docker-platform-monitor/docker_init.j2 | 2 +- dockers/docker-router-advertiser/start.sh | 2 +- dockers/docker-snmp/start.sh | 2 +- dockers/docker-sonic-telemetry/start.sh | 2 +- files/build_templates/docker_image_ctl.j2 | 1 - files/build_templates/sonic_debian_extension.j2 | 6 ------ rules/config | 2 +- rules/docker-dhcp-relay.mk | 1 - rules/docker-lldp.mk | 1 - rules/docker-platform-monitor.mk | 1 - rules/docker-router-advertiser.mk | 1 - rules/docker-snmp.mk | 1 - src/sonic-ctrmgrd/ctrmgr/container | 2 +- src/sonic-ctrmgrd/ctrmgr/ctrmgrd.py | 4 ++-- 16 files changed, 10 insertions(+), 22 deletions(-) diff --git a/dockers/docker-dhcp-relay/start.sh b/dockers/docker-dhcp-relay/start.sh index 87a9e5711f2f..16abe317bde8 100755 --- a/dockers/docker-dhcp-relay/start.sh +++ b/dockers/docker-dhcp-relay/start.sh @@ -5,7 +5,7 @@ if [ "${RUNTIME_OWNER}" == "" ]; then fi CTR_SCRIPT="/usr/share/sonic/scripts/container_startup.py" -if test -f ${CTR_SCRIPT} +if [ $RUNTIME_OWNER = "kube" ] && test -f ${CTR_SCRIPT} then ${CTR_SCRIPT} -f dhcp_relay -o ${RUNTIME_OWNER} -v ${IMAGE_VERSION} fi diff --git a/dockers/docker-lldp/start.sh b/dockers/docker-lldp/start.sh index 5a489884aea9..9ea351a3dcda 100755 --- a/dockers/docker-lldp/start.sh +++ b/dockers/docker-lldp/start.sh @@ -11,7 +11,7 @@ if [ "${RUNTIME_OWNER}" == "" ]; then fi CTR_SCRIPT="/usr/share/sonic/scripts/container_startup.py" -if test -f ${CTR_SCRIPT} +if [ $RUNTIME_OWNER = "kube" ] && test -f ${CTR_SCRIPT} then ${CTR_SCRIPT} -f lldp -o ${RUNTIME_OWNER} -v ${IMAGE_VERSION} fi diff --git a/dockers/docker-platform-monitor/docker_init.j2 b/dockers/docker-platform-monitor/docker_init.j2 index c93d1790bd00..256ec6ce40af 100755 --- a/dockers/docker-platform-monitor/docker_init.j2 +++ b/dockers/docker-platform-monitor/docker_init.j2 @@ -24,7 +24,7 @@ if [ "${RUNTIME_OWNER}" == "" ]; then fi CTR_SCRIPT="/usr/share/sonic/scripts/container_startup.py" -if test -f ${CTR_SCRIPT} +if [ $RUNTIME_OWNER = "kube" ] && test -f ${CTR_SCRIPT} then ${CTR_SCRIPT} -f pmon -o ${RUNTIME_OWNER} -v ${IMAGE_VERSION} fi diff --git a/dockers/docker-router-advertiser/start.sh b/dockers/docker-router-advertiser/start.sh index 561cd5d7cee1..1c2bbdae2b33 100755 --- a/dockers/docker-router-advertiser/start.sh +++ b/dockers/docker-router-advertiser/start.sh @@ -5,7 +5,7 @@ if [ "${RUNTIME_OWNER}" == "" ]; then fi CTR_SCRIPT="/usr/share/sonic/scripts/container_startup.py" -if test -f ${CTR_SCRIPT} +if [ $RUNTIME_OWNER = "kube" ] && test -f ${CTR_SCRIPT} then ${CTR_SCRIPT} -f radv -o ${RUNTIME_OWNER} -v ${IMAGE_VERSION} fi diff --git a/dockers/docker-snmp/start.sh b/dockers/docker-snmp/start.sh index aefd0bfc3db6..176b4ea02799 100755 --- a/dockers/docker-snmp/start.sh +++ b/dockers/docker-snmp/start.sh @@ -6,7 +6,7 @@ if [ "${RUNTIME_OWNER}" == "" ]; then fi CTR_SCRIPT="/usr/share/sonic/scripts/container_startup.py" -if test -f ${CTR_SCRIPT} +if [ $RUNTIME_OWNER = "kube" ] && test -f ${CTR_SCRIPT} then ${CTR_SCRIPT} -f snmp -o ${RUNTIME_OWNER} -v ${IMAGE_VERSION} fi diff --git a/dockers/docker-sonic-telemetry/start.sh b/dockers/docker-sonic-telemetry/start.sh index 08f7292f55ba..0278fcf4b5b6 100755 --- a/dockers/docker-sonic-telemetry/start.sh +++ b/dockers/docker-sonic-telemetry/start.sh @@ -5,7 +5,7 @@ if [ "${RUNTIME_OWNER}" == "" ]; then fi CTR_SCRIPT="/usr/share/sonic/scripts/container_startup.py" -if test -f ${CTR_SCRIPT} +if [ $RUNTIME_OWNER = "kube" ] && test -f ${CTR_SCRIPT} then ${CTR_SCRIPT} -f telemetry -o ${RUNTIME_OWNER} -v ${IMAGE_VERSION} fi diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 0a4391cf6242..45b795e5d157 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -575,7 +575,6 @@ start() { {%- endif -%} {%- if docker_container_name == "bgp" %} -v /etc/sonic/frr/$DEV:/etc/frr:rw \ - -v /usr/share/sonic/scripts:/usr/share/sonic/scripts:ro \ {%- endif %} {%- if docker_container_name == "database" %} $DB_OPT \ diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 0dc60b2b605f..9dbecf136f0b 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -491,12 +491,6 @@ sudo cp {{sonic_ctrmgmt_py3_wheel_path}} $FILESYSTEM_ROOT/$SONIC_CTRMGMT_WHEEL_N sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $SONIC_CTRMGMT_WHEEL_NAME sudo rm -rf $FILESYSTEM_ROOT/$SONIC_CTRMGMT_WHEEL_NAME -# Copy remote container mangement files -# File called from each container upon start/stop to record the state -sudo mkdir -p ${FILESYSTEM_ROOT_USR_SHARE_SONIC_SCRIPTS} -sudo cp ${files_path}/container_startup.py ${FILESYSTEM_ROOT_USR_SHARE_SONIC_SCRIPTS}/ -sudo chmod a+x ${FILESYSTEM_ROOT_USR_SHARE_SONIC_SCRIPTS}/container_startup.py - # Config file used by container mgmt scripts/service fl="${files_path}/remote_ctr.config.json" use_k8s_as_http_proxy=$(python3 -c 'import json diff --git a/rules/config b/rules/config index d436e83364aa..2f363ff279e8 100644 --- a/rules/config +++ b/rules/config @@ -178,7 +178,7 @@ INCLUDE_ROUTER_ADVERTISER ?= y # INCLUDE_KUBERNETES - if set to y kubernetes packages are installed to be able to # run as worker node in kubernetes cluster. -INCLUDE_KUBERNETES ?= y +INCLUDE_KUBERNETES ?= n KUBE_DOCKER_PROXY = http://172.16.1.1:3128/ diff --git a/rules/docker-dhcp-relay.mk b/rules/docker-dhcp-relay.mk index c26995ad143b..df1b6a7c6bfe 100644 --- a/rules/docker-dhcp-relay.mk +++ b/rules/docker-dhcp-relay.mk @@ -47,7 +47,6 @@ endif $(DOCKER_DHCP_RELAY)_CONTAINER_NAME = dhcp_relay $(DOCKER_DHCP_RELAY)_CONTAINER_PRIVILEGED = true $(DOCKER_DHCP_RELAY)_CONTAINER_VOLUMES += /etc/sonic:/etc/sonic:ro -$(DOCKER_DHCP_RELAY)_CONTAINER_VOLUMES += /usr/share/sonic/scripts:/usr/share/sonic/scripts:ro $(DOCKER_DHCP_RELAY)_CONTAINER_TMPFS += /tmp/ $(DOCKER_DHCP_RELAY)_CONTAINER_TMPFS += /var/tmp/ diff --git a/rules/docker-lldp.mk b/rules/docker-lldp.mk index b2e7b350f3bb..f0d16e3f5f17 100644 --- a/rules/docker-lldp.mk +++ b/rules/docker-lldp.mk @@ -30,7 +30,6 @@ SONIC_INSTALL_DOCKER_DBG_IMAGES += $(DOCKER_LLDP_DBG) $(DOCKER_LLDP)_CONTAINER_NAME = lldp $(DOCKER_LLDP)_RUN_OPT += --privileged -t $(DOCKER_LLDP)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro -$(DOCKER_LLDP)_RUN_OPT += -v /usr/share/sonic/scripts:/usr/share/sonic/scripts:ro $(DOCKER_LLDP)_BASE_IMAGE_FILES += lldpctl:/usr/bin/lldpctl $(DOCKER_LLDP)_BASE_IMAGE_FILES += lldpcli:/usr/bin/lldpcli diff --git a/rules/docker-platform-monitor.mk b/rules/docker-platform-monitor.mk index a87a30247337..38ab065bf4be 100644 --- a/rules/docker-platform-monitor.mk +++ b/rules/docker-platform-monitor.mk @@ -50,7 +50,6 @@ SONIC_INSTALL_DOCKER_DBG_IMAGES += $(DOCKER_PLATFORM_MONITOR_DBG) $(DOCKER_PLATFORM_MONITOR)_CONTAINER_NAME = pmon $(DOCKER_PLATFORM_MONITOR)_RUN_OPT += --privileged -t $(DOCKER_PLATFORM_MONITOR)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro -$(DOCKER_PLATFORM_MONITOR)_RUN_OPT += -v /usr/share/sonic/scripts:/usr/share/sonic/scripts:ro $(DOCKER_PLATFORM_MONITOR)_RUN_OPT += -v /var/run/platform_cache:/var/run/platform_cache:ro $(DOCKER_PLATFORM_MONITOR)_RUN_OPT += -v /usr/share/sonic/device/pddf:/usr/share/sonic/device/pddf:ro diff --git a/rules/docker-router-advertiser.mk b/rules/docker-router-advertiser.mk index 255ca00c01c7..b2dbf4e4b95c 100644 --- a/rules/docker-router-advertiser.mk +++ b/rules/docker-router-advertiser.mk @@ -31,5 +31,4 @@ endif $(DOCKER_ROUTER_ADVERTISER)_CONTAINER_NAME = radv $(DOCKER_ROUTER_ADVERTISER)_RUN_OPT += --privileged -t $(DOCKER_ROUTER_ADVERTISER)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro -$(DOCKER_ROUTER_ADVERTISER)_RUN_OPT += -v /usr/share/sonic/scripts:/usr/share/sonic/scripts:ro $(DOCKER_ROUTER_ADVERTISER)_FILES += $(SUPERVISOR_PROC_EXIT_LISTENER_SCRIPT) diff --git a/rules/docker-snmp.mk b/rules/docker-snmp.mk index 037d58936170..3c7f0057e9bb 100644 --- a/rules/docker-snmp.mk +++ b/rules/docker-snmp.mk @@ -30,7 +30,6 @@ SONIC_INSTALL_DOCKER_DBG_IMAGES += $(DOCKER_SNMP_DBG) $(DOCKER_SNMP)_CONTAINER_NAME = snmp $(DOCKER_SNMP)_RUN_OPT += --privileged -t $(DOCKER_SNMP)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro -$(DOCKER_SNMP)_RUN_OPT += -v /usr/share/sonic/scripts:/usr/share/sonic/scripts:ro $(DOCKER_SNMP)_FILES += $(SUPERVISOR_PROC_EXIT_LISTENER_SCRIPT) $(DOCKER_SNMP)_BASE_IMAGE_FILES += monit_snmp:/etc/monit/conf.d diff --git a/src/sonic-ctrmgrd/ctrmgr/container b/src/sonic-ctrmgrd/ctrmgr/container index ca2394b057bb..6ebbd58a1c9b 100755 --- a/src/sonic-ctrmgrd/ctrmgr/container +++ b/src/sonic-ctrmgrd/ctrmgr/container @@ -11,7 +11,7 @@ import datetime import docker from swsscommon import swsscommon -CTR_STATE_SCR_PATH = '/usr/share/sonic/scripts/container_startup.py' +CTR_STATE_SCR_PATH = '/etc/sonic/remote_ctr.config.json' state_db = None diff --git a/src/sonic-ctrmgrd/ctrmgr/ctrmgrd.py b/src/sonic-ctrmgrd/ctrmgr/ctrmgrd.py index 1dd329005948..7e45f44c6471 100755 --- a/src/sonic-ctrmgrd/ctrmgr/ctrmgrd.py +++ b/src/sonic-ctrmgrd/ctrmgr/ctrmgrd.py @@ -111,7 +111,7 @@ USE_K8S_PROXY: "" } -ENABLED_FEATURE_SET = {"telemetry", "snmp"} +DISABLED_FEATURE_SET = {"database"} def log_debug(m): msg = "{}: {}".format(inspect.stack()[1][3], m) @@ -271,7 +271,7 @@ def run(self): key, op, fvs = subscriber.pop() if not key: continue - if subscriber.getTableName() == FEATURE_TABLE and key not in ENABLED_FEATURE_SET: + if subscriber.getTableName() == FEATURE_TABLE and key in DISABLED_FEATURE_SET: continue log_debug("Received message : '%s'" % str((key, op, fvs))) for callback in (self.callbacks From f0cd6c1968748d899d02497ca5211525ef1ad3f3 Mon Sep 17 00:00:00 2001 From: Yun Li Date: Thu, 27 Apr 2023 18:35:23 +0800 Subject: [PATCH 05/15] Enable k8s for checking --- rules/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/config b/rules/config index 4507667d4ade..d2cc395f16d4 100644 --- a/rules/config +++ b/rules/config @@ -178,7 +178,7 @@ INCLUDE_ROUTER_ADVERTISER ?= y # INCLUDE_KUBERNETES - if set to y kubernetes packages are installed to be able to # run as worker node in kubernetes cluster. -INCLUDE_KUBERNETES ?= n +INCLUDE_KUBERNETES ?= y KUBE_DOCKER_PROXY = http://172.16.1.1:3128/ From 7014bca6a24f199fe7026745a7b596f0e1c46f4f Mon Sep 17 00:00:00 2001 From: Yun Li Date: Thu, 4 May 2023 12:03:46 +0800 Subject: [PATCH 06/15] Disable k8s as default --- rules/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/config b/rules/config index d2cc395f16d4..4507667d4ade 100644 --- a/rules/config +++ b/rules/config @@ -178,7 +178,7 @@ INCLUDE_ROUTER_ADVERTISER ?= y # INCLUDE_KUBERNETES - if set to y kubernetes packages are installed to be able to # run as worker node in kubernetes cluster. -INCLUDE_KUBERNETES ?= y +INCLUDE_KUBERNETES ?= n KUBE_DOCKER_PROXY = http://172.16.1.1:3128/ From e984011b9c1211009168ff4267859fb84f17d3c4 Mon Sep 17 00:00:00 2001 From: Yun Li Date: Mon, 8 May 2023 09:58:15 +0800 Subject: [PATCH 07/15] Drop disable feature set --- rules/config | 2 +- src/sonic-ctrmgrd/ctrmgr/ctrmgrd.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rules/config b/rules/config index 4507667d4ade..d2cc395f16d4 100644 --- a/rules/config +++ b/rules/config @@ -178,7 +178,7 @@ INCLUDE_ROUTER_ADVERTISER ?= y # INCLUDE_KUBERNETES - if set to y kubernetes packages are installed to be able to # run as worker node in kubernetes cluster. -INCLUDE_KUBERNETES ?= n +INCLUDE_KUBERNETES ?= y KUBE_DOCKER_PROXY = http://172.16.1.1:3128/ diff --git a/src/sonic-ctrmgrd/ctrmgr/ctrmgrd.py b/src/sonic-ctrmgrd/ctrmgr/ctrmgrd.py index 7e45f44c6471..1dd329005948 100755 --- a/src/sonic-ctrmgrd/ctrmgr/ctrmgrd.py +++ b/src/sonic-ctrmgrd/ctrmgr/ctrmgrd.py @@ -111,7 +111,7 @@ USE_K8S_PROXY: "" } -DISABLED_FEATURE_SET = {"database"} +ENABLED_FEATURE_SET = {"telemetry", "snmp"} def log_debug(m): msg = "{}: {}".format(inspect.stack()[1][3], m) @@ -271,7 +271,7 @@ def run(self): key, op, fvs = subscriber.pop() if not key: continue - if subscriber.getTableName() == FEATURE_TABLE and key in DISABLED_FEATURE_SET: + if subscriber.getTableName() == FEATURE_TABLE and key not in ENABLED_FEATURE_SET: continue log_debug("Received message : '%s'" % str((key, op, fvs))) for callback in (self.callbacks From 98209f67410c43c019c0e7221b79f08d411405ed Mon Sep 17 00:00:00 2001 From: Yun Li Date: Tue, 9 May 2023 18:08:07 +0800 Subject: [PATCH 08/15] Disable k8s as default --- rules/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/config b/rules/config index d2cc395f16d4..4507667d4ade 100644 --- a/rules/config +++ b/rules/config @@ -178,7 +178,7 @@ INCLUDE_ROUTER_ADVERTISER ?= y # INCLUDE_KUBERNETES - if set to y kubernetes packages are installed to be able to # run as worker node in kubernetes cluster. -INCLUDE_KUBERNETES ?= y +INCLUDE_KUBERNETES ?= n KUBE_DOCKER_PROXY = http://172.16.1.1:3128/ From bf36f853d8952decf78f0cbdfc6e6c6332f7a378 Mon Sep 17 00:00:00 2001 From: Yun Li Date: Wed, 31 May 2023 13:46:37 +0800 Subject: [PATCH 09/15] Include k8s for test --- rules/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/config b/rules/config index 4507667d4ade..d2cc395f16d4 100644 --- a/rules/config +++ b/rules/config @@ -178,7 +178,7 @@ INCLUDE_ROUTER_ADVERTISER ?= y # INCLUDE_KUBERNETES - if set to y kubernetes packages are installed to be able to # run as worker node in kubernetes cluster. -INCLUDE_KUBERNETES ?= n +INCLUDE_KUBERNETES ?= y KUBE_DOCKER_PROXY = http://172.16.1.1:3128/ From c7f9540207742d876e45f2fd8cb64e992f79e437 Mon Sep 17 00:00:00 2001 From: Yun Li Date: Thu, 1 Jun 2023 16:29:09 +0800 Subject: [PATCH 10/15] Remove conditions of executing k8s script --- dockers/docker-dhcp-relay/start.sh | 2 +- dockers/docker-lldp/start.sh | 2 +- dockers/docker-platform-monitor/docker_init.j2 | 2 +- dockers/docker-router-advertiser/start.sh | 2 +- dockers/docker-snmp/start.sh | 2 +- src/sonic-ctrmgrd/ctrmgr/container | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dockers/docker-dhcp-relay/start.sh b/dockers/docker-dhcp-relay/start.sh index 16abe317bde8..87a9e5711f2f 100755 --- a/dockers/docker-dhcp-relay/start.sh +++ b/dockers/docker-dhcp-relay/start.sh @@ -5,7 +5,7 @@ if [ "${RUNTIME_OWNER}" == "" ]; then fi CTR_SCRIPT="/usr/share/sonic/scripts/container_startup.py" -if [ $RUNTIME_OWNER = "kube" ] && test -f ${CTR_SCRIPT} +if test -f ${CTR_SCRIPT} then ${CTR_SCRIPT} -f dhcp_relay -o ${RUNTIME_OWNER} -v ${IMAGE_VERSION} fi diff --git a/dockers/docker-lldp/start.sh b/dockers/docker-lldp/start.sh index 9ea351a3dcda..5a489884aea9 100755 --- a/dockers/docker-lldp/start.sh +++ b/dockers/docker-lldp/start.sh @@ -11,7 +11,7 @@ if [ "${RUNTIME_OWNER}" == "" ]; then fi CTR_SCRIPT="/usr/share/sonic/scripts/container_startup.py" -if [ $RUNTIME_OWNER = "kube" ] && test -f ${CTR_SCRIPT} +if test -f ${CTR_SCRIPT} then ${CTR_SCRIPT} -f lldp -o ${RUNTIME_OWNER} -v ${IMAGE_VERSION} fi diff --git a/dockers/docker-platform-monitor/docker_init.j2 b/dockers/docker-platform-monitor/docker_init.j2 index 256ec6ce40af..c93d1790bd00 100755 --- a/dockers/docker-platform-monitor/docker_init.j2 +++ b/dockers/docker-platform-monitor/docker_init.j2 @@ -24,7 +24,7 @@ if [ "${RUNTIME_OWNER}" == "" ]; then fi CTR_SCRIPT="/usr/share/sonic/scripts/container_startup.py" -if [ $RUNTIME_OWNER = "kube" ] && test -f ${CTR_SCRIPT} +if test -f ${CTR_SCRIPT} then ${CTR_SCRIPT} -f pmon -o ${RUNTIME_OWNER} -v ${IMAGE_VERSION} fi diff --git a/dockers/docker-router-advertiser/start.sh b/dockers/docker-router-advertiser/start.sh index 1c2bbdae2b33..561cd5d7cee1 100755 --- a/dockers/docker-router-advertiser/start.sh +++ b/dockers/docker-router-advertiser/start.sh @@ -5,7 +5,7 @@ if [ "${RUNTIME_OWNER}" == "" ]; then fi CTR_SCRIPT="/usr/share/sonic/scripts/container_startup.py" -if [ $RUNTIME_OWNER = "kube" ] && test -f ${CTR_SCRIPT} +if test -f ${CTR_SCRIPT} then ${CTR_SCRIPT} -f radv -o ${RUNTIME_OWNER} -v ${IMAGE_VERSION} fi diff --git a/dockers/docker-snmp/start.sh b/dockers/docker-snmp/start.sh index 176b4ea02799..aefd0bfc3db6 100755 --- a/dockers/docker-snmp/start.sh +++ b/dockers/docker-snmp/start.sh @@ -6,7 +6,7 @@ if [ "${RUNTIME_OWNER}" == "" ]; then fi CTR_SCRIPT="/usr/share/sonic/scripts/container_startup.py" -if [ $RUNTIME_OWNER = "kube" ] && test -f ${CTR_SCRIPT} +if test -f ${CTR_SCRIPT} then ${CTR_SCRIPT} -f snmp -o ${RUNTIME_OWNER} -v ${IMAGE_VERSION} fi diff --git a/src/sonic-ctrmgrd/ctrmgr/container b/src/sonic-ctrmgrd/ctrmgr/container index 6ebbd58a1c9b..7e95ca618e81 100755 --- a/src/sonic-ctrmgrd/ctrmgr/container +++ b/src/sonic-ctrmgrd/ctrmgr/container @@ -11,7 +11,7 @@ import datetime import docker from swsscommon import swsscommon -CTR_STATE_SCR_PATH = '/etc/sonic/remote_ctr.config.json' +CTR_STATE_SCR_PATH = '/lib/systemd/system/ctrmgrd.service' state_db = None From eebb4b0d069c0a69ab70869f77ba0e3b6bb34552 Mon Sep 17 00:00:00 2001 From: Yun Li Date: Thu, 1 Jun 2023 16:30:23 +0800 Subject: [PATCH 11/15] Update --- dockers/docker-sonic-telemetry/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockers/docker-sonic-telemetry/start.sh b/dockers/docker-sonic-telemetry/start.sh index 0278fcf4b5b6..08f7292f55ba 100755 --- a/dockers/docker-sonic-telemetry/start.sh +++ b/dockers/docker-sonic-telemetry/start.sh @@ -5,7 +5,7 @@ if [ "${RUNTIME_OWNER}" == "" ]; then fi CTR_SCRIPT="/usr/share/sonic/scripts/container_startup.py" -if [ $RUNTIME_OWNER = "kube" ] && test -f ${CTR_SCRIPT} +if test -f ${CTR_SCRIPT} then ${CTR_SCRIPT} -f telemetry -o ${RUNTIME_OWNER} -v ${IMAGE_VERSION} fi From 3925c937382b203416c9de7580d3c336e25a710c Mon Sep 17 00:00:00 2001 From: Yun Li Date: Thu, 1 Jun 2023 18:58:17 +0800 Subject: [PATCH 12/15] Do not run the script if k8s is disabled --- src/sonic-ctrmgrd/ctrmgr/container_startup.py | 3 +++ src/sonic-ctrmgrd/tests/container_startup_test.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/sonic-ctrmgrd/ctrmgr/container_startup.py b/src/sonic-ctrmgrd/ctrmgr/container_startup.py index c22ceb2f9ce5..f8153e3f6e4c 100755 --- a/src/sonic-ctrmgrd/ctrmgr/container_startup.py +++ b/src/sonic-ctrmgrd/ctrmgr/container_startup.py @@ -216,6 +216,9 @@ def container_up(feature, owner, version): debug_msg("args: feature={}, owner={}, version={} DB: set_owner={} state_data={}".format( feature, owner, version, set_owner, json.dumps(state_data, indent=4))) + if state_data[SYSTEM_STATE] == '': + return + if owner == "local": update_state(state_db, feature, owner, version) else: diff --git a/src/sonic-ctrmgrd/tests/container_startup_test.py b/src/sonic-ctrmgrd/tests/container_startup_test.py index b21fe855662c..b8179cfd3f62 100755 --- a/src/sonic-ctrmgrd/tests/container_startup_test.py +++ b/src/sonic-ctrmgrd/tests/container_startup_test.py @@ -23,6 +23,13 @@ "set_owner": "local" } } + }, + common_test.STATE_DB_NO: { + common_test.FEATURE_TABLE: { + "snmp": { + "system_state": "up" + } + } } }, common_test.POST: { From 94e8cd279c4e68f1856fdbd433dc39c2a40103dd Mon Sep 17 00:00:00 2001 From: Yun Li Date: Mon, 5 Jun 2023 16:48:02 +0800 Subject: [PATCH 13/15] Disable k8s feature as default --- rules/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/config b/rules/config index d2cc395f16d4..4507667d4ade 100644 --- a/rules/config +++ b/rules/config @@ -178,7 +178,7 @@ INCLUDE_ROUTER_ADVERTISER ?= y # INCLUDE_KUBERNETES - if set to y kubernetes packages are installed to be able to # run as worker node in kubernetes cluster. -INCLUDE_KUBERNETES ?= y +INCLUDE_KUBERNETES ?= n KUBE_DOCKER_PROXY = http://172.16.1.1:3128/ From 679db38732e34e578a5ee4eb25c89ee07f57ca17 Mon Sep 17 00:00:00 2001 From: lixiaoyuner <35456895+lixiaoyuner@users.noreply.github.com> Date: Wed, 21 Jun 2023 09:25:26 +0800 Subject: [PATCH 14/15] Update container ctrmgrd service file variable name --- src/sonic-ctrmgrd/ctrmgr/container | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-ctrmgrd/ctrmgr/container b/src/sonic-ctrmgrd/ctrmgr/container index 7e95ca618e81..7e5051d2461c 100755 --- a/src/sonic-ctrmgrd/ctrmgr/container +++ b/src/sonic-ctrmgrd/ctrmgr/container @@ -11,7 +11,7 @@ import datetime import docker from swsscommon import swsscommon -CTR_STATE_SCR_PATH = '/lib/systemd/system/ctrmgrd.service' +CTRMGRD_SERVICE_PATH = '/lib/systemd/system/ctrmgrd.service' state_db = None @@ -61,7 +61,7 @@ def init(): cfg_db = swsscommon.DBConnector("CONFIG_DB", 0) state_db = swsscommon.DBConnector("STATE_DB", 0) - remote_ctr_enabled = os.path.exists(CTR_STATE_SCR_PATH) + remote_ctr_enabled = os.path.exists(CTRMGRD_SERVICE_PATH) def get_config_data(fld, dflt): From 8ec524027dbe7bb67db2b31f010cffcaa4aad4e9 Mon Sep 17 00:00:00 2001 From: lixiaoyuner <35456895+lixiaoyuner@users.noreply.github.com> Date: Wed, 21 Jun 2023 10:36:22 +0800 Subject: [PATCH 15/15] Update container_test.py to change the ctrmgrd service path variable name in test --- src/sonic-ctrmgrd/tests/container_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-ctrmgrd/tests/container_test.py b/src/sonic-ctrmgrd/tests/container_test.py index 4581111015e5..5077bbfebde2 100755 --- a/src/sonic-ctrmgrd/tests/container_test.py +++ b/src/sonic-ctrmgrd/tests/container_test.py @@ -467,7 +467,7 @@ class TestContainer(object): def init(self): - container.CTR_STATE_SCR_PATH = __file__ + container.CTRMGRD_SERVICE_PATH = __file__ container.SONIC_CTR_CONFIG = ( common_test.create_remote_ctr_config_json())