@flowfuse/driver-kubernetes 2.21.2 → 2.21.3-5d8b661-202509241539.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/.github/workflows/release-publish.yml +1 -1
- package/kubernetes.js +32 -23
- package/package.json +1 -1
|
@@ -13,6 +13,6 @@ jobs:
|
|
|
13
13
|
with:
|
|
14
14
|
node-version: 18
|
|
15
15
|
- run: npm ci
|
|
16
|
-
- uses: JS-DevTools/npm-publish@
|
|
16
|
+
- uses: JS-DevTools/npm-publish@ad693561f8a5b5d4c76f14407da60aa15cb10f90 # v4.0.1
|
|
17
17
|
with:
|
|
18
18
|
token: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
package/kubernetes.js
CHANGED
|
@@ -521,7 +521,8 @@ const getStaticFileUrl = async (instance, filePath) => {
|
|
|
521
521
|
}
|
|
522
522
|
|
|
523
523
|
const createMQTTTopicAgent = async (broker) => {
|
|
524
|
-
|
|
524
|
+
const agent = broker.constructor.name === 'TeamBrokerAgent'
|
|
525
|
+
this._app.log.info(`[k8s] Starting MQTT Schema agent ${agent ? 'team-broker' : broker.hashid} for ${broker.Team.hashid}`)
|
|
525
526
|
const localPod = JSON.parse(JSON.stringify(mqttSchemaAgentPodTemplate))
|
|
526
527
|
const localService = JSON.parse(JSON.stringify(mqttSchemaAgentServiceTemplate))
|
|
527
528
|
|
|
@@ -530,25 +531,29 @@ const createMQTTTopicAgent = async (broker) => {
|
|
|
530
531
|
const { token } = await broker.refreshAuthTokens()
|
|
531
532
|
localPod.spec.containers[0].env.push({ name: 'FORGE_TEAM_TOKEN', value: token })
|
|
532
533
|
localPod.spec.containers[0].env.push({ name: 'FORGE_URL', value: this._app.config.api_url })
|
|
533
|
-
localPod.spec.containers[0].env.push({ name: 'FORGE_BROKER_ID', value: broker.hashid })
|
|
534
|
+
localPod.spec.containers[0].env.push({ name: 'FORGE_BROKER_ID', value: agent ? 'team-broker' : broker.hashid })
|
|
534
535
|
localPod.spec.containers[0].env.push({ name: 'FORGE_TEAM_ID', value: broker.Team.hashid })
|
|
536
|
+
if (agent) {
|
|
537
|
+
// env vars must be strings not numbers
|
|
538
|
+
localPod.spec.containers[0].env.push({ name: 'FORGE_TIMEOUT', value: '24' })
|
|
539
|
+
}
|
|
535
540
|
|
|
536
541
|
if (this._app.config.driver.options.projectSelector) {
|
|
537
542
|
localPod.spec.nodeSelector = this._app.config.driver.options.projectSelector
|
|
538
543
|
}
|
|
539
544
|
|
|
540
|
-
localPod.metadata.name = `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${broker.hashid.toLowerCase()}`
|
|
545
|
+
localPod.metadata.name = `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${agent ? 'team-broker' : broker.hashid.toLowerCase()}`
|
|
541
546
|
localPod.metadata.labels = {
|
|
542
547
|
name: `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${broker.hashid.toLowerCase()}`,
|
|
543
548
|
team: broker.Team.hashid,
|
|
544
|
-
broker: broker.hashid
|
|
549
|
+
broker: agent ? 'team-broker' : broker.hashid
|
|
545
550
|
}
|
|
546
|
-
localService.metadata.name = `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${broker.hashid.toLowerCase()}`
|
|
551
|
+
localService.metadata.name = `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${agent ? 'team-broker' : broker.hashid.toLowerCase()}`
|
|
547
552
|
localService.metadata.labels = {
|
|
548
553
|
team: broker.Team.hashid,
|
|
549
|
-
broker: broker.hashid
|
|
554
|
+
broker: agent ? 'team-broker' : broker.hashid
|
|
550
555
|
}
|
|
551
|
-
localService.spec.selector.name = `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${broker.hashid.toLowerCase()}`
|
|
556
|
+
localService.spec.selector.name = `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${agent ? 'team-broker' : broker.hashid.toLowerCase()}`
|
|
552
557
|
|
|
553
558
|
// TODO remove registry entry
|
|
554
559
|
localPod.spec.containers[0].image = this._app.config.driver.options?.mqttSchemaContainer || `${this._app.config.driver.options.registry ? this._app.config.driver.options.registry + '/' : ''}flowfuse/mqtt-schema-agent`
|
|
@@ -560,7 +565,7 @@ const createMQTTTopicAgent = async (broker) => {
|
|
|
560
565
|
await this._k8sApi.createNamespacedPod({ namespace, body: localPod })
|
|
561
566
|
await this._k8sApi.createNamespacedService({ namespace, body: localService })
|
|
562
567
|
} catch (err) {
|
|
563
|
-
this._app.log.error(`[k8s] Problem creating MQTT Agent ${broker.hashid} in ${namespace} - ${err.toString()} ${err.stack}`)
|
|
568
|
+
this._app.log.error(`[k8s] Problem creating MQTT Agent ${agent ? 'team-broker' : broker.hashid} in ${namespace} - ${err.toString()} ${err.stack}`)
|
|
564
569
|
}
|
|
565
570
|
}
|
|
566
571
|
|
|
@@ -699,15 +704,16 @@ module.exports = {
|
|
|
699
704
|
|
|
700
705
|
// Check restarting MQTT-Schema-Agent
|
|
701
706
|
brokers.forEach(async (broker) => {
|
|
707
|
+
const agent = broker.constructor.name === 'TeamBrokerAgent'
|
|
702
708
|
if (broker.Team && broker.state === 'running') {
|
|
703
709
|
try {
|
|
704
|
-
this._app.log.info(`[k8s] Testing MQTT Agent ${broker.hashid} in ${namespace} pod exists`)
|
|
705
|
-
this._app.log.debug(`mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${broker.hashid.toLowerCase()}`)
|
|
706
|
-
await this._k8sApi.readNamespacedPodStatus({ name: `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${broker.hashid.toLowerCase()}`, namespace })
|
|
707
|
-
this._app.log.info(`[k8s] MQTT Agent pod ${broker.hashid} in ${namespace} found`)
|
|
710
|
+
this._app.log.info(`[k8s] Testing MQTT Agent ${agent ? 'team-broker' : broker.hashid} in ${namespace} pod exists`)
|
|
711
|
+
this._app.log.debug(`mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${agent ? 'team-broker' : broker.hashid.toLowerCase()}`)
|
|
712
|
+
await this._k8sApi.readNamespacedPodStatus({ name: `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${agent ? 'team-broker' : broker.hashid.toLowerCase()}`, namespace })
|
|
713
|
+
this._app.log.info(`[k8s] MQTT Agent pod ${agent ? 'team-broker' : broker.hashid} in ${namespace} found`)
|
|
708
714
|
} catch (err) {
|
|
709
|
-
this._app.log.debug(`[k8s] MQTT Agent ${broker.hashid} - failed ${err.toString()}`)
|
|
710
|
-
this._app.log.debug(`[k8s] MQTT Agent ${broker.hashid} - recreating pod`)
|
|
715
|
+
this._app.log.debug(`[k8s] MQTT Agent ${agent ? 'team-broker' : broker.hashid} - failed ${err.toString()}`)
|
|
716
|
+
this._app.log.debug(`[k8s] MQTT Agent ${agent ? 'team-broker' : broker.hashid} - recreating pod`)
|
|
711
717
|
await createMQTTTopicAgent(broker)
|
|
712
718
|
}
|
|
713
719
|
}
|
|
@@ -1142,7 +1148,7 @@ module.exports = {
|
|
|
1142
1148
|
const addresses = await getEndpoints(project)
|
|
1143
1149
|
const logRequests = []
|
|
1144
1150
|
for (const address in addresses) {
|
|
1145
|
-
logRequests.push(got.get(`http://${addresses[address]}:2880/flowforge/logs`, { timeout: { request:
|
|
1151
|
+
logRequests.push(got.get(`http://${addresses[address]}:2880/flowforge/logs`, { timeout: { request: 2000 } }).json())
|
|
1146
1152
|
}
|
|
1147
1153
|
const results = await Promise.all(logRequests)
|
|
1148
1154
|
const combinedResults = results.flat(1)
|
|
@@ -1150,7 +1156,7 @@ module.exports = {
|
|
|
1150
1156
|
return combinedResults
|
|
1151
1157
|
} else {
|
|
1152
1158
|
const prefix = project.safeName.match(/^[0-9]/) ? 'srv-' : ''
|
|
1153
|
-
const result = await got.get(`http://${prefix}${project.safeName}.${this._namespace}:2880/flowforge/logs`, { timeout: { request:
|
|
1159
|
+
const result = await got.get(`http://${prefix}${project.safeName}.${this._namespace}:2880/flowforge/logs`, { timeout: { request: 2000 } }).json()
|
|
1154
1160
|
return result
|
|
1155
1161
|
}
|
|
1156
1162
|
},
|
|
@@ -1280,31 +1286,34 @@ module.exports = {
|
|
|
1280
1286
|
createMQTTTopicAgent(broker)
|
|
1281
1287
|
},
|
|
1282
1288
|
stopBrokerAgent: async (broker) => {
|
|
1289
|
+
const agent = broker.constructor.name === 'TeamBrokerAgent'
|
|
1283
1290
|
try {
|
|
1284
|
-
await this._k8sApi.deleteNamespacedService({ name: `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${broker.hashid.toLowerCase()}`, namespace: this._namespace })
|
|
1285
|
-
await this._k8sApi.deleteNamespacedPod({ name: `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${broker.hashid.toLowerCase()}`, namespace: this._namespace })
|
|
1291
|
+
await this._k8sApi.deleteNamespacedService({ name: `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${agent ? 'team-broker' : broker.hashid.toLowerCase()}`, namespace: this._namespace })
|
|
1292
|
+
await this._k8sApi.deleteNamespacedPod({ name: `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${agent ? 'team-broker' : broker.hashid.toLowerCase()}`, namespace: this._namespace })
|
|
1286
1293
|
} catch (err) {
|
|
1287
|
-
this._app.log.error(`[k8s] Error deleting MQTT Agent ${broker.hashid}: ${err.toString()} ${err.code}`)
|
|
1294
|
+
this._app.log.error(`[k8s] Error deleting MQTT Agent ${agent ? 'team-broker' : broker.hashid}: ${err.toString()} ${err.code}`)
|
|
1288
1295
|
}
|
|
1289
1296
|
},
|
|
1290
1297
|
getBrokerAgentState: async (broker) => {
|
|
1298
|
+
const agent = broker.constructor.name === 'TeamBrokerAgent'
|
|
1291
1299
|
try {
|
|
1292
|
-
const status = await got.get(`http://mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${broker.hashid.toLowerCase()}.${this._namespace}:3500/api/v1/status`, { timeout: { request: 1000 } }).json()
|
|
1300
|
+
const status = await got.get(`http://mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${agent ? 'team-broker' : broker.hashid.toLowerCase()}.${this._namespace}:3500/api/v1/status`, { timeout: { request: 1000 } }).json()
|
|
1293
1301
|
return status
|
|
1294
1302
|
} catch (err) {
|
|
1295
1303
|
return { error: 'error_getting_status', message: err.toString() }
|
|
1296
1304
|
}
|
|
1297
1305
|
},
|
|
1298
1306
|
sendBrokerAgentCommand: async (broker, command) => {
|
|
1307
|
+
const agent = broker.constructor.name === 'TeamBrokerAgent'
|
|
1299
1308
|
if (command === 'start' || command === 'restart') {
|
|
1300
1309
|
try {
|
|
1301
|
-
await got.post(`http://mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${broker.hashid.toLowerCase()}.${this._namespace}:3500/api/v1/commands/start`, { timeout: { request: 1000 } })
|
|
1310
|
+
await got.post(`http://mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${agent ? 'team-broker' : broker.hashid.toLowerCase()}.${this._namespace}:3500/api/v1/commands/start`, { timeout: { request: 1000 } })
|
|
1302
1311
|
} catch (err) {
|
|
1303
1312
|
|
|
1304
1313
|
}
|
|
1305
1314
|
} else if (command === 'stop') {
|
|
1306
1315
|
try {
|
|
1307
|
-
await got.post(`http://mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${broker.hashid.toLowerCase()}.${this._namespace}:3500/api/v1/commands/stop`, { timeout: { request: 1000 } })
|
|
1316
|
+
await got.post(`http://mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${agent ? 'team-broker' : broker.hashid.toLowerCase()}.${this._namespace}:3500/api/v1/commands/stop`, { timeout: { request: 1000 } })
|
|
1308
1317
|
} catch (err) {
|
|
1309
1318
|
|
|
1310
1319
|
}
|
|
@@ -1333,7 +1342,7 @@ module.exports = {
|
|
|
1333
1342
|
}
|
|
1334
1343
|
} else {
|
|
1335
1344
|
const prefix = project.safeName.match(/^[0-9]/) ? 'srv-' : ''
|
|
1336
|
-
const result = await got.get(`http://${prefix}${project.safeName}.${this._namespace}:2880/flowforge/resources`, { timeout: { request:
|
|
1345
|
+
const result = await got.get(`http://${prefix}${project.safeName}.${this._namespace}:2880/flowforge/resources`, { timeout: { request: 2000 } }).json()
|
|
1337
1346
|
if (Array.isArray(result)) {
|
|
1338
1347
|
return {
|
|
1339
1348
|
meta: {},
|