Skip to content

Commit 6054f4c

Browse files
CasLubbersJehoszafat Zimnowodaj-zimnowoda
authored
feat: schema for harbor databases (#1587)
Co-authored-by: Jehoszafat Zimnowoda <[email protected]> Co-authored-by: jeho <[email protected]>
1 parent 337a405 commit 6054f4c

12 files changed

+52
-146
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ chart/otomi/README.md
1515
workflow/
1616
*.new
1717
.envrc
18-
otomi.cpuprofile
18+
otomi.cpuprofile
19+
/.idea/

helmfile.d/helmfile-04.databases.yaml

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ bases:
1111
{{- $v := .Values }}
1212
{{- $a := $v.apps }}
1313
{{- $h := $a.harbor }}
14+
{{- $hdb := $v.databases.harbor }}
15+
{{- $kdb := $v.databases.keycloak }}
1416
{{- $k := $a.keycloak }}
1517

1618
releases:
1719
- name: harbor-otomi-db
18-
installed: {{ and ($h | get "enabled") (or (eq $h.database.type "external") $h.database.importHarborDb) }}
20+
installed: {{ ($h | get "enabled") }}
1921
namespace: harbor
2022
labels:
2123
pkg: harbor
2224
<<: *otomiDb
2325
- name: keycloak-otomi-db
24-
installed: {{ or $v.databases.keycloak.useOtomiDB $v.databases.keycloak.imported }}
26+
installed: true
2527
namespace: keycloak
2628
labels:
2729
pkg: keycloak
28-
<<: *otomiDb
30+
<<: *otomiDb

helmfile.d/snippets/defaults.yaml

+4-8
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,6 @@ environments:
214214
registry:
215215
credentials:
216216
username: otomi-admin
217-
database:
218-
type: external
219-
size: '5Gi'
220-
name: harbor-otomi-db
221-
user: harbor
222-
coreDatabase: registry
223-
importHarborDb: false
224217
resources:
225218
trivy:
226219
requests:
@@ -756,7 +749,6 @@ environments:
756749
memory: 512Mi
757750
databases:
758751
keycloak:
759-
useOtomiDB: true
760752
imported: false
761753
size: '5Gi'
762754
replicas: 2
@@ -767,6 +759,10 @@ environments:
767759
requests:
768760
cpu: 50m
769761
memory: 256Mi
762+
harbor:
763+
size: '5Gi'
764+
replicas: 2
765+
coreDatabase: registry
770766
platformBackups:
771767
database:
772768
harbor:

tests/fixtures/env/apps/harbor.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
apps:
22
harbor:
33
enabled: true
4-
database:
5-
type: internal
6-
importHarborDb: true
74
persistence:
85
imageChartStorage:
96
gcs:

tests/fixtures/env/apps/secrets.harbor.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
apps:
22
harbor:
33
adminPassword: harborsomesecretvalue
4-
databasePassword: somesecretvalue
54
persistence:
65
imageChartStorage:
76
gcs:
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
databases:
2+
harbor:
3+
replicas: 3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
databases:
22
keycloak:
3-
useOtomiDB: false
43
imported: false

values-changes.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,17 @@ changes:
129129
deletions:
130130
- 'apps.loki.storage.gcs.project'
131131
- 'apps.loki.storage.gcs.instance'
132+
- version: 21
133+
deletions:
134+
- 'apps.harbor.databasePassword'
135+
- 'apps.harbor.database.type'
136+
- 'apps.harbor.database.importHarborDb'
137+
- 'apps.harbor.database.name'
138+
- 'apps.harbor.database.user'
139+
- 'apps.harbor.database'
140+
- 'databases.keycloak.useOtomiDB'
141+
additions:
142+
- databases.harbor.replicas: 2
143+
relocations:
144+
- 'apps.harbor.database.size': 'databases.harbor.size'
145+
- 'apps.harbor.resources.database': 'databases.harbor.resources'

values-schema.yaml

+11-28
Original file line numberDiff line numberDiff line change
@@ -2092,10 +2092,6 @@ properties:
20922092
adminPassword:
20932093
type: string
20942094
x-secret: ''
2095-
databasePassword:
2096-
type: string
2097-
description: Once set and deployed it cannot be changed with manual intervention.
2098-
x-secret: '{{ randAlphaNum 20 }}'
20992095
core:
21002096
properties:
21012097
secret:
@@ -2196,23 +2192,6 @@ properties:
21962192
required:
21972193
- secret
21982194
- credentials
2199-
database:
2200-
properties:
2201-
size:
2202-
type: string
2203-
type:
2204-
type: string
2205-
description: Internal is a database provided by the community chart. The external is database provided by the cloudnative-pg.
2206-
enum:
2207-
- internal
2208-
- external
2209-
name:
2210-
type: string
2211-
user:
2212-
type: string
2213-
importHarborDb:
2214-
description: Indicate if an existing database should be importend. (Once set to true you must not change it back)
2215-
type: boolean
22162195
image:
22172196
$ref: '#/definitions/imageSimple'
22182197
resources:
@@ -2222,8 +2201,6 @@ properties:
22222201
$ref: '#/definitions/resources'
22232202
core:
22242203
$ref: '#/definitions/resources'
2225-
database:
2226-
$ref: '#/definitions/resources'
22272204
jobservice:
22282205
$ref: '#/definitions/resources'
22292206
portal:
@@ -2239,8 +2216,6 @@ properties:
22392216
secretKey:
22402217
type: string
22412218
x-secret: '{{ randAlpha 16 }}'
2242-
required:
2243-
- databasePassword
22442219
httpbin:
22452220
description: The famous httpbin application.
22462221
properties:
@@ -4096,9 +4071,6 @@ properties:
40964071
keycloak:
40974072
title: Keycloak
40984073
properties:
4099-
useOtomiDB:
4100-
type: boolean
4101-
default: false
41024074
size:
41034075
type: string
41044076
resources:
@@ -4109,6 +4081,17 @@ properties:
41094081
imported:
41104082
type: boolean
41114083
default: false
4084+
harbor:
4085+
title: Harbor
4086+
properties:
4087+
size:
4088+
type: string
4089+
resources:
4090+
$ref: '#/definitions/resources'
4091+
replicas:
4092+
type: integer
4093+
default: 2
4094+
41124095
teamConfig:
41134096
additionalProperties: false
41144097
patternProperties:

values/harbor/harbor-otomi-db.gotmpl

+7-32
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{{- $v := .Values }}
2-
{{- $h := $v.apps.harbor }}
2+
{{- $hdb := $v.databases.harbor }}
33
{{- $cnpg := $v.apps.cnpg }}
44
{{- $sp := $cnpg.storage }}
55
{{- $b := $v.platformBackups.database.harbor }}
66

7-
name: {{ $h.database.name }}
7+
name: harbor-otomi-db
88
storage:
9-
size: {{ $h.database.size }}
9+
size: {{ $hdb.size }}
10+
instances: {{ $hdb.replicas }}
1011

1112
{{- if $b.enabled }}
1213
backup:
@@ -30,42 +31,16 @@ backup:
3031
{{- end }}
3132
{{- end }}
3233

33-
34-
{{- if $h.database.importHarborDb }}
3534
clusterSpec:
3635
bootstrap:
3736
initdb:
38-
database: {{ $h.database.coreDatabase }}
39-
owner: {{ $h.database.user }}
40-
import:
41-
type: microservice
42-
databases:
43-
- {{ $h.database.coreDatabase }}
44-
source:
45-
externalCluster: harbor-database
46-
externalClusters:
47-
- name: harbor-database
48-
connectionParameters:
49-
host: harbor-database.harbor.svc.cluster.local
50-
user: postgres
51-
dbname: {{ $h.database.coreDatabase }}
52-
sslmode: disable
53-
password:
54-
name: harbor-database
55-
key: POSTGRES_PASSWORD
56-
{{- else }}
57-
clusterSpec:
58-
bootstrap:
59-
initdb:
60-
database: {{ $h.database.coreDatabase }}
61-
owner: {{ $h.database.user }}
37+
database: {{ $hdb.coreDatabase }}
38+
owner: harbor
6239
localeCollate: 'en_US.UTF-8'
6340
localeCType: 'en_US.UTF-8'
64-
{{- end }}
65-
6641

6742
resources:
68-
{{- with $h | get "resources.database" nil }}
43+
{{- with $hdb | get "resources" nil }}
6944
{{- toYaml . | nindent 6 }}
7045
{{- else }}
7146
limits:

values/harbor/harbor.gotmpl

+6-43
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{{- $v := .Values }}
22
{{- $h := $v.apps.harbor }}
3+
{{- $db := $v.databases.harbor }}
34
{{- $hp := $h | get "persistence" dict }}
45
{{- $harborDomain := printf "harbor.%s" $v.cluster.domainSuffix }}
56
{{- $notaryDomain := printf "notary.%s" $v.cluster.domainSuffix }}
@@ -8,8 +9,6 @@
89
{{- $externalUrl := printf "https://%s" $harborDomain }}
910
{{- $tag := $h | get "image.tag" "v2.6.4" }}
1011
{{/*The cloudNativeDb operator is responsible for creating the secret*/}}
11-
{{- $databaseExistingSecret := printf "%s-app" $h.database.name }}
12-
{{- $databaseHost := printf "%s-rw.harbor.svc.cluster.local" $h.database.name }}
1312

1413
externalURL: {{ $externalUrl }}
1514
fullnameOverride: harbor
@@ -64,50 +63,14 @@ core:
6463
xsrfKey: {{ $h | get "core.xsrfKey" nil }}
6564

6665
database:
67-
type: {{ $h.database.type }}
68-
{{- if eq $h.database.type "internal" }}
69-
internal:
70-
priorityClassName: otomi-critical
71-
image:
72-
tag: {{ $tag }}
73-
initContainer:
74-
migrator:
75-
resources:
76-
limits:
77-
cpu: 100m
78-
memory: 512Mi
79-
requests:
80-
cpu: 50m
81-
memory: 256Mi
82-
permissions:
83-
resources:
84-
limits:
85-
cpu: 100m
86-
memory: 512Mi
87-
requests:
88-
cpu: 50m
89-
memory: 256Mi
90-
resources:
91-
{{- with $h | get "resources.database" nil }}
92-
{{- toYaml . | nindent 6 }}
93-
{{- else }}
94-
limits:
95-
cpu: 100m
96-
memory: 512Mi
97-
requests:
98-
cpu: 50m
99-
memory: 256Mi
100-
{{- end }}
101-
password: {{ $h.databasePassword }}
102-
{{- else }}
66+
type: external
10367
external:
10468
# erase default password value from the Harbor Helm chart
10569
password: null
106-
coreDatbase: {{ $h.database.coreDatabase }}
107-
username: {{ $h.database.user }}
108-
host: {{ $databaseHost }}
109-
existingSecret: {{ $databaseExistingSecret }}
110-
{{- end }}
70+
coreDatabase: {{ $db.coreDatabase }}
71+
username: harbor
72+
host: harbor-otomi-db-rw.harbor.svc.cluster.local
73+
existingSecret: harbor-otomi-db-app
11174
podAnnotations:
11275
# this exception allows the chmod fix to pass, which needs root access:
11376
policy.otomi.io/ignore.data-migrator: psp-allowed-users

values/jobs/harbor-backup.gotmpl

-26
This file was deleted.

0 commit comments

Comments
 (0)