Skip to content

Commit

Permalink
Use codegen to build multicluster base manifests
Browse files Browse the repository at this point in the history
Signed-off-by: Lan Luo <lan.luo@broadcom.com>
  • Loading branch information
luolanzone committed Mar 10, 2025
1 parent 5301249 commit 05a7ffd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
1 change: 0 additions & 1 deletion ci/check-manifest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ diff="$(git status --porcelain ${YAMLS[@]})"

MULTICLUSTER_YAMLS=($(ls multicluster/build/yamls/*.yml))

rm "${MULTICLUSTER_YAMLS[@]}"
cd multicluster; make manifests; cd ..
mcdiff="$(git status --porcelain ${MULTICLUSTER_YAMLS[@]})"

Expand Down
44 changes: 16 additions & 28 deletions multicluster/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
# the allowDangerousTypes flag is needed for CRD manifests to generate correctly.
CRD_OPTIONS ?= "crd:allowDangerousTypes=true"

GO ?= go

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
ifeq (,$(shell $(GO) env GOBIN))
GOBIN=$(shell $(GO) env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
GOBIN=$(shell $(GO) env GOBIN)
endif

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

##@ Development

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

fmt: ## Run go fmt against code.
go fmt ./...
$(GO) fmt ./...

vet: ## Run go vet against code.
go vet ./...
$(GO) vet ./...

.PHONY: .coverage
.coverage:
Expand All @@ -67,28 +68,29 @@ vet: ## Run go vet against code.
.PHONY: test-unit test-integration
test-unit: fmt vet .coverage
@echo "==> Running unit tests <=="
go test -race -coverprofile=.coverage/coverage-unit.txt -covermode=atomic -cover antrea.io/antrea/multicluster/controllers/multicluster/...
$(GO) test -race -coverprofile=.coverage/coverage-unit.txt -covermode=atomic -cover antrea.io/antrea/multicluster/controllers/multicluster/...
test-integration: .coverage
@echo "==> Running Multi-cluster integration tests <=="
$(CURDIR)/hack/verify-tools.sh
$(CURDIR)/hack/mc-integration-test.sh
##@ Build

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

.PHONY: antrea-mc-instr-binary
antrea-mc-instr-binary:
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/...
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/...

run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go
$(GO) run ./main.go

##@ Deployment

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.16.3)
.PHONY: crdgen
crdgen:
@echo "===> Updating generated base manifests <==="
$(CURDIR)/hack/update-codegen.sh crdgen

codegen:
./hack/update-codegen.sh
Expand All @@ -97,17 +99,3 @@ codegen:
mockgen:
@echo "===> Updating generated mock code <==="
$(CURDIR)/hack/update-codegen.sh mockgen

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
14 changes: 14 additions & 0 deletions multicluster/hack/update-codegen-dockerized.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ if [[ "$#" -eq 1 && $1 == "mockgen" ]]; then
exit 0
fi

function generate_multicluster_base_crds {
CRD_OPTIONS="crd:allowDangerousTypes=true"
$GOPATH/bin/controller-gen ${CRD_OPTIONS} rbac:roleName=controller-role webhook paths="./multicluster/..." \
output:crd:artifacts:config=./multicluster/config/crd/bases \
output:rbac:artifacts:config=./multicluster/config/rbac \
output:webhook:artifacts:config=./multicluster/config/webhook
copy_generated_code_to_source
}

if [[ "$#" -eq 1 && $1 == "crdgen" ]]; then
generate_multicluster_base_crds
exit 0
fi

# Remove all generated files.
git grep --files-with-matches -e 'Code generated by .* DO NOT EDIT' -- multicluster ':(exclude)multicluster/hack' ':(exclude)multicluster/test' | xargs rm

Expand Down

0 comments on commit 05a7ffd

Please sign in to comment.