@flowfuse/driver-kubernetes 2.21.2 → 2.21.3-9adc76e-202509220905.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 +31 -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,28 @@ 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
|
+
localPod.spec.containers[0].env.push({ name: 'FORGE_TIMEOUT', value: 24 })
|
|
538
|
+
}
|
|
535
539
|
|
|
536
540
|
if (this._app.config.driver.options.projectSelector) {
|
|
537
541
|
localPod.spec.nodeSelector = this._app.config.driver.options.projectSelector
|
|
538
542
|
}
|
|
539
543
|
|
|
540
|
-
localPod.metadata.name = `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${broker.hashid.toLowerCase()}`
|
|
544
|
+
localPod.metadata.name = `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${agent ? 'team-broker' : broker.hashid.toLowerCase()}`
|
|
541
545
|
localPod.metadata.labels = {
|
|
542
546
|
name: `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${broker.hashid.toLowerCase()}`,
|
|
543
547
|
team: broker.Team.hashid,
|
|
544
|
-
broker: broker.hashid
|
|
548
|
+
broker: agent ? 'team-broker' : broker.hashid
|
|
545
549
|
}
|
|
546
|
-
localService.metadata.name = `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${broker.hashid.toLowerCase()}`
|
|
550
|
+
localService.metadata.name = `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${agent ? 'team-broker' : broker.hashid.toLowerCase()}`
|
|
547
551
|
localService.metadata.labels = {
|
|
548
552
|
team: broker.Team.hashid,
|
|
549
|
-
broker: broker.hashid
|
|
553
|
+
broker: agent ? 'team-broker' : broker.hashid
|
|
550
554
|
}
|
|
551
|
-
localService.spec.selector.name = `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${broker.hashid.toLowerCase()}`
|
|
555
|
+
localService.spec.selector.name = `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${agent ? 'team-broker' : broker.hashid.toLowerCase()}`
|
|
552
556
|
|
|
553
557
|
// TODO remove registry entry
|
|
554
558
|
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 +564,7 @@ const createMQTTTopicAgent = async (broker) => {
|
|
|
560
564
|
await this._k8sApi.createNamespacedPod({ namespace, body: localPod })
|
|
561
565
|
await this._k8sApi.createNamespacedService({ namespace, body: localService })
|
|
562
566
|
} catch (err) {
|
|
563
|
-
this._app.log.error(`[k8s] Problem creating MQTT Agent ${broker.hashid} in ${namespace} - ${err.toString()} ${err.stack}`)
|
|
567
|
+
this._app.log.error(`[k8s] Problem creating MQTT Agent ${agent ? 'team-broker' : broker.hashid} in ${namespace} - ${err.toString()} ${err.stack}`)
|
|
564
568
|
}
|
|
565
569
|
}
|
|
566
570
|
|
|
@@ -699,15 +703,16 @@ module.exports = {
|
|
|
699
703
|
|
|
700
704
|
// Check restarting MQTT-Schema-Agent
|
|
701
705
|
brokers.forEach(async (broker) => {
|
|
706
|
+
const agent = broker.constructor.name === 'TeamBrokerAgent'
|
|
702
707
|
if (broker.Team && broker.state === 'running') {
|
|
703
708
|
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`)
|
|
709
|
+
this._app.log.info(`[k8s] Testing MQTT Agent ${agent ? 'team-broker' : broker.hashid} in ${namespace} pod exists`)
|
|
710
|
+
this._app.log.debug(`mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${agent ? 'team-broker' : broker.hashid.toLowerCase()}`)
|
|
711
|
+
await this._k8sApi.readNamespacedPodStatus({ name: `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${agent ? 'team-broker' : broker.hashid.toLowerCase()}`, namespace })
|
|
712
|
+
this._app.log.info(`[k8s] MQTT Agent pod ${agent ? 'team-broker' : broker.hashid} in ${namespace} found`)
|
|
708
713
|
} 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`)
|
|
714
|
+
this._app.log.debug(`[k8s] MQTT Agent ${agent ? 'team-broker' : broker.hashid} - failed ${err.toString()}`)
|
|
715
|
+
this._app.log.debug(`[k8s] MQTT Agent ${agent ? 'team-broker' : broker.hashid} - recreating pod`)
|
|
711
716
|
await createMQTTTopicAgent(broker)
|
|
712
717
|
}
|
|
713
718
|
}
|
|
@@ -1142,7 +1147,7 @@ module.exports = {
|
|
|
1142
1147
|
const addresses = await getEndpoints(project)
|
|
1143
1148
|
const logRequests = []
|
|
1144
1149
|
for (const address in addresses) {
|
|
1145
|
-
logRequests.push(got.get(`http://${addresses[address]}:2880/flowforge/logs`, { timeout: { request:
|
|
1150
|
+
logRequests.push(got.get(`http://${addresses[address]}:2880/flowforge/logs`, { timeout: { request: 2000 } }).json())
|
|
1146
1151
|
}
|
|
1147
1152
|
const results = await Promise.all(logRequests)
|
|
1148
1153
|
const combinedResults = results.flat(1)
|
|
@@ -1150,7 +1155,7 @@ module.exports = {
|
|
|
1150
1155
|
return combinedResults
|
|
1151
1156
|
} else {
|
|
1152
1157
|
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:
|
|
1158
|
+
const result = await got.get(`http://${prefix}${project.safeName}.${this._namespace}:2880/flowforge/logs`, { timeout: { request: 2000 } }).json()
|
|
1154
1159
|
return result
|
|
1155
1160
|
}
|
|
1156
1161
|
},
|
|
@@ -1280,31 +1285,34 @@ module.exports = {
|
|
|
1280
1285
|
createMQTTTopicAgent(broker)
|
|
1281
1286
|
},
|
|
1282
1287
|
stopBrokerAgent: async (broker) => {
|
|
1288
|
+
const agent = broker.constructor.name === 'TeamBrokerAgent'
|
|
1283
1289
|
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 })
|
|
1290
|
+
await this._k8sApi.deleteNamespacedService({ name: `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${agent ? 'team-broker' : broker.hashid.toLowerCase()}`, namespace: this._namespace })
|
|
1291
|
+
await this._k8sApi.deleteNamespacedPod({ name: `mqtt-schema-agent-${broker.Team.hashid.toLowerCase()}-${agent ? 'team-broker' : broker.hashid.toLowerCase()}`, namespace: this._namespace })
|
|
1286
1292
|
} catch (err) {
|
|
1287
|
-
this._app.log.error(`[k8s] Error deleting MQTT Agent ${broker.hashid}: ${err.toString()} ${err.code}`)
|
|
1293
|
+
this._app.log.error(`[k8s] Error deleting MQTT Agent ${agent ? 'team-broker' : broker.hashid}: ${err.toString()} ${err.code}`)
|
|
1288
1294
|
}
|
|
1289
1295
|
},
|
|
1290
1296
|
getBrokerAgentState: async (broker) => {
|
|
1297
|
+
const agent = broker.constructor.name === 'TeamBrokerAgent'
|
|
1291
1298
|
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()
|
|
1299
|
+
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
1300
|
return status
|
|
1294
1301
|
} catch (err) {
|
|
1295
1302
|
return { error: 'error_getting_status', message: err.toString() }
|
|
1296
1303
|
}
|
|
1297
1304
|
},
|
|
1298
1305
|
sendBrokerAgentCommand: async (broker, command) => {
|
|
1306
|
+
const agent = broker.constructor.name === 'TeamBrokerAgent'
|
|
1299
1307
|
if (command === 'start' || command === 'restart') {
|
|
1300
1308
|
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 } })
|
|
1309
|
+
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
1310
|
} catch (err) {
|
|
1303
1311
|
|
|
1304
1312
|
}
|
|
1305
1313
|
} else if (command === 'stop') {
|
|
1306
1314
|
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 } })
|
|
1315
|
+
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
1316
|
} catch (err) {
|
|
1309
1317
|
|
|
1310
1318
|
}
|
|
@@ -1333,7 +1341,7 @@ module.exports = {
|
|
|
1333
1341
|
}
|
|
1334
1342
|
} else {
|
|
1335
1343
|
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:
|
|
1344
|
+
const result = await got.get(`http://${prefix}${project.safeName}.${this._namespace}:2880/flowforge/resources`, { timeout: { request: 2000 } }).json()
|
|
1337
1345
|
if (Array.isArray(result)) {
|
|
1338
1346
|
return {
|
|
1339
1347
|
meta: {},
|