11// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
22// SPDX-License-Identifier: Apache-2.0
3- import * as gcp from '@pulumi/gcp' ;
43import * as k8s from '@pulumi/kubernetes' ;
54import * as _ from 'lodash' ;
65import {
76 activeVersion ,
7+ appsAffinityAndTolerations ,
88 CLUSTER_BASENAME ,
99 CLUSTER_HOSTNAME ,
1010 clusterSmallDisk ,
1111 config ,
1212 DomainMigrationIndex ,
1313 ExactNamespace ,
14- GCP_ZONE ,
1514 InstalledHelmChart ,
1615 installSpliceHelmChart ,
1716 isDevNet ,
1817 loadYamlFromFile ,
19- nonHyperdiskAppsAffinityAndTolerations ,
2018 SPLICE_ROOT ,
2119 SpliceCustomResourceOptions ,
20+ standardStorageClassName ,
2221 svCometBftKeysFromSecret ,
2322 withAddedDependencies ,
2423} from '@lfdecentralizedtrust/splice-pulumi-common' ;
2524import { CnChartVersion } from '@lfdecentralizedtrust/splice-pulumi-common/src/artifacts' ;
26- import { jsonStringify , Output , Resource } from '@pulumi/pulumi' ;
25+ import { hyperdiskSupportConfig } from '@lfdecentralizedtrust/splice-pulumi-common/src/config/hyperdiskSupportConfig' ;
26+ import { CustomResource } from '@pulumi/kubernetes/apiextensions' ;
27+ import { jsonStringify , Output } from '@pulumi/pulumi' ;
2728
2829import { svsConfig } from '../config' ;
2930import { SingleSvConfiguration } from '../singleSvConfig' ;
@@ -104,6 +105,41 @@ export function installCometBftNode(
104105 ? undefined
105106 : installCometBftKeysSecret ( xns , nodeConfig . validator . keyAddress , migrationId ) ;
106107
108+ let hyperdiskDbValues = { } ;
109+ if ( hyperdiskSupportConfig . hyperdiskSupport . enabled ) {
110+ hyperdiskDbValues = {
111+ pvcName : `cometbft-migration-${ migrationId } -hd-pvc` ,
112+ volumeStorageClass : standardStorageClassName ,
113+ } ;
114+ 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+ ) ;
132+ hyperdiskDbValues = {
133+ ...hyperdiskDbValues ,
134+ dataSource : {
135+ kind : 'VolumeSnapshot' ,
136+ name : pvcSnapshot . metadata . name ,
137+ apiGroup : 'snapshot.storage.k8s.io' ,
138+ } ,
139+ } ;
140+ }
141+ }
142+
107143 const cometbftChartValues = _ . mergeWith ( cometBftValues , {
108144 sv1 : nodeConfigs . sv1 ,
109145 istioVirtualService : {
@@ -138,67 +174,12 @@ export function installCometBftNode(
138174 } ,
139175 db : {
140176 volumeSize : clusterSmallDisk ? '240Gi' : svsConfig ?. cometbft ?. volumeSize ,
177+ ...hyperdiskDbValues ,
141178 } ,
142179 extraLogLevelFlags : svConfiguration . logging ?. cometbftExtraLogLevelFlags ,
143180 serviceAccountName : imagePullServiceAccountName ,
144181 resources : svConfiguration . cometbft ?. resources ,
145182 } ) ;
146- const svIdentifier = nodeConfigs . selfSvNodeName ;
147- const svIdentifierWithMigration = `${ svIdentifier } -m${ migrationId } ` ;
148- let volumeDependecies : Resource [ ] = [ ] ;
149- if ( svConfiguration ?. cometbft ?. snapshotName ) {
150- const volumeSize = cometbftChartValues . db . volumeSize ;
151- const diskSnapshot = gcp . compute . getSnapshot ( {
152- name : svConfiguration . cometbft . snapshotName ,
153- } ) ;
154-
155- if ( ! GCP_ZONE ) {
156- throw new Error ( 'Zone is required to create a disk' ) ;
157- }
158- const restoredDisk = new gcp . compute . Disk (
159- `${ svIdentifierWithMigration } -cometbft-restored-data` ,
160- {
161- name : `${ svIdentifierWithMigration } -cometbft-restored-disk` ,
162- // eslint-disable-next-line promise/prefer-await-to-then
163- size : diskSnapshot . then ( snapshot => snapshot . diskSizeGb ) ,
164- // eslint-disable-next-line promise/prefer-await-to-then
165- snapshot : diskSnapshot . then ( snapshot => snapshot . selfLink ) ,
166- type : 'pd-ssd' ,
167- zone : GCP_ZONE ,
168- } ,
169- opts
170- ) ;
171-
172- // create the underlying persistent volume that will be used by cometbft from the state of an existing PV
173- volumeDependecies = [
174- new k8s . core . v1 . PersistentVolume (
175- `${ svIdentifier } -cometbft-data` ,
176- {
177- metadata : {
178- name : `${ svIdentifier } -cometbft-data-pv` ,
179- } ,
180- spec : {
181- capacity : {
182- storage : volumeSize ,
183- } ,
184- volumeMode : 'Filesystem' ,
185- accessModes : [ 'ReadWriteOnce' ] ,
186- persistentVolumeReclaimPolicy : 'Delete' ,
187- storageClassName : cometbftChartValues . db . volumeStorageClass ,
188- claimRef : {
189- name : `global-domain-${ migrationId } -cometbft-cometbft-data` ,
190- namespace : xns . ns . metadata . name ,
191- } ,
192- csi : {
193- driver : 'pd.csi.storage.gke.io' ,
194- volumeHandle : restoredDisk . id ,
195- } ,
196- } ,
197- } ,
198- opts
199- ) ,
200- ] ;
201- }
202183 const protectCometBft = svsConfig ?. cometbft ?. protected ?? false ;
203184 const release = installSpliceHelmChart (
204185 xns ,
@@ -208,13 +189,13 @@ export function installCometBftNode(
208189 version ,
209190 // support old runbook names, can be removed once the runbooks are all reset and latest release is >= 0.2.x
210191 {
211- ...withAddedDependencies ( opts , volumeDependecies . concat ( keysSecret ? [ keysSecret ] : [ ] ) ) ,
192+ ...withAddedDependencies ( opts , keysSecret ? [ keysSecret ] : [ ] ) ,
212193 aliases : [ { name : `global-domain-${ migrationId } -cometbft` , parent : undefined } ] ,
213194 ignoreChanges : [ 'name' ] ,
214195 protect : disableProtection ? false : protectCometBft ,
215196 } ,
216197 true ,
217- nonHyperdiskAppsAffinityAndTolerations
198+ appsAffinityAndTolerations
218199 ) ;
219200 return { rpcServiceName : `${ nodeConfig . identifier } -cometbft-rpc` , release } ;
220201}
0 commit comments