-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
add cluster icon migration code #673
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/renderer/components/+cluster-settings/components/cluster-icon-setting.tsx
Outdated
Show resolved
Hide resolved
*/ | ||
try { | ||
if (cluster.preferences.icon) { | ||
const fileData = fse.readFileSync(cluster.preferences.icon); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it was absolute path to icon, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, looking at https://github.com/lensapp/lens/blob/v3.5.0/src/main/cluster-manager.ts#L36
I don't know the exact problems that using |
Had some issues while testing this. Need to figure out is it user error or real issue. |
So, back to my issue. The error I got is the following:
So the icon stored in cluster store is in format of ...
/**
* migrate cluster icon
*/
try {
if (cluster.preferences.icon) {
const fileName = path.join((app || remote.app).getPath("userData"), cluster.preferences.icon.replace("store://", ""))
const fileData = fse.readFileSync(fileName);
const mimeType = mime.lookup(fileName)
if (!mimeType) {
throw "unknown icon file type, deleting...";
}
cluster.preferences.icon = `data:${mimeType};base64, ${fileData.toString('base64')}`;
... and that seem to work better. |
oh, noticed that images seem to be rendered fine without mimetype too, ie |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look the comment I've added.
@nevalla |
Okay, I see. Nevertheless, I had some issues with this line:
I did not see any errors in the logs but for some weird reason the default electron window opened. |
fair, let me take a look |
6e1c37e
to
cdc4d96
Compare
@nevalla changed to base master |
package.json
Outdated
@@ -184,6 +185,7 @@ | |||
"jsonpath": "^1.0.2", | |||
"lodash": "^4.17.15", | |||
"mac-ca": "^1.0.4", | |||
"make-synchronous": "^0.1.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because file-type
is async only but migrations have to be sync only
package.json
Outdated
@@ -184,6 +185,7 @@ | |||
"jsonpath": "^1.0.2", | |||
"lodash": "^4.17.15", | |||
"mac-ca": "^1.0.4", | |||
"make-synchronous": "https://github.com/Nokel81/make-synchronous#e366285001da13f4d5c028888a56b9baf83f9cff", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not from npm? Btw maybe we could support async
migration and avoid this to overcomplicating simple things?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was temporary because I had made some changes that had not yet been merged upstream to this package. A comparable fix has now been published, so I will change back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot support async migration because the library that we use doesn't support it at all
const AsyncFunction = Object.getPrototypeOf(async function () { return }).constructor; | ||
const getFileTypeFnString = `return require("file-type").fromBuffer(fileData)`; | ||
const getFileType = new AsyncFunction("fileData", getFileTypeFnString); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks crazy to my eyes.. What have you tried to achieve with this? Why evaluating JS-string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair, I am just going to say fair since this was annoying to get right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed for several things:
webpack
is used which mucks withrequire
andawait import
so we need someway to deal with that. There is__non_webpack_require__
but that only exists whenwebpack
is being used (which it is not during tests)- It cannot be just a normal eval since the type that
make-synchronous
uses isAsyncFunction
AsyncFunction
is not a global and I got that first line from mozilla's web docs.
const migratedClusters: ClusterModel[] = [] | ||
const storedClusters: ClusterModel[] = store.get("clusters"); | ||
const kubeConfigBase = path.join((app || remote.app).getPath("userData"), "kubeconfigs") | ||
const userDataPath = (app || remote.app).getPath("userData") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering is it even possible to stop using remote.app
in runtime at some point and still support it in migrations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dunno, I just wanted to call this once, since it is used in many places.
Signed-off-by: Sebastian Malton <smalton@mirantis.com>
Signed-off-by: Sebastian Malton <smalton@mirantis.com>
…-type package Signed-off-by: Sebastian Malton <smalton@mirantis.com>
Signed-off-by: Sebastian Malton <smalton@mirantis.com>
Signed-off-by: Sebastian Malton <smalton@mirantis.com>
Signed-off-by: Sebastian Malton <smalton@mirantis.com>
Signed-off-by: Sebastian Malton <smalton@mirantis.com>
Signed-off-by: Sebastian Malton <smalton@mirantis.com>
7cc0b2c
to
7629e69
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Migration seems to work now correctly
preferences: { | ||
terminalCWD: "/tmp" | ||
} | ||
}, | ||
}) | ||
}), | ||
"icon_path": testDataIcon, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does it work? testDataIcon
should be a Buffer
type?
@@ -6,6 +6,10 @@ import { ClusterStore } from "./cluster-store"; | |||
import { workspaceStore } from "./workspace-store"; | |||
import { saveConfigToAppFiles } from "./kube-helpers"; | |||
|
|||
const testDataIcon = fs.readFileSync("test-data/cluster-store-migration-icon.png") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove it or at least move to __mocks__
or src/migrations
folder?
This PR adds a migration to the cluster store so that icon that were previously stored on the file system are instead stored in their base64 encoding within the cluster store.