Skip to content

Commit

Permalink
Add init cni process
Browse files Browse the repository at this point in the history
Signed-off-by: ideameshdyx <[email protected]>
  • Loading branch information
IdeaMeshDyx committed Nov 26, 2023
1 parent 041fca8 commit ed5a278
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions build/agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
32 changes: 32 additions & 0 deletions build/agent/init-cni.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF > /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
14 changes: 14 additions & 0 deletions build/agent/resources/05-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions hack/lib/golang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit ed5a278

Please sign in to comment.