From ed5a278d8b37e2c81fe30e0391971b884bb9a99b Mon Sep 17 00:00:00 2001 From: ideameshdyx Date: Sun, 26 Nov 2023 17:55:02 +0800 Subject: [PATCH] Add init cni process Signed-off-by: ideameshdyx --- Makefile | 6 +++-- build/agent/Dockerfile | 4 ++++ build/agent/init-cni.sh | 32 +++++++++++++++++++++++++ build/agent/resources/05-daemonset.yaml | 14 +++++++++++ hack/lib/golang.sh | 1 + 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 build/agent/init-cni.sh diff --git a/Makefile b/Makefile index 3254bad22..7d554fa2f 100644 --- a/Makefile +++ b/Makefile @@ -21,13 +21,15 @@ GO_LDFLAGS='$(shell hack/make-rules/version.sh)' # make all builds both agent and server binaries BINARIES=edgemesh-agent \ - edgemesh-gateway + edgemesh-gateway \ + edgemesh-cni # the env PLATFORMS defines to generate linux images for amd 64-bit, arm 64-bit and armv7 architectures # the full list of PLATFORMS is linux/amd64,linux/arm64,linux/arm/v7 PLATFORMS ?= linux/amd64,linux/arm64,linux/arm/v7 COMPONENTS=agent \ - gateway + gateway \ + cni .EXPORT_ALL_VARIABLES: OUT_DIR ?= _output/local diff --git a/build/agent/Dockerfile b/build/agent/Dockerfile index 554ec982a..5d3bd477e 100644 --- a/build/agent/Dockerfile +++ b/build/agent/Dockerfile @@ -14,6 +14,7 @@ FROM alpine:3.11 RUN apk update && apk --no-cache add iptables && apk --no-cache add dpkg COPY --from=builder /code/_output/local/bin/edgemesh-agent /usr/local/bin/edgemesh-agent +COPY --from=builder /code/_output/local/bin/edgemesh-cni /usr/local/bin/edgemesh-cni # Add support for auto-detection of iptables mode COPY --from=builder /code/build/agent/iptables-wrapper /sbin/iptables-wrapper @@ -23,4 +24,7 @@ RUN update-alternatives --install /sbin/iptables iptables /sbin/iptables-wrapper --slave /sbin/iptables-restore iptables-restore /sbin/iptables-wrapper \ --slave /sbin/iptables-save iptables-save /sbin/iptables-wrapper +# Copy cni cfg +COPY --from=builder /code/build/agent/init-cni /usr/local/init-cni + ENTRYPOINT ["edgemesh-agent"] diff --git a/build/agent/init-cni.sh b/build/agent/init-cni.sh new file mode 100644 index 000000000..b93ab740f --- /dev/null +++ b/build/agent/init-cni.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +# check if edgecore is installed +if pgrep "edgecore" >/dev/null; then + echo "Edgecore process is running. Continuing with the initialization steps." + + # copy cni to host + cp -f /usr/local/bin/edgemesh-cni /opt/cni/bin/egdemesh-cni + + # generate 10-edgemesh-cni.conflist under /etc/edgemesh/config/ + cat < /etc/edgemesh/config/10-edgemesh-cni.conflist +{ + "cniVersion": "0.0.1", + "name": "edgemesh", + "type": "edgemesh", + "delegate": { + "cniVersion": "0.0.1", + "type":"bridge", + "ipam": { + "type":"spiderpool" + } + } +} +EOF + + # cpoy it to /etc/cni/net.d + cp -f /etc/edgemesh/config/10-edgemesh-cni.conflist /etc/cni/net.d/ + +else + echo "Edgecore process is not running. Exiting." + exit 1 +fi \ No newline at end of file diff --git a/build/agent/resources/05-daemonset.yaml b/build/agent/resources/05-daemonset.yaml index 966fb41e5..97604aa2f 100644 --- a/build/agent/resources/05-daemonset.yaml +++ b/build/agent/resources/05-daemonset.yaml @@ -18,6 +18,20 @@ spec: kubeedge: edgemesh-agent spec: hostNetwork: true + initContainers: + - name: install-edgemesh-cni + image: kubeedge/edgemesh-agent:v1.14.0 + command: + - sh + - -c + - /usr/local/init-cni.sh + volumeMounts: + - name: cni-plugin + mountPath: /opt/cni/bin + - name: cni-cfg + mountPath: /etc/cni/net.d + - name: edgemesh-cfg + mountPath: /etc/edgemesh/ containers: - name: edgemesh-agent securityContext: diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh index 9645238da..28ef038c3 100755 --- a/hack/lib/golang.sh +++ b/hack/lib/golang.sh @@ -154,6 +154,7 @@ edgemesh::check::env() { ALL_BINARIES_AND_TARGETS=( edgemesh-agent:cmd/edgemesh-agent edgemesh-gateway:cmd/edgemesh-gateway + edgemesh-cni:cmd/edgemesh-cni ) edgemesh::golang::get_target_by_binary() {