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

View File

@@ -4,7 +4,7 @@ metadata:
name: linking
namespace: linkding
resources:
- deployment.yaml
- namespace.yaml
- srv.yaml
- pvc.yaml
- deployment.yaml
- namespace.yaml

2
go.mod
View File

@@ -3,7 +3,7 @@ module danicos.dev/daniel/homelab
go 1.26.2
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/fatih/color v1.19.0
github.com/fluxcd/helm-controller/api v1.5.4

4
go.sum
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.0/go.mod h1:zOhFK+bE4t14yOokp+yqh8Pht1/U102JV/29QoKBjjc=
danicos.dev/daniel/go-kube v1.13.3 h1:b42L3WEJstDKLKCaAFcgh1Egb915tRlKEYD/hKMiYXE=
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/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/cloudnative-pg/api v1.29.0 h1:mNx6yJ5qi+Xrjs0NYrUy6V4MlXBkVJxGKwvTJZIuTX4=

View File

@@ -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: {}

View File

@@ -5,15 +5,15 @@ metadata:
namespace: truenas-csi
resources:
- node-binding.yaml
- nfs-storage-class.yaml
- node-deamonset.yaml
- iscsi-storage-class.yaml
- controller-deployment.yaml
- controller-binding.yaml
- node-deamonset.yaml
- CSIDriver.yaml
- config.yaml
- namespace.yaml
- controller-service-account.yaml
- controller-cluster-role.yaml
- node-service-account.yaml
- controller-binding.yaml
- node-cluster-role.yaml
- CSIDriver.yaml
- config.yaml
- nfs-storage-class.yaml
- namespace.yaml
- node-service-account.yaml

View File

@@ -2,7 +2,6 @@ package cnpg
import (
"danicos.dev/daniel/go-kube/pkg/kube"
"danicos.dev/daniel/homelab/pkg/immich"
"danicos.dev/daniel/homelab/pkg/root"
kube_cnpg "danicos.dev/daniel/go-kube/pkg/cnpg"
@@ -10,8 +9,9 @@ import (
core "k8s.io/api/core/v1"
)
var cluster_meta = kube.NewMetadata(root.CloudNativePG+"-cluster", root.PGClusterNamespace)
func Cluster() pg.Cluster {
meta := kube.NewMetadata(root.CloudNativePG+"-cluster", PGClusterNamespace)
spec := pg.ClusterSpec{
Instances: 3,
StorageConfiguration: pg.StorageConfiguration{
@@ -28,17 +28,11 @@ func Cluster() pg.Cluster {
Name: root.Immich.Name,
Login: true,
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
*/

View File

@@ -6,21 +6,21 @@ import (
"danicos.dev/daniel/homelab/pkg/root"
)
var meta kube.Metadata
var Namespace = kube.Namespace(root.CloudNativePG + "-system")
var PGClusterNamespace = kube.Namespace(root.CloudNativePG + "-cluster")
var meta_system kube.Metadata
var SystemNamespace = kube.Namespace(root.CloudNativePG + "-system")
func init() {
meta = kube.NewMetadata(root.CloudNativePG, Namespace)
meta_system = kube.NewMetadata(root.CloudNativePG, SystemNamespace)
}
func Stack() stack.Stack {
s := stack.NewStack("cloud-native-pg", map[string]any{
"namespace": Namespace,
"cluster-namespace": PGClusterNamespace,
"namespace": SystemNamespace,
"cluster-namespace": root.PGClusterNamespace,
"helm-repository-source": HelmSource(),
"helm-release": HelmRelease(),
"pg-cluster": Cluster(),
"immich-db": ImmichDatabase(),
})
return s
}

23
pkg/cnpg/database.go Normal file
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)
}

View File

@@ -16,7 +16,7 @@ func HelmSource() source.HelmRepository {
Interval: durHour(root.FLUX_HELM_MONITORING_INTERVAL),
URL: root.HELM_CLOUD_NATIVE_PG_URL,
}
return flux.NewFluxHelmRepositorySource(meta, spec)
return flux.NewFluxHelmRepositorySource(meta_system, spec)
}
func HelmRelease() helm.HelmRelease {
@@ -30,15 +30,15 @@ func HelmRelease() helm.HelmRelease {
Interval: &interval,
SourceRef: helm.CrossNamespaceObjectReference{
Kind: flux.MetaHelmRepository.Kind,
Name: meta.Meta().Name,
Namespace: Namespace.Name,
Name: meta_system.Meta().Name,
Namespace: SystemNamespace.Name,
},
},
},
Install: &helm.Install{CRDs: helm.Create},
Upgrade: &helm.Upgrade{CRDs: helm.CreateReplace},
}
return flux.NewFluxHelmRelease(meta, spec)
return flux.NewFluxHelmRelease(meta_system, spec)
}
func durHour(d int64) metav1.Duration {

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -7,16 +7,6 @@ import (
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 Namespace = kube.Namespace(root.Immich.Name)
var srv core.Service

View File

@@ -1,5 +1,9 @@
package root
import (
"danicos.dev/daniel/go-kube/pkg/kube"
)
type Service struct {
Name string
Image string
@@ -34,9 +38,10 @@ var Immich = Service{
}
var (
Longhorn = "longhorn"
Monitoring = "monitoring"
CloudNativePG = "cnpg"
Longhorn = "longhorn"
Monitoring = "monitoring"
CloudNativePG = "cnpg"
PGClusterNamespace = kube.Namespace(CloudNativePG + "-cluster")
)
var (