proper ttl syntax on cache entries, begin work for purejs grpc server

Signed-off-by: Travis Glenn Hansen <travisghansen@yahoo.com>
This commit is contained in:
Travis Glenn Hansen 2022-03-03 22:14:48 -07:00
parent d2f8fa3f35
commit b723136f2a
7 changed files with 68 additions and 28 deletions

View File

@ -2,6 +2,7 @@
const yaml = require("js-yaml");
const fs = require("fs");
const { grpc } = require("../src/utils/grpc");
let options;
const args = require("yargs")
@ -78,8 +79,6 @@ if (!args.serverSocket && !args.serverAddress && !args.serverPort) {
const package = require("../package.json");
args.version = package.version;
//const grpc = require("grpc");
const grpc = require("grpc-uds");
const protoLoader = require("@grpc/proto-loader");
const LRU = require("lru-cache");
const cache = new LRU({ max: 500 });
@ -335,16 +334,6 @@ logger.info(
bindSocket
);
if (bindAddress) {
csiServer.bind(bindAddress, grpc.ServerCredentials.createInsecure());
}
if (bindSocket) {
csiServer.bind(bindSocket, grpc.ServerCredentials.createInsecure());
}
csiServer.start();
[`SIGINT`, `SIGUSR1`, `SIGUSR2`, `uncaughtException`, `SIGTERM`].forEach(
(eventType) => {
process.on(eventType, (code) => {
@ -359,3 +348,37 @@ csiServer.start();
});
}
);
if (require.main === module) {
(async function () {
try {
if (bindAddress) {
await new Promise((resolve, reject) => {
csiServer.bindAsync(
bindAddress,
grpc.ServerCredentials.createInsecure(),
() => {
resolve();
}
);
});
}
if (bindSocket) {
await new Promise((resolve, reject) => {
csiServer.bindAsync(
bindSocket,
grpc.ServerCredentials.createInsecure(),
() => {
resolve();
}
);
});
}
csiServer.start();
} catch (e) {
console.log(e);
process.exit(1);
}
})();
}

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "democratic-csi",
"version": "1.5.3",
"version": "1.5.5",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "democratic-csi",
"version": "1.5.4",
"version": "1.5.5",
"description": "kubernetes csi driver framework",
"main": "bin/democratic-csi",
"scripts": {

View File

@ -29,6 +29,8 @@ const VOLUME_CONTEXT_PROVISIONER_DRIVER_PROPERTY_NAME =
const VOLUME_CONTEXT_PROVISIONER_INSTANCE_ID_PROPERTY_NAME =
"democratic-csi:volume_context_provisioner_instance_id";
const MAX_ZVOL_NAME_LENGTH_CACHE_KEY = "controller-zfs:max_zvol_name_length";
/**
* Base driver to provisin zfs assets using zfs cli commands.
* Derived drivers only need to implement:
@ -413,6 +415,14 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
let kernel;
let kernel_release;
const cachedValue = await driver.ctx.cache.get(
MAX_ZVOL_NAME_LENGTH_CACHE_KEY
);
if (cachedValue) {
return cachedValue;
}
// get kernel
command = "uname -s";
driver.ctx.logger.verbose("uname command: %s", command);
@ -423,12 +433,14 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
kernel = response.stdout.trim();
}
let max;
switch (kernel.toLowerCase().trim()) {
// Linux is 255 (probably larger 4096) but scst may have a 255 limit
// https://ngelinux.com/what-is-the-maximum-file-name-length-in-linux-and-how-to-see-this-is-this-really-255-characters-answer-is-no/
// https://github.com/dmeister/scst/blob/master/iscsi-scst/include/iscsi_scst.h#L28
case "linux":
return 255;
max = 255;
break;
case "freebsd":
// get kernel_release
command = "uname -r";
@ -444,14 +456,20 @@ class ControllerZfsBaseDriver extends CsiBaseDriver {
let kernel_release_major = parts[0];
if (kernel_release_major >= 13) {
return 255;
max = 255;
} else {
return 63;
max = 63;
}
}
break;
default:
throw new Error(`unknown kernel: ${kernel}`);
}
await driver.ctx.cache.set(MAX_ZVOL_NAME_LENGTH_CACHE_KEY, max, {
ttl: 60 * 1000,
});
return max;
}
async setFilesystemMode(path, mode) {

View File

@ -208,11 +208,9 @@ class Api {
}
async setVersionInfoCache(versionInfo) {
await this.cache.set(
FREENAS_SYSTEM_VERSION_CACHE_KEY,
versionInfo,
60 * 1000
);
await this.cache.set(FREENAS_SYSTEM_VERSION_CACHE_KEY, versionInfo, {
ttl: 60 * 1000,
});
}
async getSystemVersion() {

View File

@ -2011,11 +2011,9 @@ class FreeNASSshDriver extends ControllerZfsBaseDriver {
async setVersionInfoCache(versionInfo) {
const driver = this;
await driver.ctx.cache.set(
FREENAS_SYSTEM_VERSION_CACHE_KEY,
versionInfo,
60 * 1000
);
await driver.ctx.cache.set(FREENAS_SYSTEM_VERSION_CACHE_KEY, versionInfo, {
ttl: 60 * 1000,
});
}
async getSystemVersion() {

View File

@ -7,4 +7,7 @@ class GrpcError {
}
module.exports.GrpcError = GrpcError;
module.exports.grpc = require("grpc-uds");
const grpcImplementation = process.env.GRPC_IMPLEMENTATION || "grpc-uds";
console.log(`grpc implementation: ${grpcImplementation}`);
module.exports.grpc = require(grpcImplementation);