From e180313fee7ae52ff2c1ef67a67ce764f74b5123 Mon Sep 17 00:00:00 2001 From: Edouard Schweisguth Date: Wed, 18 Feb 2026 11:43:49 +0100 Subject: [PATCH] Cleanup makefile --- .github/workflows/ci.yml | 24 +- Makefile | 403 ++++++++---------------------- scripts/install-controller-gen.sh | 18 ++ scripts/install-datadog-ci.sh | 11 + scripts/install-golangci-lint.sh | 17 ++ scripts/install-helm.sh | 26 ++ scripts/install-kubebuilder.sh | 19 ++ scripts/install-minikube.sh | 19 ++ scripts/install-mockery.sh | 26 ++ scripts/install-protobuf.sh | 27 ++ scripts/install-watchexec.sh | 12 + scripts/install-yamlfmt.sh | 23 ++ scripts/lima.sh | 190 ++++++++++++++ scripts/lima_start.sh | 18 -- scripts/run-tests.sh | 47 ++++ scripts/spellcheck.sh | 42 ++++ scripts/update-deps.sh | 8 + scripts/versions.env | 9 + 18 files changed, 599 insertions(+), 340 deletions(-) create mode 100755 scripts/install-controller-gen.sh create mode 100755 scripts/install-datadog-ci.sh create mode 100755 scripts/install-golangci-lint.sh create mode 100755 scripts/install-helm.sh create mode 100755 scripts/install-kubebuilder.sh create mode 100755 scripts/install-minikube.sh create mode 100755 scripts/install-mockery.sh create mode 100755 scripts/install-protobuf.sh create mode 100755 scripts/install-watchexec.sh create mode 100755 scripts/install-yamlfmt.sh create mode 100755 scripts/lima.sh delete mode 100755 scripts/lima_start.sh create mode 100755 scripts/run-tests.sh create mode 100755 scripts/spellcheck.sh create mode 100755 scripts/update-deps.sh create mode 100644 scripts/versions.env diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5136a38ec..64c00797d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: go-version-file: go.mod cache: true - name: Install lint tools - run: make install-golangci-lint install-controller-gen + run: make install-lint-tools - name: Format run: | make fmt @@ -49,7 +49,7 @@ jobs: with: policy: chaos-controller - name: Install tools - run: make -j4 install-controller-gen install-yamlfmt install-kubebuilder install-datadog-ci + run: make install-test-tools - name: Run unit tests run: make test GINKGO_PROCS=2 env: @@ -102,7 +102,7 @@ jobs: with: policy: chaos-controller - name: Install tools - run: make -j6 install-controller-gen install-yamlfmt install-helm install-kubebuilder install-datadog-ci + run: make install-e2e-tools - name: Download docker tarballs uses: actions/download-artifact@v4 with: @@ -160,27 +160,15 @@ jobs: go-version-file: go.mod cache: true - name: Install tools - run: make -j6 install-controller-gen install-yamlfmt install-mockery install-protobuf PROTOC_OS=linux + run: make install-generate-tools - name: Validate go dependencies run: | make godeps git diff --exit-code - - name: Validate manifests + - name: Validate code generation run: | - make manifests + make generate git diff --exit-code - - name: Validate mocks - run: | - make generate-mocks - git diff --exit-code - - name: Validate disruptionlistener protobuf - run: | - make generate-disruptionlistener-protobuf - git diff --exit-code ':!go.*' - - name: Validate chaosdogfood protobuf - run: | - make generate-chaosdogfood-protobuf - git diff --exit-code ':!go.*' python-checks: runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index 4b3b5db53..ca2dff6ce 100644 --- a/Makefile +++ b/Makefile @@ -1,30 +1,19 @@ .PHONY: * .SILENT: release +include scripts/versions.env + NOW_ISO8601 = $(shell date -u +"%Y-%m-%dT%H:%M:%S") GOOS = $(shell go env GOOS) GOARCH = $(shell go env GOARCH) -# change also github actions go build version "GO_VERSION:" if you change the version below -# https://github.com/DataDog/chaos-controller/blob/main/.github/workflows/ci.yml#L13 -BUILDGOVERSION = 1.25.6 - # GOBIN can be provided (gitlab), defined (custom user setup), or empty/guessed (default go setup) GOBIN ?= $(shell go env GOBIN) ifeq (,$(GOBIN)) GOBIN = $(shell go env GOPATH)/bin endif -INSTALL_DATADOG_AGENT = false -LIMA_INSTALL_SINK = noop -ifdef STAGING_DATADOG_API_KEY -ifdef STAGING_DATADOG_APP_KEY -INSTALL_DATADOG_AGENT = true -LIMA_INSTALL_SINK = datadog -endif -endif - # Lima requires to have images built on a specific namespace to be shared to the Kubernetes cluster when using containerd runtime # https://github.com/abiosoft/colima#interacting-with-image-registry CONTAINER_REGISTRY ?= k8s.io @@ -41,8 +30,6 @@ MANAGER_IMAGE ?= ${CONTAINER_REGISTRY}/chaos-controller INJECTOR_IMAGE ?= ${CONTAINER_REGISTRY}/chaos-injector HANDLER_IMAGE ?= ${CONTAINER_REGISTRY}/chaos-handler -LIMA_PROFILE ?= lima -LIMA_CONFIG ?= lima # default instance name will be connected user name LIMA_INSTANCE ?= $(shell whoami | tr "." "-") @@ -52,31 +39,8 @@ E2E_TEST_CLUSTER_NAME ?= lima-$(LIMA_INSTANCE) E2E_TEST_KUBECTL_CONTEXT ?= lima KUBECTL ?= limactl shell $(LIMA_INSTANCE) sudo kubectl -PROTOC_VERSION = 3.17.3 -PROTOC_OS ?= osx -PROTOC_ZIP = protoc-${PROTOC_VERSION}-${PROTOC_OS}-x86_64.zip -# you might also want to change ~/lima.yaml k3s version -KUBERNETES_MAJOR_VERSION ?= 1.28 -KUBERNETES_VERSION ?= v$(KUBERNETES_MAJOR_VERSION).0 -USE_VOLUMES ?= false HELM_VALUES ?= dev.yaml -HELM_VERSION = v3.19.0 -HELM_INSTALLED_VERSION = $(shell (helm version --template="{{ .Version }}" || echo "") | awk '{ print $$1 }') - -# TODO: reenable depguard in .golangci.yml after upgrading golangci-lint again -GOLANGCI_LINT_VERSION = 2.8.0 -GOLANGCI_LINT_INSTALLED_VERSION = $(shell (golangci-lint --version || echo "") | sed -E 's/.*version ([^ ]+).*/\1/') - -CONTROLLER_GEN_VERSION = v0.19.0 -CONTROLLER_GEN_INSTALLED_VERSION = $(shell (controller-gen --version || echo "") | awk '{ print $$2 }') - -MOCKERY_VERSION = 2.53.5 -MOCKERY_ARCH = $(GOARCH) -ifeq (amd64,$(GOARCH)) -MOCKERY_ARCH = x86_64 -endif -MOCKERY_INSTALLED_VERSION = $(shell mockery --version --quiet --config="" 2>/dev/null || echo "") # Additional args to provide to test runner (ginkgo) # examples: @@ -84,18 +48,6 @@ MOCKERY_INSTALLED_VERSION = $(shell mockery --version --quiet --config="" 2>/dev # `make test TEST_ARGS=injector` will focus on package injector to run tests TEST_ARGS ?= -DD_ENV = local -# https://circleci.com/docs/variables/ -# we rely on standard CI env var to adapt test upload configuration automatically -ifeq (true,$(CI)) -DD_ENV = ci -endif - -LIMA_CGROUPS=v1 -ifeq (v2,$(CGROUPS)) -LIMA_CGROUPS=v2 -endif - # Docker builds now happen entirely within Docker using multi-stage builds # All binaries (Go + EBPF) are built inside Docker - no local build steps required @@ -162,89 +114,41 @@ chaosli: # https://onsi.github.io/ginkgo/#recommended-continuous-integration-configuration GINKGO_PROCS ?= 4 -_ginkgo_test: -# Run the test and write a file if succeed -# Do not stop on any error - -go run github.com/onsi/ginkgo/v2/ginkgo --fail-on-pending --keep-going --vv \ - --cover --coverprofile=cover.profile --randomize-all \ - --race --trace --json-report=report-$(GO_TEST_REPORT_NAME).json --junit-report=report-$(GO_TEST_REPORT_NAME).xml \ - --compilers=$(GINKGO_PROCS) --procs=$(GINKGO_PROCS) \ - --poll-progress-after=10s --poll-progress-interval=10s \ - $(GINKGO_TEST_ARGS) \ - && touch report-$(GO_TEST_REPORT_NAME)-succeed -# Try upload test reports if allowed and necessary prerequisites exists -ifneq (true,$(GO_TEST_SKIP_UPLOAD)) # you can bypass test upload -ifdef DATADOG_API_KEY # if no API key bypass is guaranteed -ifneq (,$(shell which datadog-ci)) # same if no test binary - -DD_ENV=$(DD_ENV) datadog-ci junit upload --service chaos-controller --tags="team:chaos-engineering,type:$(GO_TEST_REPORT_NAME)" report-$(GO_TEST_REPORT_NAME).xml -else - @echo "datadog-ci binary is not installed, run 'make install-datadog-ci' to upload tests results to datadog" -endif -else - @echo "DATADOG_API_KEY env var is not defined, create a local API key https://app.datadoghq.com/personal-settings/application-keys if you want to upload your local tests results to datadog" -endif -else - @echo "datadog-ci junit upload SKIPPED" -endif -# Fail if succeed file does not exists - [ -f report-$(GO_TEST_REPORT_NAME)-succeed ] && rm -f report-$(GO_TEST_REPORT_NAME)-succeed || exit 1 - # Tests & CI ## Run unit tests -test: generate manifests +test: generate $(if $(GOPATH),,$(error GOPATH is not set. Please set GOPATH before running make test)) - $(MAKE) _ginkgo_test GO_TEST_REPORT_NAME=$@ \ - GINKGO_TEST_ARGS="-r --skip-package=controllers --randomize-suites --timeout=10m $(TEST_ARGS)" - -spellcheck-deps: -ifeq (, $(shell which npm)) - @{\ - echo "please install npm or run 'make spellcheck-docker' for a slow but platform-agnistic run" ;\ - exit 1 ;\ - } -endif -ifeq (, $(shell which mdspell)) - @{\ - echo "installing mdspell through npm -g... (might require sudo run)" ;\ - npm -g i markdown-spellcheck ;\ - } -endif + GO_TEST_REPORT_NAME=$@ GINKGO_PROCS=$(GINKGO_PROCS) \ + GINKGO_TEST_ARGS="-r --skip-package=controllers --randomize-suites --timeout=10m $(TEST_ARGS)" \ + ./scripts/run-tests.sh -spellcheck: spellcheck-deps - mdspell --en-us --ignore-acronyms --ignore-numbers \ - $(shell find . -name vendor -prune -o -name '*.md' -print); +spellcheck: + ./scripts/spellcheck.sh check -spellcheck-report: spellcheck-deps - mdspell --en-us --ignore-acronyms --ignore-numbers --report \ - $(shell find . -name vendor -prune -o -name '*.md' -print); +spellcheck-report: + ./scripts/spellcheck.sh report spellcheck-docker: - docker run --rm -ti -v $(shell pwd):/workdir tmaier/markdown-spellcheck:latest --ignore-numbers --ignore-acronyms --en-us \ - $(shell find . -name vendor -prune -o -name '*.md' -print); + ./scripts/spellcheck.sh docker spellcheck-format-spelling: - sort < .spelling | sort | uniq | grep -v '^-' | tee .spelling.tmp > /dev/null && mv .spelling.tmp .spelling - -## This target is dedicated for CI and aims to reuse the Kubernetes version defined here as the source of truth -MINIKUBE_CPUS ?= 6 -MINIKUBE_MEMORY ?= 28672 + ./scripts/spellcheck.sh format-spelling ci-install-minikube: - curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb - sudo dpkg -i minikube_latest_amd64.deb - minikube start --cpus='$(MINIKUBE_CPUS)' --memory='$(MINIKUBE_MEMORY)' --vm-driver=docker --container-runtime=containerd --kubernetes-version=${KUBERNETES_VERSION} - minikube status + MINIKUBE_CPUS="$(MINIKUBE_CPUS)" MINIKUBE_MEMORY="$(MINIKUBE_MEMORY)" ./scripts/install-minikube.sh SKIP_DEPLOY ?= ## Run e2e tests (against a real cluster) -## to run them locally you first need to run `make install-kubebuilder` -e2e-test: generate manifests +## to run them locally you first need to run `make install-dev-tools` +e2e-test: generate ifneq (true,$(SKIP_DEPLOY)) # we can only wait for a controller if it exists, local.yaml does not deploy the controller $(MAKE) lima-install HELM_VALUES=ci.yaml endif - E2E_TEST_CLUSTER_NAME=$(E2E_TEST_CLUSTER_NAME) E2E_TEST_KUBECTL_CONTEXT=$(E2E_TEST_KUBECTL_CONTEXT) $(MAKE) _ginkgo_test GO_TEST_REPORT_NAME=$@ \ - GINKGO_TEST_ARGS="--flake-attempts=3 --timeout=25m controllers" + GO_TEST_REPORT_NAME=$@ GINKGO_PROCS=$(GINKGO_PROCS) \ + E2E_TEST_CLUSTER_NAME=$(E2E_TEST_CLUSTER_NAME) E2E_TEST_KUBECTL_CONTEXT=$(E2E_TEST_KUBECTL_CONTEXT) \ + GINKGO_TEST_ARGS="--flake-attempts=3 --timeout=25m controllers" \ + ./scripts/run-tests.sh # Test chaosli API portability chaosli-test: @@ -252,7 +156,9 @@ chaosli-test: # Go actions ## Generate manifests e.g. CRD, RBAC etc. -manifests: install-controller-gen install-yamlfmt +manifests: + ./scripts/install-controller-gen.sh + ./scripts/install-yamlfmt.sh controller-gen rbac:roleName=chaos-controller crd:crdVersions=v1 paths="./..." output:crd:dir=./chart/templates/generated/ output:rbac:dir=./chart/templates/generated/ # ensure generated files stays formatted as expected yamlfmt chart/templates/generated @@ -266,15 +172,29 @@ vet: go vet ./... ## Run golangci-lint against code -lint: install-golangci-lint +lint: + ./scripts/install-golangci-lint.sh # By using GOOS=linux we aim to validate files as if we were on linux # you can use a similar trick with gopls to have vs-code linting your linux platform files instead of darwin GOOS=linux golangci-lint run -E ginkgolinter ./... GOOS=linux golangci-lint run -## Generate code -generate: install-controller-gen +## Generate all code (CRDs, RBAC, DeepCopy, mocks, protobuf, headers) +generate: + ./scripts/install-controller-gen.sh + ./scripts/install-yamlfmt.sh + ./scripts/install-mockery.sh + ./scripts/install-protobuf.sh controller-gen object:headerFile=./hack/boilerplate.go.txt paths="./..." + controller-gen rbac:roleName=chaos-controller crd:crdVersions=v1 paths="./..." output:crd:dir=./chart/templates/generated/ output:rbac:dir=./chart/templates/generated/ + yamlfmt chart/templates/generated + $(MAKE) clean-mocks + go generate ./... + cd grpc/disruptionlistener && \ + protoc --proto_path=. --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative disruptionlistener.proto + cd dogfood/chaosdogfood && \ + protoc --proto_path=. --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative chaosdogfood.proto + $(MAKE) header-fix # Lima actions ## Create a new lima cluster and deploy the chaos-controller into it @@ -284,75 +204,36 @@ lima-all: lima-start lima-install-datadog-agent lima-install-cert-manager lima-p ## Rebuild the chaos-controller images, re-install the chart and restart the chaos-controller pods lima-redeploy: lima-push-all lima-install lima-restart -## Install cert-manager chart -lima-install-cert-manager: - $(KUBECTL) apply -f https://github.com/jetstack/cert-manager/releases/download/v1.9.1/cert-manager.yaml - $(KUBECTL) -n cert-manager rollout status deployment/cert-manager-webhook --timeout=180s +lima-start: + ./scripts/lima.sh start + +lima-stop: + ./scripts/lima.sh stop + +lima-kubectx-clean: + ./scripts/lima.sh kubectx-clean + +lima-kubectx: + ./scripts/lima.sh kubectx -lima-install-demo: - $(KUBECTL) apply -f - < ./examples/namespace.yaml - $(KUBECTL) apply -f - < ./examples/demo.yaml - $(KUBECTL) -n chaos-demo rollout status deployment/demo-curl --timeout=60s - $(KUBECTL) -n chaos-demo rollout status deployment/demo-nginx --timeout=60s - -## Install CRDs and controller into a lima k3s cluster -## In order to use already built images inside the containerd runtime -## we override images for all of our components to the expected namespace lima-install: manifests - helm template \ - --set=controller.version=$(CONTAINER_VERSION) \ - --set=controller.metricsSink=$(LIMA_INSTALL_SINK) \ - --set=controller.profilerSink=$(LIMA_INSTALL_SINK) \ - --set=controller.tracerSink=$(LIMA_INSTALL_SINK) \ - --values ./chart/values/$(HELM_VALUES) \ - ./chart | $(KUBECTL) apply -f - -ifneq (local.yaml,$(HELM_VALUES)) # we can only wait for a controller if it exists, local.yaml does not deploy the controller - $(KUBECTL) -n chaos-engineering rollout status deployment/chaos-controller --timeout=60s -endif + KUBECTL="$(KUBECTL)" HELM_VALUES="$(HELM_VALUES)" CONTAINER_VERSION="$(CONTAINER_VERSION)" \ + ./scripts/lima.sh install -## Uninstall CRDs and controller from a lima k3s cluster lima-uninstall: - helm template --set=skipNamespace=true --values ./chart/values/$(HELM_VALUES) ./chart | $(KUBECTL) delete -f - + KUBECTL="$(KUBECTL)" HELM_VALUES="$(HELM_VALUES)" ./scripts/lima.sh uninstall -## Restart the chaos-controller pod lima-restart: -ifneq (local.yaml,$(HELM_VALUES)) # we can only wait for a controller if it exists, local.yaml does not deploy the controller - $(KUBECTL) -n chaos-engineering rollout restart deployment/chaos-controller - $(KUBECTL) -n chaos-engineering rollout status deployment/chaos-controller --timeout=60s -endif + KUBECTL="$(KUBECTL)" HELM_VALUES="$(HELM_VALUES)" ./scripts/lima.sh restart -## Remove lima references from kubectl config -lima-kubectx-clean: - -kubectl config delete-cluster ${LIMA_PROFILE} - -kubectl config delete-context ${LIMA_PROFILE} - -kubectl config delete-user ${LIMA_PROFILE} - kubectl config unset current-context +lima-install-cert-manager: + KUBECTL="$(KUBECTL)" ./scripts/lima.sh install-cert-manager + +lima-install-demo: + KUBECTL="$(KUBECTL)" ./scripts/lima.sh install-demo -lima-kubectx: - limactl shell $(LIMA_INSTANCE) sudo sed 's/default/lima/g' /etc/rancher/k3s/k3s.yaml > ~/.kube/config_lima - KUBECONFIG=${KUBECONFIG}:~/.kube/config:~/.kube/config_lima kubectl config view --flatten > /tmp/config - rm ~/.kube/config_lima - mv /tmp/config ~/.kube/config - chmod 600 ~/.kube/config - kubectx ${LIMA_PROFILE} - -## Stop and delete the lima cluster -lima-stop: - limactl stop -f $(LIMA_INSTANCE) - limactl delete $(LIMA_INSTANCE) - $(MAKE) lima-kubectx-clean - -## Start the lima cluster, pre-cleaning kubectl config -lima-start: lima-kubectx-clean - LIMA_CGROUPS=${LIMA_CGROUPS} LIMA_CONFIG=${LIMA_CONFIG} LIMA_INSTANCE=${LIMA_INSTANCE} ./scripts/lima_start.sh - $(MAKE) lima-kubectx - -# Longhorn is used as an alternative StorageClass in order to enable "reliable" disk throttling accross various local setup -# It aims to bypass some issues encountered with default StorageClass (local-path --> tmpfs) that led to virtual unnamed devices -# unnamed devices are linked to 0 as a major device identifier, that blkio does not support -# https://super-unix.com/unixlinux/can-you-throttle-the-bandwidth-to-a-tmpfs-based-ramdisk/ lima-install-longhorn: - $(KUBECTL) apply -f https://raw.githubusercontent.com/longhorn/longhorn/v1.4.0/deploy/longhorn.yaml + KUBECTL="$(KUBECTL)" ./scripts/lima.sh install-longhorn # CI-specific actions @@ -376,48 +257,19 @@ godeps: go mod tidy; go mod vendor update-deps: - @echo "Updating Python dependencies..." - @pip install -q uv - @uv pip compile --python-platform linux tasks/requirements.in -o tasks/requirements.txt - @echo "Updated tasks/requirements.txt" - @echo "Please commit both tasks/requirements.in and tasks/requirements.txt" + ./scripts/update-deps.sh deps: godeps license -generate-disruptionlistener-protobuf: - cd grpc/disruptionlistener && \ - go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.27.1 && \ - go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1.0 && \ - protoc --proto_path=. --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative disruptionlistener.proto - -generate-chaosdogfood-protobuf: - cd dogfood/chaosdogfood && \ - go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.27.1 && \ - go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1.0 && \ - protoc --proto_path=. --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative chaosdogfood.proto - clean-mocks: find . -type f -name "*mock*.go" -not -path "./vendor/*" -exec rm {} \; rm -rf mocks/ -generate-mocks: clean-mocks install-mockery - go generate ./... - $(MAKE) header-fix - release: VERSION=$(VERSION) ./tasks/release.sh -_pre_local: generate manifests - @$(shell $(KUBECTL) get deploy chaos-controller 2> /dev/null) -ifeq (0,$(.SHELLSTATUS)) -# uninstall using a non local value to ensure deployment is deleted - -$(MAKE) lima-uninstall HELM_VALUES=dev.yaml - $(MAKE) lima-install HELM_VALUES=local.yaml - $(KUBECTL) -n chaos-engineering get cm chaos-controller -oyaml | yq '.data["config.yaml"]' > .local.yaml - yq -i '.controller.webhook.certDir = "chart/certs"' .local.yaml -else - @echo "Chaos controller is not installed, skipped!" -endif +_pre_local: generate + KUBECTL="$(KUBECTL)" HELM_VALUES="$(HELM_VALUES)" ./scripts/lima.sh pre-local debug: _pre_local @echo "now you can launch through vs-code or your favorite IDE a controller in debug with appropriate configuration (--config=chart/values/local.yaml + CONTROLLER_NODE_NAME=local)" @@ -428,105 +280,48 @@ run: watch: _pre_local install-watchexec watchexec make SKIP_EBPF=true lima-push-injector run -install-protobuf: - curl -sSLo /tmp/${PROTOC_ZIP} https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/${PROTOC_ZIP} - unzip -o /tmp/${PROTOC_ZIP} -d ${GOPATH} bin/protoc - unzip -o /tmp/${PROTOC_ZIP} -d ${GOPATH} 'include/*' - rm -f /tmp/${PROTOC_ZIP} - -install-golangci-lint: -ifneq ($(GOLANGCI_LINT_VERSION),$(GOLANGCI_LINT_INSTALLED_VERSION)) - $(info golangci-lint version $(GOLANGCI_LINT_VERSION) is not installed or version differ ($(GOLANGCI_LINT_VERSION) != $(GOLANGCI_LINT_INSTALLED_VERSION))) - $(info installing golangci-lint v$(GOLANGCI_LINT_VERSION)...) - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v$(GOLANGCI_LINT_VERSION) -endif - -install-kubebuilder: -# download kubebuilder and install locally. - curl -sSLo $(GOBIN)/kubebuilder https://go.kubebuilder.io/dl/latest/$(GOOS)/$(GOARCH) - chmod u+x $(GOBIN)/kubebuilder -# download setup-envtest and install related binaries locally - go install -v sigs.k8s.io/controller-runtime/tools/setup-envtest@latest -# setup-envtest use -p path $(KUBERNETES_MAJOR_VERSION).x - -install-helm: -ifneq ($(HELM_INSTALLED_VERSION),$(HELM_VERSION)) - $(info helm version $(HELM_VERSION) is not installed or version differ ($(HELM_VERSION) != $(HELM_INSTALLED_VERSION))) - $(info installing helm $(HELM_VERSION)...) - curl -sSLo /tmp/helm.tar.gz "https://get.helm.sh/helm-$(HELM_VERSION)-$(GOOS)-$(GOARCH).tar.gz" - tar -xvzf /tmp/helm.tar.gz --directory=$(GOBIN) --strip-components=1 $(GOOS)-$(GOARCH)/helm - rm /tmp/helm.tar.gz -endif - -# install controller-gen expected version -install-controller-gen: -ifneq ($(CONTROLLER_GEN_INSTALLED_VERSION),$(CONTROLLER_GEN_VERSION)) - $(info controller-gen version $(CONTROLLER_GEN_VERSION) is not installed or version differ ($(CONTROLLER_GEN_VERSION) != $(CONTROLLER_GEN_INSTALLED_VERSION))) - $(info installing controller-gen $(CONTROLLER_GEN_VERSION)...) - @{ \ - set -e ;\ - CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\ - cd $$CONTROLLER_GEN_TMP_DIR ;\ - go mod init tmp ;\ - CGO_ENABLED=0 go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION) ;\ - rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ - } -endif - -install-datadog-ci: - curl -L --fail "https://github.com/DataDog/datadog-ci/releases/latest/download/datadog-ci_$(GOOS)-x64" --output "$(GOBIN)/datadog-ci" && chmod u+x $(GOBIN)/datadog-ci - -install-mockery: -# recommended way to install mockery is through their released binaries, NOT go install... -# https://vektra.github.io/mockery/installation/#github-release -ifneq ($(MOCKERY_INSTALLED_VERSION),v$(MOCKERY_VERSION)) - $(info mockery version $(MOCKERY_VERSION) is not installed or version differ (v$(MOCKERY_VERSION) != $(MOCKERY_INSTALLED_VERSION))) - $(info installing mockery v$(MOCKERY_VERSION)...) - curl -sSLo /tmp/mockery.tar.gz https://github.com/vektra/mockery/releases/download/v$(MOCKERY_VERSION)/mockery_$(MOCKERY_VERSION)_$(GOOS)_$(MOCKERY_ARCH).tar.gz - tar -xvzf /tmp/mockery.tar.gz --directory=$(GOBIN) mockery - rm /tmp/mockery.tar.gz -endif - -YAMLFMT_ARCH = $(GOARCH) -ifeq (amd64,$(GOARCH)) -YAMLFMT_ARCH = x86_64 -endif - -install-yamlfmt: -ifeq (,$(wildcard $(GOBIN)/yamlfmt)) - $(info installing yamlfmt...) - curl -sSLo /tmp/yamlfmt.tar.gz https://github.com/google/yamlfmt/releases/download/v0.9.0/yamlfmt_0.9.0_$(GOOS)_$(YAMLFMT_ARCH).tar.gz - tar -xvzf /tmp/yamlfmt.tar.gz --directory=$(GOBIN) yamlfmt - rm /tmp/yamlfmt.tar.gz -endif - install-watchexec: -ifeq (,$(wildcard $(GOBIN)/watchexec)) - $(info installing watchexec...) - brew install watchexec -endif + ./scripts/install-watchexec.sh install-go: BUILDGOVERSION=$(BUILDGOVERSION) ./scripts/install-go -EXISTING_NAMESPACE = $(shell $(KUBECTL) get ns datadog-agent -oname || echo "") +# Grouped tool installation targets +install-lint-tools: + ./scripts/install-golangci-lint.sh + ./scripts/install-controller-gen.sh + +install-test-tools: + ./scripts/install-controller-gen.sh + ./scripts/install-yamlfmt.sh + ./scripts/install-kubebuilder.sh + ./scripts/install-datadog-ci.sh + +install-generate-tools: + ./scripts/install-controller-gen.sh + ./scripts/install-yamlfmt.sh + ./scripts/install-mockery.sh + ./scripts/install-protobuf.sh + +install-e2e-tools: + ./scripts/install-controller-gen.sh + ./scripts/install-yamlfmt.sh + ./scripts/install-helm.sh + ./scripts/install-kubebuilder.sh + ./scripts/install-datadog-ci.sh + +install-dev-tools: + ./scripts/install-golangci-lint.sh + ./scripts/install-controller-gen.sh + ./scripts/install-mockery.sh + ./scripts/install-yamlfmt.sh + ./scripts/install-protobuf.sh + ./scripts/install-kubebuilder.sh + ./scripts/install-helm.sh + ./scripts/install-datadog-ci.sh lima-install-datadog-agent: -ifeq (true,$(INSTALL_DATADOG_AGENT)) -ifeq (,$(EXISTING_NAMESPACE)) - $(KUBECTL) create ns datadog-agent - helm repo add --force-update datadoghq https://helm.datadoghq.com - helm install -n datadog-agent my-datadog-operator datadoghq/datadog-operator - $(KUBECTL) create secret -n datadog-agent generic datadog-secret --from-literal api-key=${STAGING_DATADOG_API_KEY} --from-literal app-key=${STAGING_DATADOG_APP_KEY} -endif - $(KUBECTL) apply -f - < examples/datadog-agent.yaml -endif + KUBECTL="$(KUBECTL)" ./scripts/lima.sh install-datadog-agent open-dd: -ifeq (true,$(INSTALL_DATADOG_AGENT)) -ifdef STAGING_DD_SITE - open "${STAGING_DD_SITE}/infrastructure?host=lima-$(LIMA_INSTANCE)&tab=details" -else - @echo "You need to define STAGING_DD_SITE in your .zshrc or similar to use this feature" -endif -endif + ./scripts/lima.sh open-dd diff --git a/scripts/install-controller-gen.sh b/scripts/install-controller-gen.sh new file mode 100755 index 000000000..572877d12 --- /dev/null +++ b/scripts/install-controller-gen.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -euo pipefail +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${SCRIPT_DIR}/versions.env" + +if command -v controller-gen &>/dev/null; then + INSTALLED=$(controller-gen --version 2>/dev/null | awk '{ print $2 }' || echo "") + if [ "$INSTALLED" = "$CONTROLLER_GEN_VERSION" ]; then + exit 0 + fi +fi + +echo "Installing controller-gen ${CONTROLLER_GEN_VERSION}..." +TMP_DIR=$(mktemp -d) +cd "$TMP_DIR" +go mod init tmp +CGO_ENABLED=0 go install "sigs.k8s.io/controller-tools/cmd/controller-gen@${CONTROLLER_GEN_VERSION}" +rm -rf "$TMP_DIR" diff --git a/scripts/install-datadog-ci.sh b/scripts/install-datadog-ci.sh new file mode 100755 index 000000000..deaf8efec --- /dev/null +++ b/scripts/install-datadog-ci.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -euo pipefail + +GOBIN="${GOBIN:-$(go env GOBIN)}" +GOBIN="${GOBIN:-$(go env GOPATH)/bin}" + +OS=$(uname -s | tr '[:upper:]' '[:lower:]') + +echo "Installing datadog-ci..." +curl -L --fail "https://github.com/DataDog/datadog-ci/releases/latest/download/datadog-ci_${OS}-x64" --output "$GOBIN/datadog-ci" +chmod u+x "$GOBIN/datadog-ci" diff --git a/scripts/install-golangci-lint.sh b/scripts/install-golangci-lint.sh new file mode 100755 index 000000000..fccc589b2 --- /dev/null +++ b/scripts/install-golangci-lint.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -euo pipefail +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${SCRIPT_DIR}/versions.env" + +GOBIN="${GOBIN:-$(go env GOBIN)}" +GOBIN="${GOBIN:-$(go env GOPATH)/bin}" + +if command -v golangci-lint &>/dev/null; then + INSTALLED=$(golangci-lint --version 2>/dev/null | sed -E 's/.*version ([^ ]+).*/\1/' || echo "") + if [ "$INSTALLED" = "$GOLANGCI_LINT_VERSION" ]; then + exit 0 + fi +fi + +echo "Installing golangci-lint v${GOLANGCI_LINT_VERSION}..." +curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$GOBIN" "v${GOLANGCI_LINT_VERSION}" diff --git a/scripts/install-helm.sh b/scripts/install-helm.sh new file mode 100755 index 000000000..e9a98ce7c --- /dev/null +++ b/scripts/install-helm.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -euo pipefail +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${SCRIPT_DIR}/versions.env" + +GOBIN="${GOBIN:-$(go env GOBIN)}" +GOBIN="${GOBIN:-$(go env GOPATH)/bin}" + +if command -v helm &>/dev/null; then + INSTALLED=$(helm version --template="{{ .Version }}" 2>/dev/null | awk '{ print $1 }' || echo "") + if [ "$INSTALLED" = "$HELM_VERSION" ]; then + exit 0 + fi +fi + +OS=$(uname -s | tr '[:upper:]' '[:lower:]') +ARCH=$(uname -m) +case "$ARCH" in + x86_64) ARCH="amd64" ;; + aarch64|arm64) ARCH="arm64" ;; +esac + +echo "Installing helm ${HELM_VERSION}..." +curl -sSLo /tmp/helm.tar.gz "https://get.helm.sh/helm-${HELM_VERSION}-${OS}-${ARCH}.tar.gz" +tar -xzf /tmp/helm.tar.gz --directory="$GOBIN" --strip-components=1 "${OS}-${ARCH}/helm" +rm /tmp/helm.tar.gz diff --git a/scripts/install-kubebuilder.sh b/scripts/install-kubebuilder.sh new file mode 100755 index 000000000..db725fdff --- /dev/null +++ b/scripts/install-kubebuilder.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -euo pipefail + +GOBIN="${GOBIN:-$(go env GOBIN)}" +GOBIN="${GOBIN:-$(go env GOPATH)/bin}" + +OS=$(uname -s | tr '[:upper:]' '[:lower:]') +ARCH=$(uname -m) +case "$ARCH" in + x86_64) ARCH="amd64" ;; + aarch64|arm64) ARCH="arm64" ;; +esac + +echo "Installing kubebuilder..." +curl -sSLo "$GOBIN/kubebuilder" "https://go.kubebuilder.io/dl/latest/${OS}/${ARCH}" +chmod u+x "$GOBIN/kubebuilder" + +echo "Installing setup-envtest..." +go install -v sigs.k8s.io/controller-runtime/tools/setup-envtest@latest diff --git a/scripts/install-minikube.sh b/scripts/install-minikube.sh new file mode 100755 index 000000000..a38d8256b --- /dev/null +++ b/scripts/install-minikube.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -euo pipefail +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${SCRIPT_DIR}/versions.env" + +MINIKUBE_CPUS="${MINIKUBE_CPUS:-6}" +MINIKUBE_MEMORY="${MINIKUBE_MEMORY:-28672}" +KUBERNETES_MAJOR_VERSION="${KUBERNETES_MAJOR_VERSION:-1.28}" +KUBERNETES_VERSION="${KUBERNETES_VERSION:-v${KUBERNETES_MAJOR_VERSION}.0}" + +curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb +sudo dpkg -i minikube_latest_amd64.deb +minikube start \ + --cpus="${MINIKUBE_CPUS}" \ + --memory="${MINIKUBE_MEMORY}" \ + --vm-driver=docker \ + --container-runtime=containerd \ + --kubernetes-version="${KUBERNETES_VERSION}" +minikube status diff --git a/scripts/install-mockery.sh b/scripts/install-mockery.sh new file mode 100755 index 000000000..259512af1 --- /dev/null +++ b/scripts/install-mockery.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -euo pipefail +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${SCRIPT_DIR}/versions.env" + +GOBIN="${GOBIN:-$(go env GOBIN)}" +GOBIN="${GOBIN:-$(go env GOPATH)/bin}" + +if command -v mockery &>/dev/null; then + INSTALLED=$(mockery --version --quiet --config="" 2>/dev/null || echo "") + if [ "$INSTALLED" = "v${MOCKERY_VERSION}" ]; then + exit 0 + fi +fi + +OS=$(uname -s | tr '[:upper:]' '[:lower:]') +ARCH=$(uname -m) +case "$ARCH" in + x86_64) ARCH="x86_64" ;; + aarch64|arm64) ARCH="arm64" ;; +esac + +echo "Installing mockery v${MOCKERY_VERSION}..." +curl -sSLo /tmp/mockery.tar.gz "https://github.com/vektra/mockery/releases/download/v${MOCKERY_VERSION}/mockery_${MOCKERY_VERSION}_${OS}_${ARCH}.tar.gz" +tar -xzf /tmp/mockery.tar.gz --directory="$GOBIN" mockery +rm /tmp/mockery.tar.gz diff --git a/scripts/install-protobuf.sh b/scripts/install-protobuf.sh new file mode 100755 index 000000000..c500c04aa --- /dev/null +++ b/scripts/install-protobuf.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +set -euo pipefail +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${SCRIPT_DIR}/versions.env" + +GOPATH="${GOPATH:-$(go env GOPATH)}" + +OS=$(uname -s | tr '[:upper:]' '[:lower:]') +case "$OS" in + darwin) PROTOC_OS="osx" ;; + linux) PROTOC_OS="linux" ;; + *) echo "Unsupported OS: $OS"; exit 1 ;; +esac + +PROTOC_ZIP="protoc-${PROTOC_VERSION}-${PROTOC_OS}-x86_64.zip" + +echo "Installing protoc ${PROTOC_VERSION}..." +curl -sSLo "/tmp/${PROTOC_ZIP}" "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/${PROTOC_ZIP}" +unzip -o "/tmp/${PROTOC_ZIP}" -d "$GOPATH" bin/protoc +unzip -o "/tmp/${PROTOC_ZIP}" -d "$GOPATH" 'include/*' +rm -f "/tmp/${PROTOC_ZIP}" + +echo "Installing protoc-gen-go ${PROTOC_GEN_GO_VERSION}..." +go install "google.golang.org/protobuf/cmd/protoc-gen-go@${PROTOC_GEN_GO_VERSION}" + +echo "Installing protoc-gen-go-grpc ${PROTOC_GEN_GO_GRPC_VERSION}..." +go install "google.golang.org/grpc/cmd/protoc-gen-go-grpc@${PROTOC_GEN_GO_GRPC_VERSION}" diff --git a/scripts/install-watchexec.sh b/scripts/install-watchexec.sh new file mode 100755 index 000000000..e9ff971cc --- /dev/null +++ b/scripts/install-watchexec.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail + +GOBIN="${GOBIN:-$(go env GOBIN)}" +GOBIN="${GOBIN:-$(go env GOPATH)/bin}" + +if [ -f "${GOBIN}/watchexec" ] || command -v watchexec &>/dev/null; then + exit 0 +fi + +echo "Installing watchexec..." +brew install watchexec diff --git a/scripts/install-yamlfmt.sh b/scripts/install-yamlfmt.sh new file mode 100755 index 000000000..af3dd7745 --- /dev/null +++ b/scripts/install-yamlfmt.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -euo pipefail +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${SCRIPT_DIR}/versions.env" + +GOBIN="${GOBIN:-$(go env GOBIN)}" +GOBIN="${GOBIN:-$(go env GOPATH)/bin}" + +if [ -x "$GOBIN/yamlfmt" ]; then + exit 0 +fi + +OS=$(uname -s | tr '[:upper:]' '[:lower:]') +ARCH=$(uname -m) +case "$ARCH" in + x86_64) ARCH="x86_64" ;; + aarch64|arm64) ARCH="arm64" ;; +esac + +echo "Installing yamlfmt v${YAMLFMT_VERSION}..." +curl -sSLo /tmp/yamlfmt.tar.gz "https://github.com/google/yamlfmt/releases/download/v${YAMLFMT_VERSION}/yamlfmt_${YAMLFMT_VERSION}_${OS}_${ARCH}.tar.gz" +tar -xzf /tmp/yamlfmt.tar.gz --directory="$GOBIN" yamlfmt +rm /tmp/yamlfmt.tar.gz diff --git a/scripts/lima.sh b/scripts/lima.sh new file mode 100755 index 000000000..50c2153cf --- /dev/null +++ b/scripts/lima.sh @@ -0,0 +1,190 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Default configuration — all overridable via env vars +LIMA_INSTANCE="${LIMA_INSTANCE:-$(whoami | tr '.' '-')}" +LIMA_PROFILE="${LIMA_PROFILE:-lima}" +LIMA_CONFIG="${LIMA_CONFIG:-lima}" +LIMA_CGROUPS="${LIMA_CGROUPS:-v1}" +KUBECTL="${KUBECTL:-limactl shell ${LIMA_INSTANCE} sudo kubectl}" +HELM_VALUES="${HELM_VALUES:-dev.yaml}" +CONTAINER_VERSION="${CONTAINER_VERSION:-$(git rev-parse HEAD)$(git diff --quiet || echo '-dirty')}" +STAGING_DATADOG_API_KEY="${STAGING_DATADOG_API_KEY:-}" +STAGING_DATADOG_APP_KEY="${STAGING_DATADOG_APP_KEY:-}" +STAGING_DD_SITE="${STAGING_DD_SITE:-}" + +# KUBECTL wrapper using array splitting (avoids eval) +kctl() { + local -a cmd + read -ra cmd <<< "$KUBECTL" + "${cmd[@]}" "$@" +} + +# Determine if datadog agent should be installed +install_datadog_agent() { + [ -n "$STAGING_DATADOG_API_KEY" ] && [ -n "$STAGING_DATADOG_APP_KEY" ] +} + +# Determine metrics/profiler/tracer sink +get_sink() { + if install_datadog_agent; then + echo "datadog" + else + echo "noop" + fi +} + +cmd_start() { + cmd_kubectx_clean + + # Start the lima instance + limactl start --tty=false --name="${LIMA_INSTANCE}" - <"./${LIMA_CONFIG}.yaml" + + # For cgroups v1, reconfigure grub and restart the instance + if [ "${LIMA_CGROUPS}" = "v1" ]; then + echo "Reconfiguring lima instance with cgroups v1" + limactl shell "${LIMA_INSTANCE}" sudo sed -i 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="systemd.unified_cgroup_hierarchy=0"/' /etc/default/grub + limactl shell "${LIMA_INSTANCE}" sudo update-grub + limactl shell "${LIMA_INSTANCE}" sudo reboot + echo "Waiting for instance to reboot, it might take a while" + sleep 10 + limactl stop "${LIMA_INSTANCE}" + limactl start "${LIMA_INSTANCE}" + fi + + cmd_kubectx +} + +cmd_stop() { + limactl stop -f "${LIMA_INSTANCE}" + limactl delete "${LIMA_INSTANCE}" + cmd_kubectx_clean +} + +cmd_kubectx_clean() { + kubectl config delete-cluster "${LIMA_PROFILE}" 2>/dev/null || true + kubectl config delete-context "${LIMA_PROFILE}" 2>/dev/null || true + kubectl config delete-user "${LIMA_PROFILE}" 2>/dev/null || true + kubectl config unset current-context +} + +cmd_kubectx() { + limactl shell "${LIMA_INSTANCE}" sudo sed 's/default/lima/g' /etc/rancher/k3s/k3s.yaml > ~/.kube/config_lima + KUBECONFIG="${KUBECONFIG:-}:~/.kube/config:~/.kube/config_lima" kubectl config view --flatten > /tmp/config + rm ~/.kube/config_lima + mv /tmp/config ~/.kube/config + chmod 600 ~/.kube/config + kubectx "${LIMA_PROFILE}" +} + +cmd_install() { + local sink + sink="$(get_sink)" + + helm template \ + --set="controller.version=${CONTAINER_VERSION}" \ + --set="controller.metricsSink=${sink}" \ + --set="controller.profilerSink=${sink}" \ + --set="controller.tracerSink=${sink}" \ + --values "./chart/values/${HELM_VALUES}" \ + ./chart | kctl apply -f - + + # We can only wait for a controller if it exists, local.yaml does not deploy the controller + if [ "${HELM_VALUES}" != "local.yaml" ]; then + kctl -n chaos-engineering rollout status deployment/chaos-controller --timeout=60s + fi +} + +cmd_uninstall() { + helm template --set=skipNamespace=true --values "./chart/values/${HELM_VALUES}" ./chart | kctl delete -f - +} + +cmd_restart() { + # We can only restart a controller if it exists, local.yaml does not deploy the controller + if [ "${HELM_VALUES}" != "local.yaml" ]; then + kctl -n chaos-engineering rollout restart deployment/chaos-controller + kctl -n chaos-engineering rollout status deployment/chaos-controller --timeout=60s + fi +} + +cmd_install_cert_manager() { + kctl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.9.1/cert-manager.yaml + kctl -n cert-manager rollout status deployment/cert-manager-webhook --timeout=180s +} + +cmd_install_demo() { + kctl apply -f - < ./examples/namespace.yaml + kctl apply -f - < ./examples/demo.yaml + kctl -n chaos-demo rollout status deployment/demo-curl --timeout=60s + kctl -n chaos-demo rollout status deployment/demo-nginx --timeout=60s +} + +cmd_install_datadog_agent() { + if ! install_datadog_agent; then + return 0 + fi + + # Create namespace if it doesn't already exist + if ! kctl get ns datadog-agent &>/dev/null; then + kctl create ns datadog-agent + helm repo add --force-update datadoghq https://helm.datadoghq.com + helm install -n datadog-agent my-datadog-operator datadoghq/datadog-operator + kctl create secret -n datadog-agent generic datadog-secret \ + --from-literal "api-key=${STAGING_DATADOG_API_KEY}" \ + --from-literal "app-key=${STAGING_DATADOG_APP_KEY}" + fi + kctl apply -f - < examples/datadog-agent.yaml +} + +cmd_install_longhorn() { + kctl apply -f https://raw.githubusercontent.com/longhorn/longhorn/v1.4.0/deploy/longhorn.yaml +} + +cmd_pre_local() { + if kctl get deploy chaos-controller -n chaos-engineering &>/dev/null; then + # Uninstall using a non local value to ensure deployment is deleted + (HELM_VALUES=dev.yaml; cmd_uninstall) || true + (HELM_VALUES=local.yaml; cmd_install) + kctl -n chaos-engineering get cm chaos-controller -oyaml | yq '.data["config.yaml"]' > .local.yaml + yq -i '.controller.webhook.certDir = "chart/certs"' .local.yaml + else + echo "Chaos controller is not installed, skipped!" + fi +} + +cmd_open_dd() { + if ! install_datadog_agent; then + return 0 + fi + + if [ -z "${STAGING_DD_SITE}" ]; then + echo "You need to define STAGING_DD_SITE in your .zshrc or similar to use this feature" + return 0 + fi + + open "${STAGING_DD_SITE}/infrastructure?host=lima-${LIMA_INSTANCE}&tab=details" +} + +# Main dispatch +cmd="${1:-}" +shift || true + +case "$cmd" in + start) cmd_start ;; + stop) cmd_stop ;; + kubectx) cmd_kubectx ;; + kubectx-clean) cmd_kubectx_clean ;; + install) cmd_install ;; + uninstall) cmd_uninstall ;; + restart) cmd_restart ;; + install-cert-manager) cmd_install_cert_manager ;; + install-demo) cmd_install_demo ;; + install-datadog-agent) cmd_install_datadog_agent ;; + install-longhorn) cmd_install_longhorn ;; + pre-local) cmd_pre_local ;; + open-dd) cmd_open_dd ;; + *) + echo "Usage: $0 {start|stop|kubectx|kubectx-clean|install|uninstall|restart|install-cert-manager|install-demo|install-datadog-agent|install-longhorn|pre-local|open-dd}" + exit 1 + ;; +esac diff --git a/scripts/lima_start.sh b/scripts/lima_start.sh deleted file mode 100755 index 9a1dab7fe..000000000 --- a/scripts/lima_start.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -# start the lima instance with the given image and get the kube config -limactl start --tty=false --name="${LIMA_INSTANCE}" - <"./${LIMA_CONFIG}.yaml" - -# for cgroups v1, reconfigure grub and restart the instance -# we need to both call the reboot command and do a lima stop/start -# for the instance to be working (it rebinds things such as ssh to the host) -if [[ ${LIMA_CGROUPS} == "v1" ]]; then - echo "Reconfiguring lima instance with cgroups v1" - limactl shell "${LIMA_INSTANCE}" sudo sed -i 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="systemd.unified_cgroup_hierarchy=0"/' /etc/default/grub - limactl shell "${LIMA_INSTANCE}" sudo update-grub - limactl shell "${LIMA_INSTANCE}" sudo reboot - echo "Waiting for instance to reboot, it might take a while" - sleep 10 - limactl stop "${LIMA_INSTANCE}" - limactl start "${LIMA_INSTANCE}" -fi diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh new file mode 100755 index 000000000..56ecc783d --- /dev/null +++ b/scripts/run-tests.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +set -uo pipefail + +# Required env vars +: "${GO_TEST_REPORT_NAME:?GO_TEST_REPORT_NAME must be set}" +: "${GINKGO_TEST_ARGS:?GINKGO_TEST_ARGS must be set}" + +# Optional env vars with defaults +GINKGO_PROCS="${GINKGO_PROCS:-4}" +GO_TEST_SKIP_UPLOAD="${GO_TEST_SKIP_UPLOAD:-}" +DATADOG_API_KEY="${DATADOG_API_KEY:-}" +DD_ENV="${DD_ENV:-local}" + +SUCCEED_FILE="report-${GO_TEST_REPORT_NAME}-succeed" + +# Run the test and touch succeed-file on success +# Do not stop on error (-e is not set) +# shellcheck disable=SC2086 +go run github.com/onsi/ginkgo/v2/ginkgo --fail-on-pending --keep-going --vv \ + --cover --coverprofile=cover.profile --randomize-all \ + --race --trace --json-report="report-${GO_TEST_REPORT_NAME}.json" --junit-report="report-${GO_TEST_REPORT_NAME}.xml" \ + --compilers="${GINKGO_PROCS}" --procs="${GINKGO_PROCS}" \ + --poll-progress-after=10s --poll-progress-interval=10s \ + ${GINKGO_TEST_ARGS} \ + && touch "${SUCCEED_FILE}" + +# Try upload test reports if allowed and necessary prerequisites exist +if [ "${GO_TEST_SKIP_UPLOAD}" = "true" ]; then + echo "datadog-ci junit upload SKIPPED" +elif [ -z "${DATADOG_API_KEY}" ]; then + echo "DATADOG_API_KEY env var is not defined, create a local API key https://app.datadoghq.com/personal-settings/application-keys if you want to upload your local tests results to datadog" +elif ! command -v datadog-ci &>/dev/null; then + echo "datadog-ci binary is not installed, run 'make install-dev-tools' to upload tests results to datadog" +else + DD_ENV="${DD_ENV}" datadog-ci junit upload \ + --service chaos-controller \ + --tags="team:chaos-engineering,type:${GO_TEST_REPORT_NAME}" \ + "report-${GO_TEST_REPORT_NAME}.xml" || true +fi + +# Fail if succeed file does not exist +if [ -f "${SUCCEED_FILE}" ]; then + rm -f "${SUCCEED_FILE}" + exit 0 +else + exit 1 +fi diff --git a/scripts/spellcheck.sh b/scripts/spellcheck.sh new file mode 100755 index 000000000..7e48b4472 --- /dev/null +++ b/scripts/spellcheck.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +set -euo pipefail + +ensure_deps() { + if ! command -v npm &>/dev/null; then + echo "please install npm or run 'make spellcheck-docker' for a slow but platform-agnostic run" + exit 1 + fi + if ! command -v mdspell &>/dev/null; then + echo "installing mdspell through npm -g... (might require sudo run)" + npm -g i markdown-spellcheck + fi +} + +find_markdown() { + find . -name vendor -prune -o -name '*.md' -print +} + +cmd="${1:-}" +shift || true + +case "$cmd" in + check) + ensure_deps + mdspell --en-us --ignore-acronyms --ignore-numbers $(find_markdown) + ;; + report) + ensure_deps + mdspell --en-us --ignore-acronyms --ignore-numbers --report $(find_markdown) + ;; + docker) + docker run --rm -ti -v "$(pwd)":/workdir tmaier/markdown-spellcheck:latest \ + --ignore-numbers --ignore-acronyms --en-us $(find_markdown) + ;; + format-spelling) + sort < .spelling | uniq | grep -v '^-' | tee .spelling.tmp > /dev/null && mv .spelling.tmp .spelling + ;; + *) + echo "Usage: $0 {check|report|docker|format-spelling}" + exit 1 + ;; +esac diff --git a/scripts/update-deps.sh b/scripts/update-deps.sh new file mode 100755 index 000000000..797d056c8 --- /dev/null +++ b/scripts/update-deps.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail + +echo "Updating Python dependencies..." +pip install -q uv +uv pip compile --python-platform linux tasks/requirements.in -o tasks/requirements.txt +echo "Updated tasks/requirements.txt" +echo "Please commit both tasks/requirements.in and tasks/requirements.txt" diff --git a/scripts/versions.env b/scripts/versions.env new file mode 100644 index 000000000..1cc84d8f7 --- /dev/null +++ b/scripts/versions.env @@ -0,0 +1,9 @@ +BUILDGOVERSION=1.25.6 +GOLANGCI_LINT_VERSION=2.8.0 +CONTROLLER_GEN_VERSION=v0.19.0 +MOCKERY_VERSION=2.53.5 +PROTOC_VERSION=3.17.3 +PROTOC_GEN_GO_VERSION=v1.27.1 +PROTOC_GEN_GO_GRPC_VERSION=v1.1.0 +YAMLFMT_VERSION=0.9.0 +HELM_VERSION=v3.19.0