Skip to content

Commit fd33a25

Browse files
committed
v15
1 parent 931afb7 commit fd33a25

7 files changed

Lines changed: 110 additions & 9 deletions

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index.js

Lines changed: 17 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { ComponentConstraintDeploymentConfigOperatorType } from './types/component_container_deployment_config_operator_type'
2+
3+
/**
4+
* Component Container Deployment Constraint model
5+
* @remarks Maps to the Nomad constraint model.
6+
* @see https://www.nomadproject.io/docs/job-specification/constraint
7+
*/
8+
export interface ComponentContainerDeploymentConstraint {
9+
/**
10+
* Gets the attribute to apply the constraint on.
11+
* @type {string}
12+
* @memberof ComponentContainerDeploymentConstraint
13+
* @required
14+
* @remarks Maps to job.constraints.attribute.
15+
*/
16+
attribute: string
17+
18+
/**
19+
* Gets the operator to use for the constraint.
20+
* @type {ComponentConstraintDeploymentConfigOperatorType}
21+
* @memberof ComponentContainerDeploymentConstraint
22+
* @required
23+
* @remarks Maps to job.constraints.operator.
24+
*/
25+
operator: ComponentConstraintDeploymentConfigOperatorType
26+
27+
/**
28+
* Gets the value to compare the attribute against.
29+
* @type {string}
30+
* @memberof ComponentContainerDeploymentConstraint
31+
* @optional
32+
* @remarks Maps to job.constraints.value.
33+
*/
34+
value?: string
35+
}

src/models/component_deployment_configuration.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ComponentContainerDeploymentConfigurationType } from './types/component_container_deployment_configuration_type'
22
import { ComponentContainerDeploymentConfiguration } from './component_container_deployment_configuration'
3+
import { ComponentContainerDeploymentConstraint } from './component_container_deployment_constraint'
34

45
/**
56
* Component Deployment Configuration model
@@ -22,6 +23,15 @@ export interface ComponentDeploymentConfiguration {
2223
*/
2324
namespace?: string
2425

26+
/**
27+
* Gets the constraints to apply.
28+
* @type {ComponentContainerDeploymentConstraint[]}
29+
* @memberof ComponentContainerDeploymentConfiguration
30+
* @optional
31+
* @remarks Maps to job.constraints.
32+
*/
33+
constraints?: ComponentContainerDeploymentConstraint[]
34+
2535
/**
2636
* The type of Nomad job.
2737
* @type {ComponentContainerDeploymentConfigurationType}
@@ -40,13 +50,13 @@ export interface ComponentDeploymentConfiguration {
4050
job?: string
4151

4252
/**
43-
* Optional Vault policies to attach to the Nomad job.
53+
* Optional Vault role to attach to the Nomad job.
4454
* @type {string[]}
4555
* @memberof ComponentDeploymentConfiguration
4656
* @optional
47-
* @remarks If not provided, no policies will be attached.
57+
* @remarks If not provided, no role will be attached.
4858
*/
49-
vault_policies?: string[]
59+
vault_role?: string
5060

5161
/**
5262
* Any metadata to attach to the Nomad job.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Component Constraint Deployment Config Operator Type
3+
* @remarks Maps to the Nomad constraint operators.
4+
* @see https://www.nomadproject.io/docs/job-specification/constraint
5+
*/
6+
export type ComponentConstraintDeploymentConfigOperatorType =
7+
| '='
8+
| '!='
9+
| '>'
10+
| '<'
11+
| '>='
12+
| '<='
13+
| 'distinct_hosts'
14+
| 'distinct_property'
15+
| 'regexp'
16+
| 'set_contains'
17+
| 'set_contains_any'
18+
| 'version'
19+
| 'semver'
20+
| 'is_set'
21+
| 'is_not_set'

src/nomad/nomad_job.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,32 @@ export function generateNomadJob(
2424
jobText += ` namespace = "${configuration.namespace}"\n\n`
2525
}
2626

27-
if (configuration.vault_policies !== undefined) {
27+
if (configuration.vault_role !== undefined) {
2828
jobText += ' vault {\n'
29-
jobText += ` policies = ${JSON.stringify(configuration.vault_policies)}\n`
29+
jobText += ` role = "${configuration.vault_role}"\n`
3030
jobText += ' }\n\n'
3131
}
3232

33+
if (configuration.count !== undefined) {
34+
jobText += ` update {\n max_parallel = ${configuration.count}\n }\n\n`
35+
}
36+
37+
if (
38+
configuration.constraints !== undefined &&
39+
configuration.constraints.length > 0
40+
) {
41+
for (const constraint of configuration.constraints) {
42+
jobText += ' constraint {\n'
43+
jobText += ` attribute = "${constraint.attribute}"\n`
44+
jobText += ` operator = "${constraint.operator}"\n`
45+
46+
if (constraint.value !== undefined) {
47+
jobText += ` value = "${constraint.value}"\n`
48+
}
49+
jobText += ' }\n\n'
50+
}
51+
}
52+
3353
if (configuration.meta !== undefined && configuration.meta.size > 0) {
3454
jobText += ' meta {\n'
3555

0 commit comments

Comments
 (0)