-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
171 lines (133 loc) · 7.23 KB
/
Makefile
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Makefile is self-documenting, comments starting with '##' are extracted as help text.
help: ## Display this help.
@echo; echo = Targets =
@grep -E '^[A-Za-Z0-9_-]+:.*##' Makefile | sed 's/:.*##\s*/#/' | column -s'#' -t
@echo; echo = Variables =
@grep -E '^## [A-Z0-9_]+: ' Makefile | sed 's/^## \([A-Z0-9_]*\): \(.*\)/\1#\2/' | column -s'#' -t
## VERSION: Semantic version for release, use -dev for development pre-release versions.
VERSION?=0.1.8
## REGISTRY_BASE: registry/org-name for images.
REGISTRY_BASE?=$(error Set REGISTRY_BASE to push or pull images)
## KORREL8R_VERSION: Version of korrel8r operand.
KORREL8R_VERSION=0.7.2
## KORREL8R_IMAGE: Operand image containing the korrel8r executable.
KORREL8R_IMAGE?=quay.io/korrel8r/korrel8r:$(KORREL8R_VERSION)
## NAMESPACE: Operator namespace used by `make deploy` and `make bundle-run`
NAMESPACE?=korrel8r
## IMGTOOL: May be podman or docker.
IMGTOOL?=$(shell which podman || which docker)
## ENVTEST_K8S_VERSION: version of kubebuilder for envtest testing.
ENVTEST_K8S_VERSION=1.29.x
# Names of image and bundle images.
IMG?=$(REGISTRY_BASE)/operator
IMAGE=$(IMG):$(VERSION)
BUNDLE_IMAGE ?= $(IMG)-bundle:$(VERSION)
# Bundle options.
DEFAULT_CHANNEL ?= stable
BUNDLE_CHANNELS ?= --channels=$(DEFAULT_CHANNEL)
BUNDLE_DEFAULT_CHANNEL ?= --default-channel=$(DEFAULT_CHANNEL)
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
# 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
include .bingo/Variables.mk
##@ General
all: build test doc bundle ## All local build & test.
push-all: all image-push bundle-push ## Build and push all images.
##@ Development
.PHONY: manifests
manifests: $(CONTROLLER_GEN) $(KUSTOMIZE) ## Generate ClusterRole and CustomResourceDefinition objects.
cd config/default && $(KUSTOMIZE) edit set image controller=$(IMAGE)
cd config/default && $(KUSTOMIZE) edit set namespace $(NAMESPACE)
sed -e 's|value:.*|value: $(KORREL8R_IMAGE)|' config/default/manager_image_patch.yaml > \
config/default/manager_image_patch.yaml_bkp && mv config/default/manager_image_patch.yaml_bkp config/default/manager_image_patch.yaml
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
.PHONY: generate
generate: $(CONTROLLER_GEN) ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject methods.
go mod tidy
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
lint: $(GOLANGCI_LINT) ## Run linters, fix code style problems.
$(GOLANGCI_LINT) run --fix
.PHONY: test
test: generate lint $(SETUP_ENVTEST) ## Run tests.
$(shell $(SETUP_ENVTEST) use $(ENVTEST_K8S_VERSION) -p env); go test ./...
##@ Build
.PHONY: build
build: manifests generate lint ## Build manager binary.
go build -o bin/manager main.go
run: manifests generate lint install ## Build and run a controller from your host
cd config/overlays/rbac_for_test && $(KUSTOMIZE) edit set namespace $(NAMESPACE)
$(KUSTOMIZE) build config/overlays/rbac_for_test | kubectl apply -f -
KORREL8R_IMAGE=$(KORREL8R_IMAGE) go run main.go
image-build: manifests generate ## Build the manager image.
$(IMGTOOL) build -q -t $(IMAGE) .
image-push: image-build ## Push the manager image.
$(IMGTOOL) push -q $(IMAGE)
##@ Deployment
.PHONY: install
install: manifests ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
.PHONY: uninstall
uninstall: manifests ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found -f -
.PHONY: deploy
deploy: install image-push ## Deploy controller to the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl apply -f -
.PHONY: undeploy
undeploy: $(KUSTOMIZE) ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found -f -
##@ Bundle
bundle: manifests generate $(OPERATOR_SDK) ## Generate bundle manifests and metadata, then validate generated files.
$(OPERATOR_SDK) generate kustomize manifests -q
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
$(OPERATOR_SDK) bundle validate ./bundle
touch $@
WATCH=kubectl get events -n $(NAMESPACE) --watch-only& trap "kill %%" EXIT;
bundle-build: bundle ## Build the bundle image.
$(IMGTOOL) build -q -f bundle.Dockerfile -t $(BUNDLE_IMAGE) .
bundle-push: bundle-build ## Push the bundle image.
$(IMGTOOL) push -q $(BUNDLE_IMAGE)
bundle-run: install bundle-push image-push $(OPERATOR_SDK) ## Run the bundle image.
$(OPERATOR_SDK) -n $(NAMESPACE) cleanup korrel8r || true
oc create namespace $(NAMESPACE) || true
$(WATCH) $(OPERATOR_SDK) -n $(NAMESPACE) run bundle $(BUNDLE_IMAGE) --security-context-config restricted
bundle-cleanup: $(OPERATOR_SDK)
$(OPERATOR_SDK) -n $(NAMESPACE) cleanup korrel8r || true
.PHONY: push-all
push-all: image-push bundle-push
.PHONY: doc
doc: doc/zz_api-ref.adoc
doc/zz_api-ref.adoc: $(shell find api etc/crd-ref-docs) $(CRD_REF_DOCS)
$(CRD_REF_DOCS) --source-path api --config etc/crd-ref-docs/config.yaml --templates-dir etc/crd-ref-docs/templates --output-path $@
GENERATED+=doc/zz_api-ref.adoc
clean:
rm -rf bundle bundle.Dockerfile $(GENERATED) $(shell find -name zz_generated.*)
clean-cluster: bundle-cleanup undeploy ## Remove all test artifacts from the cluster.
oc delete ns/$(NAMESPACE) || true
oc get -o name operator | grep korrel8r | xargs -r oc delete || true
oc delete -l app.kubernetes.io/name=korrel8r clusterrolebinding,clusterrole || true
test-deploy: clean-cluster deploy ## Deploy via kustomize and run a smoke-test
hack/smoketest.sh
test-bundle: clean-cluster bundle-run ## Run the bundle and run a smoke-test
hack/smoketest.sh
resource: ## Create the default korrel8r resource
$(KUSTOMIZE) build config/samples | kubectl -n $(NAMESPACE) apply -f -
$(WATCH) kubectl wait -n $(NAMESPACE) --for=condition=available --timeout=60s deployment.apps/korrel8r
OPHUB?=$(error Set OPHUB to the path to your local community-operators-prod clone)
OPHUB_VERSION=$(OPHUB)/operators/korrel8r/$(VERSION)
operatorhub: bundle ## Generate manifest for operator hub. Set OPHUB and REGISTRY_BASE.
@[ "$(origin REGISTRY_BASE)" = "command line" ] || { echo "REGISTRY_BASE must be set on the command line"; exit 1; }
@[ "$$(git status -s)" = "" ] || { git status; echo "working directory not clean"; exit 1; }
mkdir -p $(OPHUB_VERSION)
cp -aT bundle $(OPHUB_VERSION)
echo -e '\n # Annotations for OperatorHub\n com.redhat.openshift.versions: "v4.10"' >> $(OPHUB_VERSION)/metadata/annotations.yaml
pre-release: ## Prepare a release commit.
@[ "$(origin REGISTRY_BASE)" = "command line" ] || { echo "REGISTRY_BASE must be set on the command line"; exit 1; }
$(MAKE) test-bundle
release: pre-release ## Set VERISON and REGISTRY_BASE to push release tags and images.
hack/tag-release.sh $(VERSION) $(TAG_FLAGS)
$(IMGTOOL) push $(IMAGE) $(IMG):latest
$(IMGTOOL) push $(BUNDLE_IMAGE) $(IMG)-bundle:latest
tools: $(BINGO) ## Download all tools needed for development
$(BINGO) get