Skip to content

Commit 1083862

Browse files
committed
chore: addressing comments
Signed-off-by: Ivo Yankov <[email protected]>
1 parent 35cb512 commit 1083862

File tree

5 files changed

+121
-134
lines changed

5 files changed

+121
-134
lines changed

src/commands/context/flags.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
1717

1818
import * as flags from '../flags.js'
1919

20-
export const DEFAULT_FLAGS = {
21-
requiredFlags: [],
22-
requiredFlagsWithDisabledPrompt: [flags.namespace, flags.cacheDir, flags.releaseTag],
23-
optionalFlags: [flags.devMode]
24-
}
25-
2620
export const USE_FLAGS = {
2721
requiredFlags: [],
2822
requiredFlagsWithDisabledPrompt: [],

src/commands/context/tasks.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ export class ContextCommandTasks {
7979

8080
this.parent.getK8().getKubeConfig().setCurrentContext(contextName)
8181

82-
this.parent.logger.info(`currentDeploymentName: ${currentDeploymentName}`)
83-
this.parent.logger.info(`contextName: ${contextName}`)
84-
this.parent.logger.info(`clusterAliases: ${clusterAliases.join(' ')}`)
85-
this.parent.logger.info('Save LocalConfig file')
82+
this.parent.logger.info(`Save LocalConfig file: [currentDeploymentName: ${currentDeploymentName}, contextName: ${contextName}, clusterAliases: ${clusterAliases.join(' ')}]`)
8683
await this.parent.getLocalConfig().write()
8784
})
8885
}

src/commands/flags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ export const context: CommandFlag = {
752752
constName: 'contextName',
753753
name: 'context',
754754
definition: {
755-
describe: 'The kind context name to be used',
755+
describe: 'The Kubernetes context name to be used',
756756
defaultValue: '',
757757
type: 'string'
758758
}

src/core/k8.ts

Lines changed: 118 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ interface TDirectoryData {directory: boolean; owner: string; group: string; size
4545
*/
4646
export class K8 {
4747
static PodReadyCondition = new Map<string, string>()
48-
.set(constants.POD_CONDITION_READY, constants.POD_CONDITION_STATUS_TRUE)
48+
.set(constants.POD_CONDITION_READY, constants.POD_CONDITION_STATUS_TRUE)
4949
private kubeConfig!: k8s.KubeConfig
5050
kubeClient!: k8s.CoreV1Api
5151
private coordinationApiClient: k8s.CoordinationV1Api
@@ -76,7 +76,7 @@ export class K8 {
7676

7777
if (!this.kubeConfig.getCurrentContext()) {
7878
throw new SoloError('No active kubernetes context found. ' +
79-
'Please set current kubernetes context.')
79+
'Please set current kubernetes context.')
8080
}
8181

8282
if (!this.kubeConfig.getCurrentCluster()) {
@@ -238,12 +238,12 @@ export class K8 {
238238
const ns = this._getNamespace()
239239
const labelSelector = labels.join(',')
240240
const result = await this.kubeClient.listNamespacedSecret(
241-
ns,
242-
undefined,
243-
undefined,
244-
undefined,
245-
undefined,
246-
labelSelector
241+
ns,
242+
undefined,
243+
undefined,
244+
undefined,
245+
undefined,
246+
labelSelector
247247
)
248248

249249
return result.body.items
@@ -442,17 +442,17 @@ export class K8 {
442442
*/
443443
async hasDir (podName: string, containerName: string, destPath: string) {
444444
return await this.execContainer(
445-
podName,
446-
containerName,
447-
['bash', '-c', '[[ -d "' + destPath + '" ]] && echo -n "true" || echo -n "false"']
445+
podName,
446+
containerName,
447+
['bash', '-c', '[[ -d "' + destPath + '" ]] && echo -n "true" || echo -n "false"']
448448
) === 'true'
449449
}
450450

451451
mkdir (podName: PodName, containerName: string, destPath: string) {
452452
return this.execContainer(
453-
podName,
454-
containerName,
455-
['bash', '-c', 'mkdir -p "' + destPath + '"']
453+
podName,
454+
containerName,
455+
['bash', '-c', 'mkdir -p "' + destPath + '"']
456456
)
457457
}
458458

@@ -493,7 +493,7 @@ export class K8 {
493493
}
494494

495495
registerOutputPassthroughStreamOnData (localContext: LocalContextObject, messagePrefix: string,
496-
outputPassthroughStream: stream.PassThrough, outputFileStream: fs.WriteStream) {
496+
outputPassthroughStream: stream.PassThrough, outputFileStream: fs.WriteStream) {
497497
outputPassthroughStream.on('data', (chunk) => {
498498
this.logger.debug(`${messagePrefix} received chunk size=${chunk.length}`)
499499
const canWrite = outputFileStream.write(chunk) // Write chunk to file and check if buffer is full
@@ -505,7 +505,7 @@ export class K8 {
505505
}
506506

507507
registerOutputFileStreamOnDrain (localContext: LocalContextObject, messagePrefix: string,
508-
outputPassthroughStream: stream.PassThrough, outputFileStream: fs.WriteStream) {
508+
outputPassthroughStream: stream.PassThrough, outputFileStream: fs.WriteStream) {
509509
outputFileStream.on('drain', () => {
510510
outputPassthroughStream.resume()
511511
this.logger.debug(`${messagePrefix} stream drained, resume write`)
@@ -565,28 +565,28 @@ export class K8 {
565565
inputStream.pipe(inputPassthroughStream)
566566

567567
execInstance.exec(namespace, podName, containerName, command, null, errPassthroughStream, inputPassthroughStream, false,
568-
({ status }) => self.handleCallback(status, localContext, messagePrefix))
569-
.then(conn => {
570-
self.logger.info(`${messagePrefix} connection established`)
571-
localContext.connection = conn
568+
({ status }) => self.handleCallback(status, localContext, messagePrefix))
569+
.then(conn => {
570+
self.logger.info(`${messagePrefix} connection established`)
571+
localContext.connection = conn
572572

573-
self.registerConnectionOnError(localContext, messagePrefix, conn)
573+
self.registerConnectionOnError(localContext, messagePrefix, conn)
574574

575-
self.registerConnectionOnMessage(messagePrefix)
575+
self.registerConnectionOnMessage(messagePrefix)
576576

577-
conn.on('close', (code, reason) => {
578-
self.logger.debug(`${messagePrefix} connection closed`)
579-
if (code !== 1000) { // code 1000 is the success code
580-
return self.exitWithError(localContext, `${messagePrefix} failed with code=${code}, reason=${reason}`)
581-
}
577+
conn.on('close', (code, reason) => {
578+
self.logger.debug(`${messagePrefix} connection closed`)
579+
if (code !== 1000) { // code 1000 is the success code
580+
return self.exitWithError(localContext, `${messagePrefix} failed with code=${code}, reason=${reason}`)
581+
}
582582

583-
// Cleanup temp file after successful copy
584-
inputPassthroughStream.end() // End the passthrough stream
585-
self._deleteTempFile(tmpFile) // Cleanup temp file
586-
self.logger.info(`${messagePrefix} Successfully copied!`)
587-
return resolve(true)
588-
})
583+
// Cleanup temp file after successful copy
584+
inputPassthroughStream.end() // End the passthrough stream
585+
self._deleteTempFile(tmpFile) // Cleanup temp file
586+
self.logger.info(`${messagePrefix} Successfully copied!`)
587+
return resolve(true)
589588
})
589+
})
590590

591591
self.registerErrorStreamOnData(localContext, errPassthroughStream)
592592

@@ -666,59 +666,59 @@ export class K8 {
666666

667667
self.logger.debug(`${messagePrefix} running...`)
668668
execInstance.exec(
669-
namespace,
670-
podName,
671-
containerName,
672-
command,
673-
outputFileStream,
674-
errPassthroughStream,
675-
null,
676-
false,
677-
({ status }) => {
678-
if (status === 'Failure') {
679-
self._deleteTempFile(tmpFile)
680-
return self.exitWithError(localContext, `${messagePrefix} Failure occurred`)
681-
}
682-
self.logger.debug(`${messagePrefix} callback(status)=${status}`)
683-
684-
})
685-
.then(conn => {
686-
self.logger.debug(`${messagePrefix} connection established`)
687-
localContext.connection = conn
669+
namespace,
670+
podName,
671+
containerName,
672+
command,
673+
outputFileStream,
674+
errPassthroughStream,
675+
null,
676+
false,
677+
({ status }) => {
678+
if (status === 'Failure') {
679+
self._deleteTempFile(tmpFile)
680+
return self.exitWithError(localContext, `${messagePrefix} Failure occurred`)
681+
}
682+
self.logger.debug(`${messagePrefix} callback(status)=${status}`)
688683

689-
conn.on('error', (e) => {
690-
self._deleteTempFile(tmpFile)
691-
return self.exitWithError(localContext, `${messagePrefix} failed, connection error: ${e.message}`)
692-
})
684+
})
685+
.then(conn => {
686+
self.logger.debug(`${messagePrefix} connection established`)
687+
localContext.connection = conn
693688

694-
self.registerConnectionOnMessage(messagePrefix)
689+
conn.on('error', (e) => {
690+
self._deleteTempFile(tmpFile)
691+
return self.exitWithError(localContext, `${messagePrefix} failed, connection error: ${e.message}`)
692+
})
695693

696-
conn.on('close', (code, reason) => {
697-
self.logger.debug(`${messagePrefix} connection closed`)
698-
if (code !== 1000) { // code 1000 is the success code
699-
return self.exitWithError(localContext, `${messagePrefix} failed with code=${code}, reason=${reason}`)
700-
}
694+
self.registerConnectionOnMessage(messagePrefix)
701695

702-
outputFileStream.end()
703-
outputFileStream.close(() => {
704-
try {
705-
fs.copyFileSync(tmpFile, destPath)
696+
conn.on('close', (code, reason) => {
697+
self.logger.debug(`${messagePrefix} connection closed`)
698+
if (code !== 1000) { // code 1000 is the success code
699+
return self.exitWithError(localContext, `${messagePrefix} failed with code=${code}, reason=${reason}`)
700+
}
706701

707-
self._deleteTempFile(tmpFile)
702+
outputFileStream.end()
703+
outputFileStream.close(() => {
704+
try {
705+
fs.copyFileSync(tmpFile, destPath)
708706

709-
const stat = fs.statSync(destPath)
710-
if (stat && stat.size === srcFileSize) {
711-
self.logger.debug(`${messagePrefix} finished`)
712-
return resolve(true)
713-
}
707+
self._deleteTempFile(tmpFile)
714708

715-
return self.exitWithError(localContext, `${messagePrefix} files did not match, srcFileSize=${srcFileSize}, stat.size=${stat?.size}`)
716-
} catch (e: Error | any) {
717-
return self.exitWithError(localContext, `${messagePrefix} failed to complete download`)
709+
const stat = fs.statSync(destPath)
710+
if (stat && stat.size === srcFileSize) {
711+
self.logger.debug(`${messagePrefix} finished`)
712+
return resolve(true)
718713
}
719-
})
714+
715+
return self.exitWithError(localContext, `${messagePrefix} files did not match, srcFileSize=${srcFileSize}, stat.size=${stat?.size}`)
716+
} catch (e: Error | any) {
717+
return self.exitWithError(localContext, `${messagePrefix} failed to complete download`)
718+
}
720719
})
721720
})
721+
})
722722

723723
self.registerErrorStreamOnData(localContext, errPassthroughStream)
724724

@@ -771,39 +771,39 @@ export class K8 {
771771

772772
self.logger.debug(`${messagePrefix} running...`)
773773
execInstance.exec(
774-
namespace,
775-
podName,
776-
containerName,
777-
command,
778-
outputFileStream,
779-
errPassthroughStream,
780-
null,
781-
false,
782-
({ status }) => self.handleCallback(status, localContext, messagePrefix))
783-
.then(conn => {
784-
self.logger.debug(`${messagePrefix} connection established`)
785-
localContext.connection = conn
786-
787-
self.registerConnectionOnError(localContext, messagePrefix, conn)
788-
789-
self.registerConnectionOnMessage(messagePrefix)
790-
791-
conn.on('close', (code, reason) => {
792-
self.logger.debug(`${messagePrefix} connection closed`)
793-
if (!localContext.errorMessage) {
794-
if (code !== 1000) { // code 1000 is the success code
795-
return self.exitWithError(localContext, `${messagePrefix} failed with code=${code}, reason=${reason}`)
796-
}
797-
798-
outputFileStream.end()
799-
outputFileStream.close(() => {
800-
self.logger.debug(`${messagePrefix} finished`)
801-
const outData = fs.readFileSync(tmpFile)
802-
return resolve(outData.toString())
803-
})
774+
namespace,
775+
podName,
776+
containerName,
777+
command,
778+
outputFileStream,
779+
errPassthroughStream,
780+
null,
781+
false,
782+
({ status }) => self.handleCallback(status, localContext, messagePrefix))
783+
.then(conn => {
784+
self.logger.debug(`${messagePrefix} connection established`)
785+
localContext.connection = conn
786+
787+
self.registerConnectionOnError(localContext, messagePrefix, conn)
788+
789+
self.registerConnectionOnMessage(messagePrefix)
790+
791+
conn.on('close', (code, reason) => {
792+
self.logger.debug(`${messagePrefix} connection closed`)
793+
if (!localContext.errorMessage) {
794+
if (code !== 1000) { // code 1000 is the success code
795+
return self.exitWithError(localContext, `${messagePrefix} failed with code=${code}, reason=${reason}`)
804796
}
805-
})
797+
798+
outputFileStream.end()
799+
outputFileStream.close(() => {
800+
self.logger.debug(`${messagePrefix} finished`)
801+
const outData = fs.readFileSync(tmpFile)
802+
return resolve(outData.toString())
803+
})
804+
}
806805
})
806+
})
807807

808808
self.registerErrorStreamOnData(localContext, errPassthroughStream)
809809

@@ -1115,17 +1115,17 @@ export class K8 {
11151115
*/
11161116
async getSecret (namespace: string, labelSelector: string) {
11171117
const result = await this.kubeClient.listNamespacedSecret(
1118-
namespace,
1119-
undefined,
1120-
undefined,
1121-
undefined,
1122-
undefined,
1123-
labelSelector,
1124-
undefined,
1125-
undefined,
1126-
undefined,
1127-
undefined,
1128-
5 * MINUTES
1118+
namespace,
1119+
undefined,
1120+
undefined,
1121+
undefined,
1122+
undefined,
1123+
labelSelector,
1124+
undefined,
1125+
undefined,
1126+
undefined,
1127+
undefined,
1128+
5 * MINUTES
11291129
)
11301130

11311131
if (result.response.statusCode === 200 && result.body.items && result.body.items.length > 0) {

src/core/task.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,5 @@
1515
*
1616
*/
1717
export class Task {
18-
constructor (public title: string, public task: Function, public skip: Function | boolean = false) {
19-
this.title = title
20-
this.task = task
21-
this.skip = skip
22-
}
18+
constructor (public title: string, public task: Function, public skip: Function | boolean = false) { }
2319
}

0 commit comments

Comments
 (0)