2021-02-18 10:27:10 +00:00
# set the shell to bash always
2020-12-21 19:31:28 +00:00
SHELL := /bin/bash
2021-02-18 10:27:10 +00:00
# set make and shell flags to exit on errors
MAKEFLAGS += --warn-undefined-variables
2020-12-21 19:31:28 +00:00
.SHELLFLAGS := -euo pipefail -c
2021-02-18 10:27:10 +00:00
2024-05-28 12:28:53 +00:00
ARCH ?= amd64 arm64 ppc64le
2022-11-23 20:25:19 +00:00
BUILD_ARGS ?= CGO_ENABLED = 0
DOCKER_BUILD_ARGS ?=
2022-10-06 17:14:13 +00:00
DOCKERFILE ?= Dockerfile
2021-07-21 15:00:43 +00:00
2021-02-18 10:27:10 +00:00
# default target is build
2020-12-21 19:31:28 +00:00
.DEFAULT_GOAL := all
2021-02-18 10:27:10 +00:00
.PHONY : all
2021-07-21 15:00:43 +00:00
all : $( addprefix build -,$ ( ARCH ) )
2021-02-18 10:27:10 +00:00
# Image registry for build/push image targets
2022-10-06 17:14:13 +00:00
export IMAGE_REGISTRY ?= ghcr.io
export IMAGE_REPO ?= external-secrets/external-secrets
export IMAGE_NAME ?= $( IMAGE_REGISTRY) /$( IMAGE_REPO)
2021-12-29 12:02:56 +00:00
2022-02-10 17:12:13 +00:00
BUNDLE_DIR ?= deploy/crds
CRD_DIR ?= config/crds
2020-11-23 14:21:01 +00:00
2021-02-18 10:27:10 +00:00
HELM_DIR ?= deploy/charts/external-secrets
2021-12-29 12:02:56 +00:00
TF_DIR ?= terraform
2021-02-18 10:27:10 +00:00
OUTPUT_DIR ?= bin
2020-11-23 14:21:01 +00:00
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
i f e q ( , $( shell go env GOBIN ) )
GOBIN = $( shell go env GOPATH) /bin
e l s e
GOBIN = $( shell go env GOBIN)
e n d i f
2021-02-18 10:27:10 +00:00
# check if there are any existing `git tag` values
i f e q ( $( shell git tag ) , )
# no tags found - default to initial tag `v0.0.0`
2022-01-21 20:05:37 +00:00
export VERSION := $( shell echo " v0.0.0- $$ (git rev-list HEAD --count)-g $$ (git describe --dirty --always) " | sed 's/-/./2' | sed 's/-/./2' )
2021-02-18 10:27:10 +00:00
e l s e
# use tags
2022-01-21 20:05:37 +00:00
export VERSION := $( shell git describe --dirty --always --tags --exclude 'helm*' | sed 's/-/./2' | sed 's/-/./2' )
2021-02-18 10:27:10 +00:00
e n d i f
2020-11-23 14:21:01 +00:00
2022-10-06 17:14:13 +00:00
TAG_SUFFIX ?=
export IMAGE_TAG ?= $( VERSION) $( TAG_SUFFIX)
2021-02-18 10:27:10 +00:00
# ====================================================================================
# Colors
2020-11-23 14:21:01 +00:00
2021-02-18 10:27:10 +00:00
BLUE := $( shell printf "\033[34m" )
YELLOW := $( shell printf "\033[33m" )
RED := $( shell printf "\033[31m" )
GREEN := $( shell printf "\033[32m" )
CNone := $( shell printf "\033[0m" )
2020-11-23 14:21:01 +00:00
2021-02-18 10:27:10 +00:00
# ====================================================================================
# Logger
2020-11-23 14:21:01 +00:00
2021-02-18 10:27:10 +00:00
TIME_LONG = ` date +%Y-%m-%d' ' %H:%M:%S`
TIME_SHORT = ` date +%H:%M:%S`
TIME = $( TIME_SHORT)
2020-11-23 14:21:01 +00:00
2021-02-18 10:27:10 +00:00
INFO = echo ${ TIME } ${ BLUE } [ .. ] ${ CNone }
WARN = echo ${ TIME } ${ YELLOW } [ WARN] ${ CNone }
ERR = echo ${ TIME } ${ RED } [ FAIL] ${ CNone }
OK = echo ${ TIME } ${ GREEN } [ OK ] ${ CNone }
FAIL = ( echo ${ TIME } ${ RED } [ FAIL] ${ CNone } && false )
2020-11-23 14:21:01 +00:00
2021-02-18 10:27:10 +00:00
# ====================================================================================
# Conformance
2020-11-23 14:21:01 +00:00
2022-11-30 19:06:59 +00:00
reviewable : generate docs manifests helm .generate helm .docs lint ## Ensure a PR is ready for review.
2021-02-18 10:27:10 +00:00
@go mod tidy
2022-10-17 14:40:18 +00:00
@cd e2e/ && go mod tidy
2021-02-18 10:27:10 +00:00
2021-10-25 18:06:11 +00:00
check-diff : reviewable ## Ensure branch is clean.
2021-02-18 10:27:10 +00:00
@$( INFO) checking that branch is clean
2021-05-18 16:37:16 +00:00
@test -z " $$ (git status --porcelain) " || ( echo " $$ (git status --porcelain) " && $( FAIL) )
2021-02-18 10:27:10 +00:00
@$( OK) branch is clean
2023-02-20 10:03:07 +00:00
update-deps :
go get -u
cd e2e && go get -u
@go mod tidy
@cd e2e/ && go mod tidy
2021-02-18 10:27:10 +00:00
# ====================================================================================
# Golang
.PHONY : test
2023-07-24 06:31:56 +00:00
test : generate envtest ## Run tests
2021-02-18 10:27:10 +00:00
@$( INFO) go test unit-tests
2023-07-24 06:31:56 +00:00
KUBEBUILDER_ASSETS = " $( shell $( ENVTEST) use $( KUBERNETES_VERSION) -p path --bin-dir $( LOCALBIN) ) " go test -race -v $( shell go list ./... | grep -v e2e) -coverprofile cover.out
2021-04-24 23:39:06 +00:00
@$( OK) go test unit-tests
.PHONY : test .e 2e
test.e2e : generate ## Run e2e tests
@$( INFO) go test e2e-tests
$( MAKE) -C ./e2e test
2022-01-21 20:05:37 +00:00
@$( OK) go test e2e-tests
2021-02-18 10:27:10 +00:00
2021-12-29 12:02:56 +00:00
.PHONY : test .e 2e .managed
2022-01-21 20:05:37 +00:00
test.e2e.managed : generate ## Run e2e tests managed
@$( INFO) go test e2e-tests-managed
2021-12-29 12:02:56 +00:00
$( MAKE) -C ./e2e test.managed
2022-01-21 20:05:37 +00:00
@$( OK) go test e2e-tests-managed
2021-12-29 12:02:56 +00:00
2021-02-18 10:27:10 +00:00
.PHONY : build
2022-01-17 20:44:33 +00:00
build : $( addprefix build -,$ ( ARCH ) ) ## Build binary
2021-07-21 15:00:43 +00:00
.PHONY : build -%
build-% : generate ## Build binary for the specified arch
@$( INFO) go build $*
2022-11-23 20:25:19 +00:00
$( BUILD_ARGS) GOOS = linux GOARCH = $* \
2021-07-21 15:00:43 +00:00
go build -o '$(OUTPUT_DIR)/external-secrets-linux-$*' main.go
2022-02-13 12:14:41 +00:00
@$( OK) go build $*
2020-11-23 14:21:01 +00:00
2023-07-24 06:31:56 +00:00
lint : golangci -lint ## Run golangci-lint
@if ! $( GOLANGCI_LINT) run; then \
2020-12-21 19:31:28 +00:00
echo -e "\033[0;33mgolangci-lint failed: some checks can be fixed with \`\033[0;32mmake fmt\033[0m\033[0;33m\`\033[0m" ; \
exit 1; \
fi
2021-10-20 23:21:21 +00:00
@$( OK) Finished linting
2020-12-21 19:31:28 +00:00
2023-07-24 06:31:56 +00:00
fmt : golangci -lint ## Ensure consistent code style
2021-02-18 10:27:10 +00:00
@go mod tidy
2022-10-17 14:40:18 +00:00
@cd e2e/ && go mod tidy
2021-02-18 10:27:10 +00:00
@go fmt ./...
2023-07-24 06:31:56 +00:00
@$( GOLANGCI_LINT) run --fix
2021-02-18 10:27:10 +00:00
@$( OK) Ensured consistent code style
2020-12-22 19:12:39 +00:00
2021-03-27 22:14:54 +00:00
generate : ## Generate code and crds
2022-07-27 17:28:59 +00:00
@./hack/crd.generate.sh $( BUNDLE_DIR) $( CRD_DIR)
2021-03-27 22:14:54 +00:00
@$( OK) Finished generating deepcopy and crds
2020-12-21 19:31:28 +00:00
2021-02-18 10:27:10 +00:00
# ====================================================================================
# Local Utility
# This is for running out-of-cluster locally, and is for convenience.
# For more control, try running the binary directly with different arguments.
2021-10-25 18:06:11 +00:00
run : generate ## Run app locally (without a k8s cluster)
2021-02-18 10:27:10 +00:00
go run ./main.go
2021-10-25 18:06:11 +00:00
manifests : helm .generate ## Generate manifests from helm chart
2021-03-27 22:14:54 +00:00
mkdir -p $( OUTPUT_DIR) /deploy/manifests
helm template external-secrets $( HELM_DIR) -f deploy/manifests/helm-values.yaml > $( OUTPUT_DIR) /deploy/manifests/external-secrets.yaml
2021-10-25 18:06:11 +00:00
crds.install : generate ## Install CRDs into a cluster. This is for convenience
2022-02-10 20:00:52 +00:00
kubectl apply -f $( BUNDLE_DIR)
2021-02-18 10:27:10 +00:00
2021-10-25 18:06:11 +00:00
crds.uninstall : ## Uninstall CRDs from a cluster. This is for convenience
2022-02-10 20:00:52 +00:00
kubectl delete -f $( BUNDLE_DIR)
2021-02-18 10:27:10 +00:00
2023-12-21 21:58:31 +00:00
tilt-up : tilt manifests ## Generates the local manifests that tilt will use to deploy the controller's objects.
$( LOCALBIN) /tilt up
2021-02-18 10:27:10 +00:00
# ====================================================================================
# Helm Chart
helm.docs : ## Generate helm docs
2021-05-27 18:09:10 +00:00
@cd $( HELM_DIR) ; \
docker run --rm -v $( shell pwd ) /$( HELM_DIR) :/helm-docs -u $( shell id -u) jnorwood/helm-docs:v1.5.0
2021-02-18 10:27:10 +00:00
2021-03-27 22:14:54 +00:00
HELM_VERSION ?= $( shell helm show chart $( HELM_DIR) | grep 'version:' | sed 's/version: //g' )
2021-02-18 10:27:10 +00:00
helm.build : helm .generate ## Build helm chart
@$( INFO) helm package
@helm package $( HELM_DIR) --dependency-update --destination $( OUTPUT_DIR) /chart
2021-03-27 22:14:54 +00:00
@mv $( OUTPUT_DIR) /chart/external-secrets-$( HELM_VERSION) .tgz $( OUTPUT_DIR) /chart/external-secrets.tgz
2021-02-18 10:27:10 +00:00
@$( OK) helm package
2022-03-28 12:36:33 +00:00
helm.generate :
2022-07-27 17:28:59 +00:00
./hack/helm.generate.sh $( BUNDLE_DIR) $( HELM_DIR)
2021-02-18 10:27:10 +00:00
@$( OK) Finished generating helm chart files
2023-03-16 00:05:03 +00:00
helm.test : helm .generate
@helm unittest --file tests/*.yaml --file 'tests/**/*.yaml' deploy/charts/external-secrets/
2023-03-16 23:31:30 +00:00
helm.test.update : helm .generate
@helm unittest -u --file tests/*.yaml --file 'tests/**/*.yaml' deploy/charts/external-secrets/
2023-03-16 00:05:03 +00:00
helm.update.appversion :
@chartversion= $$ ( yq .version ./deploy/charts/external-secrets/Chart.yaml) ; \
chartappversion = $$ ( yq .appVersion ./deploy/charts/external-secrets/Chart.yaml) ; \
chartname = $$ ( yq .name ./deploy/charts/external-secrets/Chart.yaml) ; \
$( INFO) Update chartname and chartversion string in test snapshots.; \
sed -s -i " s/^\([[:space:]]\+helm\.sh\/chart:\).*/\1 $$ {chartname}- $$ {chartversion}/ " ./deploy/charts/external-secrets/tests/__snapshot__/*.yaml.snap ; \
sed -s -i " s/^\([[:space:]]\+app\.kubernetes\.io\/version:\).*/\1 $$ {chartappversion}/ " ./deploy/charts/external-secrets/tests/__snapshot__/*.yaml.snap ; \
2023-03-16 23:31:30 +00:00
sed -s -i " s/^\([[:space:]]\+image: ghcr\.io\/external-secrets\/external-secrets:\).*/\1 $$ {chartappversion}/ " ./deploy/charts/external-secrets/tests/__snapshot__/*.yaml.snap ; \
2023-03-16 00:05:03 +00:00
$( OK) "Version strings updated"
2021-03-01 07:31:02 +00:00
# ====================================================================================
# Documentation
.PHONY : docs
2021-10-25 18:06:11 +00:00
docs : generate ## Generate docs
2021-03-01 07:31:02 +00:00
$( MAKE) -C ./hack/api-docs build
2022-02-01 13:44:34 +00:00
.PHONY : docs .publish
docs.publish : generate ## Generate and deploys docs
$( MAKE) -C ./hack/api-docs build.publish
2022-02-08 10:00:10 +00:00
.PHONY : docs .serve
docs.serve : ## Serve docs
2021-03-01 07:31:02 +00:00
$( MAKE) -C ./hack/api-docs serve
2021-02-18 10:27:10 +00:00
# ====================================================================================
# Build Artifacts
2023-06-21 09:17:00 +00:00
.PHONY : build .all
2021-10-25 21:12:11 +00:00
build.all : docker .build helm .build ## Build all artifacts (docker image, helm chart)
2021-02-18 10:27:10 +00:00
2023-06-21 09:17:00 +00:00
.PHONY : docker .image
docker.image : ## Emit IMAGE_NAME:IMAGE_TAG
2022-10-06 17:14:13 +00:00
@echo $( IMAGE_NAME) :$( IMAGE_TAG)
2023-06-21 09:17:00 +00:00
.PHONY : docker .imagename
docker.imagename : ## Emit IMAGE_NAME
@echo $( IMAGE_NAME)
.PHONY : docker .tag
docker.tag : ## Emit IMAGE_TAG
2022-10-06 17:14:13 +00:00
@echo $( IMAGE_TAG)
2022-09-15 15:17:52 +00:00
2023-06-21 09:17:00 +00:00
.PHONY : docker .build
2021-07-21 15:00:43 +00:00
docker.build : $( addprefix build -,$ ( ARCH ) ) ## Build the docker image
2021-02-18 10:27:10 +00:00
@$( INFO) docker build
2023-06-21 09:17:00 +00:00
echo docker build -f $( DOCKERFILE) . $( DOCKER_BUILD_ARGS) -t $( IMAGE_NAME) :$( IMAGE_TAG)
2023-08-28 09:45:27 +00:00
DOCKER_BUILDKIT = 1 docker build -f $( DOCKERFILE) . $( DOCKER_BUILD_ARGS) -t $( IMAGE_NAME) :$( IMAGE_TAG)
2021-02-18 10:27:10 +00:00
@$( OK) docker build
2023-06-21 09:17:00 +00:00
.PHONY : docker .push
2021-10-25 18:06:11 +00:00
docker.push : ## Push the docker image to the registry
2021-02-18 10:27:10 +00:00
@$( INFO) docker push
2022-10-06 17:14:13 +00:00
@docker push $( IMAGE_NAME) :$( IMAGE_TAG)
2021-02-18 10:27:10 +00:00
@$( OK) docker push
2022-01-21 20:05:37 +00:00
# RELEASE_TAG is tag to promote. Default is promoting to main branch, but can be overriden
2021-02-18 10:27:10 +00:00
# to promote a tag to a specific version.
2022-10-08 21:53:15 +00:00
RELEASE_TAG ?= $( IMAGE_TAG)
2022-10-06 17:14:13 +00:00
SOURCE_TAG ?= $( VERSION) $( TAG_SUFFIX)
2021-02-18 10:27:10 +00:00
2023-06-21 09:17:00 +00:00
.PHONY : docker .promote
2021-10-25 18:06:11 +00:00
docker.promote : ## Promote the docker image to the registry
2021-07-21 15:00:43 +00:00
@$( INFO) promoting $( SOURCE_TAG) to $( RELEASE_TAG)
2022-11-29 22:50:11 +00:00
docker manifest inspect --verbose $( IMAGE_NAME) :$( SOURCE_TAG) > .tagmanifest
for digest in $$ ( jq -r 'if type=="array" then .[].Descriptor.digest else .Descriptor.digest end' < .tagmanifest) ; do \
2022-10-06 17:14:13 +00:00
docker pull $( IMAGE_NAME) @$$ digest; \
2021-07-21 15:00:43 +00:00
done
2022-10-06 17:14:13 +00:00
docker manifest create $( IMAGE_NAME) :$( RELEASE_TAG) \
2022-11-29 22:50:11 +00:00
$$ ( jq -j '"--amend $(IMAGE_NAME)@" + if type=="array" then .[].Descriptor.digest else .Descriptor.digest end + " "' < .tagmanifest)
2022-10-06 17:14:13 +00:00
docker manifest push $( IMAGE_NAME) :$( RELEASE_TAG)
2021-07-21 15:00:43 +00:00
@$( OK) docker push $( RELEASE_TAG) \
2021-02-18 10:27:10 +00:00
2021-12-29 12:02:56 +00:00
# ====================================================================================
# Terraform
2024-06-14 04:04:19 +00:00
tf.plan.% : ## Runs terraform plan for a provider
2022-01-21 20:05:37 +00:00
@cd $( TF_DIR) /$* ; \
2021-12-29 12:02:56 +00:00
terraform init; \
2022-01-21 20:05:37 +00:00
terraform plan
2021-12-29 12:02:56 +00:00
2024-06-14 04:04:19 +00:00
tf.apply.% : ## Runs terraform apply for a provider
2022-01-21 20:05:37 +00:00
@cd $( TF_DIR) /$* ; \
2021-12-29 12:02:56 +00:00
terraform init; \
terraform apply -auto-approve
2024-06-14 04:04:19 +00:00
tf.destroy.% : ## Runs terraform destroy for a provider
2022-01-21 20:05:37 +00:00
@cd $( TF_DIR) /$* ; \
2021-12-29 12:02:56 +00:00
terraform init; \
terraform destroy -auto-approve
2024-06-14 04:04:19 +00:00
tf.show.% : ## Runs terraform show for a provider and outputs to a file
2022-01-21 20:05:37 +00:00
@cd $( TF_DIR) /$* ; \
2021-12-29 12:02:56 +00:00
terraform init; \
terraform plan -out tfplan.binary; \
terraform show -json tfplan.binary > plan.json
2021-02-18 10:27:10 +00:00
# ====================================================================================
# Help
2023-06-21 09:17:00 +00:00
.PHONY : help
2021-02-18 10:27:10 +00:00
# only comments after make target name are shown as help text
2021-10-25 18:06:11 +00:00
help : ## Displays this help message
2023-06-21 09:17:00 +00:00
@echo -e " $$ (grep -hE '^\S+:.*##' $( MAKEFILE_LIST) | sed -e 's/:.*##\s*/|/' -e 's/^\(.\+\):\(.*\)/\\x1b[36m\1\\x1b[m:\2/' | column -c2 -t -s'|' | sort) "
.PHONY : clean
clean : ## Clean bins
@$( INFO) clean
@rm -f $( OUTPUT_DIR) /external-secrets-linux-*
@$( OK) go build $*
2023-07-24 06:31:56 +00:00
# ====================================================================================
# Build Dependencies
2023-12-21 21:58:31 +00:00
i f e q ( $( OS ) , W i n d o w s _ N T ) # is Windows_NT on XP, 2000, 7, Vista, 10...
detected_OS := windows
arch := x86_64
e l s e
detected_OS := $( shell uname -s)
arch := $( shell uname -m)
ifeq ( $( detected_OS) ,Darwin)
detected_OS := mac
endif
ifeq ( $( detected_OS) ,Linux)
detected_OS := linux
endif
e n d i f
2023-07-24 06:31:56 +00:00
## Location to install dependencies to
LOCALBIN ?= $( shell pwd ) /bin
$(LOCALBIN) :
mkdir -p $( LOCALBIN)
## Tool Binaries
2023-12-21 21:58:31 +00:00
TILT ?= $( LOCALBIN) /tilt
2023-07-24 06:31:56 +00:00
ENVTEST ?= $( LOCALBIN) /setup-envtest
GOLANGCI_LINT ?= $( LOCALBIN) /golangci-lint
## Tool Versions
2024-04-25 09:36:11 +00:00
GOLANGCI_VERSION := 1.57.2
KUBERNETES_VERSION := 1.30.x
2023-12-21 21:58:31 +00:00
TILT_VERSION := 0.33.10
2023-07-24 06:31:56 +00:00
.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
.PHONY : golangci -lint
.PHONY : $( GOLANGCI_LINT )
golangci-lint : $( GOLANGCI_LINT ) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT) : $( LOCALBIN )
test -s $( LOCALBIN) /golangci-lint && $( LOCALBIN) /golangci-lint version --format short | grep -q $( GOLANGCI_VERSION) || \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $( LOCALBIN) v$( GOLANGCI_VERSION)
2023-12-21 21:58:31 +00:00
.PHONY : tilt
.PHONY : $( TILT )
tilt : $( TILT ) ## Download tilt locally if necessary. Architecture is locked at x86_64.
$(TILT) : $( LOCALBIN )
test -s $( LOCALBIN) /tilt || curl -fsSL https://github.com/tilt-dev/tilt/releases/download/v$( TILT_VERSION) /tilt.$( TILT_VERSION) .$( detected_OS) .$( arch) .tar.gz | tar -xz -C $( LOCALBIN) tilt