Skip to content

Commit 67081ef

Browse files
committed
extra volume snapshot to common file
[static] Signed-off-by: Nicu Reut <nicu.reut@digitalasset.com>
1 parent 3b59f60 commit 67081ef

File tree

6 files changed

+82
-73
lines changed

6 files changed

+82
-73
lines changed

cluster/pulumi/common-sv/src/synchronizer/cometbft.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
CLUSTER_HOSTNAME,
1010
clusterSmallDisk,
1111
config,
12+
createVolumeSnapshot,
1213
DomainMigrationIndex,
1314
ExactNamespace,
1415
InstalledHelmChart,
@@ -23,7 +24,6 @@ import {
2324
} from '@lfdecentralizedtrust/splice-pulumi-common';
2425
import { CnChartVersion } from '@lfdecentralizedtrust/splice-pulumi-common/src/artifacts';
2526
import { hyperdiskSupportConfig } from '@lfdecentralizedtrust/splice-pulumi-common/src/config/hyperdiskSupportConfig';
26-
import { CustomResource } from '@pulumi/kubernetes/apiextensions';
2727
import { jsonStringify, Output } from '@pulumi/pulumi';
2828

2929
import { svsConfig } from '../config';
@@ -112,30 +112,15 @@ export function installCometBftNode(
112112
volumeStorageClass: standardStorageClassName,
113113
};
114114
if (hyperdiskSupportConfig.hyperdiskSupport.migrating) {
115-
const pvcSnapshot = new CustomResource(
116-
`cometbft-${xns.logicalName}-migration-${migrationId}-snapshot`,
117-
{
118-
apiVersion: 'snapshot.storage.k8s.io/v1',
119-
kind: 'VolumeSnapshot',
120-
metadata: {
121-
name: `cometbft-migration-${migrationId}-pd-snapshot`,
122-
namespace: xns.logicalName,
123-
},
124-
spec: {
125-
volumeSnapshotClassName: 'dev-vsc',
126-
source: {
127-
persistentVolumeClaimName: `global-domain-${migrationId}-cometbft-cometbft-data`,
128-
},
129-
},
130-
}
131-
);
115+
const { dataSource } = createVolumeSnapshot({
116+
resourceName: `cometbft-${xns.logicalName}-migration-${migrationId}-snapshot`,
117+
snapshotName: `cometbft-migration-${migrationId}-pd-snapshot`,
118+
namespace: xns.logicalName,
119+
pvcName: `global-domain-${migrationId}-cometbft-cometbft-data`,
120+
});
132121
hyperdiskDbValues = {
133122
...hyperdiskDbValues,
134-
dataSource: {
135-
kind: 'VolumeSnapshot',
136-
name: pvcSnapshot.metadata.name,
137-
apiGroup: 'snapshot.storage.k8s.io',
138-
},
123+
dataSource,
139124
};
140125
}
141126
}

cluster/pulumi/common/src/config/hyperdiskSupportConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ const HyperdiskSupportConfigSchema = z.object({
88
hyperdiskSupport: z
99
.object({
1010
enabled: z.boolean().default(false),
11+
enabledForInfra: z.boolean().default(false),
1112
migrating: z.boolean().default(false),
13+
migratingInfra: z.boolean().default(false),
1214
})
1315
.default({}),
1416
});

cluster/pulumi/common/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ export * from './config/networkWideConfig';
3030
export * from './ratelimit';
3131
export * from './config/config';
3232
export * from './storage/storageClass';
33+
export * from './storage/volumeSnapshot';

cluster/pulumi/common/src/postgres.ts

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as gcp from '@pulumi/gcp';
44
import * as pulumi from '@pulumi/pulumi';
55
import * as random from '@pulumi/random';
66
import * as _ from 'lodash';
7-
import { CustomResource } from '@pulumi/kubernetes/apiextensions';
87
import { Resource } from '@pulumi/pulumi';
98

109
import { CnChartVersion } from './artifacts';
@@ -18,6 +17,7 @@ import {
1817
} from './helm';
1918
import { installPostgresPasswordSecret } from './secrets';
2019
import { standardStorageClassName } from './storage/storageClass';
20+
import { createVolumeSnapshot } from './storage/volumeSnapshot';
2121
import { ChartValues, CLUSTER_BASENAME, ExactNamespace, GCP_ZONE } from './utils';
2222

2323
const 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: ['*'],
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
import { CustomResource } from '@pulumi/kubernetes/apiextensions';
4+
import { Output } from '@pulumi/pulumi';
5+
6+
export interface VolumeSnapshotOptions {
7+
resourceName: string;
8+
snapshotName: string;
9+
namespace: string;
10+
pvcName: string;
11+
volumeSnapshotClassName?: string;
12+
}
13+
export function createVolumeSnapshot(options: VolumeSnapshotOptions): {
14+
snapshot: CustomResource;
15+
dataSource: { kind: string; name: Output<string>; apiGroup: string };
16+
} {
17+
const {
18+
resourceName,
19+
snapshotName,
20+
namespace,
21+
pvcName,
22+
volumeSnapshotClassName = 'dev-vsc',
23+
} = options;
24+
25+
const snapshot = new CustomResource(resourceName, {
26+
apiVersion: 'snapshot.storage.k8s.io/v1',
27+
kind: 'VolumeSnapshot',
28+
metadata: {
29+
name: snapshotName,
30+
namespace: namespace,
31+
},
32+
spec: {
33+
volumeSnapshotClassName: volumeSnapshotClassName,
34+
source: {
35+
persistentVolumeClaimName: pvcName,
36+
},
37+
},
38+
});
39+
40+
const dataSource = {
41+
kind: 'VolumeSnapshot',
42+
name: snapshot.metadata.name,
43+
apiGroup: 'snapshot.storage.k8s.io',
44+
};
45+
46+
return { snapshot, dataSource };
47+
}

cluster/pulumi/multi-validator/src/postgres.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import {
1212
installSpliceRunbookHelmChart,
1313
spliceConfig,
1414
standardStorageClassName,
15+
createVolumeSnapshot,
1516
} from '@lfdecentralizedtrust/splice-pulumi-common';
16-
import { CustomResource } from '@pulumi/kubernetes/apiextensions';
1717

1818
import { hyperdiskSupportConfig } from '../../common/src/config/hyperdiskSupportConfig';
1919
import { multiValidatorConfig } from './config';
@@ -41,27 +41,13 @@ export function installPostgres(
4141
hyperdiskSupportConfig.hyperdiskSupport.enabled &&
4242
hyperdiskSupportConfig.hyperdiskSupport.migrating
4343
) {
44-
const pvcSnapshot = new CustomResource(`pg-data-${xns.logicalName}-${name}-snapshot`, {
45-
apiVersion: 'snapshot.storage.k8s.io/v1',
46-
kind: 'VolumeSnapshot',
47-
metadata: {
48-
name: `pg-data-${name}-snapshot`,
49-
namespace: xns.logicalName,
50-
},
51-
spec: {
52-
volumeSnapshotClassName: 'dev-vsc',
53-
source: {
54-
persistentVolumeClaimName: `pg-data-${name}-0`,
55-
},
56-
},
44+
const { dataSource } = createVolumeSnapshot({
45+
resourceName: `pg-data-${xns.logicalName}-${name}-snapshot`,
46+
snapshotName: `pg-data-${name}-snapshot`,
47+
namespace: xns.logicalName,
48+
pvcName: `pg-data-${name}-0`,
5749
});
58-
hyperdiskMigrationValues = {
59-
dataSource: {
60-
kind: 'VolumeSnapshot',
61-
name: pvcSnapshot.metadata.name,
62-
apiGroup: 'snapshot.storage.k8s.io',
63-
},
64-
};
50+
hyperdiskMigrationValues = { dataSource };
6551
}
6652
return installSpliceRunbookHelmChart(
6753
xns,

0 commit comments

Comments
 (0)