@flowfuse/driver-kubernetes 3.0.2 → 3.0.3-11ec222-202609111420.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 CHANGED
@@ -89,7 +89,7 @@ const createDeployment = async (project, options) => {
89
89
  }
90
90
 
91
91
  localPod.metadata.labels.app = project.id
92
- localPod.metadata.labels.name = project.safeName
92
+ localPod.metadata.labels.name = project.safeName.slice(0, 63)
93
93
  localPod.spec.serviceAccount = process.env.EDITOR_SERVICE_ACCOUNT
94
94
 
95
95
  if (this._schedulerName) {
@@ -465,7 +465,7 @@ const createPersistentVolumeClaim = async (project, options) => {
465
465
  pvc.metadata.name = name
466
466
  pvc.metadata.labels = {
467
467
  'ff-project-id': project.id,
468
- 'ff-project-name': project.safeName
468
+ 'ff-project-name': project.safeName.slice(0, 63) // max label length is 64 chars
469
469
  }
470
470
  if (this._app.config.driver.options?.projectLabels) {
471
471
  pvc.metadata.labels = {
@@ -473,7 +473,7 @@ const createPersistentVolumeClaim = async (project, options) => {
473
473
  ...this._app.config.driver.options.projectLabels
474
474
  }
475
475
  }
476
- console.error(`PVC: ${JSON.stringify(pvc, null, 2)}`)
476
+ // console.error(`PVC: ${JSON.stringify(pvc, null, 2)}`)
477
477
  return pvc
478
478
  } else {
479
479
  throw err
@@ -495,7 +495,7 @@ const createProject = async (project, options) => {
495
495
  try {
496
496
  await this._k8sApi.createNamespacedPersistentVolumeClaim({ namespace, body: localPVC })
497
497
  } catch (err) {
498
- console.error(JSON.stringify(err))
498
+ // console.error(JSON.stringify(err))
499
499
  if (err.code === 409) {
500
500
  this._app.log.warn(`[k8s] PVC for instance ${project.id} already exists, proceeding...`)
501
501
  } else {
package/lib/aws-efs.js CHANGED
@@ -3,9 +3,52 @@ const retry = require('async-retry')
3
3
 
4
4
  let client
5
5
 
6
+ let inflight
7
+ let lastTime = 0
8
+ const cacheTime = 30 * 1000 // 30 seconds
9
+
6
10
  async function lookupStorageClass (tagName) {
7
11
  // console.log(`Looking for ${tagName}`)
8
12
 
13
+ let fileSystems
14
+ if (inflight && (Date.now() - lastTime) < cacheTime) {
15
+ // Share the in-flight lookup with any caller that arrives while it is still
16
+ // running. A burst of instance creations would otherwise each make their own
17
+ // set of AWS calls, which is what triggers the ThrottlingException in #401
18
+ fileSystems = await inflight
19
+ } else {
20
+ // Start the cache window now rather than on completion, so callers arriving
21
+ // during the lookup share it instead of kicking off a second one
22
+ lastTime = Date.now()
23
+ inflight = doLookupStorageClass(tagName)
24
+
25
+ try {
26
+ fileSystems = await inflight
27
+ } catch (err) {
28
+ // Don't cache a failure - let the next caller try again
29
+ inflight = undefined
30
+ lastTime = 0
31
+ throw err
32
+ }
33
+ }
34
+
35
+ if (fileSystems.length === 0) {
36
+ return undefined
37
+ }
38
+
39
+ // Account for the access point this caller is about to create. Without this a
40
+ // burst of instances served from one cached read would all land on whichever
41
+ // filesystem was least loaded when the counts were taken, rather than being
42
+ // spread across them. The count is an estimate - it assumes the caller goes on
43
+ // to create the access point - and is corrected by the next refresh
44
+ const selected = fileSystems[0]
45
+ selected.apCount++
46
+ fileSystems.sort((a, b) => a.apCount - b.apCount)
47
+
48
+ return selected.storageClass
49
+ }
50
+
51
+ async function doLookupStorageClass (tagName) {
9
52
  if (!client) {
10
53
  client = new EFSClient()
11
54
  }
@@ -75,7 +118,7 @@ async function lookupStorageClass (tagName) {
75
118
  }
76
119
  fileSystems.sort((a, b) => a.apCount - b.apCount)
77
120
 
78
- return fileSystems[0]?.storageClass
121
+ return fileSystems
79
122
  }
80
123
 
81
124
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowfuse/driver-kubernetes",
3
- "version": "3.0.2",
3
+ "version": "3.0.3-11ec222-202609111420.0",
4
4
  "description": "Kubernetes driver for FlowFuse",
5
5
  "main": "kubernetes.js",
6
6
  "scripts": {