Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First pass at file api for k8s #175

Merged
merged 6 commits into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions kubernetes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const got = require('got')
const FormData = require('form-data')
const k8s = require('@kubernetes/client-node')
const _ = require('lodash')
const awsEFS = require('./lib/aws-efs.js')
@@ -498,6 +499,11 @@ const getEndpoints = async (project) => {
}
}

const getStaticFileUrl = async (instance, filePath) => {
const prefix = instance.safeName.match(/^[0-9]/) ? 'srv-' : ''
return `http://${prefix}${instance.safeName}.${this._namespace}:2880/flowforge/files/_/${encodeURIComponent(filePath)}`
}

module.exports = {
/**
* Initialises this driver
@@ -1117,5 +1123,64 @@ module.exports = {
}

return properties
},

// Static Assets API
listFiles: async (instance, filePath) => {
const fileUrl = await getStaticFileUrl(instance, filePath)
console.log(fileUrl)
try {
return got.get(fileUrl).json()
} catch (err) {
console.log(err)
err.statusCode = err.response.statusCode
throw err
}
},

updateFile: async (instance, filePath, update) => {
const fileUrl = await getStaticFileUrl(instance, filePath)
try {
return got.put(fileUrl, {
json: update
})
} catch (err) {
err.statusCode = err.response.statusCode
throw err
}
},

deleteFile: async (instance, filePath) => {
const fileUrl = await getStaticFileUrl(instance, filePath)
try {
return got.delete(fileUrl)
} catch (err) {
err.statusCode = err.response.statusCode
throw err
}
},
createDirectory: async (instance, filePath, directoryName) => {
const fileUrl = await getStaticFileUrl(instance, filePath)
try {
return got.post(fileUrl, {
json: { path: directoryName }
})
} catch (err) {
err.statusCode = err.response.statusCode
throw err
}
},
uploadFile: async (instance, filePath, fileBuffer) => {
const form = new FormData()
form.append('file', fileBuffer, { filename: filePath })
const fileUrl = await getStaticFileUrl(instance, filePath)
try {
return got.post(fileUrl, {
body: form
})
} catch (err) {
err.statusCode = err.response.statusCode
throw err
}
}
}
44 changes: 35 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@
"dependencies": {
"@aws-sdk/client-efs": "^3.600.0",
"@kubernetes/client-node": "^0.18.1",
"form-data": "^4.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this package supported on Node versions < 18?

Because form-data is like 4y old, uses depreciated utils.isArray and FormData is now a part of Node 18.

https://developer.mozilla.org/en-US/docs/Web/API/FormData

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, we need to review this across all the static asset code, as Nick has used it in the localfs driver

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Steve-Mcl I'm going to leave this for now as it works

Copy link
Contributor

@Steve-Mcl Steve-Mcl Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, understand. Should probably raise an issue to mop this up later.

"got": "^11.8.0",
"lodash": "^4.17.21"
},