@@ -4,7 +4,6 @@ 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' ;
87import { Resource } from '@pulumi/pulumi' ;
98
109import { CnChartVersion } from './artifacts' ;
@@ -18,6 +17,7 @@ import {
1817} from './helm' ;
1918import { installPostgresPasswordSecret } from './secrets' ;
2019import { standardStorageClassName } from './storage/storageClass' ;
20+ import { createVolumeSnapshot } from './storage/volumeSnapshot' ;
2121import { ChartValues , CLUSTER_BASENAME , ExactNamespace , GCP_ZONE } from './utils' ;
2222
2323const project = gcp . organizations . getProjectOutput ( { } ) ;
@@ -227,34 +227,22 @@ export class SplicePostgres extends pulumi.ComponentResource implements Postgres
227227
228228 // an initial database named cantonnet is created automatically (configured in the Helm chart).
229229 const smallDiskSize = clusterSmallDisk ? '240Gi' : undefined ;
230- const supportsHyperdisk =
231- hyperdiskSupportConfig . hyperdiskSupport . enabled && ! useInfraAffinityAndTolerations ;
230+ const supportsHyperdisk = useInfraAffinityAndTolerations
231+ ? hyperdiskSupportConfig . hyperdiskSupport . enabledForInfra
232+ : hyperdiskSupportConfig . hyperdiskSupport . enabled ;
233+ const migratingToHyperdisk = useInfraAffinityAndTolerations
234+ ? hyperdiskSupportConfig . hyperdiskSupport . migratingInfra
235+ : hyperdiskSupportConfig . hyperdiskSupport . migrating ;
236+
232237 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- } ;
238+ if ( supportsHyperdisk && migratingToHyperdisk ) {
239+ const { dataSource } = createVolumeSnapshot ( {
240+ resourceName : `pg-data-${ xns . logicalName } -${ instanceName } -snapshot` ,
241+ snapshotName : `pg-data-${ instanceName } -snapshot` ,
242+ namespace : xns . logicalName ,
243+ pvcName : `pg-data-${ instanceName } -0` ,
244+ } ) ;
245+ hyperdiskMigrationValues = { dataSource } ;
258246 }
259247 const pg = installSpliceHelmChart (
260248 xns ,
@@ -284,7 +272,7 @@ export class SplicePostgres extends pulumi.ComponentResource implements Postgres
284272 ...( ( supportsHyperdisk &&
285273 // during the migration we first delete the stateful set, which keeps the old pvcs (stateful sets always keep the pvcs), and then recreate with the new pvcs
286274 // the stateful sets are immutable so they need to be recreated to force the change of the pvcs
287- hyperdiskSupportConfig . hyperdiskSupport . migrating ) ||
275+ migratingToHyperdisk ) ||
288276 spliceConfig . pulumiProjectConfig . replacePostgresStatefulSetOnChanges
289277 ? {
290278 replaceOnChanges : [ '*' ] ,
0 commit comments