-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
97 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,5 @@ bin | |
kubebuilder-tools-* | ||
|
||
.vscode | ||
|
||
testbin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,18 @@ | ||
# Setting SHELL to bash allows bash commands to be executed by recipes. | ||
# Options are set to exit when a recipe line exits non-zero or a piped command fails. | ||
SHELL = /usr/bin/env bash -o pipefail | ||
.SHELLFLAGS = -ec | ||
|
||
# Current Operator version | ||
VERSION ?= 0.0.18 | ||
# Image to use for building Go | ||
GO_BUILDER_IMG ?= "golang:1.22" | ||
# Image URL to use all building/pushing image targets | ||
IMG_NAME ?= ghcr.io/grafana/k6-operator | ||
IMG_TAG ?= latest | ||
# Default dockerfile to build | ||
DOCKERFILE ?= "Dockerfile.controller" | ||
|
||
# Default bundle image tag | ||
BUNDLE_IMG ?= k6-controller-bundle:$(VERSION) | ||
# Options for 'bundle-build' | ||
|
@@ -11,27 +24,40 @@ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) | |
endif | ||
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) | ||
|
||
CONTROLLER_GEN_VERSION=v0.16.1 | ||
CONTROLLER_GEN=$(GOBIN)/controller-gen | ||
## Location to install dependencies to | ||
LOCALBIN ?= $(shell pwd)/bin | ||
$(LOCALBIN): | ||
mkdir -p $(LOCALBIN) | ||
|
||
# Image to use for building Go | ||
GO_BUILDER_IMG ?= "golang:1.22" | ||
# Image URL to use all building/pushing image targets | ||
IMG_NAME ?= ghcr.io/grafana/k6-operator | ||
IMG_TAG ?= latest | ||
# Default dockerfile to build | ||
DOCKERFILE ?= "Dockerfile.controller" | ||
CRD_OPTIONS ?= "crd:maxDescLen=0" | ||
## Tool Binaries | ||
KUSTOMIZE ?= $(LOCALBIN)/kustomize | ||
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen | ||
ENVTEST ?= $(LOCALBIN)/setup-envtest | ||
|
||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) | ||
ifeq (,$(shell go env GOBIN)) | ||
GOBIN=$(shell go env GOPATH)/bin | ||
else | ||
GOBIN=$(shell go env GOBIN) | ||
endif | ||
## Tool Versions | ||
KUSTOMIZE_VERSION ?= v4.5.5 #v3.8.7 | ||
CONTROLLER_TOOLS_VERSION ?= v0.16.1 | ||
|
||
CRD_OPTIONS ?= "crd:maxDescLen=0" | ||
|
||
all: manager | ||
|
||
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | ||
.PHONY: kustomize | ||
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. | ||
$(KUSTOMIZE): $(LOCALBIN) | ||
test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); } | ||
|
||
.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: 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 | ||
|
||
# Run tests | ||
ENVTEST_VERSION ?= latest # ref. https://github.com/kubernetes-sigs/controller-runtime/tree/main/tools/setup-envtest | ||
ENVTEST_ASSETS_DIR = $(shell pwd)/testbin | ||
|
@@ -41,14 +67,10 @@ GOARCH=$(shell go env GOARCH) | |
KUBEBUILDER_ASSETS_ROOT=/tmp | ||
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS_ROOT)/kubebuilder/bin | ||
|
||
test: generate fmt vet manifests | ||
export KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS); setup-envtest use --use-env -p env $(ENVTEST_K8S_VERSION); go test ./... -coverprofile cover.out | ||
|
||
test-setup: | ||
curl -L -O "https://storage.googleapis.com/kubebuilder-tools/kubebuilder-tools-$(ENVTEST_K8S_VERSION)-$(GOOS)-$(GOARCH).tar.gz" | ||
tar -zxvf kubebuilder-tools-$(ENVTEST_K8S_VERSION)-$(GOOS)-$(GOARCH).tar.gz | ||
mv kubebuilder $(KUBEBUILDER_ASSETS_ROOT) | ||
export KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS); go install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(ENVTEST_VERSION) | ||
test: manifests generate fmt vet ## Run tests. | ||
mkdir -p ${ENVTEST_ASSETS_DIR} | ||
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh | ||
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out | ||
|
||
e2e: deploy | ||
kubectl create configmap crocodile-stress-test --from-file e2e/test.js | ||
|
@@ -112,31 +134,6 @@ docker-build: test | |
docker-push: | ||
docker push ${IMG_NAME}:${IMG_TAG} | ||
|
||
# find or download controller-gen | ||
# download controller-gen if necessary | ||
controller-gen: | ||
@{ \ | ||
if ! which $(CONTROLLER_GEN) || [ 'Version $(CONTROLLER_GEN_VERSION)' != "$$($(CONTROLLER_GEN) --version)" ]; then\ | ||
set -e ;\ | ||
go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION) ;\ | ||
fi;\ | ||
} | ||
|
||
kustomize: | ||
ifeq (, $(shell which kustomize)) | ||
@{ \ | ||
set -e ;\ | ||
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\ | ||
cd $$KUSTOMIZE_GEN_TMP_DIR ;\ | ||
go mod init tmp ;\ | ||
go install sigs.k8s.io/kustomize/kustomize/[email protected] ;\ | ||
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\ | ||
} | ||
KUSTOMIZE=$(GOBIN)/kustomize | ||
else | ||
KUSTOMIZE=$(shell which kustomize) | ||
endif | ||
|
||
# Generate bundle manifests and metadata, then validate generated files. | ||
.PHONY: bundle | ||
bundle: manifests | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters