-
Notifications
You must be signed in to change notification settings - Fork 62
/
update.ts
154 lines (131 loc) · 5.4 KB
/
update.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*********************************************************************
* 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 { boolean, string } from '@oclif/parser/lib/flags'
import { cli } from 'cli-ux'
import * as fs from 'fs-extra'
import * as Listr from 'listr'
import * as notifier from 'node-notifier'
import * as path from 'path'
import { cheDeployment, cheNamespace, listrRenderer } from '../../common-flags'
import { DEFAULT_CHE_OPERATOR_IMAGE } from '../../constants'
import { CheTasks } from '../../tasks/che'
import { InstallerTasks } from '../../tasks/installers/installer'
import { K8sTasks } from '../../tasks/platforms/k8s'
import { PlatformTasks } from '../../tasks/platforms/platform'
export default class Update extends Command {
static description = 'update Eclipse Che Server'
static flags = {
installer: string({
char: 'a',
description: 'Installer type',
options: ['helm', 'operator', 'minishift-addon'],
default: ''
}),
platform: string({
char: 'p',
description: 'Type of Kubernetes platform. Valid values are \"minikube\", \"minishift\", \"k8s (for kubernetes)\", \"openshift\", \"crc (for CodeReady Containers)\", \"microk8s\".',
options: ['minikube', 'minishift', 'k8s', 'openshift', 'microk8s', 'docker-desktop', 'crc'],
}),
chenamespace: cheNamespace,
templates: string({
char: 't',
description: 'Path to the templates folder',
default: Update.getTemplatesDir(),
env: 'CHE_TEMPLATES_FOLDER'
}),
'che-operator-image': string({
description: 'Container image of the operator. This parameter is used only when the installer is the operator',
default: DEFAULT_CHE_OPERATOR_IMAGE
}),
'skip-version-check': boolean({
description: 'Skip user confirmation on version check',
default: false
}),
'deployment-name': cheDeployment,
'listr-renderer': listrRenderer,
help: flags.help({ char: 'h' }),
}
static getTemplatesDir(): string {
// return local templates folder if present
const TEMPLATES = 'templates'
const templatesDir = path.resolve(TEMPLATES)
const exists = fs.pathExistsSync(templatesDir)
if (exists) {
return TEMPLATES
}
// else use the location from modules
return path.join(__dirname, '../../../templates')
}
checkIfInstallerSupportUpdating(flags: any) {
// matrix checks
if (!flags.installer) {
this.error('🛑 --installer parameter must be specified.')
}
if (flags.installer === 'operator') {
// operator already supports updating
return
}
if (flags.installer === 'minishift-addon' || flags.installer === 'helm') {
this.error(`🛑 The specified installer ${flags.installer} does not support updating yet.`)
}
this.error(`🛑 Unknown installer ${flags.installer} is specified.`)
}
async run() {
const { flags } = this.parse(Update)
const listrOptions: Listr.ListrOptions = { renderer: (flags['listr-renderer'] as any), collapse: false } as Listr.ListrOptions
const cheTasks = new CheTasks(flags)
const platformTasks = new PlatformTasks()
const installerTasks = new InstallerTasks()
const k8sTasks = new K8sTasks()
// Platform Checks
let platformCheckTasks = new Listr(platformTasks.preflightCheckTasks(flags, this), listrOptions)
this.checkIfInstallerSupportUpdating(flags)
// Checks if Che is already deployed
let preInstallTasks = new Listr(undefined, listrOptions)
preInstallTasks.add(k8sTasks.testApiTasks(flags, this))
preInstallTasks.add({
title: '👀 Looking for an already existing Che instance',
task: () => new Listr(cheTasks.checkIfCheIsInstalledTasks(flags, this))
})
let preUpdateTasks = new Listr(installerTasks.preUpdateTasks(flags, this), listrOptions)
let updateTasks = new Listr(undefined, listrOptions)
updateTasks.add({
title: '↺ Updating...',
task: () => new Listr(installerTasks.updateTasks(flags, this))
})
try {
const ctx: any = {}
await preInstallTasks.run(ctx)
if (!ctx.isCheDeployed) {
this.error('Eclipse Che deployment is not found. Use `chectl server:start` to initiate new deployment.')
} else {
await platformCheckTasks.run(ctx)
await preUpdateTasks.run(ctx)
if (!flags['skip-version-check']) {
await cli.anykey(` Found deployed Che with operator [${ctx.deployedCheOperatorImage}]:${ctx.deployedCheOperatorTag}.
You are going to update it to [${ctx.newCheOperatorImage}]:${ctx.newCheOperatorTag}.
Note that che operator will update components images (che server, plugin registry) only if their values
are not overridden in eclipse-che Customer Resource. So, you may need to remove them manually.
Press q to quit or any key to continue`)
}
await updateTasks.run(ctx)
}
this.log('Command server:update has completed successfully.')
} catch (err) {
this.error(err)
}
notifier.notify({
title: 'chectl',
message: 'Command server:start has completed successfully.'
})
this.exit(0)
}
}