-
Notifications
You must be signed in to change notification settings - Fork 59
[static] Add pulumi stack compatibility for v1 #1058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
| import * as k8s from '@pulumi/kubernetes'; | ||
| import * as pulumi from '@pulumi/pulumi'; | ||
| import * as semver from 'semver'; | ||
| import { Secret } from '@pulumi/kubernetes/core/v1'; | ||
| import { Resource } from '@pulumi/pulumi'; | ||
| import { | ||
| CLUSTER_BASENAME, | ||
| config, | ||
|
|
@@ -11,6 +13,7 @@ import { | |
| } from 'splice-pulumi-common'; | ||
|
|
||
| import { spliceEnvConfig } from '../config/envConfig'; | ||
| import { operatorDeploymentConfig } from './config'; | ||
| import { GitFluxRef } from './flux-source'; | ||
|
|
||
| export type EnvRefs = { [key: string]: unknown }; | ||
|
|
@@ -81,6 +84,152 @@ export function createStackCR( | |
| extraEnvs: { [key: string]: string } = {}, | ||
| dependsOn: pulumi.Resource[] = [] | ||
| ): pulumi.CustomResource { | ||
| if (operatorDeploymentConfig.useOperatorV2) { | ||
| return createStackCRV2( | ||
| name, | ||
| namespaceName, | ||
| ref, | ||
| projectName, | ||
| envRefs, | ||
| extraEnvs, | ||
| gcpSecret, | ||
| supportsResetOnSameCommit, | ||
| dependsOn | ||
| ); | ||
| } else { | ||
| return createStackCRV1( | ||
| name, | ||
| projectName, | ||
| supportsResetOnSameCommit, | ||
| ref, | ||
| envRefs, | ||
| extraEnvs, | ||
| namespaceName, | ||
| dependsOn | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /*https://github.com/pulumi/pulumi-kubernetes-operator/blob/master/docs/stacks.md*/ | ||
| export function createStackCRV1( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume you tested this? I know it's basically a revert, but to see that you have everything...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just by updating the generated files locally. Also pushed to my internal branch now |
||
| name: string, | ||
| projectName: string, | ||
| supportsResetOnSameCommit: boolean, | ||
| ref: GitFluxRef, | ||
| envRefs: EnvRefs, | ||
| extraEnvs: { [key: string]: string } = {}, | ||
| namespaceName: string = 'operator', | ||
| dependsOn: pulumi.Resource[] = [] | ||
| ): pulumi.CustomResource { | ||
| const privateConfigs = ref.config.privateConfigsDir | ||
| ? { | ||
| PRIVATE_CONFIGS_PATH: { | ||
| type: 'Literal', | ||
| literal: { | ||
| value: `/tmp/pulumi-working/operator/${name}/workspace/${ref.config.privateConfigsDir}`, | ||
| }, | ||
| }, | ||
| } | ||
| : {}; | ||
| const publicConfigs = ref.config.publicConfigsDir | ||
| ? { | ||
| PUBLIC_CONFIGS_PATH: { | ||
| type: 'Literal', | ||
| literal: { | ||
| value: `/tmp/pulumi-working/operator/${name}/workspace/${ref.config.publicConfigsDir}`, | ||
| }, | ||
| }, | ||
| } | ||
| : {}; | ||
| return new k8s.apiextensions.CustomResource( | ||
| name, | ||
| { | ||
| apiVersion: 'pulumi.com/v1', | ||
| kind: 'Stack', | ||
| metadata: { name: name, namespace: namespaceName }, | ||
| spec: { | ||
| ...{ | ||
| stack: `organization/${projectName}/${name}.${CLUSTER_BASENAME}`, | ||
| backend: config.requireEnv('PULUMI_BACKEND_URL'), | ||
| envRefs: { | ||
| ...envRefs, | ||
| SPLICE_ROOT: { | ||
| type: 'Literal', | ||
| literal: { | ||
| value: `/tmp/pulumi-working/operator/${name}/workspace/${ref.config.spliceRoot}`, | ||
| }, | ||
| }, | ||
| DEPLOYMENT_DIR: { | ||
| type: 'Literal', | ||
| literal: { | ||
| value: `/tmp/pulumi-working/operator/${name}/workspace/${ref.config.deploymentDir}`, | ||
| }, | ||
| }, | ||
| ...privateConfigs, | ||
| ...publicConfigs, | ||
| GCP_CLUSTER_BASENAME: { | ||
| type: 'Literal', | ||
| literal: { | ||
| value: CLUSTER_BASENAME, | ||
| }, | ||
| }, | ||
| ...Object.keys(extraEnvs).reduce<{ | ||
| [key: string]: unknown; | ||
| }>((acc, key) => { | ||
| acc[key] = { | ||
| type: 'Literal', | ||
| literal: { | ||
| value: extraEnvs[key], | ||
| }, | ||
| }; | ||
| return acc; | ||
| }, {}), | ||
| }, | ||
| fluxSource: { | ||
| sourceRef: { | ||
| apiVersion: ref.resource.apiVersion, | ||
| kind: ref.resource.kind, | ||
| name: ref.resource.metadata.name, | ||
| }, | ||
| dir: `${ref.config.pulumiBaseDir}/${projectName}`, | ||
| }, | ||
| // Do not resync the stack when the commit hash matches the last one | ||
| continueResyncOnCommitMatch: false, | ||
| destroyOnFinalize: false, | ||
| // Enforce that the stack already exists | ||
| useLocalStackOnly: true, | ||
| // retry if the stack is locked by another operation | ||
| retryOnUpdateConflict: true, | ||
| }, | ||
| ...(supportsResetOnSameCommit | ||
| ? { | ||
| continueResyncOnCommitMatch: true, | ||
| resyncFrequencySeconds: 300, | ||
| // TODO(#16186): consider scaling down the operator instead | ||
| refresh: true, | ||
| } | ||
| : {}), | ||
| }, | ||
| }, | ||
| { | ||
| dependsOn: dependsOn, | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| function createStackCRV2( | ||
| name: string, | ||
| namespaceName: string, | ||
| ref: GitFluxRef, | ||
| projectName: string, | ||
| envRefs: EnvRefs, | ||
| extraEnvs: { | ||
| [p: string]: string; | ||
| }, | ||
| gcpSecret: Secret, | ||
| supportsResetOnSameCommit: boolean, | ||
| dependsOn: Resource[] | ||
| ) { | ||
| const sa = new k8s.core.v1.ServiceAccount(`${name}-sa`, { | ||
| metadata: { | ||
| name: `${name}-sa`, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we adding this now? I read the issue but it doesn't actually state what the problem is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, didn't add the motivation to the issue.
Root cause is that the deployment stack follows main in our deployments, and the v2 CR is not compatible with the v2 definition.
So to first run it on our internal clusters we would need either to configure all the other clusters to not follow main or add a config flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah right makes sense, thx