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): return correct responses for pulumi plugin commands #5129

Merged
merged 2 commits into from
Oct 2, 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
11 changes: 9 additions & 2 deletions core/src/graph/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ export class ProcessTaskNode<T extends Task = Task> extends TaskNode<T> {
const dependencyResults = this.getDependencyResults()

try {
const processResult: TaskResultType<T> = await this.task.process({ status, dependencyResults, statusOnly: false })
const processResult: TaskResultType<T> = await this.task.process({
status,
dependencyResults,
statusOnly: false,
})
this.task.emit("processed", { result: processResult })
if (processResult.state === "ready") {
const msg = `${this.task.getDescription()} is ready.`
Expand Down Expand Up @@ -304,7 +308,10 @@ export class StatusTaskNode<T extends Task = Task> extends TaskNode<T> {
const dependencyResults = this.getDependencyResults()

try {
const result: TaskResultType<T> = await this.task.getStatus({ statusOnly: this.statusOnly, dependencyResults })
const result: TaskResultType<T> = await this.task.getStatus({
statusOnly: this.statusOnly,
dependencyResults,
})
this.task.emit("statusResolved", { result })
if (!this.task.force && result?.state === "ready") {
const msg = `${this.task.getDescription()} status is ready.`
Expand Down
27 changes: 19 additions & 8 deletions plugins/pulumi/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { ActionConfigContext } from "@garden-io/core/build/src/config/template-c

type PulumiBaseParams = Omit<PulumiParams, "action">

type PulumiRunFn = (params: PulumiParams) => Promise<any>
type PulumiRunFn = (params: PulumiParams) => Promise<PulumiCommandResult>

interface PulumiCommandSpec {
name: string
Expand Down Expand Up @@ -109,13 +109,19 @@ const pulumiCommandSpecs: PulumiCommandSpec[] = [
await copy(planPath, modifiedPlanPath)
log.debug(`Copied plan to ${modifiedPlanPath}`)
return {
affectedResourcesCount,
operationCounts,
modifiedPlanPath,
previewUrl,
state: "ready",
outputs: {
affectedResourcesCount,
operationCounts,
modifiedPlanPath,
previewUrl,
},
}
} else {
return null
return {
state: "ready",
outputs: {},
}
}
},
// TODO-G2-thor: Re-enable and test when 0.13 is stable enough to run commands.
Expand Down Expand Up @@ -164,7 +170,12 @@ const pulumiCommandSpecs: PulumiCommandSpec[] = [
commandDescription: "pulumi destroy",
runFn: async (params) => {
if (params.action.getSpec("allowDestroy")) {
await deletePulumiDeploy!(params)
return await deletePulumiDeploy!(params)
}
// do nothing and return ready if allowDestory is not set
return {
state: "ready",
outputs: {},
}
},
},
Expand Down Expand Up @@ -197,7 +208,7 @@ interface PulumiPluginCommandTaskParams {
pulumiParams: PulumiBaseParams
}

interface PulumiCommandResult extends ValidResultType {}
export interface PulumiCommandResult extends ValidResultType {}

@Profile()
class PulumiPluginCommandTask extends PluginActionTask<PulumiDeploy, PulumiCommandResult> {
Expand Down
24 changes: 21 additions & 3 deletions plugins/pulumi/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { PulumiProvider } from "./provider"
import { dedent, deline, naturalList } from "@garden-io/sdk/build/src/util/string"
import { Resolved } from "@garden-io/core/build/src/actions/types"
import { ActionLog } from "@garden-io/core/build/src/logger/log-entry"
import { PulumiCommandResult } from "./commands"

export interface PulumiParams {
ctx: PluginContext
Expand Down Expand Up @@ -371,7 +372,7 @@ export function countAffectedResources(plan: PulumiPlan): number {
/**
* Wrapper for `pulumi cancel --yes`. Does not throw on error, since we may also want to cancel other updates upstream.
*/
export async function cancelUpdate({ action, ctx, provider, log }: PulumiParams): Promise<void> {
export async function cancelUpdate({ action, ctx, provider, log }: PulumiParams): Promise<PulumiCommandResult> {
const res = await pulumi(ctx, provider).exec({
log,
ignoreError: true,
Expand All @@ -383,13 +384,22 @@ export async function cancelUpdate({ action, ctx, provider, log }: PulumiParams)

if (res.exitCode !== 0) {
log.warn(chalk.yellow(`pulumi cancel failed:\n${res.stderr}`))
return {
state: "failed",
outputs: {},
}
}

return {
state: "ready",
outputs: {},
}
}

/**
* Wrapper for `pulumi refresh --yes`.
*/
export async function refreshResources(params: PulumiParams): Promise<void> {
export async function refreshResources(params: PulumiParams): Promise<PulumiCommandResult> {
const { action, ctx, provider, log } = params
const configPath = await applyConfig(params)

Expand All @@ -401,12 +411,16 @@ export async function refreshResources(params: PulumiParams): Promise<void> {
cwd: getActionStackRoot(action),
})
log.info(res.stdout)
return {
state: "ready",
outputs: {},
}
}

/**
* Wrapper for `pulumi stack export|pulumi stack import`.
*/
export async function reimportStack(params: PulumiParams): Promise<void> {
export async function reimportStack(params: PulumiParams): Promise<PulumiCommandResult> {
const { action, ctx, provider, log } = params
const cwd = getActionStackRoot(action)

Expand All @@ -426,6 +440,10 @@ export async function reimportStack(params: PulumiParams): Promise<void> {
env: ensureEnv({ log, ctx, provider, action }),
cwd,
})
return {
state: "ready",
outputs: {},
}
}

// Lower-level helpers
Expand Down