Add Userspace CNI build-and-run support files. 01/72801/2
authorSridhar K. N. Rao <sridhar.rao@spirent.com>
Wed, 4 Aug 2021 12:27:09 +0000 (17:57 +0530)
committerSridhar K. N. Rao <sridhar.rao@spirent.com>
Tue, 10 Aug 2021 07:42:59 +0000 (13:12 +0530)
remove unnecessary spaces

Signed-off-by: Sridhar K. N. Rao <sridhar.rao@spirent.com>
Change-Id: Icfc1dda8a29e896802f8030c5848cc00b4c99389

tools/k8s/cluster-deployment/uscni/Dockerfile [new file with mode: 0644]
tools/k8s/cluster-deployment/uscni/entrypoint.sh [new file with mode: 0755]
tools/k8s/cluster-deployment/uscni/userspace-cni-daemonset.yml [new file with mode: 0644]

diff --git a/tools/k8s/cluster-deployment/uscni/Dockerfile b/tools/k8s/cluster-deployment/uscni/Dockerfile
new file mode 100644 (file)
index 0000000..ddfa367
--- /dev/null
@@ -0,0 +1,25 @@
+# docker build --rm -t uscni
+FROM centos:7
+SHELL ["/bin/bash", "-o", "pipefail", "-c"]
+RUN yum install -y epel-release wget; yum clean all
+RUN wget --no-check-certificate https://golang.org/dl/go1.16.6.linux-amd64.tar.gz
+RUN tar -C /usr/local -xzf go1.16.6.linux-amd64.tar.gz
+ENV PATH /usr/local/go/bin:$PATH
+RUN yum install -y git make sudo; yum clean all
+ENV GOPATH /root/go
+RUN mkdir -p "/root/go" "$GOPATH/bin" "$GOPATH/src" "$GOPATH/src" && chmod -R 777 "$GOPATH"
+WORKDIR /root/go/src/
+ENV GO111MODULE off
+RUN go get github.com/intel/userspace-cni-network-plugin > /tmp/UserspaceDockerBuild.log 2>&1 || echo "Can ignore no GO files."
+WORKDIR /root/go/src/github.com/intel/userspace-cni-network-plugin
+ENV GO111MODULE on
+ENV GOROOT /usr/local/go
+ENV GOPATH /root/go
+RUN make clean && make install-dep && make install && make
+RUN cp userspace/userspace /usr/bin/userspace
+
+FROM alpine:latest
+COPY --from=0 /usr/bin/userspace /userspace
+
+ADD entrypoint.sh /
+ENTRYPOINT ["/entrypoint.sh"]
diff --git a/tools/k8s/cluster-deployment/uscni/entrypoint.sh b/tools/k8s/cluster-deployment/uscni/entrypoint.sh
new file mode 100755 (executable)
index 0000000..0658f15
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+# Always exit on errors.
+set -e
+
+# Check if /opt/cni/bin directory exists
+if [ ! -d "/host/opt/cni/bin" ]
+then
+    echo "Directory /opt/cni/bin/ does not exists."
+    exit 1;
+fi
+
+# Copy cni-plugin on host machine
+cp -f /userspace /host/opt/cni/bin/
+
+# Sleep for 50 years.
+# sleep infinity is not available in alpine;
+sleep 2147483647
diff --git a/tools/k8s/cluster-deployment/uscni/userspace-cni-daemonset.yml b/tools/k8s/cluster-deployment/uscni/userspace-cni-daemonset.yml
new file mode 100644 (file)
index 0000000..d598fc6
--- /dev/null
@@ -0,0 +1,45 @@
+apiVersion: apps/v1
+kind: DaemonSet
+metadata:
+  name: userspace-cni-amd64
+  namespace: kube-system
+  labels:
+    tier: node
+    app: userspace-cni
+spec:
+  selector:
+    matchLabels:
+      app: userspace-cni
+  template:
+    metadata:
+      labels:
+        tier: node
+        app: userspace-cni
+    spec:
+      hostNetwork: true
+      nodeSelector:
+        beta.kubernetes.io/arch: amd64
+      tolerations:
+      - key: node-role.kubernetes.io/master
+        operator: Exists
+        effect: NoSchedule
+      containers:
+      - name: userspace-cni-plugin
+        image: uscni:latest
+        imagePullPolicy: Never
+        resources:
+          requests:
+            cpu: "100m"
+            memory: "50Mi"
+          limits:
+            cpu: "100m"
+            memory: "50Mi"
+        securityContext:
+          privileged: true
+        volumeMounts:
+        - name: cnibin
+          mountPath: /host/opt/cni/bin
+      volumes:
+        - name: cnibin
+          hostPath:
+            path: /opt/cni/bin