diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index d68a76a12b..6657c7aa40 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -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 @@ -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: | @@ -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: diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 4740af914a..190d94fc6d 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -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: diff --git a/.github/workflows/scorecard.yaml b/.github/workflows/scorecard.yaml index af6835bc21..2b6be81fec 100644 --- a/.github/workflows/scorecard.yaml +++ b/.github/workflows/scorecard.yaml @@ -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 diff --git a/Makefile b/Makefile index f80e11d3c8..cd26d6eedb 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 \ diff --git a/hack/install-kuttl.sh b/hack/install-kuttl.sh index 94326b52c0..41a725a98d 100755 --- a/hack/install-kuttl.sh +++ b/hack/install-kuttl.sh @@ -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} +