Skip to content

Commit 6753a0f

Browse files
Use k8s http-proxy or not is associated with config, instead of build time flag.
1 parent 42f4b33 commit 6753a0f

File tree

7 files changed

+28
-50
lines changed

7 files changed

+28
-50
lines changed

Makefile.work

-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# * ENABLE_ZTP: Enables zero touch provisioning.
1111
# * SHUTDOWN_BGP_ON_START: Sets admin-down state for all bgp peerings after restart.
1212
# * INCLUDE_KUBERNETES: Allows including Kubernetes
13-
# * USE_K8S_AS_HTTP_PROXY: Use kubernetes master as proxy
1413
# * ENABLE_PFCWD_ON_START: Enable PFC Watchdog (PFCWD) on server-facing ports
1514
# * by default for TOR switch.
1615
# * ENABLE_SYNCD_RPC: Enables rpc-based syncd builds.
@@ -249,7 +248,6 @@ SONIC_BUILD_INSTRUCTION := make \
249248
ENABLE_ZTP=$(ENABLE_ZTP) \
250249
SHUTDOWN_BGP_ON_START=$(SHUTDOWN_BGP_ON_START) \
251250
INCLUDE_KUBERNETES=$(INCLUDE_KUBERNETES) \
252-
USE_K8S_AS_HTTP_PROXY=$(USE_K8S_AS_HTTP_PROXY) \
253251
KUBERNETES_VERSION=$(KUBERNETES_VERSION) \
254252
KUBERNETES_CNI_VERSION=$(KUBERNETES_CNI_VERSION) \
255253
K8s_GCR_IO_PAUSE_VERSION=$(K8s_GCR_IO_PAUSE_VERSION) \

build_debian.sh

+7-21
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,6 @@ fi
223223
# pip version of 'PyGObject' will be installed during installation of 'sonic-host-services'
224224
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y remove software-properties-common gnupg2 python3-gi
225225

226-
## Add docker config drop-in to specify dockerd command line
227-
sudo mkdir -p $FILESYSTEM_ROOT/etc/systemd/system/docker.service.d/
228-
## Note: $_ means last argument of last command
229-
sudo cp files/docker/*.conf $_
230-
## Fix systemd race between docker and containerd
231-
sudo sed -i '/After=/s/$/ containerd.service/' $FILESYSTEM_ROOT/lib/systemd/system/docker.service
232-
233226
if [ "$INCLUDE_KUBERNETES" == "y" ]
234227
then
235228
## Install Kubernetes
@@ -244,24 +237,17 @@ then
244237
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install kubelet=${KUBERNETES_VERSION}-00
245238
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install kubectl=${KUBERNETES_VERSION}-00
246239
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install kubeadm=${KUBERNETES_VERSION}-00
247-
# kubeadm package auto install kubelet & kubectl
248-
if [ "$USE_K8S_AS_HTTP_PROXY" == "y" ]
249-
then
250-
PROXY_INFO="http://172.16.1.1:3128/"
251-
cat <<EOT | sudo tee $FILESYSTEM_ROOT/etc/systemd/system/docker.service.d/http_proxy.conf > /dev/null
252-
[Service]
253-
Environment="HTTP_PROXY=${PROXY_INFO}"
254-
EOT
255-
cat <<EOT | sudo tee $FILESYSTEM_ROOT/etc/systemd/system/docker.service.d/https_proxy.conf > /dev/null
256-
[Service]
257-
Environment="HTTPS_PROXY=${PROXY_INFO}"
258-
EOT
259-
fi
260-
261240
else
262241
echo '[INFO] Skipping Install kubernetes'
263242
fi
264243

244+
## Add docker config drop-in to specify dockerd command line
245+
sudo mkdir -p $FILESYSTEM_ROOT/etc/systemd/system/docker.service.d/
246+
## Note: $_ means last argument of last command
247+
sudo cp files/docker/docker.service.conf $_
248+
## Fix systemd race between docker and containerd
249+
sudo sed -i '/After=/s/$/ containerd.service/' $FILESYSTEM_ROOT/lib/systemd/system/docker.service
250+
265251
## Create default user
266252
## Note: user should be in the group with the same name, and also in sudo/docker/redis groups
267253
sudo LANG=C chroot $FILESYSTEM_ROOT useradd -G sudo,docker $USERNAME -c "$DEFAULT_USERINFO" -m -s /bin/bash

files/build_templates/sonic_debian_extension.j2

+18-6
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,27 @@ sudo cp ${files_path}/container_startup.py ${FILESYSTEM_ROOT_USR_SHARE_SONIC_SCR
452452
sudo chmod a+x ${FILESYSTEM_ROOT_USR_SHARE_SONIC_SCRIPTS}/container_startup.py
453453

454454
# Config file used by container mgmt scripts/service
455-
{% if use_k8s_as_http_proxy == "y" %}
456455
fl="${files_path}/remote_ctr.config.json"
457-
python3 -c 'import json
456+
use_k8s_as_http_proxy=$(python3 -c 'import json
458457
with open("'${fl}'", "r") as s:
459-
d=json.load(s);d["use_k8s_as_http_proxy"] = "y"; print(json.dumps(d, indent=4))
460-
' | sudo tee ${FILESYSTEM_ROOT_ETC_SONIC}/remote_ctr.config.json
461-
{% else %}
458+
d=json.load(s);print(d.get("use_k8s_as_http_proxy", ""))
459+
'
460+
if [ "${use_k8s_as_http_proxy}" == "y" ]; then
461+
# create proxy files for docker using private IP which will
462+
# be later directed to k8s master upon config
463+
PROXY_INFO="http://172.16.1.1:3128/"
464+
cat <<EOT | sudo tee $FILESYSTEM_ROOT/etc/systemd/system/docker.service.d/http_proxy.conf > /dev/null
465+
[Service]
466+
Environment="HTTP_PROXY=${PROXY_INFO}"
467+
EOT
468+
cat <<EOT | sudo tee $FILESYSTEM_ROOT/etc/systemd/system/docker.service.d/https_proxy.conf > /dev/null
469+
[Service]
470+
Environment="HTTPS_PROXY=${PROXY_INFO}"
471+
EOT
472+
fi
473+
474+
endif
462475
sudo cp ${files_path}/remote_ctr.config.json ${FILESYSTEM_ROOT_ETC_SONIC}/
463-
{% endif %}
464476
465477
# Remote container management service files
466478
sudo cp ${files_path}/ctrmgrd.service ${FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM}/

rules/config

+2-7
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,6 @@ INCLUDE_NAT = y
147147
# run as worker node in kubernetes cluster.
148148
INCLUDE_KUBERNETES = n
149149

150-
# USE_K8S_AS_HTTP_PROXY - if set to y the Kubernetes server is used as
151-
# HTTP-proxy for docker daemon to reach registry repo.
152-
# This would be effective only when INCLUDE_KUBERNETES is set to "y"
153-
USE_K8S_AS_HTTP_PROXY = y
154-
155150
# INCLUDE_MACSEC - build docker-macsec for macsec support
156151
INCLUDE_MACSEC = y
157152

@@ -160,8 +155,8 @@ INCLUDE_MACSEC = y
160155
# These are Used *only* when INCLUDE_KUBERNETES=y
161156
# NOTE: As a worker node it has to run version compatible to kubernetes master.
162157
#
163-
KUBERNETES_VERSION = 1.18.6
164-
KUBERNETES_CNI_VERSION = 0.8.6
158+
KUBERNETES_VERSION = 1.21.1
159+
KUBERNETES_CNI_VERSION = 0.8.7
165160
K8s_GCR_IO_PAUSE_VERSION = 3.2
166161

167162
# SONIC_ENABLE_IMAGE_SIGNATURE - enable image signature

slave.mk

-4
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,6 @@ $(info "INCLUDE_RESTAPI" : "$(INCLUDE_RESTAPI)")
257257
$(info "INCLUDE_SFLOW" : "$(INCLUDE_SFLOW)")
258258
$(info "INCLUDE_NAT" : "$(INCLUDE_NAT)")
259259
$(info "INCLUDE_KUBERNETES" : "$(INCLUDE_KUBERNETES)")
260-
ifeq ($(INCLUDE_KUBERNETES),y)
261-
$(info "USE_K8S_AS_HTTP_PROXY" : "$(USE_K8S_AS_HTTP_PROXY)")
262-
endif
263260
$(info "INCLUDE_MACSEC" : "$(INCLUDE_MACSEC)")
264261
$(info "TELEMETRY_WRITABLE" : "$(TELEMETRY_WRITABLE)")
265262
$(info "PDDF_SUPPORT" : "$(PDDF_SUPPORT)")
@@ -921,7 +918,6 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
921918
export shutdown_bgp_on_start="$(SHUTDOWN_BGP_ON_START)"
922919
export default_buffer_model="$(SONIC_BUFFER_MODEL)"
923920
export include_kubernetes="$(INCLUDE_KUBERNETES)"
924-
export use_k8s_as_http_proxy="$(USE_K8S_AS_HTTP_PROXY)"
925921
export enable_pfcwd_on_start="$(ENABLE_PFCWD_ON_START)"
926922
export installer_debs="$(addprefix $(IMAGE_DISTRO_DEBS_PATH)/,$($*_INSTALLS))"
927923
export lazy_installer_debs="$(foreach deb, $($*_LAZY_INSTALLS),$(foreach device, $($(deb)_PLATFORM),$(addprefix $(device)@, $(IMAGE_DISTRO_DEBS_PATH)/$(deb))))"

src/sonic-ctrmgrd/ctrmgr/ctrmgrd.py

-9
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
KUBE_LABEL_SET_KEY = "SET"
5757

5858
remote_connected = False
59-
use_k8s_master_as_docker_proxy = False
6059

6160
dflt_cfg_ser = {
6261
CFG_SER_IP: "",
@@ -593,14 +592,6 @@ def update_node_labels(self):
593592

594593

595594
def main():
596-
global use_k8s_master_as_docker_proxy
597-
598-
parser = argparse.ArgumentParser(description="ctrmgrd service")
599-
parser.add_argument("-p", "--proxy", action='store_true',
600-
help="Act as docker http-proxy", default=False)
601-
args = parser.parse_args()
602-
use_k8s_master_as_docker_proxy = args.proxy
603-
604595
init()
605596
server = MainServer()
606597
RemoteServerHandler(server)

src/sonic-ctrmgrd/ctrmgr/remote_ctr.config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"retry_join_interval_seconds": 30,
44
"retry_labels_update_seconds": 5,
55
"revert_to_local_on_wait_seconds": 60,
6-
"use_k8s_as_http_proxy": "n"
6+
"use_k8s_as_http_proxy": "y"
77
}
88

0 commit comments

Comments
 (0)