33import * as k8s from '@pulumi/kubernetes' ;
44import * as pulumi from '@pulumi/pulumi' ;
55import * as semver from 'semver' ;
6+ import { Secret } from '@pulumi/kubernetes/core/v1' ;
7+ import { Resource } from '@pulumi/pulumi' ;
68import {
79 CLUSTER_BASENAME ,
810 config ,
@@ -11,6 +13,7 @@ import {
1113} from 'splice-pulumi-common' ;
1214
1315import { spliceEnvConfig } from '../config/envConfig' ;
16+ import { operatorDeploymentConfig } from './config' ;
1417import { GitFluxRef } from './flux-source' ;
1518
1619export type EnvRefs = { [ key : string ] : unknown } ;
@@ -81,6 +84,152 @@ export function createStackCR(
8184 extraEnvs : { [ key : string ] : string } = { } ,
8285 dependsOn : pulumi . Resource [ ] = [ ]
8386) : pulumi . CustomResource {
87+ if ( operatorDeploymentConfig . useOperatorV2 ) {
88+ return createStackCRV2 (
89+ name ,
90+ namespaceName ,
91+ ref ,
92+ projectName ,
93+ envRefs ,
94+ extraEnvs ,
95+ gcpSecret ,
96+ supportsResetOnSameCommit ,
97+ dependsOn
98+ ) ;
99+ } else {
100+ return createStackCRV1 (
101+ name ,
102+ projectName ,
103+ supportsResetOnSameCommit ,
104+ ref ,
105+ envRefs ,
106+ extraEnvs ,
107+ namespaceName ,
108+ dependsOn
109+ ) ;
110+ }
111+ }
112+
113+ /*https://github.com/pulumi/pulumi-kubernetes-operator/blob/master/docs/stacks.md*/
114+ export function createStackCRV1 (
115+ name : string ,
116+ projectName : string ,
117+ supportsResetOnSameCommit : boolean ,
118+ ref : GitFluxRef ,
119+ envRefs : EnvRefs ,
120+ extraEnvs : { [ key : string ] : string } = { } ,
121+ namespaceName : string = 'operator' ,
122+ dependsOn : pulumi . Resource [ ] = [ ]
123+ ) : pulumi . CustomResource {
124+ const privateConfigs = ref . config . privateConfigsDir
125+ ? {
126+ PRIVATE_CONFIGS_PATH : {
127+ type : 'Literal' ,
128+ literal : {
129+ value : `/tmp/pulumi-working/operator/${ name } /workspace/${ ref . config . privateConfigsDir } ` ,
130+ } ,
131+ } ,
132+ }
133+ : { } ;
134+ const publicConfigs = ref . config . publicConfigsDir
135+ ? {
136+ PUBLIC_CONFIGS_PATH : {
137+ type : 'Literal' ,
138+ literal : {
139+ value : `/tmp/pulumi-working/operator/${ name } /workspace/${ ref . config . publicConfigsDir } ` ,
140+ } ,
141+ } ,
142+ }
143+ : { } ;
144+ return new k8s . apiextensions . CustomResource (
145+ name ,
146+ {
147+ apiVersion : 'pulumi.com/v1' ,
148+ kind : 'Stack' ,
149+ metadata : { name : name , namespace : namespaceName } ,
150+ spec : {
151+ ...{
152+ stack : `organization/${ projectName } /${ name } .${ CLUSTER_BASENAME } ` ,
153+ backend : config . requireEnv ( 'PULUMI_BACKEND_URL' ) ,
154+ envRefs : {
155+ ...envRefs ,
156+ SPLICE_ROOT : {
157+ type : 'Literal' ,
158+ literal : {
159+ value : `/tmp/pulumi-working/operator/${ name } /workspace/${ ref . config . spliceRoot } ` ,
160+ } ,
161+ } ,
162+ DEPLOYMENT_DIR : {
163+ type : 'Literal' ,
164+ literal : {
165+ value : `/tmp/pulumi-working/operator/${ name } /workspace/${ ref . config . deploymentDir } ` ,
166+ } ,
167+ } ,
168+ ...privateConfigs ,
169+ ...publicConfigs ,
170+ GCP_CLUSTER_BASENAME : {
171+ type : 'Literal' ,
172+ literal : {
173+ value : CLUSTER_BASENAME ,
174+ } ,
175+ } ,
176+ ...Object . keys ( extraEnvs ) . reduce < {
177+ [ key : string ] : unknown ;
178+ } > ( ( acc , key ) => {
179+ acc [ key ] = {
180+ type : 'Literal' ,
181+ literal : {
182+ value : extraEnvs [ key ] ,
183+ } ,
184+ } ;
185+ return acc ;
186+ } , { } ) ,
187+ } ,
188+ fluxSource : {
189+ sourceRef : {
190+ apiVersion : ref . resource . apiVersion ,
191+ kind : ref . resource . kind ,
192+ name : ref . resource . metadata . name ,
193+ } ,
194+ dir : `${ ref . config . pulumiBaseDir } /${ projectName } ` ,
195+ } ,
196+ // Do not resync the stack when the commit hash matches the last one
197+ continueResyncOnCommitMatch : false ,
198+ destroyOnFinalize : false ,
199+ // Enforce that the stack already exists
200+ useLocalStackOnly : true ,
201+ // retry if the stack is locked by another operation
202+ retryOnUpdateConflict : true ,
203+ } ,
204+ ...( supportsResetOnSameCommit
205+ ? {
206+ continueResyncOnCommitMatch : true ,
207+ resyncFrequencySeconds : 300 ,
208+ // TODO(#16186): consider scaling down the operator instead
209+ refresh : true ,
210+ }
211+ : { } ) ,
212+ } ,
213+ } ,
214+ {
215+ dependsOn : dependsOn ,
216+ }
217+ ) ;
218+ }
219+
220+ function createStackCRV2 (
221+ name : string ,
222+ namespaceName : string ,
223+ ref : GitFluxRef ,
224+ projectName : string ,
225+ envRefs : EnvRefs ,
226+ extraEnvs : {
227+ [ p : string ] : string ;
228+ } ,
229+ gcpSecret : Secret ,
230+ supportsResetOnSameCommit : boolean ,
231+ dependsOn : Resource [ ]
232+ ) {
84233 const sa = new k8s . core . v1 . ServiceAccount ( `${ name } -sa` , {
85234 metadata : {
86235 name : `${ name } -sa` ,
0 commit comments