diff --git a/Makefile b/Makefile index 2795d807..40b22963 100644 --- a/Makefile +++ b/Makefile @@ -5,26 +5,40 @@ IMAGE_BUILDER?=docker IMAGE_NAME?=$(IMAGE_REGISTRY)userspacecni:$(IMAGE_VERSION) default: build -all: build deploy - +local: build copy +all: build push deploy help: @echo "Make Targets:" @echo "make build - Build UserSpace CNI container." - @echo "make deploy - Copy binary from container to host: /opt/cni/bin." - @echo "make all - build and deploy" + @echo "make copy - Copy binary from container to host:/opt/cni/bin." + @echo "make local - build and copy" + @echo "make deploy - kubectl apply daemonset" + @echo "make undeploy - kubectl delete daemonset" + @echo "make all - build push and deploy to kubernetes" build: @$(IMAGE_BUILDER) build . -f ./docker/userspacecni/Dockerfile -t $(IMAGE_NAME) -deploy: +push: + @$(IMAGE_BUILDER) push $(IMAGE_NAME) + +copy: # Copying the ovs binary to host /opt/cni/bin/ @mkdir -p /opt/cni/bin/ @$(IMAGE_BUILDER) run -it --rm -v /opt/cni/bin/:/opt/cni/bin/ $(IMAGE_NAME) generate-bin: generate + # Used in dockerfile @cd userspace && go build -v generate: - for package in cnivpp/api/* ; do cd $$package ; pwd ; go generate ; cd - ; done + # Used in dockerfile + @for package in cnivpp/api/* ; do cd $$package ; pwd ; go generate ; cd - ; done + +deploy: + # Use sed to replace image name and then apply deployment file + @sed "s|\(image:\).*\(#registory\)|\1 $(IMAGE_NAME) \2|g" ./kubernetes/userspace-daemonset.yml |kubectl apply -f - +undeploy: + kubectl delete -f ./kubernetes/userspace-daemonset.yml diff --git a/kubernetes/userspace-daemonset.yml b/kubernetes/userspace-daemonset.yml new file mode 100644 index 00000000..be6ea98e --- /dev/null +++ b/kubernetes/userspace-daemonset.yml @@ -0,0 +1,28 @@ +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: userspace-cni + namespace: kube-system +spec: + selector: + matchLabels: + app: userspace-cni + template: + metadata: + labels: + app: userspace-cni + spec: + containers: + - name: userspace-cni-plugin + image: localhost:5000/userspacecni #registory:imagename + imagePullPolicy: IfNotPresent + volumeMounts: + - name: cnibin + mountPath: /opt/cni/bin + command: ["/bin/sh","-c"] + args: ["cp -rf /root/userspace-cni-network-plugin/userspace/userspace /opt/cni/bin; sleep inf"] + volumes: + - name: cnibin + hostPath: + path: /opt/cni/bin