Skip to content

Commit 79e76f7

Browse files
committed
Use codegen to build multicluster base manifests
Signed-off-by: Lan Luo <[email protected]>
1 parent 5301249 commit 79e76f7

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

ci/check-manifest.sh

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ diff="$(git status --porcelain ${YAMLS[@]})"
4343
MULTICLUSTER_YAMLS=($(ls multicluster/build/yamls/*.yml))
4444

4545
rm "${MULTICLUSTER_YAMLS[@]}"
46+
git stash
4647
cd multicluster; make manifests; cd ..
4748
mcdiff="$(git status --porcelain ${MULTICLUSTER_YAMLS[@]})"
4849

multicluster/Makefile

+16-28
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
# the allowDangerousTypes flag is needed for CRD manifests to generate correctly.
66
CRD_OPTIONS ?= "crd:allowDangerousTypes=true"
77

8+
GO ?= go
9+
810
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
9-
ifeq (,$(shell go env GOBIN))
10-
GOBIN=$(shell go env GOPATH)/bin
11+
ifeq (,$(shell $(GO) env GOBIN))
12+
GOBIN=$(shell $(GO) env GOPATH)/bin
1113
else
12-
GOBIN=$(shell go env GOBIN)
14+
GOBIN=$(shell $(GO) env GOBIN)
1315
endif
1416

1517
GO_VERSION := $(shell head -n 1 ../build/images/deps/go-version)
@@ -46,19 +48,18 @@ help: ## Display this help.
4648

4749
##@ Development
4850

49-
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
50-
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=controller-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
51+
manifests: crdgen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
5152
$(CURDIR)/hack/generate-manifest.sh -g > build/yamls/antrea-multicluster-leader-global.yml
5253
$(CURDIR)/hack/generate-manifest.sh -n antrea-multicluster > build/yamls/antrea-multicluster-leader-namespaced.yml
5354
$(CURDIR)/hack/generate-manifest.sh -l antrea-multicluster > build/yamls/antrea-multicluster-leader.yml
5455
$(CURDIR)/hack/generate-manifest.sh -m > build/yamls/antrea-multicluster-member.yml
5556
$(CURDIR)/hack/update-checksum.sh
5657

5758
fmt: ## Run go fmt against code.
58-
go fmt ./...
59+
$(GO) fmt ./...
5960

6061
vet: ## Run go vet against code.
61-
go vet ./...
62+
$(GO) vet ./...
6263

6364
.PHONY: .coverage
6465
.coverage:
@@ -67,28 +68,29 @@ vet: ## Run go vet against code.
6768
.PHONY: test-unit test-integration
6869
test-unit: fmt vet .coverage
6970
@echo "==> Running unit tests <=="
70-
go test -race -coverprofile=.coverage/coverage-unit.txt -covermode=atomic -cover antrea.io/antrea/multicluster/controllers/multicluster/...
71+
$(GO) test -race -coverprofile=.coverage/coverage-unit.txt -covermode=atomic -cover antrea.io/antrea/multicluster/controllers/multicluster/...
7172
test-integration: .coverage
7273
@echo "==> Running Multi-cluster integration tests <=="
7374
$(CURDIR)/hack/verify-tools.sh
7475
$(CURDIR)/hack/mc-integration-test.sh
7576
##@ Build
7677

7778
bin: fmt vet ## Build manager binary.
78-
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/antrea-mc-controller antrea.io/antrea/multicluster/cmd/...
79+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -o bin/antrea-mc-controller antrea.io/antrea/multicluster/cmd/...
7980

8081
.PHONY: antrea-mc-instr-binary
8182
antrea-mc-instr-binary:
82-
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -cover -coverpkg=antrea.io/antrea/multicluster/...,antrea.io/antrea/multicluster/cmd/... -o bin/antrea-mc-controller-coverage antrea.io/antrea/multicluster/cmd/...
83+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -cover -coverpkg=antrea.io/antrea/multicluster/...,antrea.io/antrea/multicluster/cmd/... -o bin/antrea-mc-controller-coverage antrea.io/antrea/multicluster/cmd/...
8384

8485
run: manifests generate fmt vet ## Run a controller from your host.
85-
go run ./main.go
86+
$(GO) run ./main.go
8687

8788
##@ Deployment
8889

89-
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
90-
controller-gen: ## Download controller-gen locally if necessary.
91-
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
90+
.PHONY: crdgen
91+
crdgen:
92+
@echo "===> Updating generated base manifests <==="
93+
$(CURDIR)/hack/update-codegen.sh crdgen
9294

9395
codegen:
9496
./hack/update-codegen.sh
@@ -97,17 +99,3 @@ codegen:
9799
mockgen:
98100
@echo "===> Updating generated mock code <==="
99101
$(CURDIR)/hack/update-codegen.sh mockgen
100-
101-
# go-get-tool will 'go get' any package $2 and install it to $1.
102-
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
103-
define go-get-tool
104-
@[ -f $(1) ] || { \
105-
set -e ;\
106-
TMP_DIR=$$(mktemp -d) ;\
107-
cd $$TMP_DIR ;\
108-
go mod init tmp ;\
109-
echo "Downloading $(2)" ;\
110-
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
111-
rm -rf $$TMP_DIR ;\
112-
}
113-
endef

multicluster/hack/update-codegen-dockerized.sh

+16-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ trap "popd; rm -rf ${ANTREA_CODEGEN_PATH}" EXIT
3737
function copy_generated_code_to_source {
3838
git ls-files --modified --others --exclude-standard | while read file; do
3939
if [ -e $file ]; then
40-
cp $file ${ANTREA_SRC_PATH}/$file
40+
cp $file ${ANTREA_SRC_PATH}/multicluster/$file
4141
else
42-
rm ${ANTREA_SRC_PATH}/$file
42+
rm ${ANTREA_SRC_PATH}/multicluster/$file
4343
fi
4444
done
4545
}
@@ -62,6 +62,20 @@ if [[ "$#" -eq 1 && $1 == "mockgen" ]]; then
6262
exit 0
6363
fi
6464

65+
function generate_multicluster_base_crds {
66+
CRD_OPTIONS="crd:allowDangerousTypes=true"
67+
$GOPATH/bin/controller-gen ${CRD_OPTIONS} rbac:roleName=controller-role webhook paths="./multicluster/..." \
68+
output:crd:artifacts:config=./multicluster/config/crd/bases \
69+
output:rbac:artifacts:config=./multicluster/config/rbac \
70+
output:webhook:artifacts:config=./multicluster/config/webhook
71+
copy_generated_code_to_source
72+
}
73+
74+
if [[ "$#" -eq 1 && $1 == "crdgen" ]]; then
75+
generate_multicluster_base_crds
76+
exit 0
77+
fi
78+
6579
# Remove all generated files.
6680
git grep --files-with-matches -e 'Code generated by .* DO NOT EDIT' -- multicluster ':(exclude)multicluster/hack' ':(exclude)multicluster/test' | xargs rm
6781

0 commit comments

Comments
 (0)