-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
141 lines (107 loc) · 6.46 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
# ------------------------------------------------------------------------------
# Define variables
PWD ?= $(shell pwd)
DIST ?= $(PWD)/target/release
BIN_DIR ?= $(HOME)/.local/bin
NAME ?= clever-operator
VERSION ?= $(shell git describe --candidates 1 --tags HEAD 2>/dev/null || echo HEAD)
DOCKER ?= $(shell which docker)
DOCKER_OPTS ?= --log-level debug
DOCKER_IMG ?= clevercloud/$(NAME):$(VERSION)
KUBE ?= $(shell which kubectl)
KUBE_VERSION ?= v1.24.0
OLM_SDK ?= $(shell which operator-sdk)
OLM_SDK_VERSION ?= 1.26.1
OLM_VERSION ?= 0.5.5
OCP_VALIDATOR ?= $(shell which ocp-olm-catalog-validator)
OCP_VERSION ?= 0.1.0
K8S_VALIDATOR ?= $(shell which k8s-community-bundle-validator)
K8S_VERSION ?= 0.1.0
KUBE_SCORE_VERSION ?= 1.16.1
KUBE_SCORE ?= $(shell which kube-score)
DEPLOY_KUBE ?= deployments/kubernetes/$(KUBE_VERSION)
DEPLOY_OLM ?= deployments/operator-lifecycle-manager/bundle-$(OLM_VERSION)
FIND ?= $(shell which find)
CARGO ?= $(shell which cargo)
CARGO_OPTS ?= --verbose
CURL ?= $(shell which curl)
MKDIR ?= $(shell which mkdir)
CHMOD ?= $(shell which chmod)
# ------------------------------------------------------------------------------
# Build operator
.PHONY: build
build: $(DIST)/$(NAME) $(shell $(FIND) -type f -name '*.rs')
$(DIST)/$(NAME): $(shell $(FIND) -type f -name '*.rs')
$(CARGO) build $(CARGO_OPTS) --release
# ------------------------------------------------------------------------------
# Install command line tools
.PHONY: install-cli-tools
install-cli-tools:
$(MKDIR) -p $(BIN_DIR)
$(CURL) -L https://github.com/operator-framework/operator-sdk/releases/download/v$(OLM_SDK_VERSION)/operator-sdk_linux_amd64 > $(BIN_DIR)/operator-sdk && $(CHMOD) +x $(BIN_DIR)/operator-sdk
$(CURL) -L https://github.com/k8s-operatorhub/bundle-validator/releases/download/v$(K8S_VERSION)/linux-amd64-k8s-community-bundle-validator > $(BIN_DIR)/k8s-community-bundle-validator && $(CHMOD) +x $(BIN_DIR)/k8s-community-bundle-validator
$(CURL) -L https://github.com/zegl/kube-score/releases/download/v$(KUBE_SCORE_VERSION)/kube-score_$(KUBE_SCORE_VERSION)_linux_amd64 > $(BIN_DIR)/kube-score && $(CHMOD) +x $(BIN_DIR)/kube-score
# ------------------------------------------------------------------------------
# Build docker
.PHONY: docker-build
docker-build: $(shell $(FIND) -type f -name '*.rs') Dockerfile
$(DOCKER) $(DOCKER_OPTS) build -t $(DOCKER_IMG) $(PWD)
.PHONY: docker-push
docker-push: docker-build
$(DOCKER) $(DOCKER_OPTS) push $(DOCKER_IMG)
# ------------------------------------------------------------------------------
# Kubernetes deployment
.PHONY: crd
crd: build $(DEPLOY_OLM)/manifests/clever-operator-pulsar.crd.yaml $(DEPLOY_KUBE)/10-custom-resource-definition.yaml $(DEPLOY_OLM)/manifests/clever-operator-mongodb.crd.yaml $(DEPLOY_OLM)/manifests/clever-operator-mysql.crd.yaml $(DEPLOY_OLM)/manifests/clever-operator-postgresql.crd.yaml $(DEPLOY_OLM)/manifests/clever-operator-redis.crd.yaml
$(DEPLOY_KUBE)/10-custom-resource-definition.yaml:
$(DIST)/$(NAME) custom-resource-definition view > $(DEPLOY_KUBE)/10-custom-resource-definition.yaml
$(DEPLOY_OLM)/manifests/clever-operator-postgresql.crd.yaml:
$(DIST)/$(NAME) custom-resource-definition view postgresql > $(DEPLOY_OLM)/manifests/clever-operator-postgresql.crd.yaml
$(DEPLOY_OLM)/manifests/clever-operator-redis.crd.yaml:
$(DIST)/$(NAME) custom-resource-definition view redis > $(DEPLOY_OLM)/manifests/clever-operator-redis.crd.yaml
$(DEPLOY_OLM)/manifests/clever-operator-mysql.crd.yaml:
$(DIST)/$(NAME) custom-resource-definition view mysql > $(DEPLOY_OLM)/manifests/clever-operator-mysql.crd.yaml
$(DEPLOY_OLM)/manifests/clever-operator-mongodb.crd.yaml:
$(DIST)/$(NAME) custom-resource-definition view mongodb > $(DEPLOY_OLM)/manifests/clever-operator-mongodb.crd.yaml
$(DEPLOY_OLM)/manifests/clever-operator-pulsar.crd.yaml:
$(DIST)/$(NAME) custom-resource-definition view pulsar > $(DEPLOY_OLM)/manifests/clever-operator-pulsar.crd.yaml
$(DEPLOY_OLM)/manifests/clever-operator-elasticsearch.crd.yaml:
$(DIST)/$(NAME) custom-resource-definition view elasticsearch > $(DEPLOY_OLM)/manifests/clever-operator-elasticsearch.crd.yaml
$(DEPLOY_OLM)/manifests/clever-operator-config-provider.crd.yaml:
$(DIST)/$(NAME) custom-resource-definition view config-provider > $(DEPLOY_OLM)/manifests/clever-operator-config-provider.crd.yaml
.PHONY: validate
validate: $(shell $(FIND) -type f -name '*.yaml')
$(KUBE_SCORE) score $(shell $(FIND) $(DEPLOY_KUBE) -type f -name '*.yaml')
$(OLM_SDK) bundle validate $(DEPLOY_OLM)
# $(OCP_VALIDATOR) $(DEPLOY_OLM) --optional-values="file=$(DEPLOY_OLM)/metadata/annotations.yaml" --output json-alpha1
$(K8S_VALIDATOR) $(DEPLOY_OLM) --output json-alpha1
.PHONY: deploy-kubernetes-crd
deploy-kubernetes-crd: crd validate $(DEPLOY_KUBE)/10-custom-resource-definition.yaml
$(KUBE) apply -f $(DEPLOY_KUBE)/10-custom-resource-definition.yaml
.PHONY: deploy-kubernetes
deploy-kubernetes: crd validate deploy-kubernete-crd
$(KUBE) apply -f $(DEPLOY_KUBE)/manifests/clever-operator.clusterserviceversion.yaml
.PHONY: deploy-olm-crd
deploy-olm-crd: crd $(DEPLOY_OLM)/manifests/clever-operator-elasticsearch.crd.yaml $(DEPLOY_OLM)/manifests/clever-operator-config-provider.crd.yaml $(DEPLOY_OLM)/manifests/clever-operator-postgresql.crd.yaml $(DEPLOY_OLM)/manifests/clever-operator-redis.crd.yaml $(DEPLOY_OLM)/manifests/clever-operator-mysql.crd.yaml $(DEPLOY_OLM)/manifests/clever-operator-mongodb.crd.yaml $(DEPLOY_OLM)/manifests/clever-operator-pulsar.crd.yaml validate
$(KUBE) apply -f $(DEPLOY_OLM)/manifests/clever-operator-postgresql.crd.yaml
$(KUBE) apply -f $(DEPLOY_OLM)/manifests/clever-operator-redis.crd.yaml
$(KUBE) apply -f $(DEPLOY_OLM)/manifests/clever-operator-mysql.crd.yaml
$(KUBE) apply -f $(DEPLOY_OLM)/manifests/clever-operator-mongodb.crd.yaml
$(KUBE) apply -f $(DEPLOY_OLM)/manifests/clever-operator-pulsar.crd.yaml
$(KUBE) apply -f $(DEPLOY_OLM)/manifests/clever-operator-config-provider.crd.yaml
$(KUBE) apply -f $(DEPLOY_OLM)/manifests/clever-operator-elasticsearch.crd.yaml
.PHONY: deploy-olm
deploy-olm: crd validate deploy-olm-crd
$(KUBE) apply -f $(DEPLOY_OLM)
# ------------------------------------------------------------------------------
# Clean up
.PHONY: clean
clean: clean-kubernetes clean-olm
$(CARGO) clean $(CARGO_OPTS)
rm $(DEPLOY_KUBE)/10-custom-resource-definition.yaml
.PHONY: clean-kubernetes
clean-kubernetes:
$(KUBE) delete -f $(DEPLOY_KUBE)
.PHONY: clean-olm
clean-olm:
$(KUBE) delete -f $(DEPLOY_OLM)/manifests