-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(pulumi): include build deps in plugin commands
In 0.12, we included build dependencies for Pulumi modules (e.g. when previewing). A build dependency (e.g. on an `exec` Module or Build) is a common way to ensure that the relevant language SDK is installed for the module/action before running Pulumi. We didn't bring this logic along when we adapted the Pulumi plugin commands for 0.13—this is fixed here. Also added a lightweight test project to test this logic (which should also serve us well when making further fixes to this plugin).
- Loading branch information
Showing
33 changed files
with
11,102 additions
and
3,379 deletions.
There are no files selected for viewing
3,886 changes: 2,249 additions & 1,637 deletions
3,886
examples/pulumi/k8s-deployment/package-lock.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
config: | ||
kubernetes:context: docker-desktop | ||
pulumi-k8s:namespace: pulumi-k8s | ||
backend: | ||
url: https://api.pulumi.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3,898 changes: 2,254 additions & 1,644 deletions
3,898
examples/pulumi/k8s-namespace/package-lock.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"ignorePatterns": ["test-project*/"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (C) 2018-2024 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { dirname, resolve } from "path" | ||
import { fileURLToPath } from "node:url" | ||
import type { ResolvedConfigGraph } from "@garden-io/core/build/src/graph/config-graph.js" | ||
import type { PluginContext } from "@garden-io/core/build/src/plugin-context.js" | ||
import { makeTestGarden, type TestGarden } from "@garden-io/sdk/build/src/testing.js" | ||
import type { Log } from "@garden-io/sdk/build/src/types.js" | ||
import type { PulumiProvider } from "../src/provider.js" | ||
import { gardenPlugin as pulumiPlugin } from "../src/index.js" | ||
import { ensureNodeModules } from "./test-helpers.js" | ||
import { getPulumiCommands } from "../src/commands.js" | ||
import { expect } from "chai" | ||
import { type LogEntry, resolveMsg } from "@garden-io/core/build/src/logger/log-entry.js" | ||
import stripAnsi from "strip-ansi" | ||
|
||
const moduleDirName = dirname(fileURLToPath(import.meta.url)) | ||
|
||
// Careful here! | ||
// We have some packages in the test directory but when this here runs we're a subfolder of '/build' | ||
// so to actually find the files we need to traverse back to the source folder. | ||
// TODO: Find a better way to do this. | ||
const projectRoot = resolve(moduleDirName, "../../test/", "test-project-local-script") | ||
|
||
const deployARoot = resolve(projectRoot, "deploy-a") | ||
const deployBRoot = resolve(projectRoot, "deploy-b") | ||
|
||
describe("pulumi plugin commands", () => { | ||
let garden: TestGarden | ||
let graph: ResolvedConfigGraph | ||
let ctx: PluginContext | ||
let log: Log | ||
let provider: PulumiProvider | ||
|
||
before(async () => { | ||
await ensureNodeModules([deployARoot, deployBRoot]) | ||
const plugin = pulumiPlugin() | ||
garden = await makeTestGarden(projectRoot, { plugins: [plugin] }) | ||
log = garden.log | ||
provider = (await garden.resolveProvider({ log, name: "pulumi" })) as PulumiProvider | ||
ctx = await garden.getPluginContext({ provider, templateContext: undefined, events: undefined }) | ||
graph = await garden.getResolvedConfigGraph({ log, emit: false }) | ||
}) | ||
|
||
// Note: Since the stacks in this test project don't have any side-effects, we don't need an after-cleanup step here. | ||
|
||
describe("preview command", () => { | ||
it("executes Build dependencies, but not Run dependencies", async () => { | ||
const previewCmd = getPulumiCommands().find((cmd) => cmd.name === "preview")! | ||
await previewCmd.handler({ garden, ctx, args: [], graph, log }) | ||
const buildALogEntries = findProcessingEntries(garden.log.entries, "Build", "build-a") | ||
const buildBLogEntries = findProcessingEntries(garden.log.entries, "Build", "build-b") | ||
const runALogEntries = findProcessingEntries(garden.log.entries, "Run", "run-a") | ||
const runBLogEntries = findProcessingEntries(garden.log.entries, "Run", "run-b") | ||
expect(buildALogEntries.length, "number of log entries for build-a to be greater than 0").to.be.greaterThan(0) | ||
expect(buildBLogEntries.length, "number of log entries for build-b to be greater than 0").to.be.greaterThan(0) | ||
expect(runALogEntries.length, "number of log entries for run-a to be 0").to.eql(0) | ||
expect(runBLogEntries.length, "number of log entries for run-b to be 0").to.eql(0) | ||
}) | ||
}) | ||
}) | ||
|
||
function findProcessingEntries(entries: LogEntry[], kind: string, name: string): LogEntry[] { | ||
const msgRegex = new RegExp(`Task nodes in progress: processing ${kind} type=exec name=${name}`) | ||
return entries.filter((e) => msgRegex.test(stripAnsi(resolveMsg(e) || ""))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.