Skip to content

Commit

Permalink
Revert "fix: resolve multiline variables in kubernetes manifests corr…
Browse files Browse the repository at this point in the history
…ectly (#5270)" (#5283)

This reverts commit 946e74b.
  • Loading branch information
stefreak authored Oct 23, 2023
1 parent 5f92abd commit e79fc54
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 76 deletions.
4 changes: 2 additions & 2 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
"check-package-lock": "git diff-index --quiet HEAD -- package-lock.json || (echo 'package-lock.json is dirty!' && exit 1)",
"check-types": "tsc -p . --noEmit",
"clean": "shx rm -rf build",
"dev": "nodemon --watch src/template-string/*.pegjs --exec npm run build",
"dev": "nodemon --watch src/template-string/*.pegjs --exec yarn build",
"fix-format": "npm run lint -- --fix --quiet",
"lint": "eslint --ignore-pattern 'src/lib/**' --ext .ts src/ test/",
"migration:generate": "typeorm migration:generate --config ormconfig.js -n",
Expand All @@ -292,4 +292,4 @@
"fsevents": "^2.3.3"
},
"gitHead": "b0647221a4d2ff06952bae58000b104215aed922"
}
}
9 changes: 4 additions & 5 deletions core/src/plugins/kubernetes/kubernetes-type/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,13 @@ async function readFileManifests(
resolvedFiles.map(async (path): Promise<DeclaredManifest[]> => {
const absPath = resolve(manifestPath, path)
log.debug(`Reading manifest for ${action.longDescription()} from path ${absPath}`)
// parse manifests as yaml before resolving the template strings
// to avoid the whole yaml file being treated as single string.
const str = (await readFile(absPath)).toString()
const resolved = ctx.resolveTemplateStrings(str, { allowPartial: true, unescape: true })
const manifests = await parseKubernetesManifests(
(await readFile(absPath)).toString(),
resolved,
`${basename(absPath)} in directory ${dirname(absPath)} (specified in ${action.longDescription()})`
)
const resolved = ctx.resolveTemplateStrings(manifests, { allowPartial: true, unescape: true })
return resolved.map((manifest, index) => ({
return manifests.map((manifest, index) => ({
declaration: {
type: "file",
filename: absPath,
Expand Down

This file was deleted.

This file was deleted.

58 changes: 6 additions & 52 deletions core/test/integ/src/plugins/kubernetes/kubernetes-type/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@
import { expect } from "chai"
import cloneDeep from "fast-copy"

import dedent from "dedent"
import { omit } from "lodash"
import { dirname, join } from "path"
import { Resolved } from "../../../../../../src/actions/types"
import { ProviderConfigContext } from "../../../../../../src/config/template-contexts/provider"
import { ConfigGraph } from "../../../../../../src/graph/config-graph"
import { PluginContext } from "../../../../../../src/plugin-context"
import { KubeApi } from "../../../../../../src/plugins/kubernetes/api"
import { KubernetesProvider } from "../../../../../../src/plugins/kubernetes/config"
import { getManifests } from "../../../../../../src/plugins/kubernetes/kubernetes-type/common"
import { KubernetesDeployAction } from "../../../../../../src/plugins/kubernetes/kubernetes-type/config"
import { expectError, getDataDir, getExampleDir, makeTestGarden, TestGarden } from "../../../../../helpers"
import { KubernetesDeployAction } from "../../../../../../src/plugins/kubernetes/kubernetes-type/config"
import { Resolved } from "../../../../../../src/actions/types"
import { KubeApi } from "../../../../../../src/plugins/kubernetes/api"
import { KubernetesProvider } from "../../../../../../src/plugins/kubernetes/config"
import dedent from "dedent"
import { dirname, join } from "path"

let kubernetesTestGarden: TestGarden

Expand Down Expand Up @@ -151,50 +149,6 @@ describe("getManifests", () => {
})
})

context("resolve template strings in manifests", () => {
let action: Resolved<KubernetesDeployAction>

before(async () => {
garden = await getKubernetesTestGarden()
})

beforeEach(async () => {
graph = await garden.getConfigGraph({ log: garden.log, emit: false })
})

it("resolves multi-line template strings in the manifests correctly", async () => {
action = await garden.resolveAction<KubernetesDeployAction>({
action: cloneDeep(graph.getDeploy("multiline-var-in-manifest-deploy")),
log: garden.log,
graph,
})
const provider = (await garden.resolveProvider(garden.log, "local-kubernetes")) as KubernetesProvider
ctx = await garden.getPluginContext({
provider,
templateContext: new ProviderConfigContext(garden, provider.dependencies, action.getVariables()),
events: undefined,
})
api = await KubeApi.factory(garden.log, ctx, provider)

const manifests = await getManifests({ ctx, api, action, log: garden.log, defaultNamespace })
const configmap = manifests.find((m) => m.metadata.name === "test-configmap")
const expectedConfigMap = {
...configmap,
// remove annotations/labels added by garden
metadata: omit(configmap?.metadata, ["annotations", "labels"]),
}
expect(expectedConfigMap).eql({
apiVersion: "v1",
kind: "ConfigMap",
metadata: {
name: "test-configmap",
namespace: "foobar",
},
data: { hello: "this is a\nmultiline\nvariable\n" },
})
})
})

context("kustomize", () => {
const exampleDir = getExampleDir("kustomize")

Expand Down

0 comments on commit e79fc54

Please sign in to comment.