diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 8cbb29fbc7..f7a0846922 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -26,18 +26,6 @@ jobs: - name: go mod vendor run: go mod vendor - - name: build linux - run: | - set -e - for arch in ${LINUX_ARCHES}; do - echo "Building for arch $arch" - ARCH=$arch make dist/flanneld-$arch - file dist/flanneld-$arch - done - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -50,8 +38,7 @@ jobs: tags: | type=ref, event=branch - - name: Build and push Docker image - # if: github.repository_owner == 'flannel-io' && success() + - name: Build multi-arch Docker image uses: docker/build-push-action@v5 with: context: . @@ -60,3 +47,8 @@ jobs: platforms: linux/amd64,linux/arm64,linux/arm,linux/s390x,linux/ppc64le,linux/riscv64 tags: ${{ steps.meta.outputs.tags }} build-args: TAG=${{ env.GIT_TAG }} + + - name: build for windows + run: make dist/flanneld.exe + + \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 50f9a59e92..ee400a70ba 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -31,15 +31,6 @@ jobs: - name: go mod vendor run: go mod vendor - - name: build linux - run: | - set -e - for arch in ${LINUX_ARCHES}; do - echo "Building for arch $arch" - ARCH=$arch make dist/flanneld-$arch - file dist/flanneld-$arch - done - - name: Set up QEMU uses: docker/setup-qemu-action@v3 diff --git a/.gitignore b/.gitignore index afff66fc6a..9fca9aa772 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ dist/*.tar.gz dist/flanneld* dist/*.docker dist/here.txt +dist/flannel_oci.tar cover.out .editorconfig .idea/ diff --git a/Documentation/building.md b/Documentation/building.md index 6b2060222f..cd584f55d0 100644 --- a/Documentation/building.md +++ b/Documentation/building.md @@ -19,6 +19,22 @@ If you want to cross-compile for a different platform (e.g. you're running `amd6 Then you should be able to set the ARCH as above * ARCH=arm make image +## Building a multi-arch image + +To build the multi-arch image of flannel locally, you need to install [Docker buildx](https://github.com/docker/buildx). +Then you can use the following target: +``` +make build-multi-arch +``` + +If you don't already have a builder running locally, you can this target to start it: +``` +make buildx-create-builder +``` + +See the [buildx documentation](https://docs.docker.com/reference/cli/docker/buildx/) for more details. + + ## Building manually 1. Make sure you have required dependencies installed on your machine. diff --git a/Makefile b/Makefile index 19f6135132..fe9cb19d21 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: test e2e-test deps cover gofmt gofmt-fix license-check clean tar.gz docker-push release docker-push-all flannel-git docker-manifest-amend docker-manifest-push +.PHONY: test e2e-test deps cover gofmt gofmt-fix license-check clean tar.gz release buildx-create-builder build-multi-arch # Registry used for publishing images REGISTRY?=quay.io/coreos/flannel @@ -58,9 +58,9 @@ dist/flanneld-$(ARCH): deps dist/qemu-$(ARCH)-static mv dist/flanneld dist/flanneld-$(ARCH)' ## Create a docker image on disk for a specific arch and tag -image: dist/flanneld-$(TAG)-$(ARCH).docker -dist/flanneld-$(TAG)-$(ARCH).docker: dist/flanneld-$(ARCH) - docker build -f images/Dockerfile --platform=$(ARCH) --build-arg TAG=$(TAG) -t $(REGISTRY):$(TAG)-$(ARCH) . +image: deps dist/flanneld-$(TAG)-$(ARCH).docker +dist/flanneld-$(TAG)-$(ARCH).docker: + docker buildx build -f images/Dockerfile --platform=$(ARCH) --build-arg TAG=$(TAG) -t $(REGISTRY):$(TAG)-$(ARCH) --load . docker save -o dist/flanneld-$(TAG)-$(ARCH).docker $(REGISTRY):$(TAG)-$(ARCH) # amd64 gets an image without the suffix too (i.e. it's the default) @@ -126,14 +126,6 @@ verify-modules: !go mod tidy 2>&1|read && \ !go vet 2>&1|read' -gofmt-fix: - docker run --rm -e CGO_ENABLED=$(CGO_ENABLED) -e GOARCH=$(ARCH) \ - -u $(shell id -u):$(shell id -g) \ - -v $(CURDIR):/go/src/github.com/flannel-io/flannel \ - -v $(CURDIR)/dist:/go/src/github.com/flannel-io/flannel/dist \ - golang:$(GO_VERSION) /bin/bash -c '\ - cd /go/src/github.com/flannel-io/flannel && \ - gofmt -w $(PACKAGES)' bash_unit: wget https://raw.githubusercontent.com/pgrange/bash_unit/v2.0.1/bash_unit @@ -157,7 +149,7 @@ endif # Make a release after creating a tag # To build cross platform Docker images, the qemu-static binaries are needed. On ubuntu "apt-get install qemu-user-static" -release: tar.gz dist/qemu-s390x-static dist/qemu-ppc64le-static dist/qemu-arm64-static dist/qemu-arm-static dist/qemu-riscv64-static release-chart release-helm #release-tests +release: tar.gz dist/qemu-s390x-static dist/qemu-ppc64le-static dist/qemu-arm64-static dist/qemu-arm-static dist/qemu-riscv64-static release-chart release-helm ARCH=amd64 make dist/flanneld-$(TAG)-amd64.docker ARCH=arm make dist/flanneld-$(TAG)-arm.docker ARCH=arm64 make dist/flanneld-$(TAG)-arm64.docker @@ -215,108 +207,18 @@ tar.gz: tar --transform='flags=r;s|-riscv64||' -zcvf dist/flannel-$(TAG)-linux-riscv64.tar.gz -C dist flanneld-riscv64 mk-docker-opts.sh ../README.md tar -tvf dist/flannel-$(TAG)-linux-riscv64.tar.gz -release-tests: release-etcd-tests release-k8s-tests - -release-etcd-tests: bash_unit - # Run the functional tests with different etcd versions. - ETCD_IMG="quay.io/coreos/etcd:latest" ./bash_unit dist/functional-test.sh - ETCD_IMG="quay.io/coreos/etcd:v3.2.7" ./bash_unit dist/functional-test.sh - # Etcd v2 docker image format is different. Override the etcd binary location so it works. - ETCD_IMG="quay.io/coreos/etcd:v2.3.8" ETCD_LOCATION=" " ./bash_unit dist/functional-test.sh - -release-k8s-tests: bash_unit - # Run the functional tests with different k8s versions. Currently these are the latest point releases. - # This list should be updated during the release process. - K8S_VERSION="1.25.2" HYPERKUBE_CMD=" " HYPERKUBE_APISERVER_CMD="kube-apiserver" ./bash_unit dist/functional-test-k8s.sh - K8S_VERSION="1.24.6" HYPERKUBE_CMD=" " HYPERKUBE_APISERVER_CMD="kube-apiserver" ./bash_unit dist/functional-test-k8s.sh - K8S_VERSION="1.23.12" HYPERKUBE_CMD=" " HYPERKUBE_APISERVER_CMD="kube-apiserver" ./bash_unit dist/functional-test-k8s.sh - K8S_VERSION="1.22.15" HYPERKUBE_CMD=" " HYPERKUBE_APISERVER_CMD="kube-apiserver" ./bash_unit dist/functional-test-k8s.sh - K8S_VERSION="1.17.3" HYPERKUBE_CMD=" " HYPERKUBE_APISERVER_CMD="kube-apiserver" ./bash_unit dist/functional-test-k8s.sh - -docker-push: dist/flanneld-$(TAG)-$(ARCH).docker - docker push $(REGISTRY):$(TAG)-$(ARCH) - -docker-manifest-amend: - DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create --amend $(REGISTRY):$(TAG) $(REGISTRY):$(TAG)-$(ARCH) - -docker-manifest-push: - DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push --purge $(REGISTRY):$(TAG) - -docker-push-all: - ARCH=amd64 make docker-push docker-manifest-amend - ARCH=arm make docker-push docker-manifest-amend - ARCH=arm64 make docker-push docker-manifest-amend - ARCH=ppc64le make docker-push docker-manifest-amend - ARCH=s390x make docker-push docker-manifest-amend - ARCH=riscv64 make docker-push docker-manifest-amend - make docker-manifest-push - -flannel-git: - ARCH=amd64 REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-amd64.docker docker-push docker-manifest-amend - ARCH=arm REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-arm.docker docker-push docker-manifest-amend - ARCH=arm64 REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-arm64.docker docker-push docker-manifest-amend - ARCH=ppc64le REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-ppc64le.docker docker-push docker-manifest-amend - ARCH=s390x REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-s390x.docker docker-push docker-manifest-amend - ARCH=riscv64 REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-riscv64.docker docker-push docker-manifest-amend - REGISTRY=quay.io/coreos/flannel-git make docker-manifest-push - install: # This is intended as just a developer convenience to help speed up non-containerized builds # It is NOT how you install flannel CGO_ENABLED=$(CGO_ENABLED) go install -v github.com/flannel-io/flannel -minikube-start: - minikube start --network-plugin cni - -minikube-build-image: - CGO_ENABLED=1 go build -v -o dist/flanneld-amd64 - # Make sure the minikube docker is being used "eval $(minikube docker-env)" - sh -c 'eval $$(minikube docker-env) && docker build -f images/Dockerfile.amd64 -t flannel/minikube .' - -minikube-deploy-flannel: - kubectl apply -f Documentation/minikube.yml - -minikube-remove-flannel: - kubectl delete -f Documentation/minikube.yml - -minikube-restart-pod: - # Use this to pick up a new image - kubectl delete pods -l app=flannel --grace-period=0 - -kubernetes-logs: - kubectl logs `kubectl get po -l app=flannel -o=custom-columns=NAME:metadata.name --no-headers=true` -c kube-flannel -f - -LOCAL_IP_ENV?=$(shell ip route get 8.8.8.8 | head -1 | awk '{print $$7}') -run-etcd: stop-etcd - docker run --detach \ - -p 2379:2379 \ - --name flannel-etcd quay.io/coreos/etcd \ - -e ETCD_UNSUPPORTED_ARCH=$(ARCH) \ - etcd \ - --advertise-client-urls "http://$(LOCAL_IP_ENV):2379,http://127.0.0.1:2379,http://$(LOCAL_IP_ENV):4001,http://127.0.0.1:4001" \ - --listen-client-urls "http://0.0.0.0:2379,http://0.0.0.0:4001" - -stop-etcd: - @-docker rm -f flannel-etcd - -run-k8s-apiserver: stop-k8s-apiserver - docker run --detach --net=host \ - --name calico-k8s-apiserver \ - docker.io/rancher/hyperkube:v$(K8S_VERSION)-rancher1-linux-amd64 \ - /hyperkube apiserver --etcd-servers=http://$(LOCAL_IP_ENV):2379 \ - --service-cluster-ip-range=10.101.0.0/16 - -stop-k8s-apiserver: - @-docker rm -f calico-k8s-apiserver - -run-local-kube-flannel-with-prereqs: run-etcd run-k8s-apiserver dist/flanneld - while ! kubectl apply -f dist/fake-node.yaml; do sleep 1; done - $(MAKE) run-local-kube-flannel - -run-local-kube-flannel: - # Currently this requires the netconf to be in /etc/kube-flannel/net-conf.json - sudo NODE_NAME=test dist/flanneld --kube-subnet-mgr --kube-api-url http://127.0.0.1:8080 - deps: go mod vendor go mod tidy + +buildx-create-builder: + docker buildx create --name mybuilder --use --bootstrap + +build-multi-arch: + docker buildx build --platform linux/amd64,linux/arm64,linux/arm,linux/s390x,linux/ppc64le,linux/riscv64 -t $(REGISTRY):$(TAG) -f images/Dockerfile --build-arg TAG=$(TAG) -o type=oci,dest=dist/flannel_oci.tar --progress plain . + diff --git a/pkg/trafficmngr/iptables/iptables_windows.go b/pkg/trafficmngr/iptables/iptables_windows.go index a397144ac5..c63900b4b9 100644 --- a/pkg/trafficmngr/iptables/iptables_windows.go +++ b/pkg/trafficmngr/iptables/iptables_windows.go @@ -29,14 +29,14 @@ type IPTables interface { Exists(table string, chain string, rulespec ...string) (bool, error) } -func (iptm IPTablesManager) SetupAndEnsureForwardRules(flannelIPv4Network, flannelIPv6Network string, resyncPeriod int) { +func (iptm IPTablesManager) SetupAndEnsureForwardRules(flannelIPv4Network ip.IP4Net, flannelIPv6Network ip.IP6Net, resyncPeriod int) { } func (iptm IPTablesManager) SetupAndEnsureMasqRules(flannelIPv4Net, prevSubnet ip.IP4Net, prevNetworks []ip.IP4Net, - currentlease *lease.Lease, flannelIPv6Net, prevIPv6Subnet ip.IP6Net, prevIPv6Networks []ip.IP6Net, + currentlease *lease.Lease, resyncPeriod int) error { return nil }