forked from che-incubator/chectl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logs.ts
67 lines (58 loc) · 2.27 KB
/
logs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*********************************************************************
* Copyright (c) 2019 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
import { Command, flags } from '@oclif/command'
import { string } from '@oclif/parser/lib/flags'
import * as notifier from 'node-notifier'
import * as os from 'os'
import * as path from 'path'
import { CheHelper } from '../../api/che'
import { skipKubeHealthzCheck } from '../../common-flags'
export default class Logs extends Command {
static description = 'Collect workspace(s) logs'
static flags: flags.Input<any> = {
help: flags.help({ char: 'h' }),
workspace: string({
char: 'w',
description: 'Target workspace id. Can be found in workspace configuration \'id\' field.',
required: true
}),
namespace: string({
char: 'n',
description: 'The namespace where workspace is located. Can be found in workspace configuration \'attributes.infrastructureNamespace\' field.',
required: true
}),
directory: string({
char: 'd',
description: 'Directory to store logs into',
env: 'CHE_LOGS'
}),
'skip-kubernetes-health-check': skipKubeHealthzCheck
}
async run() {
const { flags } = this.parse(Logs)
const logsDirectory = path.resolve(flags.directory ? flags.directory : path.resolve(os.tmpdir(), 'chectl-logs', Date.now().toString()))
const cheHelper = new CheHelper(flags)
const workspaceRun = await cheHelper.readWorkspacePodLog(flags.namespace, flags.workspace, logsDirectory)
try {
this.log(`Eclipse Che logs will be available in '${logsDirectory}'`)
if (!workspaceRun) {
this.log(`Workspace ${flags.workspace} probably hasn't been started yet.`)
this.log('The program will keep running and collecting logs...')
this.log('Terminate the program when all logs are gathered...')
}
} catch (error) {
this.error(error)
}
notifier.notify({
title: 'chectl',
message: 'Command workspace:logs has completed successfully.'
})
}
}