DeployPostgresDatabases deploys the CloudNative PostgreSQL operator and PostgreSQL cluster
(ctx *pulumi.Context, cluster *providers.ProviderInfo, environment string)
| 12 | |
| 13 | // DeployPostgresDatabases deploys the CloudNative PostgreSQL operator and PostgreSQL cluster |
| 14 | func DeployPostgresDatabases(ctx *pulumi.Context, cluster *providers.ProviderInfo, environment string) (*apiextensions.CustomResource, error) { |
| 15 | // Create cnpg-system namespace |
| 16 | cnpgNamespace, err := corev1.NewNamespace(ctx, "cnpg-system", &corev1.NamespaceArgs{ |
| 17 | Metadata: &metav1.ObjectMetaArgs{ |
| 18 | Name: pulumi.String("cnpg-system"), |
| 19 | }, |
| 20 | }, pulumi.Provider(cluster.Provider)) |
| 21 | if err != nil { |
| 22 | return nil, err |
| 23 | } |
| 24 | |
| 25 | // Install cloudnative-pg Helm chart |
| 26 | cloudNativePG, err := helm.NewChart(ctx, "cloudnative-pg", helm.ChartArgs{ |
| 27 | Chart: pulumi.String("cloudnative-pg"), |
| 28 | Version: pulumi.String("v0.26.0"), |
| 29 | FetchArgs: helm.FetchArgs{ |
| 30 | Repo: pulumi.String("https://cloudnative-pg.github.io/charts"), |
| 31 | }, |
| 32 | Namespace: cnpgNamespace.Metadata.Name().Elem(), |
| 33 | Values: pulumi.Map{ |
| 34 | "webhooks": pulumi.Map{ |
| 35 | "replicaCount": pulumi.Int(1), |
| 36 | }, |
| 37 | }, |
| 38 | }, pulumi.Provider(cluster.Provider)) |
| 39 | if err != nil { |
| 40 | return nil, err |
| 41 | } |
| 42 | |
| 43 | // Create PostgreSQL cluster |
| 44 | pgCluster, err := apiextensions.NewCustomResource(ctx, "registry-pg", &apiextensions.CustomResourceArgs{ |
| 45 | ApiVersion: pulumi.String("postgresql.cnpg.io/v1"), |
| 46 | Kind: pulumi.String("Cluster"), |
| 47 | Metadata: &metav1.ObjectMetaArgs{ |
| 48 | Name: pulumi.String("registry-pg"), |
| 49 | Namespace: pulumi.String("default"), |
| 50 | Labels: pulumi.StringMap{ |
| 51 | "app": pulumi.String("registry-pg"), |
| 52 | "environment": pulumi.String(environment), |
| 53 | }, |
| 54 | }, |
| 55 | OtherFields: map[string]any{ |
| 56 | "spec": map[string]any{ |
| 57 | "instances": 1, |
| 58 | "enablePDB": false, |
| 59 | "storage": map[string]any{ |
| 60 | "size": "50Gi", |
| 61 | }, |
| 62 | // Explicit resource budget. PG was previously unlimited which made |
| 63 | // node-level OOM behaviour unpredictable. With max_connections=200 |
| 64 | // the worst-case per-connection memory (~10–15MB each) plus |
| 65 | // shared_buffers and overhead lands around 3–4GiB; 4Gi limit gives |
| 66 | // headroom for query workspaces (work_mem) and OS-level effects. |
| 67 | "resources": map[string]any{ |
| 68 | "requests": map[string]any{ |
| 69 | "memory": "512Mi", |
| 70 | "cpu": "200m", |
| 71 | }, |