-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
139 lines (111 loc) · 4.98 KB
/
Copy pathMakefile
File metadata and controls
139 lines (111 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Include ODC common make targets
DEV_KIT_VERSION := v1.0.14
-include common.mk
common.mk:
curl --fail -sSL https://raw.githubusercontent.com/opendefensecloud/dev-kit/$(DEV_KIT_VERSION)/common.mk -o common.mk.download && \
mv common.mk.download $@
APIGEN ?= $(LOCALGOBIN)/apigen
KCP ?= $(LOCALBIN)/kcp
# Primary kcp version: the one CI gates on and the project supports.
KCP_VERSION ?= 0.31.6
# kcp versions exercised by the *-matrix targets. See docs/compatibility.md.
KCP_VERSIONS ?= 0.30.3 0.31.6 0.32.3
# kcp server version the e2e suite pins on the kcp-operator RootShard, Shard and
# FrontProxy. Defaults to KCP_VERSION so e2e tests the version we support rather
# than whatever kcp-operator happens to default to. Set empty to use that default.
E2E_KCP_VERSION ?= $(KCP_VERSION)
export E2E_KCP_VERSION
IMG_REGISTRY ?= ghcr.io/opendefensecloud
IMG_TAG ?= latest
CONTROLLER_IMG ?= $(IMG_REGISTRY)/dependency-controller:$(IMG_TAG)
WEBHOOK_IMG ?= $(IMG_REGISTRY)/dependency-webhook:$(IMG_TAG)
TIMESTAMP := $(shell date '+%Y%m%d%H%M%S')
DEV_TAG ?= dev.$(TIMESTAMP)
export DEV_TAG
LICENSE := apache
LICENSE_COMMENT := BWI GmbH and Dependency Controller contributors
##@ Development
.PHONY: generate
generate: $(CONTROLLER_GEN) ## Generate deepcopy methods.
$(CONTROLLER_GEN) object paths="./api/..."
.PHONY: manifests
manifests: $(CONTROLLER_GEN) $(APIGEN) ## Generate CRDs and convert to kcp APIResourceSchemas + APIExport.
$(CONTROLLER_GEN) crd paths="./api/..." output:crd:dir=config/crds
$(APIGEN) --input-dir=config/crds --output-dir=config/kcp
cp config/crds/* charts/dependency-controller/files/
cp config/kcp/apiresourceschema-*.yaml charts/dependency-controller/files/
cp config/kcp/apiexport-*.yaml charts/dependency-controller/files/
.PHONY: fmt
fmt: $(ADDLICENSE) $(GOLANGCI_LINT) ## Add license headers and format code.
$(MAKE) addlicense license=$(LICENSE) comment='$(LICENSE_COMMENT)' pattern='*\.go'
$(GO) fmt ./...
$(GOLANGCI_LINT) run --fix
.PHONY: lint
lint: lint-no-golangci golangci-lint ## Run all linters.
.PHONY: lint-no-golangci
lint-no-golangci: ## Run linters except golangci-lint (license headers + shellcheck).
$(MAKE) addlicense-check license=$(LICENSE) comment='$(LICENSE_COMMENT)' pattern='*\.go'
.PHONY: vet
vet: ## Run go vet.
$(GO) vet ./...
##@ Build
.PHONY: build
build: generate ## Build the controller and webhook binaries.
$(GO) build -o $(LOCALBIN)/dependency-controller ./cmd/controller/
$(GO) build -o $(LOCALBIN)/dependency-webhook ./cmd/webhook/
.PHONY: run
run-controller: generate ## Run the controller from source.
$(GO) run ./cmd/controller/
.PHONY: run-webhook
run-webhook: generate ## Run the webhook server from source.
$(GO) run ./cmd/webhook/
.PHONY: docker-build
docker-build: ## Build the Docker image.
$(DOCKER) build --platform linux/amd64,linux/arm64 -t $(CONTROLLER_IMG) .
.PHONY: docker-push
docker-push: ## Push the Docker image.
$(DOCKER) push $(CONTROLLER_IMG)
.PHONY: helm-package
helm-package: manifests ## Package Helm chart.
helm package charts/dependency-controller
##@ Testing
.PHONY: test
test: $(GINKGO) $(KCP) generate ## Run all tests (excludes e2e).
TEST_KCP_ASSETS=$(LOCALBIN) $(GINKGO) -r -cover --fail-fast --require-suite -covermode count --output-dir=$(BUILD_PATH) -coverprofile=coverprofile --skip-package=test/e2e $(testargs)
.PHONY: test-matrix
test-matrix: ## Run tests against every kcp version in KCP_VERSIONS.
@for v in $(KCP_VERSIONS); do \
echo ""; \
echo "=== make test against kcp $$v ==="; \
$(MAKE) --no-print-directory test KCP_VERSION=$$v || exit 1; \
done
.PHONY: test-e2e
test-e2e: $(GINKGO) ## Run e2e tests (kind + kcp + helm). Set E2E_SHARD_CONFIG=single-shard|multi-shard (default: multi-shard).
$(GINKGO) -r --fail-fast -v --timeout 30m ./test/e2e/ $(testargs)
.PHONY: test-e2e-matrix
test-e2e-matrix: ## Run e2e tests against both shard configs (single-shard, multi-shard).
$(MAKE) clean-e2e
E2E_SHARD_CONFIG=single-shard $(MAKE) test-e2e
$(MAKE) clean-e2e
E2E_SHARD_CONFIG=multi-shard $(MAKE) test-e2e
.PHONY: test-e2e-kcp-matrix
test-e2e-kcp-matrix: ## Run e2e against every kcp version in KCP_VERSIONS.
@for v in $(KCP_VERSIONS); do \
echo ""; \
echo "=== make test-e2e against kcp $$v ==="; \
$(MAKE) --no-print-directory clean-e2e; \
E2E_KCP_VERSION=$$v $(MAKE) --no-print-directory test-e2e || exit 1; \
done
$(MAKE) --no-print-directory clean-e2e
.PHONY: clean-e2e
clean-e2e: ## Remove kind cluster from e2e tests.
-$(KIND) delete cluster --name dep-ctrl-e2e 2>/dev/null
##@ Tool Dependencies
.PHONY: $(KCP)
$(KCP): $(LOCALBIN) ## Download kcp binary locally if necessary.
@test -s $(LOCALBIN)/kcp && $(LOCALBIN)/kcp --version 2>&1 | grep -q "$(KCP_VERSION)" || (\
echo "Downloading kcp v$(KCP_VERSION) for $(OS)/$(ARCH)..."; \
curl -fsSL -o $(LOCALBIN)/kcp.tar.gz "https://github.com/kcp-dev/kcp/releases/download/v$(KCP_VERSION)/kcp_$(KCP_VERSION)_$(OS)_$(ARCH).tar.gz"; \
tar -xzf $(LOCALBIN)/kcp.tar.gz -C $(LOCALBIN) --strip-components=1 bin/; \
rm -f $(LOCALBIN)/kcp.tar.gz; \
chmod +x $(LOCALBIN)/kcp)