This document explains the architectural decision behind using PostCreateHook Jobs for PostgreSQL installation instead of Helm subchart dependencies in KubeFlex.
PostgreSQL in KubeFlex is installed via a PostCreateHook Job mechanism rather than as a traditional Helm subchart dependency. This decision addresses several technical challenges and compatibility requirements.
This document answers the key questions raised in GitHub Issue #401:
Problem: Older Helm versions (< 3.17.1) have a critical bug with conditional subchart dependencies.
# This configuration fails in older Helm versions
dependencies:
- name: postgresql
condition: postgresql.enabled
# values.yaml
postgresql:
enabled: false # Should disable PostgreSQL
What happens in old Helm:
condition: postgresql.enabled fieldenabled: falseImpact:
Problem: OpenShift requires specific security context configurations that vary by platform.
# OpenShift requires conditional templating
postgresql:
primary:
securityContext:
enabled: false
containerSecurityContext:
runAsUser: null
runAsGroup: null
postgresql:
primary:
securityContext:
runAsUser: 999
runAsGroup: 999
Subchart Limitation:
values.yaml files do not support templatingCurrent Solution:
Problem: Control planes need dynamic configuration based on runtime parameters.
# PostCreateHook supports dynamic variables
vars:
Namespace: "" # Generated at runtime
ControlPlaneName: "" # Unique per control plane
HookName: "" # Template variable
DATABASE_NAME: "-db" # Dynamic database naming
Subchart Limitation:
PostCreateHook Benefits:
Why PostgreSQL is Optional:
Multiple Backend Support: KubeFlex supports both shared and dedicated database backends
spec:
backend: shared # Uses shared PostgreSQL
# OR
backend: dedicated # Uses dedicated database per control plane
External Database Integration: Users may want to use existing database infrastructure
# Users can skip PostgreSQL and use external databases
kflex create cp1 --type k8s # No PostgreSQL hook
Resource Optimization: Not all deployments need PostgreSQL
Deployment Flexibility: Different control plane types have different requirements
kflex create cp1 --type host # No database needed
kflex create cp2 --type k8s --postcreate-hook postgres # Database needed
Why PostgreSQL Uses Fixed Namespace:
Control Plane Isolation: Each control plane gets its own namespace
kflex-cp1/ # Control plane 1 resources
kflex-cp2/ # Control plane 2 resources
postgres/ # Shared PostgreSQL instance
Resource Sharing: Multiple control planes can share PostgreSQL instance
# Multiple control planes, PostgreSQL
spec:
backend: shared # All control planes use same PostgreSQL
Lifecycle Management: PostgreSQL lifecycle independent of individual control planes
Security Boundaries: Clear separation between compute and data layers
Control Plane Namespace: Application logic, API servers
PostgreSQL Namespace: Data persistence, database operations