Skip to content

Commit

Permalink
Merge pull request #681 from mikedanese/patch
Browse files Browse the repository at this point in the history
switch kube subnet manager to PATCH
  • Loading branch information
tomdee authored Apr 18, 2017
2 parents 142bb9c + bc1fcc6 commit 01fb325
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ dist/*.tar.gz
dist/flanneld*
dist/iptables-*
dist/libpthread*
dist/ld64*
dist/libc*
dist/*.aci
dist/*.docker
cover.out
Expand Down
10 changes: 6 additions & 4 deletions Dockerfile.amd64
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FROM busybox:1.25.0-glibc
FROM frolvlad/alpine-glibc

MAINTAINER Tom Denham <[email protected]>

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"]

12 changes: 9 additions & 3 deletions Dockerfile.arm
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ FROM armel/busybox:glibc

MAINTAINER Tom Denham <[email protected]>

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"]
12 changes: 7 additions & 5 deletions Dockerfile.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ FROM aarch64/busybox:glibc

MAINTAINER Tom Denham <[email protected]>

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
12 changes: 7 additions & 5 deletions Dockerfile.ppc64le
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ FROM ppc64le/busybox:glibc

MAINTAINER Tom Denham <[email protected]>

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 changes: 14 additions & 0 deletions Dockerfile.s390x
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM s390x/busybox:glibc

MAINTAINER Tom Denham <[email protected]>

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"]
7 changes: 6 additions & 1 deletion Documentation/kube-flannel-rbac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ rules:
- nodes
verbs:
- list
- update
- watch
- apiGroups:
- ""
resources:
- nodes/status
verbs:
- patch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
Expand Down
37 changes: 26 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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 \
Expand All @@ -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):
Expand Down Expand Up @@ -148,13 +157,17 @@ 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
ARCH=amd64 make dist/flanneld-$(TAG)-amd64.aci
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"
Expand All @@ -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
Expand All @@ -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
28 changes: 27 additions & 1 deletion subnet/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 01fb325

Please sign in to comment.