@flowfuse/driver-kubernetes 2.2.0 → 2.2.1-ed72f4f-202403271515.0
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/kubernetes.js +0 -122
- package/package.json +1 -1
package/kubernetes.js
CHANGED
|
@@ -14,59 +14,6 @@ const _ = require('lodash')
|
|
|
14
14
|
*
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
const podTemplate = {
|
|
18
|
-
apiVersion: 'v1',
|
|
19
|
-
kind: 'Pod',
|
|
20
|
-
metadata: {
|
|
21
|
-
// name: "k8s-client-test",
|
|
22
|
-
labels: {
|
|
23
|
-
// name: "k8s-client-test",
|
|
24
|
-
nodered: 'true'
|
|
25
|
-
// app: "k8s-client-test",
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
spec: {
|
|
29
|
-
securityContext: {
|
|
30
|
-
runAsUser: 1000,
|
|
31
|
-
runAsGroup: 1000,
|
|
32
|
-
fsGroup: 1000
|
|
33
|
-
},
|
|
34
|
-
containers: [
|
|
35
|
-
{
|
|
36
|
-
resources: {
|
|
37
|
-
request: {
|
|
38
|
-
// 10th of a core
|
|
39
|
-
cpu: '100m',
|
|
40
|
-
memory: '128Mi'
|
|
41
|
-
},
|
|
42
|
-
limits: {
|
|
43
|
-
cpu: '125m',
|
|
44
|
-
memory: '192Mi'
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
name: 'node-red',
|
|
48
|
-
// image: "docker-pi.local:5000/bronze-node-red",
|
|
49
|
-
imagePullPolicy: 'Always',
|
|
50
|
-
env: [
|
|
51
|
-
// {name: "APP_NAME", value: "test"},
|
|
52
|
-
{ name: 'TZ', value: 'Europe/London' }
|
|
53
|
-
],
|
|
54
|
-
ports: [
|
|
55
|
-
{ name: 'web', containerPort: 1880, protocol: 'TCP' }
|
|
56
|
-
],
|
|
57
|
-
securityContext: {
|
|
58
|
-
allowPrivilegeEscalation: false
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
]
|
|
62
|
-
// nodeSelector: {
|
|
63
|
-
// role: 'projects'
|
|
64
|
-
// }
|
|
65
|
-
|
|
66
|
-
},
|
|
67
|
-
enableServiceLinks: false
|
|
68
|
-
}
|
|
69
|
-
|
|
70
17
|
const deploymentTemplate = {
|
|
71
18
|
apiVersion: 'apps/v1',
|
|
72
19
|
kind: 'Deployment',
|
|
@@ -514,75 +461,6 @@ const createProject = async (project, options) => {
|
|
|
514
461
|
this._projects[project.id].state = 'starting'
|
|
515
462
|
}
|
|
516
463
|
|
|
517
|
-
// eslint-disable-next-line no-unused-vars
|
|
518
|
-
const createPod = async (project, options) => {
|
|
519
|
-
// const namespace = this._app.config.driver.options.projectNamespace || 'flowforge'
|
|
520
|
-
const stack = project.ProjectStack.properties
|
|
521
|
-
|
|
522
|
-
const localPod = JSON.parse(JSON.stringify(podTemplate))
|
|
523
|
-
localPod.metadata.name = project.safeName
|
|
524
|
-
localPod.metadata.labels.name = project.safeName
|
|
525
|
-
localPod.metadata.labels.app = project.id
|
|
526
|
-
if (stack.container) {
|
|
527
|
-
localPod.spec.containers[0].image = stack.container
|
|
528
|
-
} else {
|
|
529
|
-
localPod.spec.containers[0].image = `${this._options.registry}flowforge/node-red`
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
const baseURL = new URL(this._app.config.base_url)
|
|
533
|
-
const projectURL = `${baseURL.protocol}//${project.safeName}.${this._options.domain}`
|
|
534
|
-
const teamID = this._app.db.models.Team.encodeHashid(project.TeamId)
|
|
535
|
-
const authTokens = await project.refreshAuthTokens()
|
|
536
|
-
localPod.spec.containers[0].env.push({ name: 'FORGE_CLIENT_ID', value: authTokens.clientID })
|
|
537
|
-
localPod.spec.containers[0].env.push({ name: 'FORGE_CLIENT_SECRET', value: authTokens.clientSecret })
|
|
538
|
-
localPod.spec.containers[0].env.push({ name: 'FORGE_URL', value: this._app.config.api_url })
|
|
539
|
-
localPod.spec.containers[0].env.push({ name: 'BASE_URL', value: projectURL })
|
|
540
|
-
localPod.spec.containers[0].env.push({ name: 'FORGE_TEAM_ID', value: teamID })
|
|
541
|
-
localPod.spec.containers[0].env.push({ name: 'FORGE_PROJECT_ID', value: project.id })
|
|
542
|
-
localPod.spec.containers[0].env.push({ name: 'FORGE_PROJECT_TOKEN', value: authTokens.token })
|
|
543
|
-
// Inbound connections for k8s disabled by default
|
|
544
|
-
localPod.spec.containers[0].env.push({ name: 'FORGE_NR_NO_TCP_IN', value: 'true' }) // MVP. Future iteration could present this to YML or UI
|
|
545
|
-
localPod.spec.containers[0].env.push({ name: 'FORGE_NR_NO_UDP_IN', value: 'true' }) // MVP. Future iteration could present this to YML or UI
|
|
546
|
-
if (authTokens.broker) {
|
|
547
|
-
localPod.spec.containers[0].env.push({ name: 'FORGE_BROKER_URL', value: authTokens.broker.url })
|
|
548
|
-
localPod.spec.containers[0].env.push({ name: 'FORGE_BROKER_USERNAME', value: authTokens.broker.username })
|
|
549
|
-
localPod.spec.containers[0].env.push({ name: 'FORGE_BROKER_PASSWORD', value: authTokens.broker.password })
|
|
550
|
-
}
|
|
551
|
-
if (this._app.license.active()) {
|
|
552
|
-
localPod.spec.containers[0].env.push({ name: 'FORGE_LICENSE_TYPE', value: 'ee' })
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
const credentialSecret = await project.getSetting('credentialSecret')
|
|
556
|
-
if (credentialSecret) {
|
|
557
|
-
localPod.spec.containers[0].env.push({ name: 'FORGE_NR_SECRET', value: credentialSecret })
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
if (this._app.config.driver.options.projectSelector) {
|
|
561
|
-
localPod.spec.nodeSelector = this._app.config.driver.options.projectSelector
|
|
562
|
-
}
|
|
563
|
-
if (this._app.config.driver.options.registrySecrets) {
|
|
564
|
-
localPod.spec.imagePullSecrets = []
|
|
565
|
-
this._app.config.driver.options.registrySecrets.forEach(sec => {
|
|
566
|
-
const entry = {
|
|
567
|
-
name: sec
|
|
568
|
-
}
|
|
569
|
-
localPod.spec.imagePullSecrets.push(entry)
|
|
570
|
-
})
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
if (stack.memory && stack.cpu) {
|
|
574
|
-
localPod.spec.containers[0].resources.request.memory = `${stack.memory}Mi`
|
|
575
|
-
localPod.spec.containers[0].resources.limits.memory = `${stack.memory}Mi`
|
|
576
|
-
localPod.spec.containers[0].resources.request.cpu = `${stack.cpu * 10}m`
|
|
577
|
-
localPod.spec.containers[0].resources.limits.cpu = `${stack.cpu * 10}m`
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
project.url = projectURL
|
|
581
|
-
await project.save()
|
|
582
|
-
|
|
583
|
-
return localPod
|
|
584
|
-
}
|
|
585
|
-
|
|
586
464
|
const getEndpoints = async (project) => {
|
|
587
465
|
const prefix = project.safeName.match(/^[0-9]/) ? 'srv-' : ''
|
|
588
466
|
if (await project.getSetting('ha')) {
|