Skip to content

Commit

Permalink
chore: Make server:update command more informative (#827)
Browse files Browse the repository at this point in the history
* Make server:update command more informative

Signed-off-by: Anatolii Bazko <abazko@redhat.com>
  • Loading branch information
tolusha committed Aug 28, 2020
1 parent 90f4700 commit 3ba7a8c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
44 changes: 34 additions & 10 deletions src/commands/server/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import { InstallerTasks } from '../../tasks/installers/installer'
import { ApiTasks } from '../../tasks/platforms/api'
import { CommonPlatformTasks } from '../../tasks/platforms/common-platform-tasks'
import { PlatformTasks } from '../../tasks/platforms/platform'
import { isKubernetesPlatformFamily } from '../../util'
import { getImageTag, isKubernetesPlatformFamily } from '../../util'

export default class Update extends Command {
static description = 'update Eclipse Che server'
static description = 'Update Eclipse Che server.'

static flags = {
installer: string({
Expand Down Expand Up @@ -99,6 +99,7 @@ export default class Update extends Command {
ctx.highlightedMessages = [] as string[]

const cheTasks = new CheTasks(flags)
const kubeHelper = new KubeHelper(flags)
const platformTasks = new PlatformTasks()
const installerTasks = new InstallerTasks()
const apiTasks = new ApiTasks()
Expand Down Expand Up @@ -132,21 +133,44 @@ export default class Update extends Command {
await preInstallTasks.run(ctx)

if (!ctx.isCheDeployed) {
this.error('Eclipse Che deployment is not found. Use `chectl server:start` to initiate new deployment.')
this.error('Eclipse Che deployment is not found. Use `chectl server:start` to initiate a new deployment.')
} else {
if (isKubernetesPlatformFamily(flags.platform!)) {
await this.setDomainFlag(flags)
}
await platformCheckTasks.run(ctx)

await preUpdateTasks.run(ctx)

if (!flags['skip-version-check'] && flags.installer !== 'olm') {
await cli.anykey(` Found deployed Eclipse Che with operator [${ctx.deployedCheOperatorImage}]:${ctx.deployedCheOperatorTag}.
You are going to update it to [${ctx.newCheOperatorImage}]:${ctx.newCheOperatorTag}.
Note that Eclipse Che operator will update component images (server, plugin registry) only if their values
are not overridden in eclipse-che Custom Resource. So, you may need to remove them manually.
Press q to quit or any key to continue`)
if (!flags['skip-version-check'] && flags.installer === 'operator') {
cli.info(`Existed Eclipse Che operator: ${ctx.deployedCheOperatorImage}:${ctx.deployedCheOperatorTag}.`)
cli.info(`New Eclipse Che operator : ${ctx.newCheOperatorImage}:${ctx.newCheOperatorTag}.`)

if (flags['che-operator-image'] !== DEFAULT_CHE_OPERATOR_IMAGE) {
cli.warn(`This command updates Eclipse Che to ${getImageTag(DEFAULT_CHE_OPERATOR_IMAGE)} version, but custom operator image is specified.`)
cli.warn('Make sure that the new version of the Eclipse Che is corresponding to the version of the tool you use.')
cli.warn('Consider using \'chectl update [stable|next]\' to update to the latest version of chectl.')
}

const cheCluster = await kubeHelper.getCheCluster(flags.chenamespace)
if (cheCluster.spec.server.cheImage
|| cheCluster.spec.server.devfileRegistryImage
|| cheCluster.spec.database.postgresImage
|| cheCluster.spec.server.pluginRegistryImage
|| cheCluster.spec.auth.identityProviderImage) {
cli.warn(`Eclipse Che operator won't update some components since their images are defined
in the '${cheCluster.metadata.name}' Custom Resource of the namespace '${flags.chenamespace}'
Please consider removing them from the Custom Resource when update is completed:`)
cheCluster.spec.server.cheImage && cli.warn(`Eclipse Che server [${cheCluster.spec.server.cheImage}:${cheCluster.spec.server.cheImageTag}]`)
cheCluster.spec.database.postgresImage && cli.warn(`Database [${cheCluster.spec.database.postgresImage}]`)
cheCluster.spec.server.devfileRegistryImage && cli.warn(`Devfile registry [${cheCluster.spec.server.devfileRegistryImage}]`)
cheCluster.spec.server.pluginRegistryImage && cli.warn(`Plugin registry [${cheCluster.spec.server.pluginRegistryImage}]`)
cheCluster.spec.auth.identityProviderImage && cli.warn(`Identity provider [${cheCluster.spec.auth.identityProviderImage}]`)
}

const confirmed = await cli.confirm('If you want to continue - press Y')
if (!confirmed) {
this.exit(0)
}
}

await updateTasks.run(ctx)
Expand Down
17 changes: 16 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ export function base64Decode(arg: string): string {
*/
export function isStableVersion(flags: any): boolean {
const operatorImage = flags['che-operator-image'] || DEFAULT_CHE_OPERATOR_IMAGE
const cheVersion = operatorImage.split(':')[1]
const cheVersion = getImageTag(operatorImage)
return cheVersion !== 'nightly' && cheVersion !== 'latest'
}

/**
* Returns the tag of the image.
*/
export function getImageTag(image: string): string | undefined {
let entries = image.split('@')
if (entries.length === 2) {
// digest
return entries[1]
}

entries = image.split(':')
// tag
return entries[1]
}

0 comments on commit 3ba7a8c

Please sign in to comment.