Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
278 lines (222 loc) · 11.2 KB
/
Copy pathMakefile
File metadata and controls
278 lines (222 loc) · 11.2 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# Copyright 2022 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
LOCAL_OS := $(shell uname)
ifeq ($(LOCAL_OS),Linux)
TARGET_OS ?= linux
XARGS_FLAGS="-r"
else ifeq ($(LOCAL_OS),Darwin)
TARGET_OS ?= darwin
XARGS_FLAGS=
else
$(error "This system's OS $(LOCAL_OS) isn't recognized/supported")
endif
FINDFILES=find . \( -path ./.git -o -path ./.github \) -prune -o -type f
XARGS = xargs -0 ${XARGS_FLAGS}
CLEANXARGS = xargs ${XARGS_FLAGS}
REGISTRY = quay.io/stolostron
VERSION = latest
IMAGE_NAME_AND_VERSION ?= $(REGISTRY)/multicloud-integrations:$(VERSION)
# clusteradm CLI version - installs stable OCM components by default
CLUSTERADM_VERSION ?= v1.1.1
export GOPACKAGES = $(shell go list ./... | grep -v /manager | grep -v /bindata | grep -v /vendor | grep -v /internal | grep -v /build | grep -v /test | grep -v /e2e )
K8S_VERSION ?=1.28.3
SETUP_ENVTEST ?= $(LOCALBIN)/setup-envtest
.PHONY: build
build:
@common/scripts/gobuild.sh build/_output/bin/gitopscluster ./cmd/gitopscluster
@common/scripts/gobuild.sh build/_output/bin/gitopssyncresc ./cmd/gitopssyncresc
@common/scripts/gobuild.sh build/_output/bin/multiclusterstatusaggregation ./cmd/multiclusterstatusaggregation
@common/scripts/gobuild.sh build/_output/bin/propagation ./cmd/propagation
@common/scripts/gobuild.sh build/_output/bin/gitopsaddon ./cmd/gitopsaddon
@common/scripts/gobuild.sh build/_output/bin/maestroPropagation ./cmd/maestropropagation
@common/scripts/gobuild.sh build/_output/bin/maestroAggregation ./cmd/maestroaggregation
local:
@GOOS=darwin common/scripts/gobuild.sh build/_output/bin/gitopscluster ./cmd/gitopscluster
@GOOS=darwin common/scripts/gobuild.sh build/_output/bin/gitopssyncresc ./cmd/gitopssyncresc
@GOOS=darwin common/scripts/gobuild.sh build/_output/bin/multiclusterstatusaggregation ./cmd/multiclusterstatusaggregation
@GOOS=darwin common/scripts/gobuild.sh build/_output/bin/propagation ./cmd/propagation
@GOOS=darwin common/scripts/gobuild.sh build/_output/bin/gitopsaddon ./cmd/gitopsaddon
@GOOS=darwin common/scripts/gobuild.sh build/_output/bin/maestroPropagation ./cmd/maestropropagation
@GOOS=darwin common/scripts/gobuild.sh build/_output/bin/maestroAggregation ./cmd/maestroaggregation
.PHONY: build-images
build-images: build
@docker build -t ${IMAGE_NAME_AND_VERSION} -f build/Dockerfile .
# build local linux/amd64 images on non-amd64 hosts such as Apple M3
# need to create the buildx builder as a fixed name and clean it up after usage
# Or a new builder is created everytime and it will fail docker buildx image build eventually.
build-images-non-amd64-docker:
@if docker buildx ls | grep -q "local-builder"; then \
echo "Removing existing local-builder..."; \
docker buildx rm local-builder; \
fi
docker buildx create --name local-builder --use
docker buildx inspect local-builder --bootstrap
docker buildx build --platform linux/amd64 -t ${IMAGE_NAME_AND_VERSION} -f build/Dockerfile --load .
docker buildx rm local-builder
build-images-non-amd64-podman:
podman build --platform linux/amd64 -t ${IMAGE_NAME_AND_VERSION} -f build/Dockerfile .
.PHONY: lint
lint: lint-all
.PHONY: lint-all
lint-all:lint-go
.PHONY: lint-go
lint-go:
@true
.PHONY: test
# download the kubebuilder-tools to get kube-apiserver binaries from it
.PHONY: setup-envtest
setup-envtest: $(SETUP_ENVTEST)
# Pinned (not @latest): setup-envtest's newest tagged releases (v0.24.0+) require go >= 1.26,
# newer than this repo's go.mod (go 1.25.0) / controller-runtime v0.21.0 dependency. @latest
# breaks the build the moment a newer setup-envtest release ships, with no code change on our
# side - confirmed by "requires go >= 1.26.0 (running go 1.25.11)" failing here. Pinned to the
# commit setup-envtest was built from on the release-0.21 branch (the line matching this repo's
# controller-runtime version), verified installable and working under go 1.25.
SETUP_ENVTEST_VERSION ?= v0.0.0-20250626154428-7fd020cb5fc3
$(SETUP_ENVTEST): $(LOCALBIN)
@if [ -s $(SETUP_ENVTEST) ] && [ "$$($(SETUP_ENVTEST) version 2>/dev/null | awk '{print $$NF}')" = "$(SETUP_ENVTEST_VERSION)" ]; then \
exit 0; \
fi; \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(SETUP_ENVTEST_VERSION)
test: test-unit
test-unit: setup-envtest
KUBEBUILDER_ASSETS="$(shell $(SETUP_ENVTEST) use $(K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -timeout 300s -v ./pkg/...
KUBEBUILDER_ASSETS="$(shell $(SETUP_ENVTEST) use $(K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -timeout 300s -v ./propagation-controller/...
KUBEBUILDER_ASSETS="$(shell $(SETUP_ENVTEST) use $(K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -timeout 300s -v ./gitopsaddon/...
KUBEBUILDER_ASSETS="$(shell $(SETUP_ENVTEST) use $(K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -timeout 300s -v ./maestroapplication/...
KUBEBUILDER_ASSETS="$(shell $(SETUP_ENVTEST) use $(K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -timeout 300s -v ./cmd/...
test-integration: setup-envtest
KUBEBUILDER_ASSETS="$(shell $(SETUP_ENVTEST) use $(K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -tags=integration -timeout 300s -v ./pkg/...
KUBEBUILDER_ASSETS="$(shell $(SETUP_ENVTEST) use $(K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -tags=integration -timeout 300s -v ./propagation-controller/...
KUBEBUILDER_ASSETS="$(shell $(SETUP_ENVTEST) use $(K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -tags=integration -timeout 300s -v ./gitopsaddon/...
KUBEBUILDER_ASSETS="$(shell $(SETUP_ENVTEST) use $(K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -tags=integration -timeout 300s -v ./maestroapplication/...
.PHONY: manifests
manifests: controller-gen
$(CONTROLLER_GEN) crd webhook paths="./..." output:crd:artifacts:config=deploy/crds
.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
CONTROLLER_TOOLS_VERSION ?= v0.17.3
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
.PHONY: deploy-ocm
deploy-ocm:
CLUSTERADM_VERSION=$(CLUSTERADM_VERSION) deploy/ocm/install.sh
# E2E Test Configuration
HUB_CLUSTER ?= hub
SPOKE_CLUSTER ?= cluster1
E2E_IMG ?= quay.io/stolostron/multicloud-integrations:latest
ARGOCD_OPERATOR_VERSION ?= v0.18.0
ARGOCD_OPERATOR_IMAGE ?= quay.io/argoprojlabs/argocd-operator:$(ARGOCD_OPERATOR_VERSION)
export ARGOCD_OPERATOR_IMAGE
KIND ?= kind
KUBECTL ?= kubectl
##@ Cluster-Import E2E Tests (legacy script-based)
.PHONY: test-e2e
test-e2e:
e2e/run_e2e.sh
.PHONY: test-local-e2e
test-local-e2e:
@$(KIND) delete cluster --name $(HUB_CLUSTER) || true
@$(KIND) delete cluster --name $(SPOKE_CLUSTER) || true
@$(KIND) create cluster --name $(HUB_CLUSTER)
@$(KIND) create cluster --name $(SPOKE_CLUSTER)
$(MAKE) build-images IMAGE_NAME_AND_VERSION=$(E2E_IMG)
$(KIND) load docker-image $(E2E_IMG) --name $(HUB_CLUSTER)
$(KIND) load docker-image $(E2E_IMG) --name $(SPOKE_CLUSTER)
E2E_IMG=$(E2E_IMG) CLUSTERADM_VERSION=$(CLUSTERADM_VERSION) e2e/run_e2e.sh
.PHONY: test-e2e-cluster-secret-deletion
test-e2e-cluster-secret-deletion:
e2e/cluster_secret_deletion_test.sh
.PHONY: test-local-e2e-cluster-secret-deletion
test-local-e2e-cluster-secret-deletion:
@$(KIND) delete cluster --name $(HUB_CLUSTER) || true
@$(KIND) delete cluster --name $(SPOKE_CLUSTER) || true
@$(KIND) create cluster --name $(HUB_CLUSTER)
@$(KIND) create cluster --name $(SPOKE_CLUSTER)
$(MAKE) build-images IMAGE_NAME_AND_VERSION=$(E2E_IMG)
$(KIND) load docker-image $(E2E_IMG) --name $(HUB_CLUSTER)
$(KIND) load docker-image $(E2E_IMG) --name $(SPOKE_CLUSTER)
E2E_IMG=$(E2E_IMG) CLUSTERADM_VERSION=$(CLUSTERADM_VERSION) e2e/run_e2e.sh
e2e/cluster_secret_deletion_test.sh
##@ GitOps Addon E2E Tests (Go / Ginkgo, driven by test/e2e/gitopsaddon/)
# --- Internal helpers (not called directly) ---
define SETUP_KIND_CLUSTERS
@$(KIND) delete cluster --name $(HUB_CLUSTER) || true
@$(KIND) delete cluster --name $(SPOKE_CLUSTER) || true
@$(KIND) create cluster --name $(HUB_CLUSTER)
@$(KIND) create cluster --name $(SPOKE_CLUSTER)
$(MAKE) build-images IMAGE_NAME_AND_VERSION=$(E2E_IMG)
$(KIND) load docker-image $(E2E_IMG) --name $(HUB_CLUSTER)
$(KIND) load docker-image $(E2E_IMG) --name $(SPOKE_CLUSTER)
docker pull $(ARGOCD_OPERATOR_IMAGE) || true
$(KIND) load docker-image $(ARGOCD_OPERATOR_IMAGE) --name $(HUB_CLUSTER)
$(KIND) load docker-image $(ARGOCD_OPERATOR_IMAGE) --name $(SPOKE_CLUSTER)
endef
define RUN_GITOPSADDON_E2E
E2E_IMG=$(E2E_IMG) CLUSTERADM_VERSION=$(CLUSTERADM_VERSION) ARGOCD_OPERATOR_IMAGE=$(ARGOCD_OPERATOR_IMAGE) ./test/e2e/gitopsaddon/scripts/setup_env.sh
$(KUBECTL) config use-context kind-$(HUB_CLUSTER)
go test -tags=e2e -timeout 30m ./test/e2e/gitopsaddon/ -v -ginkgo.v --ginkgo.label-filter="$(1)"
endef
# --- Scenarios (CI) ---
.PHONY: test-e2e-gitopsaddon-embedded
test-e2e-gitopsaddon-embedded: manifests
$(call RUN_GITOPSADDON_E2E,embedded)
.PHONY: test-e2e-gitopsaddon-embedded-agent
test-e2e-gitopsaddon-embedded-agent: manifests
$(call RUN_GITOPSADDON_E2E,embedded-agent)
.PHONY: test-e2e-gitopsaddon-olm-override
test-e2e-gitopsaddon-olm-override: manifests
$(call RUN_GITOPSADDON_E2E,olm-override)
.PHONY: test-e2e-gitopsaddon-embedded-autonomous
test-e2e-gitopsaddon-embedded-autonomous: manifests
$(call RUN_GITOPSADDON_E2E,embedded-autonomous)
# --- Scenarios (Local) ---
.PHONY: test-local-e2e-gitopsaddon-embedded
test-local-e2e-gitopsaddon-embedded:
$(SETUP_KIND_CLUSTERS)
$(MAKE) test-e2e-gitopsaddon-embedded
.PHONY: test-local-e2e-gitopsaddon-embedded-agent
test-local-e2e-gitopsaddon-embedded-agent:
$(SETUP_KIND_CLUSTERS)
$(MAKE) test-e2e-gitopsaddon-embedded-agent
.PHONY: test-local-e2e-gitopsaddon-olm-override
test-local-e2e-gitopsaddon-olm-override:
$(SETUP_KIND_CLUSTERS)
$(MAKE) test-e2e-gitopsaddon-olm-override
.PHONY: test-local-e2e-gitopsaddon-embedded-autonomous
test-local-e2e-gitopsaddon-embedded-autonomous:
$(SETUP_KIND_CLUSTERS)
$(MAKE) test-e2e-gitopsaddon-embedded-autonomous
# --- Aggregate targets ---
.PHONY: test-e2e-gitopsaddon-all
test-e2e-gitopsaddon-all:
$(MAKE) test-e2e-gitopsaddon-embedded
$(MAKE) test-e2e-gitopsaddon-embedded-agent
$(MAKE) test-e2e-gitopsaddon-olm-override
$(MAKE) test-e2e-gitopsaddon-embedded-autonomous
.PHONY: clean-e2e
clean-e2e:
@$(KIND) delete cluster --name $(HUB_CLUSTER) || true
@$(KIND) delete cluster --name $(SPOKE_CLUSTER) || true
.PHONY: all
all: build test
.PHONY: clean
clean: clean-e2e