logs: use context logger in client drivers

This commit is contained in:
Danil Uzlov 2025-03-24 21:42:05 +00:00
parent 2e29580a64
commit f897bf6133
1 changed files with 29 additions and 29 deletions

View File

@ -156,9 +156,9 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
return access_modes;
}
assertCapabilities(capabilities) {
assertCapabilities(capabilities, callContext) {
const driver = this;
this.ctx.logger.verbose("validating capabilities: %j", capabilities);
callContext.logger.verbose("validating capabilities: %j", capabilities);
let message = null;
let fs_types = driver.getFsTypes();
@ -548,7 +548,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
*
* @param {*} call
*/
async CreateVolume(call) {
async CreateVolume(call, callContext) {
const driver = this;
const config_key = driver.getConfigKey();
@ -560,7 +560,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
call.request.volume_capabilities &&
call.request.volume_capabilities.length > 0
) {
const result = this.assertCapabilities(call.request.volume_capabilities);
const result = this.assertCapabilities(call.request.volume_capabilities, callContext);
if (result.valid !== true) {
throw new GrpcError(grpc.status.INVALID_ARGUMENT, result.message);
}
@ -661,7 +661,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
);
}
driver.ctx.logger.debug(
callContext.logger.debug(
"controller volume source path: %s",
source_path
);
@ -740,7 +740,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
);
}
break;
// must be available when adverstising CLONE_VOLUME
// must be available when advertising CLONE_VOLUME
// create snapshot first, then clone
case "volume":
source_path = driver.getControllerVolumePath(
@ -754,7 +754,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
);
}
driver.ctx.logger.debug(
callContext.logger.debug(
"controller volume source path: %s",
source_path
);
@ -770,7 +770,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
// set mode
if (this.options[config_key].dirPermissionsMode) {
driver.ctx.logger.verbose(
callContext.logger.verbose(
"setting dir mode to: %s on dir: %s",
this.options[config_key].dirPermissionsMode,
volume_path
@ -783,14 +783,14 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
this.options[config_key].dirPermissionsUser ||
this.options[config_key].dirPermissionsGroup
) {
driver.ctx.logger.verbose(
callContext.logger.verbose(
"setting ownership to: %s:%s on dir: %s",
this.options[config_key].dirPermissionsUser,
this.options[config_key].dirPermissionsGroup,
volume_path
);
if (this.getNodeIsWindows()) {
driver.ctx.logger.warn("chown not implemented on windows");
callContext.logger.warn("chown not implemented on windows");
} else {
await driver.exec("chown", [
(this.options[config_key].dirPermissionsUser
@ -840,7 +840,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
*
* @param {*} call
*/
async DeleteVolume(call) {
async DeleteVolume(call, callContext) {
const driver = this;
const volume_id = call.request.volume_id;
@ -873,7 +873,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
*
* @param {*} call
*/
async ControllerExpandVolume(call) {
async ControllerExpandVolume(call, callContext) {
throw new GrpcError(
grpc.status.UNIMPLEMENTED,
`operation not supported by driver`
@ -885,7 +885,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
*
* @param {*} call
*/
async GetCapacity(call) {
async GetCapacity(call, callContext) {
const driver = this;
if (
@ -902,7 +902,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
}
if (call.request.volume_capabilities) {
const result = this.assertCapabilities(call.request.volume_capabilities);
const result = this.assertCapabilities(call.request.volume_capabilities, callContext);
if (result.valid !== true) {
return { available_capacity: 0 };
@ -925,7 +925,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
*
* @param {*} call
*/
async ListVolumes(call) {
async ListVolumes(call, callContext) {
throw new GrpcError(
grpc.status.UNIMPLEMENTED,
`operation not supported by driver`
@ -936,7 +936,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
*
* @param {*} call
*/
async ListSnapshots(call) {
async ListSnapshots(call, callContext) {
throw new GrpcError(
grpc.status.UNIMPLEMENTED,
`operation not supported by driver`
@ -963,7 +963,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
*
* @param {*} call
*/
async CreateSnapshot(call) {
async CreateSnapshot(call, callContext) {
const driver = this;
const config_key = driver.getConfigKey();
@ -1003,7 +1003,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
);
}
driver.ctx.logger.verbose("requested snapshot name: %s", name);
callContext.logger.verbose("requested snapshot name: %s", name);
let invalid_chars;
invalid_chars = name.match(/[^a-z0-9_\-:.+]+/gi);
@ -1020,7 +1020,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
// https://stackoverflow.com/questions/32106243/regex-to-remove-all-non-alpha-numeric-and-replace-spaces-with/32106277
name = name.replace(/[^a-z0-9_\-:.+]+/gi, "");
driver.ctx.logger.verbose("cleansed snapshot name: %s", name);
callContext.logger.verbose("cleansed snapshot name: %s", name);
const volume_path = driver.getControllerVolumePath(source_volume_id);
//const volume_path = "/home/thansen/beets/";
//const volume_path = "/var/lib/docker/";
@ -1044,11 +1044,11 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
await driver.cloneDir(volume_path, snapshot_path).finally(() => {
SNAPSHOTS_CUT_IN_FLIGHT.delete(name);
});
driver.ctx.logger.info(
callContext.logger.info(
`filecopy backup finished: snapshot_id=${snapshot_id}, path=${volume_path}`
);
} else {
driver.ctx.logger.debug(
callContext.logger.debug(
`filecopy backup already cut: ${snapshot_id}`
);
}
@ -1099,7 +1099,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
if (response.length > 0) {
snapshot_exists = true;
const snapshot = response[response.length - 1];
driver.ctx.logger.debug(
callContext.logger.debug(
`restic backup already cut: ${snapshot.id}`
);
const stats = await restic.stats([snapshot.id]);
@ -1136,7 +1136,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
return message.message_type == "summary";
});
snapshot_id = summary.snapshot_id;
driver.ctx.logger.info(
callContext.logger.info(
`restic backup finished: snapshot_id=${snapshot_id}, path=${volume_path}, total_duration=${
summary.total_duration | 0
}s`
@ -1194,7 +1194,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
);
}
snapshot_id = snapshot.id;
driver.ctx.logger.info(
callContext.logger.info(
`restic backup successfully applied additional tags: new_snapshot_id=${snapshot_id}, original_snapshot_id=${original_snapshot_id} path=${volume_path}`
);
}
@ -1233,7 +1233,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
if (response.length > 0) {
snapshot_exists = true;
const snapshot = response[response.length - 1];
driver.ctx.logger.debug(
callContext.logger.debug(
`kopia snapshot already cut: ${snapshot.id}`
);
@ -1262,7 +1262,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
1000;
size_bytes = response.rootEntry.summ.size;
driver.ctx.logger.info(
callContext.logger.info(
`kopia backup finished: snapshot_id=${snapshot_id}, path=${volume_path}, total_duration=${
total_duration | 0
}s`
@ -1305,7 +1305,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
*
* @param {*} call
*/
async DeleteSnapshot(call) {
async DeleteSnapshot(call, callContext) {
const driver = this;
let snapshot_id = call.request.snapshot_id;
@ -1393,7 +1393,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
*
* @param {*} call
*/
async ValidateVolumeCapabilities(call) {
async ValidateVolumeCapabilities(call, callContext) {
const driver = this;
const volume_id = call.request.volume_id;
@ -1414,7 +1414,7 @@ class ControllerClientCommonDriver extends CsiBaseDriver {
);
}
const result = this.assertCapabilities(call.request.volume_capabilities);
const result = this.assertCapabilities(call.request.volume_capabilities, callContext);
if (result.valid !== true) {
return { message: result.message };