From 57a2b65f201099c9d831f1afe8181c1dfa8b4fe2 Mon Sep 17 00:00:00 2001 From: Daniel Cosme Date: Sat, 2 May 2026 06:55:29 -0400 Subject: [PATCH] Split CloudNativePG from Postgres Cluster --- apps/hydra/linkding/kustomization.yaml | 2 +- cmd/apps/main.go | 2 + .../hydra/cloud-native-pg/kustomization.yaml | 3 - infrastructure/hydra/kustomization.yaml | 2 +- .../hydra/longhorn/kustomization.yaml | 2 +- .../hydra/monitoring/kustomization.yaml | 2 +- .../cluster-namespace.yaml | 0 .../immich-db.yaml | 0 .../hydra/postgres/kustomization.yaml | 9 +++ .../pg-cluster.yaml | 0 .../hydra/truenas-csi/kustomization.yaml | 2 +- pkg/cnpg/cluster.go | 37 ----------- pkg/cnpg/cnpg.go | 3 - pkg/cnpg/database.go | 22 ------- pkg/postgres/postgres.go | 65 +++++++++++++++++++ 15 files changed, 81 insertions(+), 70 deletions(-) rename infrastructure/hydra/{cloud-native-pg => postgres}/cluster-namespace.yaml (100%) rename infrastructure/hydra/{cloud-native-pg => postgres}/immich-db.yaml (100%) create mode 100644 infrastructure/hydra/postgres/kustomization.yaml rename infrastructure/hydra/{cloud-native-pg => postgres}/pg-cluster.yaml (100%) create mode 100644 pkg/postgres/postgres.go diff --git a/apps/hydra/linkding/kustomization.yaml b/apps/hydra/linkding/kustomization.yaml index 96e2f9e..f79e113 100644 --- a/apps/hydra/linkding/kustomization.yaml +++ b/apps/hydra/linkding/kustomization.yaml @@ -4,7 +4,7 @@ metadata: name: linking namespace: linkding resources: -- srv.yaml - pvc.yaml - deployment.yaml - namespace.yaml +- srv.yaml diff --git a/cmd/apps/main.go b/cmd/apps/main.go index d83be59..6c26046 100644 --- a/cmd/apps/main.go +++ b/cmd/apps/main.go @@ -11,6 +11,7 @@ import ( "danicos.dev/daniel/homelab/pkg/linkding" "danicos.dev/daniel/homelab/pkg/longhorn" "danicos.dev/daniel/homelab/pkg/monitoring" + "danicos.dev/daniel/homelab/pkg/postgres" "danicos.dev/daniel/homelab/pkg/root" "danicos.dev/daniel/homelab/pkg/truenas" /* @@ -29,6 +30,7 @@ func main() { "longhorn": longhorn.Stack(), "truenas-csi": truenas.Stack(), "cloud-native-pg": cnpg.Stack(), + "postgres": postgres.Stack(), } for name, s := range hydra_infrastructure { fmt.Printf("STACK: %s\n", name) diff --git a/infrastructure/hydra/cloud-native-pg/kustomization.yaml b/infrastructure/hydra/cloud-native-pg/kustomization.yaml index 8ad6c57..1571fea 100644 --- a/infrastructure/hydra/cloud-native-pg/kustomization.yaml +++ b/infrastructure/hydra/cloud-native-pg/kustomization.yaml @@ -5,8 +5,5 @@ metadata: namespace: cnpg-system resources: - namespace.yaml -- cluster-namespace.yaml - helm-repository-source.yaml - helm-release.yaml -- pg-cluster.yaml -- immich-db.yaml diff --git a/infrastructure/hydra/kustomization.yaml b/infrastructure/hydra/kustomization.yaml index e267aa8..e18e437 100644 --- a/infrastructure/hydra/kustomization.yaml +++ b/infrastructure/hydra/kustomization.yaml @@ -6,4 +6,4 @@ resources: - truenas-csi-driver.yaml - monitoring/ - longhorn/ - # - cloud-native-pg/ + - cloud-native-pg/ diff --git a/infrastructure/hydra/longhorn/kustomization.yaml b/infrastructure/hydra/longhorn/kustomization.yaml index b4b7f31..821183c 100644 --- a/infrastructure/hydra/longhorn/kustomization.yaml +++ b/infrastructure/hydra/longhorn/kustomization.yaml @@ -4,6 +4,6 @@ metadata: name: longhorn namespace: longhorn-system resources: -- namespace.yaml - longhorn-stack.yaml - release.yaml +- namespace.yaml diff --git a/infrastructure/hydra/monitoring/kustomization.yaml b/infrastructure/hydra/monitoring/kustomization.yaml index f7b18cc..e6f7beb 100644 --- a/infrastructure/hydra/monitoring/kustomization.yaml +++ b/infrastructure/hydra/monitoring/kustomization.yaml @@ -4,6 +4,6 @@ metadata: name: monitoring namespace: monitoring resources: -- namespace.yaml - kube-prometheus-stack.yaml - release.yaml +- namespace.yaml diff --git a/infrastructure/hydra/cloud-native-pg/cluster-namespace.yaml b/infrastructure/hydra/postgres/cluster-namespace.yaml similarity index 100% rename from infrastructure/hydra/cloud-native-pg/cluster-namespace.yaml rename to infrastructure/hydra/postgres/cluster-namespace.yaml diff --git a/infrastructure/hydra/cloud-native-pg/immich-db.yaml b/infrastructure/hydra/postgres/immich-db.yaml similarity index 100% rename from infrastructure/hydra/cloud-native-pg/immich-db.yaml rename to infrastructure/hydra/postgres/immich-db.yaml diff --git a/infrastructure/hydra/postgres/kustomization.yaml b/infrastructure/hydra/postgres/kustomization.yaml new file mode 100644 index 0000000..057d6bc --- /dev/null +++ b/infrastructure/hydra/postgres/kustomization.yaml @@ -0,0 +1,9 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +metadata: + name: cnpg-cluster + namespace: cnpg-cluster +resources: +- pg-cluster.yaml +- immich-db.yaml +- cluster-namespace.yaml diff --git a/infrastructure/hydra/cloud-native-pg/pg-cluster.yaml b/infrastructure/hydra/postgres/pg-cluster.yaml similarity index 100% rename from infrastructure/hydra/cloud-native-pg/pg-cluster.yaml rename to infrastructure/hydra/postgres/pg-cluster.yaml diff --git a/infrastructure/hydra/truenas-csi/kustomization.yaml b/infrastructure/hydra/truenas-csi/kustomization.yaml index 96ca872..1509ea8 100644 --- a/infrastructure/hydra/truenas-csi/kustomization.yaml +++ b/infrastructure/hydra/truenas-csi/kustomization.yaml @@ -4,7 +4,7 @@ metadata: name: truenas-csi namespace: truenas-csi resources: +- namespace.yaml - config.yaml - nfs-storage-class.yaml - iscsi-storage-class.yaml -- namespace.yaml diff --git a/pkg/cnpg/cluster.go b/pkg/cnpg/cluster.go index a9117f4..ce28c66 100644 --- a/pkg/cnpg/cluster.go +++ b/pkg/cnpg/cluster.go @@ -1,38 +1 @@ package cnpg - -import ( - "danicos.dev/daniel/go-kube/pkg/kube" - "danicos.dev/daniel/homelab/pkg/root" - - kube_cnpg "danicos.dev/daniel/go-kube/pkg/cnpg" - pg "github.com/cloudnative-pg/api/pkg/api/v1" - core "k8s.io/api/core/v1" -) - -var cluster_meta = kube.NewMetadata(root.CloudNativePG+"-cluster", root.PGClusterNamespace) - -func Cluster() pg.Cluster { - spec := pg.ClusterSpec{ - Instances: 3, - StorageConfiguration: pg.StorageConfiguration{ - StorageClass: new(root.KUBE_LOCAL_STORAGE_CLASS), - Size: "10Gi", - ResizeInUseVolumes: new(true), - PersistentVolumeClaimTemplate: &core.PersistentVolumeClaimSpec{ - StorageClassName: new(root.KUBE_LOCAL_STORAGE_CLASS), - }, - }, - Managed: &pg.ManagedConfiguration{ - Roles: []pg.RoleConfiguration{ - { - Name: root.Immich.Name, - Login: true, - PasswordSecret: &pg.LocalObjectReference{ - Name: ImmichPGSecret.Name, - }, - }, - }, - }, - } - return kube_cnpg.NewCluster(cluster_meta, spec) -} diff --git a/pkg/cnpg/cnpg.go b/pkg/cnpg/cnpg.go index bc2cfc4..e66b89f 100644 --- a/pkg/cnpg/cnpg.go +++ b/pkg/cnpg/cnpg.go @@ -18,11 +18,8 @@ func Stack() stack.Stack { meta_system, map[string]any{ "namespace": SystemNamespace, - "cluster-namespace": root.PGClusterNamespace, "helm-repository-source": HelmSource(), "helm-release": HelmRelease(), - "pg-cluster": Cluster(), - "immich-db": ImmichDatabase(), }, ) return kz.Stack("cloud-native-pg") diff --git a/pkg/cnpg/database.go b/pkg/cnpg/database.go index 1dd2ac6..ce28c66 100644 --- a/pkg/cnpg/database.go +++ b/pkg/cnpg/database.go @@ -1,23 +1 @@ package cnpg - -import ( - kube_cnpg "danicos.dev/daniel/go-kube/pkg/cnpg" - "danicos.dev/daniel/go-kube/pkg/kube" - "danicos.dev/daniel/homelab/pkg/root" - pg "github.com/cloudnative-pg/api/pkg/api/v1" - core "k8s.io/api/core/v1" -) - -var ImmichPGSecret = kube_cnpg.NewPGSecret(root.Immich.Name, root.PGClusterNamespace) - -func ImmichDatabase() pg.Database { - meta := kube.NewMetadata(root.Immich.Name+"-db", root.PGClusterNamespace) - spec := pg.DatabaseSpec{ - Name: root.Immich.Name, - Owner: root.Immich.Name, - ClusterRef: core.LocalObjectReference{ - Name: cluster_meta.Meta().Name, - }, - } - return kube_cnpg.NewDatabase(meta, spec) -} diff --git a/pkg/postgres/postgres.go b/pkg/postgres/postgres.go new file mode 100644 index 0000000..673f766 --- /dev/null +++ b/pkg/postgres/postgres.go @@ -0,0 +1,65 @@ +package postgres + +import ( + "danicos.dev/daniel/go-kube/pkg/kube" + "danicos.dev/daniel/go-kube/pkg/stack" + "danicos.dev/daniel/homelab/pkg/root" + + kube_cnpg "danicos.dev/daniel/go-kube/pkg/cnpg" + pg "github.com/cloudnative-pg/api/pkg/api/v1" + core "k8s.io/api/core/v1" +) + +var cluster_meta = kube.NewMetadata(root.CloudNativePG+"-cluster", root.PGClusterNamespace) + +func Stack() stack.Stack { + kz := kube.NewKuztomizedStack( + cluster_meta, + map[string]any{ + "cluster-namespace": root.PGClusterNamespace, + "pg-cluster": Cluster(), + "immich-db": ImmichDatabase(), + }, + ) + return kz.Stack("postgres") +} + +func Cluster() pg.Cluster { + spec := pg.ClusterSpec{ + Instances: 3, + StorageConfiguration: pg.StorageConfiguration{ + StorageClass: new(root.KUBE_LOCAL_STORAGE_CLASS), + Size: "10Gi", + ResizeInUseVolumes: new(true), + PersistentVolumeClaimTemplate: &core.PersistentVolumeClaimSpec{ + StorageClassName: new(root.KUBE_LOCAL_STORAGE_CLASS), + }, + }, + Managed: &pg.ManagedConfiguration{ + Roles: []pg.RoleConfiguration{ + { + Name: root.Immich.Name, + Login: true, + PasswordSecret: &pg.LocalObjectReference{ + Name: ImmichPGSecret.Name, + }, + }, + }, + }, + } + return kube_cnpg.NewCluster(cluster_meta, spec) +} + +var ImmichPGSecret = kube_cnpg.NewPGSecret(root.Immich.Name, root.PGClusterNamespace) + +func ImmichDatabase() pg.Database { + meta := kube.NewMetadata(root.Immich.Name+"-db", root.PGClusterNamespace) + spec := pg.DatabaseSpec{ + Name: root.Immich.Name, + Owner: root.Immich.Name, + ClusterRef: core.LocalObjectReference{ + Name: cluster_meta.Meta().Name, + }, + } + return kube_cnpg.NewDatabase(meta, spec) +}