Skip to content

Commit

Permalink
Merge pull request #1883 from thomasferrandiz/cleanup-makefile
Browse files Browse the repository at this point in the history
Clean-up Makefile and use docker buildx locally
  • Loading branch information
thomasferrandiz authored Feb 28, 2024
2 parents a3a9176 + e90a170 commit 50fcbb8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 135 deletions.
20 changes: 6 additions & 14 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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: .
Expand All @@ -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


9 changes: 0 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dist/*.tar.gz
dist/flanneld*
dist/*.docker
dist/here.txt
dist/flannel_oci.tar
cover.out
.editorconfig
.idea/
Expand Down
16 changes: 16 additions & 0 deletions Documentation/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
122 changes: 12 additions & 110 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 .

4 changes: 2 additions & 2 deletions pkg/trafficmngr/iptables/iptables_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 50fcbb8

Please sign in to comment.