Skip to content
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

fix(pulumi): propagate resolved action context to pulumi plugin commands #5324

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 33 additions & 14 deletions plugins/pulumi/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ import { TemplatableConfigContext } from "@garden-io/core/build/src/config/templ
import { ActionTaskProcessParams, ValidResultType } from "@garden-io/core/build/src/tasks/base"
import { deletePulumiDeploy } from "./handlers"
import { ActionLog, createActionLog, Log } from "@garden-io/core/build/src/logger/log-entry"
import { ActionConfigContext } from "@garden-io/core/build/src/config/template-contexts/actions"
import { ActionSpecContext } from "@garden-io/core/build/src/config/template-contexts/actions"
import { ProviderMap } from "@garden-io/core/build/src/config/provider"

type PulumiBaseParams = Omit<PulumiParams, "action">

Expand Down Expand Up @@ -181,15 +182,23 @@ const pulumiCommandSpecs: PulumiCommandSpec[] = [
},
]

const makePluginContextForDeploy = async (params: PulumiParams & { garden: Garden; graph: ConfigGraph }) => {
const { garden, provider, ctx, action } = params
const templateContext = new ActionConfigContext({
const makePluginContextForDeploy = async (
params: PulumiParams & {
garden: Garden
graph: ConfigGraph
resolvedProviders: ProviderMap
}
) => {
const { garden, graph, provider, resolvedProviders, ctx, action } = params
const templateContext = new ActionSpecContext({
garden,
config: action.getConfig(),
thisContextParams: {
name: action.name,
mode: action.mode(),
},
resolvedProviders,
action,
partialRuntimeResolution: false,
modules: graph.getModules(),
resolvedDependencies: action.getResolvedDependencies(),
executedDependencies: action.getExecutedDependencies(),
inputs: action.getInternal().inputs || {},
variables: action.getVariables(),
})
const ctxForDeploy = await garden.getPluginContext({ provider, templateContext, events: ctx.events })
Expand All @@ -206,6 +215,7 @@ interface PulumiPluginCommandTaskParams {
skipRuntimeDependencies: boolean
runFn: PulumiRunFn
pulumiParams: PulumiBaseParams
resolvedProviders: ProviderMap
}

export type PulumiCommandResult = ValidResultType
Expand All @@ -217,6 +227,7 @@ class PulumiPluginCommandTask extends PluginActionTask<PulumiDeploy, PulumiComma
commandDescription: string
override skipRuntimeDependencies: boolean
runFn: PulumiRunFn
resolvedProviders: ProviderMap

constructor({
garden,
Expand All @@ -228,6 +239,7 @@ class PulumiPluginCommandTask extends PluginActionTask<PulumiDeploy, PulumiComma
skipRuntimeDependencies = false,
runFn,
pulumiParams,
resolvedProviders,
}: PulumiPluginCommandTaskParams) {
super({
garden,
Expand All @@ -243,6 +255,7 @@ class PulumiPluginCommandTask extends PluginActionTask<PulumiDeploy, PulumiComma
this.pulumiParams = pulumiParams
const provider = <PulumiProvider>pulumiParams.ctx.provider
this.concurrencyLimit = provider.config.pluginTaskConcurrencyLimit
this.resolvedProviders = resolvedProviders
}

getDescription() {
Expand Down Expand Up @@ -275,6 +288,7 @@ class PulumiPluginCommandTask extends PluginActionTask<PulumiDeploy, PulumiComma
skipRuntimeDependencies: this.skipRuntimeDependencies,
runFn: this.runFn,
pulumiParams: this.pulumiParams,
resolvedProviders: this.resolvedProviders,
})
})

Expand All @@ -288,7 +302,11 @@ class PulumiPluginCommandTask extends PluginActionTask<PulumiDeploy, PulumiComma
async process({ dependencyResults }: ActionTaskProcessParams<PulumiDeploy, PulumiCommandResult>) {
this.log.info(chalk.gray(`Running ${chalk.white(this.commandDescription)}`))

const params = { ...this.pulumiParams, action: this.getResolvedAction(this.action, dependencyResults) }
const params = {
...this.pulumiParams,
action: this.getResolvedAction(this.action, dependencyResults),
resolvedProviders: this.resolvedProviders,
}

try {
await selectStack(params)
Expand Down Expand Up @@ -349,24 +367,25 @@ function makePulumiCommand({ name, commandDescription, beforeFn, runFn, afterFn

beforeFn && (await beforeFn({ ctx, log }))

const provider = ctx.provider as PulumiProvider

const pulumiProvider = ctx.provider as PulumiProvider
const actions = graph.getDeploys({ names }).filter((a) => a.type === "pulumi")
const resolvedProviders = await garden.resolveProviders(log)

const tasks = await Promise.all(
actions.map(async (action) => {
const templateContext = new TemplatableConfigContext(garden, action.getConfig())
const actionLog = createActionLog({ log, actionName: action.name, actionKind: action.kind })

const pulumiParams: PulumiBaseParams = {
ctx: await garden.getPluginContext({ provider, templateContext, events: ctx.events }),
provider,
ctx: await garden.getPluginContext({ provider: pulumiProvider, templateContext, events: ctx.events }),
provider: pulumiProvider,
log: actionLog,
}

return new PulumiPluginCommandTask({
garden,
graph,
resolvedProviders,
log: actionLog,
action,
commandName: name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pulumi-k8s-test:appName: api-varfile1-override
pulumi-k8s-test:appName: api-varfile1-override
pulumi-k8s-test:nsName: ${actions["k8s-namespace"].name}-varfile2-override
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pulumi-k8s-test:appName: api-varfile2-override
pulumi-k8s-test:appName: api-varfile2-override
pulumi-k8s-test:nsName: ${actions["k8s-namespace"].name}-varfile2-override