-
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(module-conversion): always include build deps (#5671)
* fix(module-conversion): always include build deps Before this fix, build dependencies weren't being transferred to the generated actions in all cases. This was a problem e.g. if using a `helm` module with a build dependency on a `container` module, whose built image was referenced in the chart (since the missing build dependency meant that the image wasn't necessarily ready by the time the deploy started). This was fixed by simply ensuring that any explicit build dependencies (i.e. under `module.build.dependencies`) are included in the dependencies of any generated runtime actions (Deploys, Tests and Runs). This reflects the 0.12-era semantics, where every test, service and task had a build dependency on the module's build step, which in turn respected any build dependencies declared on the module (under `build.dependencies`). * chore: remove unnecessary null-checker * chore: extract some local vars and fix typo * fix(container): don't add build dep on PVCs In the module conversion logic for the `persistentvolumeclaim` type, we don't generate any Build actions (just a single Deploy). This means we shouldn't declare a build dependency for it (since we'd be declaring a dependency on an action that won't exist after the conversion). * chore(test): add logging env vars for testing Sometimes, it's convenient to see the logger output while debugging test suites. By default, we use the `quiet` logger (which doesn't log anything). Here, we introduce two new env vars for testing, `GARDEN_TESTS_SHOW_LOGS` and `GAREDEN_TESTS_LOG_LEVEL`. * test: update test assertions --------- Co-authored-by: Vladimir Vagaytsev <[email protected]>
- Loading branch information
1 parent
a833eac
commit 47c24d5
Showing
6 changed files
with
159 additions
and
12 deletions.
There are no files selected for viewing
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
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
137 changes: 137 additions & 0 deletions
137
core/test/unit/src/plugins/kubernetes/container/module-conversion.ts
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,137 @@ | ||
/* | ||
* Copyright (C) 2018-2023 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 { expect } from "chai" | ||
import type { ConfigGraph } from "../../../../../../src/graph/config-graph.js" | ||
import type { TempDirectory, TestGarden } from "../../../../../helpers.js" | ||
import { makeModuleConfig, makeTempGarden } from "../../../../../helpers.js" | ||
import type { Log } from "../../../../../../src/logger/log-entry.js" | ||
import { gardenPlugin } from "../../../../../../src/plugins/container/container.js" | ||
import type { | ||
ContainerModuleConfig, | ||
ContainerServiceSpec, | ||
} from "../../../../../../src/plugins/container/moduleConfig.js" | ||
import { defaultContainerResources } from "../../../../../../src/plugins/container/moduleConfig.js" | ||
import { actionReferenceToString } from "../../../../../../src/actions/base.js" | ||
|
||
describe("kubernetes container module conversion", () => { | ||
let tmpDir: TempDirectory | ||
let garden: TestGarden | ||
let log: Log | ||
let graph: ConfigGraph | ||
|
||
before(async () => { | ||
const result = await makeTempGarden({ plugins: [gardenPlugin()] }) | ||
tmpDir = result.tmpDir | ||
garden = result.garden | ||
log = garden.log | ||
}) | ||
|
||
after(async () => { | ||
tmpDir.cleanup() | ||
}) | ||
|
||
it("should ", async () => { | ||
garden.setModuleConfigs([ | ||
makeModuleConfig<ContainerModuleConfig>(garden.projectRoot, { | ||
name: "test-image", | ||
type: "container", | ||
variables: {}, | ||
spec: { | ||
build: { | ||
timeout: 300, | ||
}, | ||
buildArgs: {}, | ||
extraFlags: [], | ||
dockerfile: "foo.dockerfile", | ||
services: [], | ||
tests: [], | ||
tasks: [], | ||
}, | ||
}), | ||
makeModuleConfig<ContainerModuleConfig>(garden.projectRoot, { | ||
name: "test-deploy", | ||
type: "container", | ||
variables: {}, | ||
build: { | ||
timeout: 300, | ||
dependencies: [ | ||
{ | ||
name: "test-image", | ||
copy: [], | ||
}, | ||
], | ||
}, | ||
spec: { | ||
build: { | ||
timeout: 300, | ||
}, | ||
buildArgs: {}, | ||
extraFlags: [], | ||
dockerfile: "foo.dockerfile", | ||
services: [ | ||
{ | ||
...dummyContainerServiceSpec, | ||
name: "test-deploy", | ||
}, | ||
], | ||
tests: [], | ||
tasks: [], | ||
}, | ||
}), | ||
]) | ||
graph = await garden.getConfigGraph({ log, emit: false }) | ||
const testDeploy = graph.getDeploy("test-deploy") | ||
const deployDeps = testDeploy.getDependencyReferences().map(actionReferenceToString) | ||
expect(deployDeps.sort()).to.eql(["build.test-deploy", "build.test-image"]) | ||
}) | ||
}) | ||
|
||
const dummyContainerServiceSpec: ContainerServiceSpec = { | ||
name: "service-a", | ||
annotations: {}, | ||
args: ["echo"], | ||
dependencies: [], | ||
daemon: false, | ||
disabled: false, | ||
ingresses: [ | ||
{ | ||
annotations: {}, | ||
path: "/", | ||
port: "http", | ||
}, | ||
], | ||
env: { | ||
SOME_ENV_VAR: "value", | ||
}, | ||
healthCheck: { | ||
httpGet: { | ||
path: "/health", | ||
port: "http", | ||
}, | ||
livenessTimeoutSeconds: 10, | ||
readinessTimeoutSeconds: 10, | ||
}, | ||
limits: { | ||
cpu: 123, | ||
memory: 456, | ||
}, | ||
cpu: defaultContainerResources.cpu, | ||
memory: defaultContainerResources.memory, | ||
ports: [ | ||
{ | ||
name: "http", | ||
protocol: "TCP", | ||
containerPort: 8080, | ||
servicePort: 8080, | ||
}, | ||
], | ||
replicas: 1, | ||
volumes: [], | ||
deploymentStrategy: "RollingUpdate", | ||
} |