Add Immich Database

This commit is contained in:
Daniel Cosme
2026-04-30 19:29:26 -04:00
parent 4d0c2f1cd9
commit 7fd65110bd
15 changed files with 68 additions and 45 deletions
+2 -2
View File
@@ -4,7 +4,7 @@ metadata:
name: linking name: linking
namespace: linkding namespace: linkding
resources: resources:
- deployment.yaml
- namespace.yaml
- srv.yaml - srv.yaml
- pvc.yaml - pvc.yaml
- deployment.yaml
- namespace.yaml
+1 -1
View File
@@ -3,7 +3,7 @@ module danicos.dev/daniel/homelab
go 1.26.2 go 1.26.2
require ( require (
danicos.dev/daniel/go-kube v1.13.0 danicos.dev/daniel/go-kube v1.13.3
github.com/cloudnative-pg/api v1.29.0 github.com/cloudnative-pg/api v1.29.0
github.com/fatih/color v1.19.0 github.com/fatih/color v1.19.0
github.com/fluxcd/helm-controller/api v1.5.4 github.com/fluxcd/helm-controller/api v1.5.4
+2 -2
View File
@@ -1,5 +1,5 @@
danicos.dev/daniel/go-kube v1.13.0 h1:4c6LAkwbiWJ2qXPEPlKF5eD5KAOIN/oSCqgr+rdMykw= danicos.dev/daniel/go-kube v1.13.3 h1:b42L3WEJstDKLKCaAFcgh1Egb915tRlKEYD/hKMiYXE=
danicos.dev/daniel/go-kube v1.13.0/go.mod h1:zOhFK+bE4t14yOokp+yqh8Pht1/U102JV/29QoKBjjc= danicos.dev/daniel/go-kube v1.13.3/go.mod h1:zOhFK+bE4t14yOokp+yqh8Pht1/U102JV/29QoKBjjc=
github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0= github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0=
github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/cloudnative-pg/api v1.29.0 h1:mNx6yJ5qi+Xrjs0NYrUy6V4MlXBkVJxGKwvTJZIuTX4= github.com/cloudnative-pg/api v1.29.0 h1:mNx6yJ5qi+Xrjs0NYrUy6V4MlXBkVJxGKwvTJZIuTX4=
@@ -0,0 +1,11 @@
apiVersion: postgresql.cnpg.io/v1
kind: Database
metadata:
name: immich-db
namespace: cnpg-cluster
spec:
cluster:
name: cnpg-cluster
name: immich
owner: immich
status: {}
@@ -5,15 +5,15 @@ metadata:
namespace: truenas-csi namespace: truenas-csi
resources: resources:
- node-binding.yaml - node-binding.yaml
- nfs-storage-class.yaml - node-deamonset.yaml
- iscsi-storage-class.yaml - iscsi-storage-class.yaml
- controller-deployment.yaml - controller-deployment.yaml
- controller-binding.yaml
- node-deamonset.yaml
- CSIDriver.yaml
- config.yaml
- namespace.yaml
- controller-service-account.yaml - controller-service-account.yaml
- controller-cluster-role.yaml - controller-cluster-role.yaml
- node-service-account.yaml - controller-binding.yaml
- node-cluster-role.yaml - node-cluster-role.yaml
- CSIDriver.yaml
- config.yaml
- nfs-storage-class.yaml
- namespace.yaml
- node-service-account.yaml
+4 -10
View File
@@ -2,7 +2,6 @@ package cnpg
import ( import (
"danicos.dev/daniel/go-kube/pkg/kube" "danicos.dev/daniel/go-kube/pkg/kube"
"danicos.dev/daniel/homelab/pkg/immich"
"danicos.dev/daniel/homelab/pkg/root" "danicos.dev/daniel/homelab/pkg/root"
kube_cnpg "danicos.dev/daniel/go-kube/pkg/cnpg" kube_cnpg "danicos.dev/daniel/go-kube/pkg/cnpg"
@@ -10,8 +9,9 @@ import (
core "k8s.io/api/core/v1" core "k8s.io/api/core/v1"
) )
var cluster_meta = kube.NewMetadata(root.CloudNativePG+"-cluster", root.PGClusterNamespace)
func Cluster() pg.Cluster { func Cluster() pg.Cluster {
meta := kube.NewMetadata(root.CloudNativePG+"-cluster", PGClusterNamespace)
spec := pg.ClusterSpec{ spec := pg.ClusterSpec{
Instances: 3, Instances: 3,
StorageConfiguration: pg.StorageConfiguration{ StorageConfiguration: pg.StorageConfiguration{
@@ -28,17 +28,11 @@ func Cluster() pg.Cluster {
Name: root.Immich.Name, Name: root.Immich.Name,
Login: true, Login: true,
PasswordSecret: &pg.LocalObjectReference{ PasswordSecret: &pg.LocalObjectReference{
Name: immich.Secret.Name, Name: ImmichPGSecret.Name,
}, },
}, },
}, },
}, },
} }
return kube_cnpg.NewCluster(meta, spec) return kube_cnpg.NewCluster(cluster_meta, spec)
} }
/*
PG expects username, password
PG Secret
*/
+6 -6
View File
@@ -6,21 +6,21 @@ import (
"danicos.dev/daniel/homelab/pkg/root" "danicos.dev/daniel/homelab/pkg/root"
) )
var meta kube.Metadata var meta_system kube.Metadata
var Namespace = kube.Namespace(root.CloudNativePG + "-system") var SystemNamespace = kube.Namespace(root.CloudNativePG + "-system")
var PGClusterNamespace = kube.Namespace(root.CloudNativePG + "-cluster")
func init() { func init() {
meta = kube.NewMetadata(root.CloudNativePG, Namespace) meta_system = kube.NewMetadata(root.CloudNativePG, SystemNamespace)
} }
func Stack() stack.Stack { func Stack() stack.Stack {
s := stack.NewStack("cloud-native-pg", map[string]any{ s := stack.NewStack("cloud-native-pg", map[string]any{
"namespace": Namespace, "namespace": SystemNamespace,
"cluster-namespace": PGClusterNamespace, "cluster-namespace": root.PGClusterNamespace,
"helm-repository-source": HelmSource(), "helm-repository-source": HelmSource(),
"helm-release": HelmRelease(), "helm-release": HelmRelease(),
"pg-cluster": Cluster(), "pg-cluster": Cluster(),
"immich-db": ImmichDatabase(),
}) })
return s return s
} }
+23
View File
@@ -0,0 +1,23 @@
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)
}
+4 -4
View File
@@ -16,7 +16,7 @@ func HelmSource() source.HelmRepository {
Interval: durHour(root.FLUX_HELM_MONITORING_INTERVAL), Interval: durHour(root.FLUX_HELM_MONITORING_INTERVAL),
URL: root.HELM_CLOUD_NATIVE_PG_URL, URL: root.HELM_CLOUD_NATIVE_PG_URL,
} }
return flux.NewFluxHelmRepositorySource(meta, spec) return flux.NewFluxHelmRepositorySource(meta_system, spec)
} }
func HelmRelease() helm.HelmRelease { func HelmRelease() helm.HelmRelease {
@@ -30,15 +30,15 @@ func HelmRelease() helm.HelmRelease {
Interval: &interval, Interval: &interval,
SourceRef: helm.CrossNamespaceObjectReference{ SourceRef: helm.CrossNamespaceObjectReference{
Kind: flux.MetaHelmRepository.Kind, Kind: flux.MetaHelmRepository.Kind,
Name: meta.Meta().Name, Name: meta_system.Meta().Name,
Namespace: Namespace.Name, Namespace: SystemNamespace.Name,
}, },
}, },
}, },
Install: &helm.Install{CRDs: helm.Create}, Install: &helm.Install{CRDs: helm.Create},
Upgrade: &helm.Upgrade{CRDs: helm.CreateReplace}, Upgrade: &helm.Upgrade{CRDs: helm.CreateReplace},
} }
return flux.NewFluxHelmRelease(meta, spec) return flux.NewFluxHelmRelease(meta_system, spec)
} }
func durHour(d int64) metav1.Duration { func durHour(d int64) metav1.Duration {
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-10
View File
@@ -7,16 +7,6 @@ import (
core "k8s.io/api/core/v1" core "k8s.io/api/core/v1"
) )
var Secret = struct {
Name string
DB_UserKey string
DB_PasswordKey string
}{
Name: root.Immich.Name,
DB_UserKey: "db_username",
DB_PasswordKey: "db_password",
}
var meta kube.Metadata var meta kube.Metadata
var Namespace = kube.Namespace(root.Immich.Name) var Namespace = kube.Namespace(root.Immich.Name)
var srv core.Service var srv core.Service
+8 -3
View File
@@ -1,5 +1,9 @@
package root package root
import (
"danicos.dev/daniel/go-kube/pkg/kube"
)
type Service struct { type Service struct {
Name string Name string
Image string Image string
@@ -34,9 +38,10 @@ var Immich = Service{
} }
var ( var (
Longhorn = "longhorn" Longhorn = "longhorn"
Monitoring = "monitoring" Monitoring = "monitoring"
CloudNativePG = "cnpg" CloudNativePG = "cnpg"
PGClusterNamespace = kube.Namespace(CloudNativePG + "-cluster")
) )
var ( var (