diff --git a/infrastructure/hydra/postgres/image-cataglog.yaml b/infrastructure/hydra/postgres/image-cataglog.yaml new file mode 100644 index 0000000..7884225 --- /dev/null +++ b/infrastructure/hydra/postgres/image-cataglog.yaml @@ -0,0 +1,12 @@ +apiVersion: postgresql.cnpg.io/v1 +kind: ClusterImageCatalog +metadata: + name: pg-minimal-trixie +spec: + images: + - extensions: + - image: + reference: ghcr.io/cloudnative-pg/pgvector:0.8.2-18-trixie + name: pgvector + image: ghcr.io/cloudnative-pg/postgresql:18.3-minimal-trixie + major: 18 diff --git a/infrastructure/hydra/postgres/kustomization.yaml b/infrastructure/hydra/postgres/kustomization.yaml index 63ec40e..53590a0 100644 --- a/infrastructure/hydra/postgres/kustomization.yaml +++ b/infrastructure/hydra/postgres/kustomization.yaml @@ -5,5 +5,6 @@ metadata: namespace: cnpg-cluster resources: - cluster-namespace.yaml +- image-cataglog.yaml - immich-db.yaml - pg-cluster.yaml diff --git a/infrastructure/hydra/postgres/pg-cluster.yaml b/infrastructure/hydra/postgres/pg-cluster.yaml index 9a9007d..a000426 100644 --- a/infrastructure/hydra/postgres/pg-cluster.yaml +++ b/infrastructure/hydra/postgres/pg-cluster.yaml @@ -5,6 +5,11 @@ metadata: namespace: cnpg-cluster spec: affinity: {} + imageCatalogRef: + apiGroup: postgresql.cnpg.io/v1 + kind: ClusterImageCatalog + major: 18 + name: pg-minimal-trixie instances: 3 managed: roles: @@ -13,6 +18,9 @@ spec: passwordSecret: name: immich postgresql: + extensions: + - image: {} + name: pgvector syncReplicaElectionConstraint: enabled: false resources: {} diff --git a/pkg/postgres/postgres.go b/pkg/postgres/postgres.go index 7a154f3..1026ca4 100644 --- a/pkg/postgres/postgres.go +++ b/pkg/postgres/postgres.go @@ -8,9 +8,15 @@ import ( kube_cnpg "danicos.dev/daniel/go-kube/pkg/cnpg" pg "github.com/cloudnative-pg/api/pkg/api/v1" core "k8s.io/api/core/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) var cluster_meta = kube.NewMetadata(root.CloudNativePG+"-cluster", root.PGClusterNamespace) +var image_catalog pg.ImageCatalog + +func init() { + image_catalog = ImageCatalog() +} func Stack() stack.Stack { kz := kube.NewKuztomizedStack( @@ -19,6 +25,7 @@ func Stack() stack.Stack { "cluster-namespace": root.PGClusterNamespace, "pg-cluster": Cluster(), "immich-db": ImmichDatabase(), + "image-cataglog": image_catalog, }, ) return kz.Stack("postgres") @@ -35,19 +42,21 @@ func Cluster() pg.Cluster { StorageClassName: new(root.KUBE_LOCAL_STORAGE_CLASS), }, }, - // PostgresConfiguration: pg.PostgresConfiguration{ - // Extensions: []pg.ExtensionConfiguration{ - // { - // Name: "vector", - // ImageVolumeSource: core.ImageVolumeSource{}, - // ExtensionControlPath: []string{}, - // DynamicLibraryPath: []string{}, - // LdLibraryPath: []string{}, - // BinPath: []string{}, - // Env: []pg.ExtensionEnvVar{}, - // }, - // }, - // }, + ImageCatalogRef: &pg.ImageCatalogRef{ + TypedLocalObjectReference: core.TypedLocalObjectReference{ + APIGroup: &image_catalog.APIVersion, + Kind: image_catalog.Kind, + Name: image_catalog.Name, + }, + Major: root.PG_VERSION_18, + }, + PostgresConfiguration: pg.PostgresConfiguration{ + Extensions: []pg.ExtensionConfiguration{ + { + Name: "pgvector", + }, + }, + }, Managed: &pg.ManagedConfiguration{ Roles: []pg.RoleConfiguration{ { @@ -63,6 +72,32 @@ func Cluster() pg.Cluster { return kube_cnpg.NewCluster(cluster_meta, spec) } +func ImageCatalog() pg.ImageCatalog { + return pg.ImageCatalog{ + TypeMeta: meta.TypeMeta{ + Kind: "ClusterImageCatalog", + APIVersion: "postgresql.cnpg.io/v1", + }, + ObjectMeta: kube.ObjectMeta(root.PG_VERSION_NAME, ""), + Spec: pg.ImageCatalogSpec{ + Images: []pg.CatalogImage{ + { + Major: root.PG_VERSION_18, + Image: root.PG_VERSION_18_IMAGE, + Extensions: []pg.ExtensionConfiguration{ + { + Name: "pgvector", + ImageVolumeSource: core.ImageVolumeSource{ + Reference: "ghcr.io/cloudnative-pg/pgvector:0.8.2-18-trixie", + }, + }, + }, + }, + }, + }, + } +} + var ImmichPGSecret = kube_cnpg.NewPGSecret(root.Immich.Name, root.PGClusterNamespace) func ImmichDatabase() pg.Database { @@ -76,7 +111,7 @@ func ImmichDatabase() pg.Database { Extensions: []pg.ExtensionSpec{ // { // DatabaseObjectSpec: pg.DatabaseObjectSpec{ - // Name: "vectors", + // Name: "pgvector", // Ensure: pg.EnsurePresent, // }, // }, diff --git a/pkg/root/root.go b/pkg/root/root.go index 00f2694..d037b12 100644 --- a/pkg/root/root.go +++ b/pkg/root/root.go @@ -38,6 +38,9 @@ const ( HELM_CLOUD_NATIVE_PG_URL = "https://cloudnative-pg.github.io/charts" HELM_CLOUD_NATIVE_PG_CHART = "cloudnative-pg" HELM_CLOUD_NATIVE_PG_CHART_VERSION = "0.28.0" + PG_VERSION_NAME = "pg-minimal-trixie" + PG_VERSION_18 = 18 + PG_VERSION_18_IMAGE = "ghcr.io/cloudnative-pg/postgresql:18.3-minimal-trixie" ) var (