From 750e88dfe5c596799ae83e2fe79ea8b78e94b8e3 Mon Sep 17 00:00:00 2001 From: Vladimir Vagaytsev Date: Wed, 1 Nov 2023 10:40:05 +0100 Subject: [PATCH] fix(pulumi): propagate resolved action context to pulumi plugin commands (#5324) * fix(pulumi): propagate resolved action context to pulumi plugin commands * test(pulumi): use action references in varfiles to test the fix * chore: remove misleading comment Providers are already resolved and cached. --- plugins/pulumi/src/commands.ts | 47 +++++++++++++------ .../k8s-deployment/varfile1.yaml | 3 +- .../k8s-deployment/varfile2.yaml | 3 +- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/plugins/pulumi/src/commands.ts b/plugins/pulumi/src/commands.ts index 768441f8b9..ec2e1b1649 100644 --- a/plugins/pulumi/src/commands.ts +++ b/plugins/pulumi/src/commands.ts @@ -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 @@ -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 }) @@ -206,6 +215,7 @@ interface PulumiPluginCommandTaskParams { skipRuntimeDependencies: boolean runFn: PulumiRunFn pulumiParams: PulumiBaseParams + resolvedProviders: ProviderMap } export type PulumiCommandResult = ValidResultType @@ -217,6 +227,7 @@ class PulumiPluginCommandTask extends PluginActionTaskpulumiParams.ctx.provider this.concurrencyLimit = provider.config.pluginTaskConcurrencyLimit + this.resolvedProviders = resolvedProviders } getDescription() { @@ -278,6 +291,7 @@ class PulumiPluginCommandTask extends PluginActionTask) { 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) @@ -352,9 +370,9 @@ 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) => { @@ -362,14 +380,15 @@ function makePulumiCommand({ name, commandDescription, beforeFn, runFn, afterFn 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, diff --git a/plugins/pulumi/test/test-project-k8s/k8s-deployment/varfile1.yaml b/plugins/pulumi/test/test-project-k8s/k8s-deployment/varfile1.yaml index 97d7611ef4..d8ccdb86db 100644 --- a/plugins/pulumi/test/test-project-k8s/k8s-deployment/varfile1.yaml +++ b/plugins/pulumi/test/test-project-k8s/k8s-deployment/varfile1.yaml @@ -1 +1,2 @@ -pulumi-k8s-test:appName: api-varfile1-override \ No newline at end of file +pulumi-k8s-test:appName: api-varfile1-override +pulumi-k8s-test:nsName: ${actions["k8s-namespace"].name}-varfile2-override diff --git a/plugins/pulumi/test/test-project-k8s/k8s-deployment/varfile2.yaml b/plugins/pulumi/test/test-project-k8s/k8s-deployment/varfile2.yaml index 339bf9ed17..28c2013187 100644 --- a/plugins/pulumi/test/test-project-k8s/k8s-deployment/varfile2.yaml +++ b/plugins/pulumi/test/test-project-k8s/k8s-deployment/varfile2.yaml @@ -1 +1,2 @@ -pulumi-k8s-test:appName: api-varfile2-override \ No newline at end of file +pulumi-k8s-test:appName: api-varfile2-override +pulumi-k8s-test:nsName: ${actions["k8s-namespace"].name}-varfile2-override