Skip to content

Commit d6f49fe

Browse files
authored
[Feature] Kustomization support (#578)
1 parent 0c1eeb6 commit d6f49fe

33 files changed

+2807
-98
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
- Add Encryption Key rotation feature for ArangoDB EE 3.7+
55
- Improve TLS CA and Keyfile rotation for CE and EE
66
- Add runtime TLS rotation for ArangoDB EE 3.7+
7+
- Add Kustomize support
8+
- Improve Helm 3 support
79

810
## [1.0.3](https://github.com/arangodb/kube-arangodb/tree/1.0.3) (2020-05-25)
911
- Prevent deletion of not known PVC's

Makefile

Lines changed: 70 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ DOCKERDURATIONTESTFILE := tests/duration/Dockerfile
3333

3434
HELM ?= $(shell which helm)
3535

36+
UPPER = $(shell echo '$1' | tr '[:lower:]' '[:upper:]')
37+
LOWER = $(shell echo '$1' | tr '[:upper:]' '[:lower:]')
38+
UPPER_ENV = $(shell echo '$1' | tr '[:lower:]' '[:upper:]' | tr -d '-')
39+
3640
.PHONY: helm
3741
helm:
3842
ifeq ($(HELM),)
@@ -73,7 +77,15 @@ MANIFESTPATHDEPLOYMENT := manifests/arango-deployment$(MANIFESTSUFFIX).yaml
7377
MANIFESTPATHDEPLOYMENTREPLICATION := manifests/arango-deployment-replication$(MANIFESTSUFFIX).yaml
7478
MANIFESTPATHBACKUP := manifests/arango-backup$(MANIFESTSUFFIX).yaml
7579
MANIFESTPATHSTORAGE := manifests/arango-storage$(MANIFESTSUFFIX).yaml
80+
MANIFESTPATHALL := manifests/arango-all$(MANIFESTSUFFIX).yaml
7681
MANIFESTPATHTEST := manifests/arango-test$(MANIFESTSUFFIX).yaml
82+
KUSTOMIZEPATHCRD := manifests/kustomize/crd/arango-crd$(MANIFESTSUFFIX).yaml
83+
KUSTOMIZEPATHDEPLOYMENT := manifests/kustomize/deployment/arango-deployment$(MANIFESTSUFFIX).yaml
84+
KUSTOMIZEPATHDEPLOYMENTREPLICATION := manifests/kustomize/deployment-replication/arango-deployment-replication$(MANIFESTSUFFIX).yaml
85+
KUSTOMIZEPATHBACKUP := manifests/kustomize/backup/arango-backup$(MANIFESTSUFFIX).yaml
86+
KUSTOMIZEPATHSTORAGE := manifests/kustomize/storage/arango-storage$(MANIFESTSUFFIX).yaml
87+
KUSTOMIZEPATHALL := manifests/kustomize/all/arango-all$(MANIFESTSUFFIX).yaml
88+
KUSTOMIZEPATHTEST := manifests/kustomize/test/arango-test$(MANIFESTSUFFIX).yaml
7789
ifndef DEPLOYMENTNAMESPACE
7890
DEPLOYMENTNAMESPACE := default
7991
endif
@@ -272,81 +284,77 @@ endif
272284

273285
# Manifests
274286

275-
.PHONY: manifests-crd
276-
manifests-crd: export CHART_NAME := kube-arangodb-crd
277-
manifests-crd: export NAME := crd
278-
manifests-crd: helm
279-
@echo Building manifests for CRD - $(MANIFESTPATHCRD)
280-
@$(HELM_CMD) > "$(MANIFESTPATHCRD)"
281-
282-
.PHONY: manifests-test
283-
manifests-test: export CHART_NAME := kube-arangodb-test
284-
manifests-test: export NAME := arangodb-test
285-
manifests-test: helm
286-
@echo Building manifests for test - $(MANIFESTPATHTEST)
287-
@$(HELM_CMD) > "$(MANIFESTPATHTEST)"
288-
289-
.PHONY: manifests-operator-deployment
290-
manifests-operator-deployment: export CHART_NAME := kube-arangodb
291-
manifests-operator-deployment: export NAME := deployment
292-
manifests-operator-deployment: helm
293-
@echo Building manifests for Operator Deployment - $(MANIFESTPATHDEPLOYMENT)
294-
@$(HELM_CMD) \
295-
--set "operator.features.deployment=true" \
296-
--set "operator.features.deploymentReplications=false" \
297-
--set "operator.features.storage=false" \
298-
--set "operator.features.backup=false" > "$(MANIFESTPATHDEPLOYMENT)"
299-
300-
.PHONY: manifests-operator-deployment-replication
301-
manifests-operator-deployment-replication: export CHART_NAME := kube-arangodb
302-
manifests-operator-deployment-replication: export NAME := deployment-replication
303-
manifests-operator-deployment-replication: helm
304-
@echo Building manifests for Operator Deployment Replication - $(MANIFESTPATHDEPLOYMENTREPLICATION)
305-
@$(HELM_CMD) \
306-
--set "operator.features.deployment=false" \
307-
--set "operator.features.deploymentReplications=true" \
308-
--set "operator.features.storage=false" \
309-
--set "operator.features.backup=false" > "$(MANIFESTPATHDEPLOYMENTREPLICATION)"
310-
311-
.PHONY: manifests-operator-storage
312-
manifests-operator-storage: export CHART_NAME := kube-arangodb
313-
manifests-operator-storage: export NAME := storage
314-
manifests-operator-storage: helm
315-
@echo Building manifests for Operator Storage - $(MANIFESTPATHSTORAGE)
316-
@$(HELM_CMD) \
317-
--set "operator.features.deployment=false" \
318-
--set "operator.features.deploymentReplications=false" \
319-
--set "operator.features.storage=true" \
320-
--set "operator.features.backup=false" > "$(MANIFESTPATHSTORAGE)"
321-
322-
.PHONY: manifests-operator-backup
323-
manifests-operator-backup: export CHART_NAME := kube-arangodb
324-
manifests-operator-backup: export NAME := backup
325-
manifests-operator-backup: helm
326-
@echo Building manifests for Operator Backup - $(MANIFESTPATHBACKUP)
327-
@$(HELM_CMD) \
328-
--set "operator.features.deployment=false" \
329-
--set "operator.features.deploymentReplications=false" \
330-
--set "operator.features.storage=false" \
331-
--set "operator.features.backup=true" > "$(MANIFESTPATHBACKUP)"
332-
333-
.PHONY: manifests-operator
334-
manifests-operator: manifests-operator-deployment manifests-operator-deployment-replication manifests-operator-storage manifests-operator-backup
287+
define manifest-generator
288+
$(eval _TARGET:=$(call LOWER,$1))
289+
$(eval _ENV:=$(call UPPER_ENV,$1))
290+
.PHONY: manifests-$(_TARGET)-file
291+
manifests-$(_TARGET)-file: export CHART_NAME := $2
292+
manifests-$(_TARGET)-file: export NAME := $(_TARGET)
293+
manifests-$(_TARGET)-file: helm
294+
@echo Building manifests for $(_ENV) - $$(MANIFESTPATH$(_ENV))
295+
@$$(HELM_CMD) $3 > "$$(MANIFESTPATH$(_ENV))"
296+
manifests: manifests-$(_TARGET)-file
297+
298+
.PHONY: manifests-$(_TARGET)-kustomize
299+
manifests-$(_TARGET)-kustomize: export CHART_NAME := $2
300+
manifests-$(_TARGET)-kustomize: export NAME := $(_TARGET)
301+
manifests-$(_TARGET)-kustomize: helm
302+
@echo Building kustomize manifests for $(_ENV) - $$(KUSTOMIZEPATH$(_ENV))
303+
@$$(HELM_CMD) $3 > "$$(KUSTOMIZEPATH$(_ENV))"
304+
manifests: manifests-$(_TARGET)-kustomize
305+
endef
306+
307+
.PHONY: manifests
308+
manifests:
309+
310+
$(eval $(call manifest-generator, crd, kube-arangodb-crd))
311+
312+
$(eval $(call manifest-generator, test, kube-arangodb-test))
313+
314+
$(eval $(call manifest-generator, deployment, kube-arangodb, \
315+
--set "operator.features.deployment=true" \
316+
--set "operator.features.deploymentReplications=false" \
317+
--set "operator.features.storage=false" \
318+
--set "operator.features.backup=false"))
319+
320+
$(eval $(call manifest-generator, deployment-replication, kube-arangodb, \
321+
--set "operator.features.deployment=false" \
322+
--set "operator.features.deploymentReplications=true" \
323+
--set "operator.features.storage=false" \
324+
--set "operator.features.backup=false"))
325+
326+
$(eval $(call manifest-generator, storage, kube-arangodb, \
327+
--set "operator.features.deployment=false" \
328+
--set "operator.features.deploymentReplications=false" \
329+
--set "operator.features.storage=true" \
330+
--set "operator.features.backup=false"))
331+
332+
$(eval $(call manifest-generator, backup, kube-arangodb, \
333+
--set "operator.features.deployment=false" \
334+
--set "operator.features.deploymentReplications=false" \
335+
--set "operator.features.storage=false" \
336+
--set "operator.features.backup=true"))
337+
338+
$(eval $(call manifest-generator, all, kube-arangodb, \
339+
--set "operator.features.deployment=true" \
340+
--set "operator.features.deploymentReplications=true" \
341+
--set "operator.features.storage=true" \
342+
--set "operator.features.backup=true"))
335343

336344
.PHONY: chart-crd
337345
chart-crd: export CHART_NAME := kube-arangodb-crd
338346
chart-crd: helm
339347
@mkdir -p "$(ROOTDIR)/bin/charts"
340348
@$(HELM_PACKAGE_CMD)
349+
manifests: chart-crd
341350

342351
.PHONY: chart-operator
343352
chart-operator: export CHART_NAME := kube-arangodb
344353
chart-operator: helm
345354
@mkdir -p "$(ROOTDIR)/bin/charts"
346355
@$(HELM_PACKAGE_CMD)
347356

348-
.PHONY: manifests
349-
manifests: helm manifests-crd manifests-operator manifests-test chart-crd chart-operator
357+
manifests: chart-operator
350358

351359
# Testing
352360

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,25 @@ kubectl apply -f https://raw.githubusercontent.com/arangodb/kube-arangodb/1.0.3/
8686
This procedure can also be used for upgrades and will not harm any
8787
running ArangoDB deployments.
8888

89+
## Installation of latest release using kustomize
90+
91+
Installation using [kustomize](https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/) looks like installation from yaml files,
92+
but user is allowed to modify namespace or resource names without yaml modifications.
93+
94+
IT is recommended to use kustomization instead of handcrafting namespace in yaml files - kustomization will replace not only resource namespaces,
95+
but also namespace references in resources like ClusterRoleBinding.
96+
97+
Example kustomization file:
98+
```
99+
apiVersion: kustomize.config.k8s.io/v1beta1
100+
kind: Kustomization
101+
102+
namespace: my-custom-namespace
103+
104+
bases:
105+
- https://github.com/arangodb/kube-arangodb/manifests/kustomize/deployment/?ref=1.0.3
106+
```
107+
89108
## Installation of latest release using Helm
90109

91110
Only use this procedure for a new install of the operator. See below for

chart/kube-arangodb/templates/_helpers.tpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,14 @@ Create the name of the Operator RBAC role
3434
{{- define "kube-arangodb.rbac" -}}
3535
{{- printf "%s-%s" (include "kube-arangodb.operatorName" .) "rbac" | trunc 63 | trimSuffix "-" -}}
3636
{{- end -}}
37+
38+
{{/*
39+
Create the name of the Operator Cluster resources
40+
*/}}
41+
{{- define "kube-arangodb.rbac-cluster" -}}
42+
{{- if eq .Release.Namespace "default" -}}
43+
{{- printf "%s-rbac" (include "kube-arangodb.operatorName" .) | trunc 63 | trimSuffix "-" -}}
44+
{{- else -}}
45+
{{- printf "%s-%s-rbac" (include "kube-arangodb.operatorName" .) .Release.Namespace | trunc 63 | trimSuffix "-" -}}
46+
{{- end -}}
47+
{{- end -}}

chart/kube-arangodb/templates/backup-operator/cluster-role-binding.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
apiVersion: rbac.authorization.k8s.io/v1
55
kind: ClusterRoleBinding
66
metadata:
7-
name: {{ template "kube-arangodb.rbac" . }}-storage
8-
namespace: {{ .Release.Namespace }}
7+
name: {{ template "kube-arangodb.rbac-cluster" . }}-backup
98
labels:
109
app.kubernetes.io/name: {{ template "kube-arangodb.name" . }}
1110
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
@@ -15,7 +14,7 @@ metadata:
1514
roleRef:
1615
apiGroup: rbac.authorization.k8s.io
1716
kind: ClusterRole
18-
name: {{ template "kube-arangodb.rbac" . }}-backup
17+
name: {{ template "kube-arangodb.rbac-cluster" . }}-backup
1918
subjects:
2019
- kind: ServiceAccount
2120
name: {{ template "kube-arangodb.operatorName" . }}

chart/kube-arangodb/templates/backup-operator/cluster-role.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
apiVersion: rbac.authorization.k8s.io/v1
55
kind: ClusterRole
66
metadata:
7-
name: {{ template "kube-arangodb.rbac" . }}-backup
8-
namespace: {{ .Release.Namespace }}
7+
name: {{ template "kube-arangodb.rbac-cluster" . }}-backup
98
labels:
109
app.kubernetes.io/name: {{ template "kube-arangodb.name" . }}
1110
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}

chart/kube-arangodb/templates/deployment-operator/cluster-role-binding.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
apiVersion: rbac.authorization.k8s.io/v1
55
kind: ClusterRoleBinding
66
metadata:
7-
name: {{ template "kube-arangodb.rbac" . }}-deployment
8-
namespace: {{ .Release.Namespace }}
7+
name: {{ template "kube-arangodb.rbac-cluster" . }}-deployment
98
labels:
109
app.kubernetes.io/name: {{ template "kube-arangodb.name" . }}
1110
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
@@ -15,7 +14,7 @@ metadata:
1514
roleRef:
1615
apiGroup: rbac.authorization.k8s.io
1716
kind: ClusterRole
18-
name: {{ template "kube-arangodb.rbac" . }}-deployment
17+
name: {{ template "kube-arangodb.rbac-cluster" . }}-deployment
1918
subjects:
2019
- kind: ServiceAccount
2120
name: {{ template "kube-arangodb.operatorName" . }}

chart/kube-arangodb/templates/deployment-operator/cluster-role.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
apiVersion: rbac.authorization.k8s.io/v1
55
kind: ClusterRole
66
metadata:
7-
name: {{ template "kube-arangodb.rbac" . }}-deployment
8-
namespace: {{ .Release.Namespace }}
7+
name: {{ template "kube-arangodb.rbac-cluster" . }}-deployment
98
labels:
109
app.kubernetes.io/name: {{ template "kube-arangodb.name" . }}
1110
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}

chart/kube-arangodb/templates/deployment-replications-operator/cluster-role-binding.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ apiVersion: rbac.authorization.k8s.io/v1
55
kind: ClusterRoleBinding
66
metadata:
77
name: {{ template "kube-arangodb.rbac" . }}-deployment-replication
8-
namespace: {{ .Release.Namespace }}
98
labels:
109
app.kubernetes.io/name: {{ template "kube-arangodb.name" . }}
1110
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
@@ -15,7 +14,7 @@ metadata:
1514
roleRef:
1615
apiGroup: rbac.authorization.k8s.io
1716
kind: ClusterRole
18-
name: {{ template "kube-arangodb.rbac" . }}-deployment-replication
17+
name: {{ template "kube-arangodb.rbac-cluster" . }}-deployment-replication
1918
subjects:
2019
- kind: ServiceAccount
2120
name: {{ template "kube-arangodb.operatorName" . }}

chart/kube-arangodb/templates/deployment-replications-operator/cluster-role.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
apiVersion: rbac.authorization.k8s.io/v1
55
kind: ClusterRole
66
metadata:
7-
name: {{ template "kube-arangodb.rbac" . }}-deployment-replication
8-
namespace: {{ .Release.Namespace }}
7+
name: {{ template "kube-arangodb.rbac-cluster" . }}-deployment-replication
98
labels:
109
app.kubernetes.io/name: {{ template "kube-arangodb.name" . }}
1110
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}

0 commit comments

Comments
 (0)