@toa.io/operations 1.0.0-alpha.54 → 1.0.0-alpha.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/operations",
3
- "version": "1.0.0-alpha.54",
3
+ "version": "1.0.0-alpha.56",
4
4
  "description": "Toa Deployment",
5
5
  "homepage": "https://toa.io",
6
6
  "author": {
@@ -22,17 +22,17 @@
22
22
  "access": "public"
23
23
  },
24
24
  "main": "src/index.js",
25
- "types": "types/index.d.ts",
25
+ "types": "types/index.ts",
26
26
  "scripts": {
27
27
  "test": "echo \"Error: run tests from root\" && exit 1"
28
28
  },
29
29
  "dependencies": {
30
- "@toa.io/filesystem": "1.0.0-alpha.54",
31
- "@toa.io/generic": "1.0.0-alpha.54",
32
- "@toa.io/norm": "1.0.0-alpha.54",
33
- "@toa.io/yaml": "1.0.0-alpha.54",
30
+ "@toa.io/filesystem": "1.0.0-alpha.56",
31
+ "@toa.io/generic": "1.0.0-alpha.56",
32
+ "@toa.io/norm": "1.0.0-alpha.56",
33
+ "@toa.io/yaml": "1.0.0-alpha.56",
34
34
  "execa": "5.1.1",
35
35
  "fs-extra": "11.1.1"
36
36
  },
37
- "gitHead": "6be27bc53f3f8b31d0ce140140eeb40ef1de9a7f"
37
+ "gitHead": "15ee832b26d9893fdbcf6bde1b081b5fddf8d6da"
38
38
  }
@@ -1,10 +1,12 @@
1
1
  'use strict'
2
2
 
3
3
  const { addVariables } = require('./variables')
4
+ const { addMounts } = require('./mounts')
4
5
 
5
- function compositions (compositions, variables) {
6
+ function compositions (compositions, dependency) {
6
7
  for (const composition of compositions) {
7
- addVariables(composition, variables)
8
+ addVariables(composition, dependency.variables)
9
+ addMounts(composition, dependency.mounts)
8
10
  }
9
11
  }
10
12
 
@@ -0,0 +1,24 @@
1
+ 'use strict'
2
+
3
+ function addMounts (composition, mounts) {
4
+ if (mounts === undefined)
5
+ return
6
+
7
+ const used = new Set()
8
+
9
+ for (const [key, mount] of Object.entries(mounts)) {
10
+ if (key !== 'global' && !composition.components?.includes(key))
11
+ continue
12
+
13
+ for (const { name, path, claim } of mount) {
14
+ if (used.has(name))
15
+ continue
16
+
17
+ composition.mounts ??= []
18
+ composition.mounts.push({ name, path, claim })
19
+ used.add(name)
20
+ }
21
+ }
22
+ }
23
+
24
+ exports.addMounts = addMounts
@@ -1,17 +1,18 @@
1
1
  'use strict'
2
2
 
3
- function addVariables (deployment, variables) {
3
+ function addVariables (composition, variables) {
4
4
  const used = new Set()
5
5
 
6
- deployment.variables ??= []
6
+ composition.variables ??= []
7
7
 
8
8
  for (const [key, set] of Object.entries(variables)) {
9
- if (key !== 'global' && !deployment.components?.includes(key)) continue
9
+ if (key !== 'global' && !composition.components?.includes(key))
10
+ continue
10
11
 
11
12
  for (const variable of set) {
12
13
  if (used.has(variable.name)) continue
13
14
 
14
- deployment.variables.push(variable)
15
+ composition.variables.push(variable)
15
16
  used.add(variable.name)
16
17
  }
17
18
  }
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const get = require('./.describe')
3
+ const desc = require('./.describe')
4
4
 
5
5
  const describe = (context, compositions, dependency) => {
6
6
  const { services } = dependency
@@ -17,11 +17,11 @@ const describe = (context, compositions, dependency) => {
17
17
  }
18
18
  )
19
19
 
20
- const components = get.components(compositions)
20
+ const components = desc.components(compositions)
21
21
  const credentials = context.registry?.credentials
22
22
 
23
- get.compositions(compositions, dependency.variables, context.environment)
24
- get.services(services, dependency.variables)
23
+ desc.compositions(compositions, dependency)
24
+ desc.services(services, dependency.variables)
25
25
 
26
26
  return {
27
27
  compositions,
@@ -13,14 +13,17 @@ const merge = (dependencies) => {
13
13
  /** @type {toa.deployment.dependency.Variables} */
14
14
  const variables = {}
15
15
 
16
+ const mounts = {}
17
+
16
18
  for (const dependency of dependencies) {
17
19
  if (dependency.references !== undefined) references.push(...dependency.references)
18
20
  if (dependency.services !== undefined) services.push(...dependency.services)
19
21
  if (dependency.proxies !== undefined) proxies.push(...dependency.proxies)
20
22
  if (dependency.variables !== undefined) append(variables, dependency.variables)
23
+ if (dependency.mounts !== undefined) append(mounts, dependency.mounts)
21
24
  }
22
25
 
23
- return { references, services, proxies, variables }
26
+ return { references, services, proxies, variables, mounts }
24
27
  }
25
28
 
26
29
  const append = (merged, variables) => {
@@ -25,9 +25,24 @@ spec:
25
25
  {{- include "env.var" . | indent 12 }}
26
26
  {{- end }}
27
27
  {{- end }}
28
+ {{- if .mounts }}
29
+ volumeMounts:
30
+ {{- range .mounts }}
31
+ - name: {{ .name }}
32
+ mountPath: {{ .path }}
33
+ {{- end }}
34
+ {{- end }}
28
35
  {{- if $.Values.credentials }}
29
36
  imagePullSecrets:
30
37
  - name: {{ $.Values.credentials }}
31
38
  {{- end }}
39
+ {{- if .mounts }}
40
+ volumes:
41
+ {{- range .mounts }}
42
+ - name: {{ .name }}
43
+ persistentVolumeClaim:
44
+ claimName: {{ .claim }}
45
+ {{- end }}
46
+ {{- end }}
32
47
  ---
33
48
  {{- end }}
@@ -3,6 +3,10 @@ compositions:
3
3
  - name: todos
4
4
  image: localhost:5000/composition-todos:0.0.0
5
5
  replicas: 2
6
+ mounts:
7
+ - name: mount-name
8
+ path: /storage
9
+ claim: storage-pvc
6
10
  components:
7
11
  - todos-tasks
8
12
  - todos-stats
@@ -18,7 +22,6 @@ compositions:
18
22
  replicas: 3
19
23
  components:
20
24
  - users-users
21
- # TODO: create component services only if sync binding is being used
22
25
  components:
23
26
  - todos-tasks
24
27
  - todos-stats
@@ -1,4 +1,4 @@
1
- export type Service = {
1
+ export interface Service {
2
2
  group: string
3
3
  name: string
4
4
  version: string
@@ -9,24 +9,26 @@ export type Service = {
9
9
  probe?: Probe
10
10
  }
11
11
 
12
- export type Variable = {
12
+ export interface Variable {
13
13
  name: string
14
14
  value?: string
15
15
  secret?: {
16
- name: string,
16
+ name: string
17
17
  key: string
18
18
  optional?: boolean
19
19
  }
20
20
  }
21
21
 
22
22
  export type Variables = Record<'global' | string, Variable[]>
23
+ export type Mounts = Record<'global' | string, Mount[]>
23
24
 
24
- export type Dependency = {
25
+ export interface Dependency {
25
26
  services?: Service[]
26
27
  variables?: Variables
28
+ mounts?: Mounts
27
29
  }
28
30
 
29
- type Ingress = {
31
+ interface Ingress {
30
32
  hosts: string[]
31
33
  class?: string
32
34
  annotations?: object
@@ -37,3 +39,9 @@ interface Probe {
37
39
  path: string
38
40
  delay?: number
39
41
  }
42
+
43
+ interface Mount {
44
+ name: string
45
+ path: string
46
+ claim: string
47
+ }
File without changes