-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
94 lines (73 loc) · 3.62 KB
/
Copy pathMakefile
File metadata and controls
94 lines (73 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Build Path and Tools
BUILD_PATH ?= .
LOCALBIN ?= $(BUILD_PATH)/operator/bin
GO ?= go
DOCKER ?= docker
CONTROLLER_GEN ?= $(GO) run sigs.k8s.io/controller-tools/cmd/controller-gen@v0.19.0
OCM_REGISTRY ?=
# Chart paths relative to root
CHART_DIR ?= ./charts/keycloak-operator
CRD_DIR ?= $(CHART_DIR)/crds
CHART_RBAC_DIR ?= $(CHART_DIR)/files
# Paths relative to operator/ for controller-gen outputs
OPERATOR_RBAC_OUT ?= ./config/rbac
CHART_CRD_OUT ?= ../$(CRD_DIR)
CHART_RBAC_OUT ?= ../$(CHART_RBAC_DIR)
##@ General
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: clean
clean: ## Clean local binary tools.
rm -rf $(LOCALBIN)
.PHONY: generate-test-secrets
generate-test-secrets: ## Generate throwaway local test Secret manifests outside the repository.
./hack/generate-test-secrets.sh
##@ Development
.PHONY: manifests
manifests: controller-gen ## Generate Role and CustomResourceDefinition objects.
cd operator && $(CONTROLLER_GEN) rbac:roleName=manager-role crd paths="./api/v1alpha1/...;./internal/controller/..." output:rbac:artifacts:config=$(OPERATOR_RBAC_OUT) output:crd:artifacts:config=$(CHART_CRD_OUT)
cd operator && $(CONTROLLER_GEN) rbac:roleName=manager-role paths="./api/v1alpha1/...;./internal/controller/..." output:rbac:artifacts:config=$(CHART_RBAC_OUT)
# Patch generated ClusterRole -> namespace-scoped Role. Use a portable rewrite
# (no `sed -i -e`) so macOS BSD sed does not leave *.yaml-e backup artifacts.
for f in $(CHART_RBAC_DIR)/role.yaml operator/$(OPERATOR_RBAC_OUT)/role.yaml; do \
sed 's/kind: ClusterRole/kind: Role/g' "$$f" > "$$f.tmp" && mv "$$f.tmp" "$$f"; \
done
.PHONY: check-versions
check-versions: ## Assert OCM component version matches Helm chart appVersion.
@OCM_VERSION=$$(grep '^version:' component-constructor.yaml | awk '{print $$2}'); \
CHART_APP_VERSION=$$(grep '^appVersion:' charts/keycloak-operator/Chart.yaml | awk '{print $$2}' | tr -d '"'); \
if [ "$$OCM_VERSION" != "$$CHART_APP_VERSION" ]; then \
echo "ERROR: OCM version ($$OCM_VERSION) != chart appVersion ($$CHART_APP_VERSION)"; \
exit 1; \
fi
@echo "Version check passed: $(shell grep '^version:' component-constructor.yaml | awk '{print $$2}')"
.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
cd operator && $(CONTROLLER_GEN) object:headerFile="./hack/boilerplate.go.txt" paths="./api/v1alpha1/...;./internal/controller/..."
.PHONY: fmt
fmt: ## Run go fmt against code.
cd operator && $(GO) fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
cd operator && $(GO) vet ./...
.PHONY: test
test: manifests generate fmt vet ## Run tests.
cd operator && $(GO) test ./... -coverprofile cover.out
##@ Build
.PHONY: build
build: generate fmt vet ## Build manager binary.
cd operator && $(GO) build -o bin/manager cmd/main.go
.PHONY: docker-build
docker-build: ## Build docker image with the manager.
cd operator && $(DOCKER) build -t operator:latest .
.PHONY: docker-push-dev
docker-push-dev: docker-build ## Tag and push operator image to OCM_REGISTRY/keycloak-operator-dev.
@test -n "$(OCM_REGISTRY)" || (echo "Error: set OCM_REGISTRY, for example ghcr.io/<org>" >&2; exit 2)
$(DOCKER) tag operator:latest $(OCM_REGISTRY)/keycloak-operator-dev:dev
$(DOCKER) push $(OCM_REGISTRY)/keycloak-operator-dev:dev
##@ Tooling
$(LOCALBIN):
mkdir -p $(LOCALBIN)
.PHONY: controller-gen
controller-gen: ## (Handled dynamically via go run)