Split CloudNativePG from Postgres Cluster

This commit is contained in:
Daniel Cosme
2026-05-02 06:55:29 -04:00
parent e6973e801c
commit 57a2b65f20
15 changed files with 81 additions and 70 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ metadata:
name: linking name: linking
namespace: linkding namespace: linkding
resources: resources:
- srv.yaml
- pvc.yaml - pvc.yaml
- deployment.yaml - deployment.yaml
- namespace.yaml - namespace.yaml
- srv.yaml
+2
View File
@@ -11,6 +11,7 @@ import (
"danicos.dev/daniel/homelab/pkg/linkding" "danicos.dev/daniel/homelab/pkg/linkding"
"danicos.dev/daniel/homelab/pkg/longhorn" "danicos.dev/daniel/homelab/pkg/longhorn"
"danicos.dev/daniel/homelab/pkg/monitoring" "danicos.dev/daniel/homelab/pkg/monitoring"
"danicos.dev/daniel/homelab/pkg/postgres"
"danicos.dev/daniel/homelab/pkg/root" "danicos.dev/daniel/homelab/pkg/root"
"danicos.dev/daniel/homelab/pkg/truenas" "danicos.dev/daniel/homelab/pkg/truenas"
/* /*
@@ -29,6 +30,7 @@ func main() {
"longhorn": longhorn.Stack(), "longhorn": longhorn.Stack(),
"truenas-csi": truenas.Stack(), "truenas-csi": truenas.Stack(),
"cloud-native-pg": cnpg.Stack(), "cloud-native-pg": cnpg.Stack(),
"postgres": postgres.Stack(),
} }
for name, s := range hydra_infrastructure { for name, s := range hydra_infrastructure {
fmt.Printf("STACK: %s\n", name) fmt.Printf("STACK: %s\n", name)
@@ -5,8 +5,5 @@ metadata:
namespace: cnpg-system namespace: cnpg-system
resources: resources:
- namespace.yaml - namespace.yaml
- cluster-namespace.yaml
- helm-repository-source.yaml - helm-repository-source.yaml
- helm-release.yaml - helm-release.yaml
- pg-cluster.yaml
- immich-db.yaml
+1 -1
View File
@@ -6,4 +6,4 @@ resources:
- truenas-csi-driver.yaml - truenas-csi-driver.yaml
- monitoring/ - monitoring/
- longhorn/ - longhorn/
# - cloud-native-pg/ - cloud-native-pg/
@@ -4,6 +4,6 @@ metadata:
name: longhorn name: longhorn
namespace: longhorn-system namespace: longhorn-system
resources: resources:
- namespace.yaml
- longhorn-stack.yaml - longhorn-stack.yaml
- release.yaml - release.yaml
- namespace.yaml
@@ -4,6 +4,6 @@ metadata:
name: monitoring name: monitoring
namespace: monitoring namespace: monitoring
resources: resources:
- namespace.yaml
- kube-prometheus-stack.yaml - kube-prometheus-stack.yaml
- release.yaml - release.yaml
- namespace.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
@@ -4,7 +4,7 @@ metadata:
name: truenas-csi name: truenas-csi
namespace: truenas-csi namespace: truenas-csi
resources: resources:
- namespace.yaml
- config.yaml - config.yaml
- nfs-storage-class.yaml - nfs-storage-class.yaml
- iscsi-storage-class.yaml - iscsi-storage-class.yaml
- namespace.yaml
-37
View File
@@ -1,38 +1 @@
package cnpg 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)
}
-3
View File
@@ -18,11 +18,8 @@ func Stack() stack.Stack {
meta_system, meta_system,
map[string]any{ map[string]any{
"namespace": SystemNamespace, "namespace": SystemNamespace,
"cluster-namespace": root.PGClusterNamespace,
"helm-repository-source": HelmSource(), "helm-repository-source": HelmSource(),
"helm-release": HelmRelease(), "helm-release": HelmRelease(),
"pg-cluster": Cluster(),
"immich-db": ImmichDatabase(),
}, },
) )
return kz.Stack("cloud-native-pg") return kz.Stack("cloud-native-pg")
-22
View File
@@ -1,23 +1 @@
package cnpg 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)
}
+65
View File
@@ -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)
}