This commit is contained in:
2023-08-06 21:07:18 +02:00
parent 10570d29fe
commit b464ef24d7
12 changed files with 694 additions and 503 deletions

View File

@@ -159,7 +159,7 @@ resource "kubectl_manifest" "config" {
namespace: "${var.namespace}"
labels: ${jsonencode(local.common-labels)}
data:
DOLI_DB_HOST: "${var.instance}-${var.component}.${var.namespace}.svc"
DOLI_DB_HOST: "${var.instance}-${var.component}-pg-rw.${var.namespace}.svc"
DOLI_DB_USER: "${var.component}"
DOLI_DB_NAME: "${var.component}"
DOLI_DB_PORT: "5432"

View File

@@ -95,7 +95,7 @@ spec:
valueFrom:
secretKeyRef:
key: password
name: "${var.component}.${var.instance}-${var.component}.credentials.postgresql.acid.zalan.do"
name: "${var.instance}-${var.component}-pg-app"
envFrom:
- configMapRef:
name: "${kubectl_manifest.config.name}"

View File

@@ -6,11 +6,6 @@ metadata:
name: dolibarr
description: null
options:
domain-name:
default: your_company.com
examples:
- your_company.com
type: string
redis:
default:
exporter:
@@ -44,86 +39,6 @@ options:
default: 2Gi
type: string
type: object
domain:
default: your-company
examples:
- your-company
type: string
ingress-class:
default: traefik
examples:
- traefik
type: string
parameters:
default:
MAIN_LANG_DEFAULT: auto
examples:
- MAIN_LANG_DEFAULT: auto
properties:
MAIN_LANG_DEFAULT:
default: auto
type: string
type: object
storage:
default:
accessMode: ReadWriteOnce
size: 10Gi
type: Filesystem
examples:
- accessMode: ReadWriteOnce
size: 10Gi
type: Filesystem
properties:
accessMode:
default: ReadWriteOnce
enum:
- ReadWriteOnce
- ReadOnlyMany
- ReadWriteMany
type: string
size:
default: 10Gi
type: string
type:
default: Filesystem
enum:
- Filesystem
- block
type: string
type: object
issuer:
default: letsencrypt-prod
examples:
- letsencrypt-prod
type: string
modules:
default:
- societe
examples:
- - societe
items:
type: string
type: array
sub-domain:
default: erp
examples:
- erp
type: string
user-groups:
default:
- admin: true
name: dolibarr-admin
examples:
- - admin: true
name: dolibarr-admin
items:
properties:
admin:
type: boolean
name:
type: string
type: object
type: array
hpa:
default:
avg-cpu: 50
@@ -144,6 +59,125 @@ options:
default: 1
type: integer
type: object
postgres:
default:
replicas: 1
storage: 5Gi
version: '14'
examples:
- replicas: 1
storage: 5Gi
version: '14'
properties:
replicas:
default: 1
type: integer
storage:
default: 5Gi
type: string
version:
default: '14'
type: string
type: object
resources:
default:
limits:
cpu: 200m
memory: 256Mi
requests:
cpu: 50m
memory: 100Mi
examples:
- limits:
cpu: 200m
memory: 256Mi
requests:
cpu: 50m
memory: 100Mi
properties:
limits:
default:
cpu: 200m
memory: 256Mi
properties:
cpu:
default: 200m
type: string
memory:
default: 256Mi
type: string
type: object
requests:
default:
cpu: 50m
memory: 100Mi
properties:
cpu:
default: 50m
type: string
memory:
default: 100Mi
type: string
type: object
type: object
sub-domain:
default: erp
examples:
- erp
type: string
issuer:
default: letsencrypt-prod
examples:
- letsencrypt-prod
type: string
log-level:
default: 5
examples:
- 5
type: integer
ingress-class:
default: traefik
examples:
- traefik
type: string
modules:
default:
- societe
examples:
- - societe
items:
type: string
type: array
domain-name:
default: your_company.com
examples:
- your_company.com
type: string
user-groups:
default:
- admin: true
name: dolibarr-admin
examples:
- - admin: true
name: dolibarr-admin
items:
properties:
admin:
type: boolean
name:
type: string
type: object
type: array
parameters:
default:
MAIN_LANG_DEFAULT: auto
examples:
- MAIN_LANG_DEFAULT: auto
properties:
MAIN_LANG_DEFAULT:
default: auto
type: string
type: object
images:
default:
dolibarr:
@@ -209,71 +243,37 @@ options:
type: string
type: object
type: object
log-level:
default: 5
domain:
default: your-company
examples:
- 5
type: integer
postgres:
- your-company
type: string
storage:
default:
replicas: 1
storage: 5Gi
version: '14'
accessMode: ReadWriteOnce
size: 10Gi
type: Filesystem
examples:
- replicas: 1
storage: 5Gi
version: '14'
- accessMode: ReadWriteOnce
size: 10Gi
type: Filesystem
properties:
replicas:
default: 1
type: integer
storage:
default: 5Gi
accessMode:
default: ReadWriteOnce
enum:
- ReadWriteOnce
- ReadOnlyMany
- ReadWriteMany
type: string
version:
default: '14'
size:
default: 10Gi
type: string
type:
default: Filesystem
enum:
- Filesystem
- block
type: string
type: object
resources:
default:
limits:
cpu: 200m
memory: 256Mi
requests:
cpu: 50m
memory: 100Mi
examples:
- limits:
cpu: 200m
memory: 256Mi
requests:
cpu: 50m
memory: 100Mi
properties:
limits:
default:
cpu: 200m
memory: 256Mi
properties:
cpu:
default: 200m
type: string
memory:
default: 256Mi
type: string
type: object
requests:
default:
cpu: 50m
memory: 100Mi
properties:
cpu:
default: 50m
type: string
memory:
default: 100Mi
type: string
type: object
type: object
dependencies:
- dist: null
@@ -287,7 +287,7 @@ dependencies:
component: cert-manager-self-sign
- dist: null
category: dbo
component: postgresql
component: pg
- dist: null
category: dbo
component: redis
@@ -298,3 +298,4 @@ providers:
postgresql: null
restapi: true
http: true
tfaddtype: null

View File

@@ -1,5 +1,8 @@
locals {
pg-labels = merge(local.common-labels, {
"app.kubernetes.io/component" = "pg"
})
postgres-labels = merge(local.common-labels, {
"app.kubernetes.io/component" = "postgresql"
})
}
@@ -10,7 +13,7 @@ resource "kubectl_manifest" "dolibarr_postgresql" {
metadata:
name: "${var.instance}-${var.component}"
namespace: "${var.namespace}"
labels: ${jsonencode(local.pg-labels)}
labels: ${jsonencode(local.postgres-labels)}
spec:
databases:
${var.component}: "${var.component}"
@@ -29,3 +32,76 @@ resource "kubectl_manifest" "dolibarr_postgresql" {
size: "${var.postgres.storage}"
EOF
}
resource "kubectl_manifest" "prj_pre_migrate_pg" {
yaml_body = <<-EOF
apiVersion: batch/v1
kind: Job
metadata:
name: "${var.instance}-remove-zalando-extensions"
namespace: "${var.namespace}"
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: clean
image: docker.io/postgres:15.3-bookworm
imagePullPolicy: IfNotPresent
env:
- name: USERNAME
valueFrom:
secretKeyRef:
key: username
name: postgres.${var.instance}-${var.component}.credentials.postgresql.acid.zalan.do
- name: PASSWORD
valueFrom:
secretKeyRef:
key: password
name: postgres.${var.instance}-${var.component}.credentials.postgresql.acid.zalan.do
- name: DBURL
value: "${var.instance}-${var.component}"
- name: DBNAME
value: "${var.component}"
command:
- /bin/bash
- "-c"
- "echo -ne 'drop view if exists metric_helpers.pg_stat_statements;\ndrop function if exists metric_helpers.pg_stat_statements;\nDROP EXTENSION IF EXISTS pg_stat_statements;\nDROP EXTENSION IF EXISTS pg_stat_kcache;\nDROP EXTENSION IF EXISTS set_user;\n'| PGPASSWORD=\"$PASSWORD\" psql -U $USERNAME -d $DBNAME -h $DBURL"
EOF
}
resource "kubectl_manifest" "prj_pg" {
depends_on = [kubectl_manifest.prj_pre_migrate_pg]
yaml_body = <<-EOF
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: "${var.instance}-${var.component}-pg"
namespace: "${var.namespace}"
labels: ${jsonencode(local.pg-labels)}
spec:
instances: ${var.postgres.replicas}
storage:
size: "${var.postgres.storage}"
bootstrap:
initdb:
database: ${var.component}
owner: ${var.component}
import:
type: microservice
databases:
- ${var.component}
source:
externalCluster: "${var.instance}-${var.component}"
externalClusters:
- name: "${var.instance}-${var.component}"
connectionParameters:
host: "${var.instance}-${var.component}"
user: postgres
dbname: postgres
sslmode: require
password:
name: "postgres.${var.instance}-${var.component}.credentials.postgresql.acid.zalan.do"
key: password
EOF
}