浏览代码

Merge pull request #681 from mikedanese/patch

switch kube subnet manager to PATCH
Tom Denham 8 年之前
父节点
当前提交
01fb3254e0
共有 9 个文件被更改,包括 104 次插入30 次删除
  1. 2 0
      .gitignore
  2. 6 4
      Dockerfile.amd64
  3. 9 3
      Dockerfile.arm
  4. 7 5
      Dockerfile.arm64
  5. 7 5
      Dockerfile.ppc64le
  6. 14 0
      Dockerfile.s390x
  7. 6 1
      Documentation/kube-flannel-rbac.yml
  8. 26 11
      Makefile
  9. 27 1
      subnet/kube/kube.go

+ 2 - 0
.gitignore

@@ -2,6 +2,8 @@ dist/*.tar.gz
 dist/flanneld*
 dist/iptables-*
 dist/libpthread*
+dist/ld64*
+dist/libc*
 dist/*.aci
 dist/*.docker
 cover.out

+ 6 - 4
Dockerfile.amd64

@@ -1,10 +1,12 @@
-FROM busybox:1.25.0-glibc
+FROM frolvlad/alpine-glibc
 
 MAINTAINER Tom Denham <tom@tigera.io>
 
-COPY dist/flanneld-amd64 /opt/bin/flanneld
-COPY dist/iptables-amd64 /usr/local/bin/iptables
+ENV FLANNEL_ARCH=amd64
+
+COPY dist/flanneld-$FLANNEL_ARCH /opt/bin/flanneld
+COPY dist/iptables-$FLANNEL_ARCH /usr/local/bin/iptables
 COPY dist/mk-docker-opts.sh /opt/bin/
-COPY dist/libpthread.so.0-amd64 /lib/libpthread.so.0
+
 CMD ["/opt/bin/flanneld"]
 

+ 9 - 3
Dockerfile.arm

@@ -2,8 +2,14 @@ FROM armel/busybox:glibc
 
 MAINTAINER Tom Denham <tom@tigera.io>
 
-COPY dist/flanneld-arm /opt/bin/flanneld
-COPY dist/iptables-arm /usr/local/bin/iptables
+ENV FLANNEL_ARCH=arm
+
+COPY dist/flanneld-$FLANNEL_ARCH /opt/bin/flanneld
+COPY dist/iptables-$FLANNEL_ARCH /usr/local/bin/iptables
 COPY dist/mk-docker-opts.sh /opt/bin/
-COPY dist/libpthread.so.0-arm /lib/libpthread.so.0
+COPY dist/libpthread.so.0-$FLANNEL_ARCH /lib/libpthread.so.0
+COPY dist/ld64.so.1-$FLANNEL_ARCH /lib/ld64.so.1
+COPY dist/libc.so.6-$FLANNEL_ARCH /lib/libc.so.6
+
+
 CMD ["/opt/bin/flanneld"]

+ 7 - 5
Dockerfile.arm64

@@ -2,9 +2,11 @@ FROM aarch64/busybox:glibc
 
 MAINTAINER Tom Denham <tom@tigera.io>
 
-COPY dist/flanneld-arm64 /opt/bin/flanneld
-COPY dist/iptables-arm64 /usr/local/bin/iptables
-COPY dist/mk-docker-opts.sh /opt/bin/
-COPY dist/libpthread.so.0-arm64 /lib/libpthread.so.0
-CMD ["/opt/bin/flanneld"]
+ENV FLANNEL_ARCH=arm64
 
+COPY dist/flanneld-$FLANNEL_ARCH /opt/bin/flanneld
+COPY dist/iptables-$FLANNEL_ARCH /usr/local/bin/iptables
+COPY dist/mk-docker-opts.sh /opt/bin/
+COPY dist/libpthread.so.0-$FLANNEL_ARCH /lib/libpthread.so.0
+COPY dist/ld64.so.1-$FLANNEL_ARCH /lib/ld64.so.1
+COPY dist/libc.so.6-$FLANNEL_ARCH /lib/libc.so.6

+ 7 - 5
Dockerfile.ppc64le

@@ -2,9 +2,11 @@ FROM ppc64le/busybox:glibc
 
 MAINTAINER Tom Denham <tom@tigera.io>
 
-COPY dist/flanneld-ppc64le /opt/bin/flanneld
-COPY dist/iptables-ppc64le /usr/local/bin/iptables
-COPY dist/mk-docker-opts.sh /opt/bin/
-COPY dist/libpthread.so.0-ppc64le /lib/libpthread.so.0
-CMD ["/opt/bin/flanneld"]
+ENV FLANNEL_ARCH=ppc64le
 
+COPY dist/flanneld-$FLANNEL_ARCH /opt/bin/flanneld
+COPY dist/iptables-$FLANNEL_ARCH /usr/local/bin/iptables
+COPY dist/mk-docker-opts.sh /opt/bin/
+COPY dist/libpthread.so.0-$FLANNEL_ARCH /lib/libpthread.so.0
+COPY dist/ld64.so.1-$FLANNEL_ARCH /lib/ld64.so.1
+COPY dist/libc.so.6-$FLANNEL_ARCH /lib/libc.so.6

+ 14 - 0
Dockerfile.s390x

@@ -0,0 +1,14 @@
+FROM s390x/busybox:glibc
+
+MAINTAINER Tom Denham <tom@tigera.io>
+
+ENV FLANNEL_ARCH=s390x
+
+COPY dist/flanneld-$FLANNEL_ARCH /opt/bin/flanneld
+COPY dist/iptables-$FLANNEL_ARCH /usr/local/bin/iptables
+COPY dist/mk-docker-opts.sh /opt/bin/
+COPY dist/libpthread.so.0-$FLANNEL_ARCH /lib/libpthread.so.0
+COPY dist/ld64.so.1-$FLANNEL_ARCH /lib/ld64.so.1
+COPY dist/libc.so.6-$FLANNEL_ARCH /lib/libc.so.6
+
+CMD ["/opt/bin/flanneld"]

+ 6 - 1
Documentation/kube-flannel-rbac.yml

@@ -20,8 +20,13 @@ rules:
       - nodes
     verbs:
       - list
-      - update
       - watch
+  - apiGroups:
+      - ""
+    resources:
+      - nodes/status
+    verbs:
+      - patch
 ---
 kind: ClusterRoleBinding
 apiVersion: rbac.authorization.k8s.io/v1beta1

+ 26 - 11
Makefile

@@ -15,23 +15,30 @@ PACKAGES_EXPANDED=$(PACKAGES:%=github.com/coreos/flannel/%)
 
 # Set the (cross) compiler to use for different architectures
 ifeq ($(ARCH),amd64)
-	LIB_DIR=x86_64-linux-gnu
+	LIB_DIR=/lib/x86_64-linux-gnu
 	CC=gcc
 endif
 ifeq ($(ARCH),arm)
-	LIB_DIR=arm-linux-gnueabi
-	CC=arm-linux-gnueabi-gcc
+	LIB_DIR=/usr/arm-linux-gnueabihf/lib
+	CC=arm-linux-gnueabihf-gcc
 endif
 ifeq ($(ARCH),arm64)
-	LIB_DIR=aarch64-linux-gnu
+	LIB_DIR=/usr/aarch64-linux-gnu/lib
 	CC=aarch64-linux-gnu-gcc
 endif
 ifeq ($(ARCH),ppc64le)
-	LIB_DIR=powerpc64le-linux-gnu
+	LIB_DIR=/usr/powerpc64le-linux-gnu/lib
 	CC=powerpc64le-linux-gnu-gcc
 endif
-GOARM=6
-KUBE_CROSS_TAG=v1.6.2-2
+ifeq ($(ARCH),s390x)
+	LIB_DIR=s390x-linux-gnu
+	CC=s390x-linux-gnu-gcc
+endif
+
+GOARM=7
+
+# List images with gcloud alpha container images list-tags gcr.io/google_containers/kube-cross
+KUBE_CROSS_TAG=v1.7.5-3
 IPTABLES_VERSION=1.4.21
 
 dist/flanneld: $(shell find . -type f  -name '*.go')
@@ -97,7 +104,7 @@ endif
 ## Build an architecture specific flanneld binary
 dist/flanneld-$(ARCH):
 	# Build for other platforms with 'ARCH=$$ARCH make dist/flanneld-$$ARCH'
-	# valid values for $$ARCH are [amd64 arm arm64 ppc64le]
+	# valid values for $$ARCH are [amd64 arm arm64 ppc64le s390x]
 	docker run -e CC=$(CC) -e GOARM=$(GOARM) -e GOARCH=$(ARCH) \
 		-u $(shell id -u):$(shell id -g) \
 	    -v $(CURDIR):/go/src/github.com/coreos/flannel:ro \
@@ -108,9 +115,11 @@ dist/flanneld-$(ARCH):
 		mv dist/flanneld dist/flanneld-$(ARCH) && \
 		file dist/flanneld-$(ARCH)'
 
-## Busybox images are missing pthread. Pull it out of the kube-cross image
-dist/libpthread.so.0-$(ARCH):
-	docker run --rm -v `pwd`:/host gcr.io/google_containers/kube-cross:$(KUBE_CROSS_TAG) cp /lib/$(LIB_DIR)/libpthread.so.0 /host/dist/libpthread.so.0-$(ARCH)
+## Busybox images need updated libs. Pull them out of the kube-cross image
+dist/libpthread.so.0-$(ARCH) dist/libc.so.6-$(ARCH) dist/ld64.so.1-$(ARCH):
+	docker run --rm -v $(CURDIR):/host gcr.io/google_containers/kube-cross:$(KUBE_CROSS_TAG) cp $(LIB_DIR)/libc-2.23.so /host/dist/libc.so.6-$(ARCH)
+	docker run --rm -v $(CURDIR):/host gcr.io/google_containers/kube-cross:$(KUBE_CROSS_TAG) cp $(LIB_DIR)/ld-2.23.so /host/dist/ld64.so.1-$(ARCH)
+	docker run --rm -v $(CURDIR):/host gcr.io/google_containers/kube-cross:$(KUBE_CROSS_TAG) cp $(LIB_DIR)/libpthread.so.0 /host/dist/libpthread.so.0-$(ARCH)
 
 ## Build an architecture specific iptables binary
 dist/iptables-$(ARCH):
@@ -148,6 +157,9 @@ tar.gz:
 	ARCH=arm64 make dist/flanneld-arm64
 	tar --transform='flags=r;s|-arm64||' -zcvf dist/flannel-$(TAG)-linux-arm64.tar.gz -C dist flanneld-arm64 mk-docker-opts.sh ../README.md
 	tar -tvf dist/flannel-$(TAG)-linux-arm64.tar.gz
+	ARCH=s390x make dist/flanneld-s390x
+	tar --transform='flags=r;s|-s390x||' -zcvf dist/flannel-$(TAG)-linux-s390x.tar.gz -C dist flanneld-s390x mk-docker-opts.sh ../README.md
+	tar -tvf dist/flannel-$(TAG)-linux-s390x.tar.gz
 
 ## Make a release after creating a tag
 release: tar.gz
@@ -155,6 +167,7 @@ release: tar.gz
 	ARCH=arm make dist/flanneld-$(TAG)-arm.aci
 	ARCH=arm64 make dist/flanneld-$(TAG)-arm64.aci
 	ARCH=ppc64le make dist/flanneld-$(TAG)-ppc64le.aci
+	ARCH=s390x make dist/flanneld-$(TAG)-s390x.aci
 	@echo "Everything should be built for $(TAG)"
 	@echo "Add all *.aci, flanneld-* and *.tar.gz files from dist/ to the Github release"
 	@echo "Use make docker-push-all to push the images to a registry"
@@ -164,6 +177,7 @@ docker-push-all:
 	ARCH=arm make docker-push
 	ARCH=arm64 make docker-push
 	ARCH=ppc64le make docker-push
+	ARCH=s390x make docker-push
 
 flannel-git:
 	ARCH=amd64 REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-amd64.docker docker-push
@@ -172,3 +186,4 @@ flannel-git:
 	ARCH=arm REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-arm.docker docker-push
 	ARCH=arm64 REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-arm64.docker docker-push
 	ARCH=ppc64le REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-ppc64le.docker docker-push
+	ARCH=s390x REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-s390x.docker docker-push

+ 27 - 1
subnet/kube/kube.go

@@ -29,12 +29,14 @@ import (
 	"github.com/golang/glog"
 	"golang.org/x/net/context"
 	"k8s.io/kubernetes/pkg/api"
+	"k8s.io/kubernetes/pkg/api/v1"
 	"k8s.io/kubernetes/pkg/client/cache"
 	clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
 	"k8s.io/kubernetes/pkg/client/restclient"
 	"k8s.io/kubernetes/pkg/controller/framework"
 	"k8s.io/kubernetes/pkg/runtime"
 	utilruntime "k8s.io/kubernetes/pkg/util/runtime"
+	"k8s.io/kubernetes/pkg/util/strategicpatch"
 	"k8s.io/kubernetes/pkg/util/wait"
 	"k8s.io/kubernetes/pkg/watch"
 )
@@ -231,7 +233,31 @@ func (ksm *kubeSubnetManager) AcquireLease(ctx context.Context, network string,
 		n.Annotations[backendDataAnnotation] = string(bd)
 		n.Annotations[backendPublicIPAnnotation] = attrs.PublicIP.String()
 		n.Annotations[subnetKubeManagedAnnotation] = "true"
-		n, err = ksm.client.Core().Nodes().Update(n)
+
+		var oldNode, newNode v1.Node
+		if err := api.Scheme.Convert(cacheNode, &oldNode, nil); err != nil {
+			return nil, err
+		}
+		if err := api.Scheme.Convert(n, &newNode, nil); err != nil {
+			return nil, err
+		}
+
+		oldData, err := json.Marshal(oldNode)
+		if err != nil {
+			return nil, err
+		}
+
+		newData, err := json.Marshal(newNode)
+		if err != nil {
+			return nil, err
+		}
+
+		patchBytes, err := strategicpatch.CreateTwoWayMergePatch(oldData, newData, v1.Node{})
+		if err != nil {
+			return nil, fmt.Errorf("failed to create patch for node %q: %v", ksm.nodeName, err)
+		}
+
+		_, err = ksm.client.Core().Nodes().Patch(ksm.nodeName, api.StrategicMergePatchType, patchBytes, "status")
 		if err != nil {
 			return nil, err
 		}