diff --git a/.travis.yml b/.travis.yml index 19bfac48..eaabeee0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,13 +4,17 @@ services: - docker go: - 1.8.x -before_install: +before_install: + - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - + - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" + - sudo apt-get update + - sudo apt-get -y install docker-ce + install: - make release script: - echo "test skip" -before_deploy: -- make install + deploy: provider: releases api_key: diff --git a/Dockerfile b/Dockerfile index fd9a84ab..1ec40f89 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,35 @@ +FROM alpine:edge AS build +RUN apk update +RUN apk upgrade +RUN apk add go gcc g++ make git linux-headers +WORKDIR /app +ENV GOPATH /app +ADD . /app/src/github.com/yunify/hostnic-cni +RUN cd /app/src/github.com/yunify/hostnic-cni && rm -rf bin/ && make go-build + FROM alpine:latest MAINTAINER martinyunify -ADD daemon / +COPY --from=build /app/src/github.com/yunify/hostnic-cni/bin/daemon /bin/daemon + +EXPOSE 31080 31081 + +ENV LOGLEVEL info + +ENV VXNETS vxnet-xxxxxxx + +ENV POOLSIZE 3 + +ENV CLEANUPCACHEONEXIT false + +RUN mkdir -p /opt/cni/bin/ && mkdir -p /etc/cni/net.d/ + +VOLUME /etc/qingcloud/ + +VOLUME /etc/cni/net.d/ +COPY --from=build /app/src/github.com/yunify/hostnic-cni/bin/hostnic /opt/cni/bin/hostnic +ENTRYPOINT ["/bin/daemon"] -ENTRYPOINT ["/daemon"] \ No newline at end of file +CMD ["start"] \ No newline at end of file diff --git a/Makefile b/Makefile index ec050c50..99836f84 100644 --- a/Makefile +++ b/Makefile @@ -79,14 +79,14 @@ bin/hostnic.tar.gz : bin/hostnic bin/daemon : $(foreach dir,$(daemon_pkg),$(wildcard $(dir)/*.go)) go build -o bin/daemon $(GO_BUILD_FLAGS) $(GIT_REPOSITORY)/cmd/daemon/ -bin/.docker-images-build-timestamp : bin/daemon - cp -u Dockerfile bin - docker build -q -t $(DOCKER_IMAGE_NAME):$(BUILD_LABEL) bin/ > bin/.docker-images-build-timestamp +bin/.docker-images-build-timestamp : $(foreach dir,$(daemon_pkg),$(wildcard $(dir)/*.go)) Dockerfile + docker build -q -t $(DOCKER_IMAGE_NAME):$(BUILD_LABEL) -t $(DOCKER_IMAGE_NAME):latest . > bin/.docker-images-build-timestamp release : test bin/hostnic.tar.gz bin/.docker-images-build-timestamp install : release docker push $(DOCKER_IMAGE_NAME):$(BUILD_LABEL) + docker push $(DOCKER_IMAGE_NAME):latest clean : docker rmi `cat bin/.docker-images-build-timestamp` diff --git a/generate_version.sh b/generate_version.sh index 813ddd21..f565c93d 100755 --- a/generate_version.sh +++ b/generate_version.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Define the project string to be used PROJECT=hostnic-cni diff --git a/kube-hostnic.yaml b/kube-hostnic.yaml new file mode 100644 index 00000000..bc6f25ce --- /dev/null +++ b/kube-hostnic.yaml @@ -0,0 +1,119 @@ +kind: ClusterRole +apiVersion: rbac.authorization.k8s.io/v1beta1 +metadata: + name: hostnic +rules: + - apiGroups: + - "" + resources: + - pods + verbs: + - get + - apiGroups: + - "" + resources: + - nodes + verbs: + - list + - watch + - apiGroups: + - "" + resources: + - nodes/status + verbs: + - patch +--- +kind: ClusterRoleBinding +apiVersion: rbac.authorization.k8s.io/v1beta1 +metadata: + name: hostnic +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: hostnic +subjects: +- kind: ServiceAccount + name: hostnic + namespace: kube-system +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: hostnic + namespace: kube-system +--- +kind: ConfigMap +apiVersion: v1 +metadata: + name: kube-hostnic-cni-cfg + namespace: kube-system + labels: + tier: node + app: hostnic +data: + 10-hostnic.conf: | + { + "cniVersion": "0.3.1", + "name": "hostnic", + "type": "hostnic", + "bindaddr":"localhost:31080", + "ipam":{ + "routes":[{"dst":"10.96.0.0/24","gw":"0.0.0.0"}] + }, + "isGateway": true + } +--- +apiVersion: extensions/v1beta1 +kind: DaemonSet +metadata: + name: kube-qingcloud-hostnic + namespace: kube-system + labels: + tier: node + app: kube-qingcloud-hostnic +spec: + template: + metadata: + labels: + tier: node + app: kube-qingcloud-hostnic + spec: + hostNetwork: true + nodeSelector: + beta.kubernetes.io/arch: amd64 + tolerations: + - key: node-role.kubernetes.io/master + operator: Exists + effect: NoSchedule + serviceAccountName: hostnic + containers: + - name: kube-qingcloud-hostnic + image: dockerhub.qingcloud.com/qingcloud/hostnic-cni:hostnic-cni-v0.8-1-g89dae0f + command: [ "start" ] + securityContext: + privileged: true + env: + - name: LOGLEVEL + value: "info" + + - name: VXNETS + value: "vxnet-2xj9lrp,vxnet-h00g66q" + + - name: POOLSIZE + value: "3" + + volumeMounts: + - name: hostnic-cfg + mountPath: /etc/cni/ + + - name: qingcloud-cfg + mountPath: /etc/qingcloud/ + + volumes: + - name: hostnic-cfg + configMap: + name: kube-hostnic-cni-cfg + + - name: qingcloud-cfg + hostPath: + path: /etc/qingcloud/