@@ -4,17 +4,20 @@ import * as gcp from '@pulumi/gcp';
44import * as pulumi from '@pulumi/pulumi' ;
55import * as random from '@pulumi/random' ;
66import * as _ from 'lodash' ;
7+ import { CustomResource } from '@pulumi/kubernetes/apiextensions' ;
78import { Resource } from '@pulumi/pulumi' ;
89
910import { CnChartVersion } from './artifacts' ;
1011import { clusterSmallDisk , CloudSqlConfig , config } from './config' ;
1112import { spliceConfig } from './config/config' ;
13+ import { hyperdiskSupportConfig } from './config/hyperdiskSupportConfig' ;
1214import {
15+ appsAffinityAndTolerations ,
1316 infraAffinityAndTolerations ,
1417 installSpliceHelmChart ,
15- nonHyperdiskAppsAffinityAndTolerations ,
1618} from './helm' ;
1719import { installPostgresPasswordSecret } from './secrets' ;
20+ import { standardStorageClassName } from './storage/storageClass' ;
1821import { ChartValues , CLUSTER_BASENAME , ExactNamespace , GCP_ZONE } from './utils' ;
1922
2023const project = gcp . organizations . getProjectOutput ( { } ) ;
@@ -224,6 +227,35 @@ export class SplicePostgres extends pulumi.ComponentResource implements Postgres
224227
225228 // an initial database named cantonnet is created automatically (configured in the Helm chart).
226229 const smallDiskSize = clusterSmallDisk ? '240Gi' : undefined ;
230+ const supportsHyperdisk =
231+ hyperdiskSupportConfig . hyperdiskSupport . enabled && ! useInfraAffinityAndTolerations ;
232+ let hyperdiskMigrationValues = { } ;
233+ if ( supportsHyperdisk && hyperdiskSupportConfig . hyperdiskSupport . migrating ) {
234+ const pvcSnapshot = new CustomResource (
235+ `pg-data-${ xns . logicalName } -${ instanceName } -snapshot` ,
236+ {
237+ apiVersion : 'snapshot.storage.k8s.io/v1' ,
238+ kind : 'VolumeSnapshot' ,
239+ metadata : {
240+ name : `pg-data-${ instanceName } -snapshot` ,
241+ namespace : xns . logicalName ,
242+ } ,
243+ spec : {
244+ volumeSnapshotClassName : 'dev-vsc' ,
245+ source : {
246+ persistentVolumeClaimName : `pg-data-${ instanceName } -0` ,
247+ } ,
248+ } ,
249+ }
250+ ) ;
251+ hyperdiskMigrationValues = {
252+ dataSource : {
253+ kind : 'VolumeSnapshot' ,
254+ name : pvcSnapshot . metadata . name ,
255+ apiGroup : 'snapshot.storage.k8s.io' ,
256+ } ,
257+ } ;
258+ }
227259 const pg = installSpliceHelmChart (
228260 xns ,
229261 instanceName ,
@@ -233,6 +265,13 @@ export class SplicePostgres extends pulumi.ComponentResource implements Postgres
233265 volumeSize : overrideDbSizeFromValues
234266 ? values ?. db ?. volumeSize || smallDiskSize
235267 : smallDiskSize ,
268+ ...( supportsHyperdisk
269+ ? {
270+ volumeStorageClass : standardStorageClassName ,
271+ pvcTemplateName : 'pg-data-hd' ,
272+ ...hyperdiskMigrationValues ,
273+ }
274+ : { } ) ,
236275 } ,
237276 persistence : {
238277 secretName : this . secretName ,
@@ -242,11 +281,19 @@ export class SplicePostgres extends pulumi.ComponentResource implements Postgres
242281 {
243282 aliases : [ { name : logicalNameAlias , type : 'kubernetes:helm.sh/v3:Release' } ] ,
244283 dependsOn : [ passwordSecret ] ,
284+ ...( ( supportsHyperdisk &&
285+ // during the migration we first delete the stateful set, which keeps the old pvcs, and the recreate with the new pvcs
286+ // the stateful sets are immutable so they need to be recreated to force the change of the pvcs
287+ hyperdiskSupportConfig . hyperdiskSupport . migrating ) ||
288+ spliceConfig . pulumiProjectConfig . replacePostgresStatefulSetOnChanges
289+ ? {
290+ replaceOnChanges : [ '*' ] ,
291+ deleteBeforeReplace : true ,
292+ }
293+ : { } ) ,
245294 } ,
246295 true ,
247- useInfraAffinityAndTolerations
248- ? infraAffinityAndTolerations
249- : nonHyperdiskAppsAffinityAndTolerations
296+ useInfraAffinityAndTolerations ? infraAffinityAndTolerations : appsAffinityAndTolerations
250297 ) ;
251298 this . pg = pg ;
252299
0 commit comments