Skip to content

Commit

Permalink
feat(config): add var alias for variables template key
Browse files Browse the repository at this point in the history
Because why not?
  • Loading branch information
edvald committed Apr 4, 2019
1 parent cff9883 commit ede49e5
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/reference/template-strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ lookups of keys. However, it is possible to do nested templating. For a somewhat
```yaml
# ...
env:
OTHER_MODULE_ENDPOINT: http://${variables.auth-module}/api/${modules.${variables.auth-module}.version}
OTHER_MODULE_ENDPOINT: http://${var.auth-module}/api/${modules.${var.auth-module}.version}
```
There the name of the module is pulled from the project/environment configuration, and used to find the
Expand Down
2 changes: 1 addition & 1 deletion docs/using-garden/configuration-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ provider instead of `local-kubernetes`.
Here, project-wide configuration variables can also be specified (global, and/or environment-specific). These are
then available for substitution in any string value in any module's `garden.yml`.

For example, assuming the above project configuration, `"foo-${variables.my-variable}-bar"` would evaluate to
For example, assuming the above project configuration, `"foo-${var.my-variable}-bar"` would evaluate to
`"foo-hello-variable-bar"` when used as a string value in a module's `garden.yml`.

## Module Configuration
Expand Down
2 changes: 1 addition & 1 deletion examples/kubernetes-module/postgres/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ manifests:
heritage: "Tiller"
type: Opaque
data:
postgresql-password: ${variables.postgres-password}
postgresql-password: ${var.postgres-password}
# Source: postgresql/templates/svc-headless.yaml
- apiVersion: v1
kind: Service
Expand Down
8 changes: 7 additions & 1 deletion garden-service/src/config/config-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ export class ModuleConfigContext extends ProjectConfigContext {
)
public variables: PrimitiveMap

@schema(
joiIdentifierMap(joiPrimitive())
.description("Alias for the variables field."),
)
public var: PrimitiveMap

constructor(
garden: Garden,
environment: Environment,
Expand Down Expand Up @@ -301,6 +307,6 @@ export class ModuleConfigContext extends ProjectConfigContext {

this.providers = new Map(environment.providers.map(p => <[string, Provider]>[p.name, p]))

this.variables = environment.variables
this.var = this.variables = environment.variables
}
}
2 changes: 1 addition & 1 deletion garden-service/src/docs/templates/template-strings.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ lookups of keys. However, it is possible to do nested templating. For a somewhat
```yaml
# ...
env:
OTHER_MODULE_ENDPOINT: http://${variables.auth-module}/api/${modules.${variables.auth-module}.version}
OTHER_MODULE_ENDPOINT: http://${var.auth-module}/api/${modules.${var.auth-module}.version}
```

There the name of the module is pulled from the project/environment configuration, and used to find the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ module:
repo: https://openfaas.github.io/faas-netes/
chart: openfaas
version: 1.7.0
releaseName: ${variables.release-name}
releaseName: ${var.release-name}
values:
exposeServices: false
functionNamespace: ${variables.function-namespace}
functionNamespace: ${var.function-namespace}
ingress:
enabled: true
hosts:
- host: ${variables.gateway-hostname}
- host: ${var.gateway-hostname}
serviceName: gateway
servicePort: 8080
path: /function/
- host: ${variables.gateway-hostname}
- host: ${var.gateway-hostname}
serviceName: gateway
servicePort: 8080
path: /system/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module:
- name: service-a
command: [echo, "${local.env.TEST_VARIABLE}"]
build:
command: [echo, "${variables.service-a-build-command}"]
command: [echo, "${var.service-a-build-command}"]
tests:
- name: unit
command: [echo, OK]
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module:
dependencies:
- service-a
build:
command: [echo, "${variables.service-a-build-command}"]
command: [echo, "${var.service-a-build-command}"]
tests:
- name: unit
command: [echo, OK]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module:
name: module-a
type: test
build:
command: [echo, "${variables.echo-string}"]
command: [echo, "${var.echo-string}"]
tests:
- name: unit
command: [echo, OK]
4 changes: 4 additions & 0 deletions garden-service/test/unit/src/config/config-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,8 @@ describe("ModuleConfigContext", () => {
it("should should resolve a project variable", async () => {
expect(await c.resolve({ key: ["variables", "some"], nodePath: [], opts: {} })).to.equal("variable")
})

it("should should resolve a project variable under the var alias", async () => {
expect(await c.resolve({ key: ["var", "some"], nodePath: [], opts: {} })).to.equal("variable")
})
})

0 comments on commit ede49e5

Please sign in to comment.