Skip to content

Commit 719a937

Browse files
authored
Speed up tests in CI (#2595)
* Avoid unnecessary binary rebuilds We had some unnecessary -a flags in our build commands, forcing a rebuild every time. Most likely a workaround for golang/go#9344 that is no longer necessary. * Install kind locally via the Makefile * Install kuttl locally via the Makefile * Cache tool binaries in CI
1 parent aca7df0 commit 719a937

File tree

5 files changed

+75
-62
lines changed

5 files changed

+75
-62
lines changed

.github/workflows/continuous-integration.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ jobs:
2323
with:
2424
go-version: "~1.21.1"
2525

26+
- name: Cache tools
27+
uses: actions/cache@v4
28+
with:
29+
path: bin
30+
key: ${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('Makefile') }}
31+
32+
- name: Install tools
33+
run: make install-tools
34+
2635
- name: "basic checks"
2736
run: make ci
2837

@@ -38,6 +47,15 @@ jobs:
3847
with:
3948
go-version: "~1.21.1"
4049

50+
- name: Cache tools
51+
uses: actions/cache@v4
52+
with:
53+
path: bin
54+
key: ${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('Makefile') }}
55+
56+
- name: Install tools
57+
run: make install-tools
58+
4159
- uses: actions/cache@v4
4260
with:
4361
path: |
@@ -58,6 +76,11 @@ jobs:
5876
- name: Check out code into the Go module directory
5977
uses: actions/checkout@v4
6078

79+
- name: Set up Go
80+
uses: actions/setup-go@v5
81+
with:
82+
go-version: "~1.21.1"
83+
6184
- name: Initialize CodeQL
6285
uses: github/codeql-action/init@v3
6386
with:

.github/workflows/e2e.yaml

+7-6
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ jobs:
4747
with:
4848
go-version: "~1.21.3"
4949

50-
- name: Setup kind
51-
env:
52-
KIND_VERSION: "0.20.0"
53-
run: go install sigs.k8s.io/kind@v${KIND_VERSION}
50+
- name: Cache tools
51+
uses: actions/cache@v4
52+
with:
53+
path: bin
54+
key: ${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('Makefile') }}
5455

55-
- name: "install kuttl"
56-
run: ./hack/install-kuttl.sh
56+
- name: Install tools
57+
run: make install-tools
5758

5859
- name: "run tests"
5960
env:

.github/workflows/scorecard.yaml

+9-8
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,22 @@ jobs:
2727
with:
2828
go-version: "~1.21.1"
2929

30-
- name: Setup kind
31-
env:
32-
KIND_VERSION: "0.20.0"
33-
run: go install sigs.k8s.io/kind@v${KIND_VERSION}
34-
3530
- name: Check out code into the Go module directory
3631
uses: actions/checkout@v4
3732

38-
- name: "install kuttl and kind"
39-
run: ./hack/install-kuttl.sh
33+
- name: Cache tools
34+
uses: actions/cache@v4
35+
with:
36+
path: bin
37+
key: ${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('Makefile') }}
38+
39+
- name: Install tools
40+
run: make install-tools
4041

4142
- name: "start kind"
4243
env:
4344
KUBE_VERSION: ${{ matrix.kube-version }}
44-
run: kind create cluster --config kind-$KUBE_VERSION.yaml
45+
run: make start-kind
4546

4647
- name: "wait until cluster is ready"
4748
run: kubectl wait --timeout=5m --for=condition=available deployment/coredns -n kube-system

Makefile

+26-45
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ manager: generate fmt vet
110110

111111
# Build target allocator binary
112112
targetallocator:
113-
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) go build -a -installsuffix cgo -o cmd/otel-allocator/bin/targetallocator_${ARCH} -ldflags "${COMMON_LDFLAGS}" ./cmd/otel-allocator
113+
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) go build -o cmd/otel-allocator/bin/targetallocator_${ARCH} -ldflags "${COMMON_LDFLAGS}" ./cmd/otel-allocator
114114

115115
# Build opamp bridge binary
116116
operator-opamp-bridge:
117-
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) go build -a -installsuffix cgo -o cmd/operator-opamp-bridge/bin/opampbridge_${ARCH} -ldflags "${COMMON_LDFLAGS}" ./cmd/operator-opamp-bridge
117+
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) go build -o cmd/operator-opamp-bridge/bin/opampbridge_${ARCH} -ldflags "${COMMON_LDFLAGS}" ./cmd/operator-opamp-bridge
118118

119119
# Run against the configured Kubernetes cluster in ~/.kube/config
120120
.PHONY: run
@@ -288,9 +288,9 @@ container-operator-opamp-bridge: operator-opamp-bridge
288288
docker build -t ${OPERATOROPAMPBRIDGE_IMG} cmd/operator-opamp-bridge
289289

290290
.PHONY: start-kind
291-
start-kind:
291+
start-kind: kind
292292
ifeq (true,$(START_KIND_CLUSTER))
293-
kind create cluster --name $(KIND_CLUSTER_NAME) --config $(KIND_CONFIG) || true
293+
$(KIND) create cluster --name $(KIND_CLUSTER_NAME) --config $(KIND_CONFIG) || true
294294
endif
295295

296296
.PHONY: install-metrics-server
@@ -310,26 +310,26 @@ install-targetallocator-prometheus-crds:
310310
load-image-all: load-image-operator load-image-target-allocator load-image-operator-opamp-bridge
311311

312312
.PHONY: load-image-operator
313-
load-image-operator: container
313+
load-image-operator: container kind
314314
ifeq (true,$(START_KIND_CLUSTER))
315-
kind load --name $(KIND_CLUSTER_NAME) docker-image $(IMG)
315+
$(KIND) load --name $(KIND_CLUSTER_NAME) docker-image $(IMG)
316316
else
317317
$(MAKE) container-push
318318
endif
319319

320320

321321
.PHONY: load-image-target-allocator
322-
load-image-target-allocator: container-target-allocator
322+
load-image-target-allocator: container-target-allocator kind
323323
ifeq (true,$(START_KIND_CLUSTER))
324-
kind load --name $(KIND_CLUSTER_NAME) docker-image $(TARGETALLOCATOR_IMG)
324+
$(KIND) load --name $(KIND_CLUSTER_NAME) docker-image $(TARGETALLOCATOR_IMG)
325325
else
326326
$(MAKE) container-target-allocator-push
327327
endif
328328

329329

330330
.PHONY: load-image-operator-opamp-bridge
331-
load-image-operator-opamp-bridge: container-operator-opamp-bridge
332-
kind load --name $(KIND_CLUSTER_NAME) docker-image ${OPERATOROPAMPBRIDGE_IMG}
331+
load-image-operator-opamp-bridge: container-operator-opamp-bridge kind
332+
$(KIND) load --name $(KIND_CLUSTER_NAME) docker-image ${OPERATOROPAMPBRIDGE_IMG}
333333

334334
.PHONY: cert-manager
335335
cert-manager: cmctl
@@ -355,6 +355,8 @@ cmctl:
355355
}
356356

357357
KUSTOMIZE ?= $(LOCALBIN)/kustomize
358+
KIND ?= $(LOCALBIN)/kind
359+
KUTTL ?= $(LOCALBIN)/kubectl-kuttl
358360
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
359361
ENVTEST ?= $(LOCALBIN)/setup-envtest
360362
CHLOGGEN ?= $(LOCALBIN)/chloggen
@@ -363,24 +365,33 @@ GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
363365
KUSTOMIZE_VERSION ?= v5.0.3
364366
CONTROLLER_TOOLS_VERSION ?= v0.12.0
365367
GOLANGCI_LINT_VERSION ?= v1.54.0
368+
KIND_VERSION ?= v0.20.0
369+
KUTTL_VERSION ?= 0.15.0
366370

371+
.PHONY: install-tools
372+
install-tools: kustomize golangci-lint kind controller-gen envtest crdoc kuttl kind operator-sdk
367373

368374
.PHONY: kustomize
369375
kustomize: ## Download kustomize locally if necessary.
370376
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))
371377

378+
.PHONY: golangci-lint
372379
golangci-lint: ## Download golangci-lint locally if necessary.
373380
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
374381

382+
.PHONY: kind
383+
kind: ## Download kind locally if necessary.
384+
$(call go-get-tool,$(KIND),sigs.k8s.io/kind,$(KIND_VERSION))
385+
375386
.PHONY: controller-gen
376387
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
377388
$(CONTROLLER_GEN): $(LOCALBIN)
378-
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
389+
@test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
379390

380391
.PHONY: envtest
381392
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
382393
$(ENVTEST): $(LOCALBIN)
383-
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
394+
@test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
384395

385396
CRDOC = $(shell pwd)/bin/crdoc
386397
.PHONY: crdoc
@@ -403,42 +414,12 @@ rm -rf $$TMP_DIR ;\
403414
endef
404415

405416
.PHONY: kuttl
406-
kuttl:
407-
ifeq (, $(shell which kubectl-kuttl))
408-
echo ${PATH}
409-
ls -l /usr/local/bin
410-
which kubectl-kuttl
411-
412-
@{ \
413-
set -e ;\
414-
echo "" ;\
415-
echo "ERROR: kuttl not found." ;\
416-
echo "Please check https://kuttl.dev/docs/cli.html for installation instructions and try again." ;\
417-
echo "" ;\
418-
exit 1 ;\
419-
}
420-
else
421-
KUTTL=$(shell which kubectl-kuttl)
422-
endif
423-
424-
.PHONY: kind
425-
kind:
426-
ifeq (, $(shell which kind))
427-
@{ \
428-
set -e ;\
429-
echo "" ;\
430-
echo "ERROR: kind not found." ;\
431-
echo "Please check https://kind.sigs.k8s.io/docs/user/quick-start/#installation for installation instructions and try again." ;\
432-
echo "" ;\
433-
exit 1 ;\
434-
}
435-
else
436-
KIND=$(shell which kind)
437-
endif
417+
kuttl: $(LOCALBIN)
418+
@KUTTL=$(KUTTL) KUTTL_VERSION=$(KUTTL_VERSION) ./hack/install-kuttl.sh
438419

439420
OPERATOR_SDK = $(shell pwd)/bin/operator-sdk
440421
.PHONY: operator-sdk
441-
operator-sdk:
422+
operator-sdk: $(LOCALBIN)
442423
@{ \
443424
set -e ;\
444425
if (`pwd`/bin/operator-sdk version | grep ${OPERATOR_SDK_VERSION}) > /dev/null 2>&1 ; then \

hack/install-kuttl.sh

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#!/bin/bash
22

3-
sudo curl -Lo /usr/local/bin/kubectl-kuttl https://github.com/kudobuilder/kuttl/releases/download/v0.15.0/kubectl-kuttl_0.15.0_linux_x86_64
4-
sudo chmod +x /usr/local/bin/kubectl-kuttl
5-
export PATH=$PATH:/usr/local/bin
3+
if (${KUTTL} version | grep ${KUTTL_VERSION}) > /dev/null 2>&1; then
4+
exit 0;
5+
fi
6+
7+
OS=$(go env GOOS)
8+
ARCH=$(uname -m)
9+
10+
curl -Lo ${KUTTL} https://github.com/kudobuilder/kuttl/releases/download/v${KUTTL_VERSION}/kubectl-kuttl_${KUTTL_VERSION}_${OS}_${ARCH}
11+
chmod +x ${KUTTL}
12+

0 commit comments

Comments
 (0)