1+ # The tests in this directory use the projectcalico.org/v3 API group for CRDs.
2+ CALICO_API_GROUP ?= projectcalico.org/v3
3+
14# If ../metadata.mk exists, we're running this logic from within the calico repository.
25# If it does not, then we're in the api repo and we should use the local metadata.mk.
36ifneq ("$(wildcard ../metadata.mk) ", "")
@@ -12,6 +15,7 @@ LOCAL_CHECKS = lint-cache-dir check-copyright
1215BINDIR ?= bin
1316BUILD_DIR ?= build
1417TOP_SRC_DIRS = pkg
18+ KIND_CONFIG = $(KIND_DIR ) /kind-single.config
1519
1620# #############################################################################
1721# Download and include ../lib.Makefile before anything else
@@ -35,6 +39,7 @@ DOCKER_RUN := mkdir -p ../.go-pkg-cache bin $(GOMOD_CACHE) && \
3539 --net=host \
3640 --init \
3741 $(EXTRA_DOCKER_ARGS ) \
42+ $(DOCKER_GIT_WORKTREE_ARGS ) \
3843 -e LOCAL_USER_ID=$(LOCAL_USER_ID ) \
3944 -e GOCACHE=/go-cache \
4045 $(GOARCH_FLAGS ) \
@@ -54,6 +59,18 @@ build: gen-files examples
5459# Regenerate all files if the gen exes changed or any "types.go" files changed
5560.PHONY : gen-files
5661gen-files .generate_files : lint-cache-dir clean-generated
62+ # Generate CRDs without descriptions
63+ $(DOCKER_RUN ) $(CALICO_BUILD ) sh -c ' $(GIT_CONFIG_SSH) controller-gen crd:allowDangerousTypes=true,crdVersions=v1,deprecatedV1beta1CompatibilityPreserveUnknownFields=false,maxDescLen=0 paths=./pkg/apis/... output:crd:dir=config/crd/'
64+ # Remove the first yaml separator line.
65+ $(DOCKER_RUN ) $(CALICO_BUILD ) sh -c ' find ./config/crd -name "*.yaml" | xargs sed -i 1d'
66+ # Run prettier to fix indentation
67+ docker run --rm --user $(id -u ) :$(id -g ) -v $(CURDIR ) /config/crd/:/work/config/crd/ tmknom/prettier --write --parser=yaml /work
68+ # Patch in manual tweaks to the generated CRDs.
69+ # - Add nullable to IPAM block allocations field to allow null values in the allocations array.
70+ # - Remove the profiles CRD. Profiles are backed by Namespaces in Kubernetes and the CRD is not needed.
71+ patch -p2 < patches/0001-Add-nullable-to-IPAM-block-allocations-field.patch
72+ rm -f config/crd/projectcalico.org_profiles.yaml
73+
5774 # Generate defaults
5875 $(DOCKER_RUN) $(CALICO_BUILD) \
5976 sh -c '$(GIT_CONFIG_SSH) defaulter-gen \
@@ -62,6 +79,7 @@ gen-files .generate_files: lint-cache-dir clean-generated
6279 --extra-peer-dirs "$(PACKAGE_NAME)/pkg/apis/projectcalico/v3" \
6380 --output-file zz_generated.defaults.go \
6481 "$(PACKAGE_NAME)/pkg/apis/projectcalico/v3"'
82+
6583 # Generate deep copies
6684 $(DOCKER_RUN) $(CALICO_BUILD) \
6785 sh -c '$(GIT_CONFIG_SSH) deepcopy-gen \
@@ -70,6 +88,13 @@ gen-files .generate_files: lint-cache-dir clean-generated
7088 --bounding-dirs $(PACKAGE_NAME) \
7189 --output-file zz_generated.deepcopy.go \
7290 "$(PACKAGE_NAME)/pkg/apis/projectcalico/v3"'
91+ $(DOCKER_RUN) $(CALICO_BUILD) \
92+ sh -c '$(GIT_CONFIG_SSH) deepcopy-gen \
93+ --v 1 --logtostderr \
94+ --go-header-file "/go/src/$(PACKAGE_NAME)/hack/boilerplate/boilerplate.go.txt" \
95+ --bounding-dirs $(PACKAGE_NAME) \
96+ --output-file zz_generated.deepcopy.go \
97+ "$(PACKAGE_NAME)/pkg/apis/usage.tigera.io/v1"'
7398
7499 # generate all pkg/client contents
75100 $(DOCKER_RUN) $(CALICO_BUILD) \
@@ -135,9 +160,14 @@ WHAT?=.
135160GINKGO_FOCUS? =.*
136161
137162.PHONY :ut
138- ut :
139- $(DOCKER_RUN ) --privileged $(CALICO_BUILD ) \
140- sh -c ' cd /go/src/$(PACKAGE_NAME) && ginkgo -r -focus="$(GINKGO_FOCUS)" $(WHAT)'
163+ ut : kind-cluster-create
164+ mkdir -p report
165+ $(DOCKER_RUN ) \
166+ --privileged \
167+ -e KUBECONFIG=/kubeconfig.yaml \
168+ -v $(KIND_KUBECONFIG ) :/kubeconfig.yaml \
169+ $(CALICO_BUILD ) \
170+ sh -c ' cd /go/src/$(PACKAGE_NAME) && ginkgo -r --focus="$(GINKGO_FOCUS)" $(WHAT)'
141171
142172# # Check if generated files are out of date
143173.PHONY : check-generated-files
@@ -154,4 +184,4 @@ check-generated-files: .generate_files
154184# ##############################################################################
155185.PHONY : ci
156186# # Run what CI runs
157- ci : clean check-generated-files build ut static-checks
187+ ci : clean check-generated-files static-checks build ut
0 commit comments