Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up tests in CI #2595

Merged
merged 4 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ jobs:
with:
go-version: "~1.21.1"

- name: Cache tools
uses: actions/cache@v4
with:
path: bin
key: ${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('Makefile') }}

- name: Install tools
run: make install-tools

- name: "basic checks"
run: make ci

Expand All @@ -38,6 +47,15 @@ jobs:
with:
go-version: "~1.21.1"

- name: Cache tools
uses: actions/cache@v4
with:
path: bin
key: ${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('Makefile') }}

- name: Install tools
run: make install-tools

- uses: actions/cache@v4
with:
path: |
Expand All @@ -58,6 +76,11 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "~1.21.1"

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ jobs:
with:
go-version: "~1.21.3"

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

- name: "install kuttl"
run: ./hack/install-kuttl.sh
- name: Install tools
run: make install-tools

- name: "run tests"
env:
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/scorecard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,22 @@ jobs:
with:
go-version: "~1.21.1"

- name: Setup kind
env:
KIND_VERSION: "0.20.0"
run: go install sigs.k8s.io/kind@v${KIND_VERSION}

- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: "install kuttl and kind"
run: ./hack/install-kuttl.sh
- name: Cache tools
uses: actions/cache@v4
with:
path: bin
key: ${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('Makefile') }}

- name: Install tools
run: make install-tools

- name: "start kind"
env:
KUBE_VERSION: ${{ matrix.kube-version }}
run: kind create cluster --config kind-$KUBE_VERSION.yaml
run: make start-kind

- name: "wait until cluster is ready"
run: kubectl wait --timeout=5m --for=condition=available deployment/coredns -n kube-system
Expand Down
71 changes: 26 additions & 45 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ manager: generate fmt vet

# Build target allocator binary
targetallocator:
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
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) go build -o cmd/otel-allocator/bin/targetallocator_${ARCH} -ldflags "${COMMON_LDFLAGS}" ./cmd/otel-allocator

# Build opamp bridge binary
operator-opamp-bridge:
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
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) go build -o cmd/operator-opamp-bridge/bin/opampbridge_${ARCH} -ldflags "${COMMON_LDFLAGS}" ./cmd/operator-opamp-bridge

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

.PHONY: start-kind
start-kind:
start-kind: kind
ifeq (true,$(START_KIND_CLUSTER))
kind create cluster --name $(KIND_CLUSTER_NAME) --config $(KIND_CONFIG) || true
$(KIND) create cluster --name $(KIND_CLUSTER_NAME) --config $(KIND_CONFIG) || true
endif

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

.PHONY: load-image-operator
load-image-operator: container
load-image-operator: container kind
ifeq (true,$(START_KIND_CLUSTER))
kind load --name $(KIND_CLUSTER_NAME) docker-image $(IMG)
$(KIND) load --name $(KIND_CLUSTER_NAME) docker-image $(IMG)
else
$(MAKE) container-push
endif


.PHONY: load-image-target-allocator
load-image-target-allocator: container-target-allocator
load-image-target-allocator: container-target-allocator kind
ifeq (true,$(START_KIND_CLUSTER))
kind load --name $(KIND_CLUSTER_NAME) docker-image $(TARGETALLOCATOR_IMG)
$(KIND) load --name $(KIND_CLUSTER_NAME) docker-image $(TARGETALLOCATOR_IMG)
else
$(MAKE) container-target-allocator-push
endif


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

.PHONY: cert-manager
cert-manager: cmctl
Expand All @@ -355,6 +355,8 @@ cmctl:
}

KUSTOMIZE ?= $(LOCALBIN)/kustomize
KIND ?= $(LOCALBIN)/kind
KUTTL ?= $(LOCALBIN)/kubectl-kuttl
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
CHLOGGEN ?= $(LOCALBIN)/chloggen
Expand All @@ -363,24 +365,33 @@ GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
KUSTOMIZE_VERSION ?= v5.0.3
CONTROLLER_TOOLS_VERSION ?= v0.12.0
GOLANGCI_LINT_VERSION ?= v1.54.0
KIND_VERSION ?= v0.20.0
KUTTL_VERSION ?= 0.15.0

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

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

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

.PHONY: kind
kind: ## Download kind locally if necessary.
$(call go-get-tool,$(KIND),sigs.k8s.io/kind,$(KIND_VERSION))

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
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)
@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)

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

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

.PHONY: kuttl
kuttl:
ifeq (, $(shell which kubectl-kuttl))
echo ${PATH}
ls -l /usr/local/bin
which kubectl-kuttl

@{ \
set -e ;\
echo "" ;\
echo "ERROR: kuttl not found." ;\
echo "Please check https://kuttl.dev/docs/cli.html for installation instructions and try again." ;\
echo "" ;\
exit 1 ;\
}
else
KUTTL=$(shell which kubectl-kuttl)
endif

.PHONY: kind
kind:
ifeq (, $(shell which kind))
@{ \
set -e ;\
echo "" ;\
echo "ERROR: kind not found." ;\
echo "Please check https://kind.sigs.k8s.io/docs/user/quick-start/#installation for installation instructions and try again." ;\
echo "" ;\
exit 1 ;\
}
else
KIND=$(shell which kind)
endif
kuttl: $(LOCALBIN)
@KUTTL=$(KUTTL) KUTTL_VERSION=$(KUTTL_VERSION) ./hack/install-kuttl.sh

OPERATOR_SDK = $(shell pwd)/bin/operator-sdk
.PHONY: operator-sdk
operator-sdk:
operator-sdk: $(LOCALBIN)
@{ \
set -e ;\
if (`pwd`/bin/operator-sdk version | grep ${OPERATOR_SDK_VERSION}) > /dev/null 2>&1 ; then \
Expand Down
13 changes: 10 additions & 3 deletions hack/install-kuttl.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/bin/bash

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
sudo chmod +x /usr/local/bin/kubectl-kuttl
export PATH=$PATH:/usr/local/bin
if (${KUTTL} version | grep ${KUTTL_VERSION}) > /dev/null 2>&1; then
exit 0;
fi

OS=$(go env GOOS)
ARCH=$(uname -m)

curl -Lo ${KUTTL} https://github.com/kudobuilder/kuttl/releases/download/v${KUTTL_VERSION}/kubectl-kuttl_${KUTTL_VERSION}_${OS}_${ARCH}
chmod +x ${KUTTL}

Loading