-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Improve messages in server:update command #1022
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import { string } from '@oclif/parser/lib/flags' | |
import { cli } from 'cli-ux' | ||
import * as fs from 'fs-extra' | ||
import * as Listr from 'listr' | ||
import { merge } from 'lodash' | ||
import * as path from 'path' | ||
|
||
import { ChectlContext } from '../../api/context' | ||
|
@@ -23,11 +24,20 @@ import { getPrintHighlightedMessagesTask } from '../../tasks/installers/common-t | |
import { InstallerTasks } from '../../tasks/installers/installer' | ||
import { ApiTasks } from '../../tasks/platforms/api' | ||
import { CommonPlatformTasks } from '../../tasks/platforms/common-platform-tasks' | ||
import { getCommandErrorMessage, getCommandSuccessMessage, getImageTag, notifyCommandCompletedSuccessfully } from '../../util' | ||
import { getCommandErrorMessage, getCommandSuccessMessage, getCurrentChectlName, getCurrentChectlVersion, getImageTag, getLatestChectlVersion, notifyCommandCompletedSuccessfully } from '../../util' | ||
|
||
export default class Update extends Command { | ||
static description = 'Update Eclipse Che server.' | ||
|
||
static examples = [ | ||
'# Update Eclipse Che:\n' + | ||
'chectl server:update', | ||
'\n\n# Update Eclipse Che in \'eclipse-che\' namespace:' + | ||
'chectl server:update -n eclipse-che', | ||
'\n\n# Update Eclipse Che and update its configuration in the custom resource:' + | ||
`chectl server:update --${CHE_OPERATOR_CR_PATCH_YAML_KEY} patch.yaml`, | ||
] | ||
|
||
static flags: flags.Input<any> = { | ||
installer: string({ | ||
char: 'a', | ||
|
@@ -110,40 +120,116 @@ export default class Update extends Command { | |
|
||
try { | ||
await preUpdateTasks.run(ctx) | ||
} catch (err) { | ||
this.error(getCommandErrorMessage(err)) | ||
} | ||
|
||
if (!flags.yes) { | ||
cli.info(`Existed Eclipse Che operator: ${ctx.deployedCheOperatorImage}:${ctx.deployedCheOperatorTag}.`) | ||
cli.info(`New Eclipse Che operator : ${ctx.newCheOperatorImage}:${ctx.newCheOperatorTag}.`) | ||
if (flags.installer === 'operator') { | ||
const existedOperatorImage = `${ctx.deployedCheOperatorImage}:${ctx.deployedCheOperatorTag}` | ||
const newOperatorImage = `${ctx.newCheOperatorImage}:${ctx.newCheOperatorTag}` | ||
cli.info(`Existed Eclipse Che operator: ${existedOperatorImage}.`) | ||
cli.info(`New Eclipse Che operator : ${newOperatorImage}.`) | ||
|
||
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 defaultOperatorImageTag = getImageTag(DEFAULT_CHE_OPERATOR_IMAGE) | ||
const chectlChannel = defaultOperatorImageTag === 'nightly' ? 'next' : 'stable' | ||
const currentChectlVersion = getCurrentChectlVersion() | ||
const latestChectlVersion = await getLatestChectlVersion(chectlChannel) | ||
const chectlName = getCurrentChectlName() | ||
|
||
const cheCluster = await kubeHelper.getCheCluster(flags.chenamespace) | ||
if (cheCluster.spec.server.cheImage | ||
|| cheCluster.spec.server.cheImageTag | ||
|| cheCluster.spec.server.devfileRegistryImage | ||
|| cheCluster.spec.database.postgresImage | ||
|| cheCluster.spec.server.pluginRegistryImage | ||
|| cheCluster.spec.auth.identityProviderImage) { | ||
cli.warn(`In order to update Eclipse Che the images defined in the '${cheCluster.metadata.name}' | ||
Custom Resource of the namespace '${flags.chenamespace}' will be cleaned up:`) | ||
cheCluster.spec.server.cheImageTag && cli.warn(`Eclipse Che server image tag [${cheCluster.spec.server.cheImageTag}]`) | ||
cheCluster.spec.server.cheImage && cli.warn(`Eclipse Che server [${cheCluster.spec.server.cheImage}]`) | ||
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}]`) | ||
// the same version is already installed | ||
if (newOperatorImage === existedOperatorImage) { | ||
if (chectlName === 'chectl' && latestChectlVersion) { | ||
// suggest update chectl first | ||
if (currentChectlVersion !== latestChectlVersion) { | ||
cli.warn(`It is not possible to update Eclipse Che to a newer version | ||
using the current '${currentChectlVersion}' version of chectl. Please, update 'chectl' | ||
to a newer version '${latestChectlVersion}' with the command 'chectl update ${chectlChannel}' | ||
and then try again.`) | ||
} else if (!flags[CHE_OPERATOR_CR_PATCH_YAML_KEY]) { | ||
// same version, no patch then nothing to update | ||
cli.info('Eclipse Che is already up to date.') | ||
this.exit(0) | ||
} | ||
} else { | ||
// unknown project, no patch file then suggest to update | ||
if (!flags[CHE_OPERATOR_CR_PATCH_YAML_KEY]) { | ||
cli.warn(`It is not possible to update Eclipse Che to a newer version | ||
using the current '${currentChectlVersion}' version of '${getCurrentChectlName()}'. | ||
Please, update '${getCurrentChectlName()}' and then try again.`) | ||
this.exit(0) | ||
} | ||
} | ||
// custom operator image is used | ||
} else if (newOperatorImage !== DEFAULT_CHE_OPERATOR_IMAGE) { | ||
cli.warn(`Eclipse Che operator deployment will be updated with the provided image, | ||
but other Eclipse Che components will be updated to the ${defaultOperatorImageTag} version. | ||
Consider removing '--che-operator-image' to update Eclipse Che operator to the same version.`) | ||
} | ||
|
||
if (!flags.yes && !await cli.confirm('If you want to continue - press Y')) { | ||
cli.info('Update cancelled by user.') | ||
this.exit(0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be nice to print something into output, like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree |
||
} | ||
} | ||
|
||
const cheCluster = await kubeHelper.getCheCluster(flags.chenamespace) | ||
if (cheCluster.spec.server.cheImage | ||
|| cheCluster.spec.server.cheImageTag | ||
|| cheCluster.spec.server.devfileRegistryImage | ||
|| cheCluster.spec.database.postgresImage | ||
|| cheCluster.spec.server.pluginRegistryImage | ||
|| cheCluster.spec.auth.identityProviderImage) { | ||
let imagesListMsg = '' | ||
|
||
const crPatch = ctx[ChectlContext.CR_PATCH] || {} | ||
if (cheCluster.spec.server.pluginRegistryImage | ||
&& (!crPatch.spec || !crPatch.spec.server || !crPatch.spec.server.pluginRegistryImage)) { | ||
imagesListMsg += `\n - Plugin registry image: ${cheCluster.spec.server.pluginRegistryImage}` | ||
merge(crPatch, { spec: { server: { pluginRegistryImage: '' } } }) | ||
} | ||
|
||
const confirmed = await cli.confirm('If you want to continue - press Y') | ||
if (!confirmed) { | ||
if (cheCluster.spec.server.devfileRegistryImage | ||
&& (!crPatch.spec || !crPatch.spec.server || !crPatch.spec.server.devfileRegistryImage)) { | ||
imagesListMsg += `\n - Devfile registry image: ${cheCluster.spec.server.devfileRegistryImage}` | ||
merge(crPatch, { spec: { server: { devfileRegistryImage: '' } } }) | ||
} | ||
|
||
if (cheCluster.spec.server.postgresImage | ||
&& (!crPatch.spec || !crPatch.spec.database || !crPatch.spec.database.postgresImage)) { | ||
imagesListMsg += `\n - Postgres image: ${cheCluster.spec.database.postgresImage}` | ||
merge(crPatch, { spec: { database: { postgresImage: '' } } }) | ||
} | ||
|
||
if (cheCluster.spec.server.identityProviderImage | ||
&& (!crPatch.spec || !crPatch.spec.auth || !crPatch.spec.auth.identityProviderImage)) { | ||
imagesListMsg += `\n - Identity provider image: ${cheCluster.spec.auth.identityProviderImage}` | ||
merge(crPatch, { spec: { auth: { identityProviderImage: '' } } }) | ||
} | ||
|
||
if (cheCluster.spec.server.cheImage | ||
&& (!crPatch.spec || !crPatch.spec.server || !crPatch.spec.server.cheImage)) { | ||
imagesListMsg += `\n - Eclipse Che server image name: ${cheCluster.spec.server.cheImage}` | ||
merge(crPatch, { spec: { server: { cheImage: '' } } }) | ||
} | ||
|
||
if (cheCluster.spec.server.cheImageTag | ||
&& (!crPatch.spec || !crPatch.spec.server || !crPatch.spec.server.cheImageTag)) { | ||
imagesListMsg += `\n - Eclipse Che server image tag: ${cheCluster.spec.server.cheImageTag}` | ||
merge(crPatch, { spec: { server: { cheImageTag: '' } } }) | ||
} | ||
ctx[ChectlContext.CR_PATCH] = crPatch | ||
|
||
if (imagesListMsg) { | ||
cli.warn(`In order to update Eclipse Che to a newer version the fields defining the images in the '${cheCluster.metadata.name}' | ||
Custom Resource in the '${flags.chenamespace}' namespace will be cleaned up:${imagesListMsg}`) | ||
if (!flags.yes && !await cli.confirm('If you want to continue - press Y')) { | ||
cli.info('Update cancelled by user.') | ||
this.exit(0) | ||
mmorhun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
|
||
try { | ||
await updateTasks.run(ctx) | ||
await postUpdateTasks.run(ctx) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move into a function with args that returns the message? Then block below will not be duplicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is slightly different.