Skip to content

Commit ca29197

Browse files
Move k8s script to docker-config-engine (#14788)
Why I did it To reduce the container's dependency from host system Work item tracking Microsoft ADO (number only): 17713469 How I did it Move the k8s container startup script to config engine container, other than mount it from host. How to verify it Check file path(/usr/share/sonic/scripts/container_startup.py) inside config engine container. Signed-off-by: Yun Li <[email protected]> Co-authored-by: Qi Luo <[email protected]>
1 parent 4e78f58 commit ca29197

16 files changed

+17
-16
lines changed

dockers/docker-config-engine-bullseye/Dockerfile.j2

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ RUN pip3 install redis==4.5.4
4444

4545
# Copy files
4646
COPY ["files/swss_vars.j2", "/usr/share/sonic/templates/"]
47+
COPY ["files/container_startup.py", "/usr/share/sonic/scripts/"]
4748

4849
## Clean up
4950
RUN apt-get purge -y \

dockers/docker-config-engine-buster/Dockerfile.j2

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ RUN pip3 install redis==4.5.4
4444

4545
# Copy files
4646
COPY ["files/swss_vars.j2", "/usr/share/sonic/templates/"]
47+
COPY ["files/container_startup.py", "/usr/share/sonic/scripts/"]
4748

4849
## Clean up
4950
RUN apt-get purge -y \

files/build_templates/docker_image_ctl.j2

-1
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,6 @@ start() {
579579
{%- endif -%}
580580
{%- if docker_container_name == "bgp" %}
581581
-v /etc/sonic/frr/$DEV:/etc/frr:rw \
582-
-v /usr/share/sonic/scripts:/usr/share/sonic/scripts:ro \
583582
{%- endif %}
584583
{%- if docker_container_name == "database" %}
585584
$DB_OPT \

files/build_templates/sonic_debian_extension.j2

-6
Original file line numberDiff line numberDiff line change
@@ -503,12 +503,6 @@ sudo cp {{sonic_ctrmgmt_py3_wheel_path}} $FILESYSTEM_ROOT/$SONIC_CTRMGMT_WHEEL_N
503503
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $SONIC_CTRMGMT_WHEEL_NAME
504504
sudo rm -rf $FILESYSTEM_ROOT/$SONIC_CTRMGMT_WHEEL_NAME
505505

506-
# Copy remote container mangement files
507-
# File called from each container upon start/stop to record the state
508-
sudo mkdir -p ${FILESYSTEM_ROOT_USR_SHARE_SONIC_SCRIPTS}
509-
sudo cp ${files_path}/container_startup.py ${FILESYSTEM_ROOT_USR_SHARE_SONIC_SCRIPTS}/
510-
sudo chmod a+x ${FILESYSTEM_ROOT_USR_SHARE_SONIC_SCRIPTS}/container_startup.py
511-
512506
# Config file used by container mgmt scripts/service
513507
fl="${files_path}/remote_ctr.config.json"
514508
use_k8s_as_http_proxy=$(python3 -c 'import json

rules/docker-config-engine-bullseye.mk

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ $(DOCKER_CONFIG_ENGINE_BULLSEYE)_LOAD_DOCKERS += $(DOCKER_BASE_BULLSEYE)
1919
$(DOCKER_CONFIG_ENGINE_BULLSEYE)_FILES += $(SWSS_VARS_TEMPLATE)
2020
$(DOCKER_CONFIG_ENGINE_BULLSEYE)_FILES += $(RSYSLOG_PLUGIN_CONF_J2)
2121
$(DOCKER_CONFIG_ENGINE_BULLSEYE)_FILES += $($(SONIC_CTRMGRD)_CONTAINER_SCRIPT)
22+
$(DOCKER_CONFIG_ENGINE_BULLSEYE)_FILES += $($(SONIC_CTRMGRD)_STARTUP_SCRIPT)
2223

2324
$(DOCKER_CONFIG_ENGINE_BULLSEYE)_DBG_DEPENDS = $($(DOCKER_BASE_BULLSEYE)_DBG_DEPENDS) \
2425
$(LIBSWSSCOMMON_DBG) \

rules/docker-config-engine-buster.mk

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ $(DOCKER_CONFIG_ENGINE_BUSTER)_LOAD_DOCKERS += $(DOCKER_BASE_BUSTER)
1818
$(DOCKER_CONFIG_ENGINE_BUSTER)_FILES += $(SWSS_VARS_TEMPLATE)
1919
$(DOCKER_CONFIG_ENGINE_BUSTER)_FILES += $(RSYSLOG_PLUGIN_CONF_J2)
2020
$(DOCKER_CONFIG_ENGINE_BUSTER)_FILES += $($(SONIC_CTRMGRD)_CONTAINER_SCRIPT)
21+
$(DOCKER_CONFIG_ENGINE_BUSTER)_FILES += $($(SONIC_CTRMGRD)_STARTUP_SCRIPT)
2122

2223
$(DOCKER_CONFIG_ENGINE_BUSTER)_DBG_DEPENDS = $($(DOCKER_BASE_BUSTER)_DBG_DEPENDS) \
2324
$(LIBSWSSCOMMON_DBG) \

rules/docker-dhcp-relay.mk

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ $(DOCKER_DHCP_RELAY)_CONTAINER_NAME = dhcp_relay
4848
$(DOCKER_DHCP_RELAY)_CONTAINER_PRIVILEGED = true
4949
$(DOCKER_DHCP_RELAY)_CONTAINER_VOLUMES += /etc/sonic:/etc/sonic:ro
5050
$(DOCKER_DHCP_RELAY)_CONTAINER_VOLUMES += /etc/timezone:/etc/timezone:ro
51-
$(DOCKER_DHCP_RELAY)_CONTAINER_VOLUMES += /usr/share/sonic/scripts:/usr/share/sonic/scripts:ro
5251
$(DOCKER_DHCP_RELAY)_CONTAINER_TMPFS += /tmp/
5352
$(DOCKER_DHCP_RELAY)_CONTAINER_TMPFS += /var/tmp/
5453

rules/docker-lldp.mk

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ $(DOCKER_LLDP)_CONTAINER_NAME = lldp
3131
$(DOCKER_LLDP)_RUN_OPT += --privileged -t
3232
$(DOCKER_LLDP)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro
3333
$(DOCKER_LLDP)_RUN_OPT += -v /etc/timezone:/etc/timezone:ro
34-
$(DOCKER_LLDP)_RUN_OPT += -v /usr/share/sonic/scripts:/usr/share/sonic/scripts:ro
3534

3635
$(DOCKER_LLDP)_BASE_IMAGE_FILES += lldpctl:/usr/bin/lldpctl
3736
$(DOCKER_LLDP)_BASE_IMAGE_FILES += lldpcli:/usr/bin/lldpcli

rules/docker-platform-monitor.mk

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ $(DOCKER_PLATFORM_MONITOR)_CONTAINER_NAME = pmon
5151
$(DOCKER_PLATFORM_MONITOR)_RUN_OPT += --privileged -t
5252
$(DOCKER_PLATFORM_MONITOR)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro
5353
$(DOCKER_PLATFORM_MONITOR)_RUN_OPT += -v /etc/timezone:/etc/timezone:ro
54-
$(DOCKER_PLATFORM_MONITOR)_RUN_OPT += -v /usr/share/sonic/scripts:/usr/share/sonic/scripts:ro
5554
$(DOCKER_PLATFORM_MONITOR)_RUN_OPT += -v /var/run/platform_cache:/var/run/platform_cache:ro
5655
$(DOCKER_PLATFORM_MONITOR)_RUN_OPT += -v /usr/share/sonic/device/pddf:/usr/share/sonic/device/pddf:ro
5756

rules/docker-router-advertiser.mk

-1
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@ $(DOCKER_ROUTER_ADVERTISER)_CONTAINER_NAME = radv
3232
$(DOCKER_ROUTER_ADVERTISER)_RUN_OPT += --privileged -t
3333
$(DOCKER_ROUTER_ADVERTISER)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro
3434
$(DOCKER_ROUTER_ADVERTISER)_RUN_OPT += -v /etc/timezone:/etc/timezone:ro
35-
$(DOCKER_ROUTER_ADVERTISER)_RUN_OPT += -v /usr/share/sonic/scripts:/usr/share/sonic/scripts:ro
3635
$(DOCKER_ROUTER_ADVERTISER)_FILES += $(SUPERVISOR_PROC_EXIT_LISTENER_SCRIPT)

rules/docker-snmp.mk

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ $(DOCKER_SNMP)_CONTAINER_NAME = snmp
3131
$(DOCKER_SNMP)_RUN_OPT += --privileged -t
3232
$(DOCKER_SNMP)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro
3333
$(DOCKER_SNMP)_RUN_OPT += -v /etc/timezone:/etc/timezone:ro
34-
$(DOCKER_SNMP)_RUN_OPT += -v /usr/share/sonic/scripts:/usr/share/sonic/scripts:ro
3534
$(DOCKER_SNMP)_FILES += $(SUPERVISOR_PROC_EXIT_LISTENER_SCRIPT)
3635
$(DOCKER_SNMP)_BASE_IMAGE_FILES += monit_snmp:/etc/monit/conf.d
3736

rules/docker-telemetry.mk

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ $(DOCKER_TELEMETRY)_CONTAINER_NAME = telemetry
3131
$(DOCKER_TELEMETRY)_RUN_OPT += --privileged -t
3232
$(DOCKER_TELEMETRY)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro
3333
$(DOCKER_TELEMETRY)_RUN_OPT += -v /etc/timezone:/etc/timezone:ro
34-
$(DOCKER_TELEMETRY)_RUN_OPT += -v /usr/share/sonic/scripts:/usr/share/sonic/scripts:ro
3534
ifneq ($(INCLUDE_SYSTEM_GNMI), y)
3635
$(DOCKER_TELEMETRY)_RUN_OPT += -v /var/run/dbus:/var/run/dbus:rw
3736
endif

src/sonic-ctrmgrd/ctrmgr/container

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import datetime
1111
import docker
1212
from swsscommon import swsscommon
1313

14-
CTR_STATE_SCR_PATH = '/usr/share/sonic/scripts/container_startup.py'
14+
CTRMGRD_SERVICE_PATH = '/lib/systemd/system/ctrmgrd.service'
1515

1616
state_db = None
1717

@@ -62,7 +62,7 @@ def init():
6262
cfg_db = swsscommon.DBConnector("CONFIG_DB", 0)
6363
state_db = swsscommon.DBConnector("STATE_DB", 0)
6464

65-
remote_ctr_enabled = os.path.exists(CTR_STATE_SCR_PATH)
65+
remote_ctr_enabled = os.path.exists(CTRMGRD_SERVICE_PATH)
6666

6767

6868
def get_config_data(fld, dflt):

src/sonic-ctrmgrd/ctrmgr/container_startup.py

+3
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ def container_up(feature, owner, version):
221221
debug_msg("args: feature={}, owner={}, version={} DB: set_owner={} state_data={}".format(
222222
feature, owner, version, set_owner, json.dumps(state_data, indent=4)))
223223

224+
if state_data[SYSTEM_STATE] == '':
225+
return
226+
224227
if owner == "local":
225228
update_state(state_db, feature, owner, version)
226229
else:

src/sonic-ctrmgrd/tests/container_startup_test.py

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
"set_owner": "local"
2424
}
2525
}
26+
},
27+
common_test.STATE_DB_NO: {
28+
common_test.FEATURE_TABLE: {
29+
"snmp": {
30+
"system_state": "up"
31+
}
32+
}
2633
}
2734
},
2835
common_test.POST: {

src/sonic-ctrmgrd/tests/container_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@
468468
class TestContainer(object):
469469

470470
def init(self):
471-
container.CTR_STATE_SCR_PATH = __file__
471+
container.CTRMGRD_SERVICE_PATH = __file__
472472
container.SONIC_CTR_CONFIG = (
473473
common_test.create_remote_ctr_config_json())
474474

0 commit comments

Comments
 (0)