Skip to content

Commit

Permalink
chore: Drop --version flag (#2021)
Browse files Browse the repository at this point in the history
* chore: Drop --version flag

Signed-off-by: Anatolii Bazko <[email protected]>
  • Loading branch information
tolusha authored Feb 15, 2022
1 parent ca9e61a commit 5c2a73e
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 335 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/minikube-chectl-commands-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ jobs:
uses: che-incubator/setup-minikube-action@next
with:
minikube-version: v1.23.2
- name: Install chectl from the stable channel
run: bash <(curl -sL https://www.eclipse.org/che/chectl/) --channel=stable
- name: Install NodeJS
uses: actions/[email protected]
with:
Expand Down
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Issues are tracked on the main Eclipse Che Repository: https://github.com/eclips

<!-- toc -->
* [Installation](#installation)
* [Updating](#updating)
* [Usage](#usage)
* [Commands](#commands)
* [Contributing](#contributing)
Expand Down Expand Up @@ -53,15 +54,27 @@ $ bash <(curl -sL https://www.eclipse.org/che/chectl/)
$ bash <(curl -sL https://www.eclipse.org/che/chectl/) --channel=next
```

Assemblies of chectl are available at [https://github.com/che-incubator/chectl/releases](https://github.com/che-incubator/chectl/releases)

Manual install:

1) Download a .tgz file based on your Operating System / Arch
1) Download a .tgz file based on your Operating System / Arch from [https://github.com/che-incubator/chectl/releases](https://github.com/che-incubator/chectl/releases)
2) Unpack the assembly
3) Move `chectl` folder into a folder like `$HOME/chectl`
4) Add alias `alias chectl=$HOME/chectl/bin/run`

# Updating

1) Download a .tgz file based on your Operating System / Arch from [https://github.com/che-incubator/chectl/releases](https://github.com/che-incubator/chectl/releases)
2) Unpack the assembly into a local repository
```bash
CHECTL_VERSION=<DOWNLOADED_CHECTL_VERSION>
CHECTL_BINARIES=<DOWNLOADED_BINARIES_PATH>

CLIENT_DIR=${XDG_DATA_HOME:="$(cd && pwd)/.local/share"}/chectl/client/${CHECTL_VERSION}
mkdir ${CLIENT_DIR} -p
tar -xzf ${CHECTL_BINARIES} -C ${CLIENT_DIR} --strip-components=1
```
3) Update `chectl` from the local repository `chectl update --from-local` by prompting the downloaded version

# Usage
```sh-session
$ chectl server:start
Expand Down Expand Up @@ -269,9 +282,6 @@ OPTIONS
-t, --templates=templates
Path to the templates folder
-v, --version=version
Version to deploy (e.g. 7.15.2). Defaults to the same as chectl.
--[no-]auto-update
Auto update approval strategy for installation Eclipse Che.
With this strategy will be provided auto-update Eclipse Che without any human interaction.
Expand Down Expand Up @@ -487,9 +497,6 @@ OPTIONS
-n, --chenamespace=chenamespace Eclipse Che Kubernetes namespace. Default to 'eclipse-che'
-t, --templates=templates Path to the templates folder
-v, --version=version Version to deploy (e.g. 7.15.2). Defaults to the same as
chectl.
-y, --yes Automatic yes to prompts; assume "yes" as answer to all
prompts and run non-interactively
Expand Down
4 changes: 2 additions & 2 deletions src/api/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ export namespace VersionHelper {
/**
* Indicates if stable version of Eclipse Che is specified or meant implicitly.
*/
export function isDeployingStableVersion(flags: any): boolean {
return Boolean(flags.version) || !ChectlContext.get().isDevVersion
export function isDeployingStableVersion(_flags: any): boolean {
return !ChectlContext.get().isDevVersion
}

/**
Expand Down
56 changes: 9 additions & 47 deletions src/commands/server/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@ import { Command, flags } from '@oclif/command'
import { boolean, string } from '@oclif/parser/lib/flags'
import { cli } from 'cli-ux'
import * as Listr from 'listr'
import * as semver from 'semver'
import { ChectlContext, OIDCContextKeys, OLM } from '../../api/context'
import { KubeHelper } from '../../api/kube'
import { batch, cheDeployment, cheDeployVersion, cheNamespace, cheOperatorCRPatchYaml, cheOperatorCRYaml, CHE_OPERATOR_CR_PATCH_YAML_KEY, CHE_OPERATOR_CR_YAML_KEY, CHE_TELEMETRY, DEPLOY_VERSION_KEY, k8sPodDownloadImageTimeout, K8SPODDOWNLOADIMAGETIMEOUT_KEY, k8sPodErrorRecheckTimeout, K8SPODERRORRECHECKTIMEOUT_KEY, k8sPodReadyTimeout, K8SPODREADYTIMEOUT_KEY, k8sPodWaitTimeout, K8SPODWAITTIMEOUT_KEY, listrRenderer, logsDirectory, LOG_DIRECTORY_KEY, skipKubeHealthzCheck as skipK8sHealthCheck } from '../../common-flags'
import { DEFAULT_ANALYTIC_HOOK_NAME, DEFAULT_CHE_NAMESPACE, DEFAULT_OLM_SUGGESTED_NAMESPACE, DOCS_LINK_INSTALL_RUNNING_CHE_LOCALLY, DOC_LINK_CONFIGURE_API_SERVER, MIN_CHE_OPERATOR_INSTALLER_VERSION, MIN_OLM_INSTALLER_VERSION } from '../../constants'
import { DEFAULT_ANALYTIC_HOOK_NAME, DEFAULT_CHE_NAMESPACE, DEFAULT_OLM_SUGGESTED_NAMESPACE, DOCS_LINK_INSTALL_RUNNING_CHE_LOCALLY, DOC_LINK_CONFIGURE_API_SERVER } from '../../constants'
import { CheTasks } from '../../tasks/che'
import { DevWorkspaceTasks } from '../../tasks/component-installers/devfile-workspace-operator-installer'
import { DexTasks } from '../../tasks/component-installers/dex'
import { checkChectlAndCheVersionCompatibility, createNamespaceTask, downloadTemplates, getPrintHighlightedMessagesTask, retrieveCheCaCertificateTask } from '../../tasks/installers/common-tasks'
import { createNamespaceTask, getPrintHighlightedMessagesTask, retrieveCheCaCertificateTask } from '../../tasks/installers/common-tasks'
import { InstallerTasks } from '../../tasks/installers/installer'
import { ApiTasks } from '../../tasks/platforms/api'
import { PlatformTasks } from '../../tasks/platforms/platform'
import { askForChectlUpdateIfNeeded, getCommandSuccessMessage, getEmbeddedTemplatesDirectory, getProjectName, getTlsSupport, isDevWorkspaceEnabled, isKubernetesPlatformFamily, isOpenshiftPlatformFamily, notifyCommandCompletedSuccessfully, wrapCommandError } from '../../util'
import { askForChectlUpdateIfNeeded, getCommandSuccessMessage, getEmbeddedTemplatesDirectory, getTlsSupport, getWarnVersionFlagMsg, isDevWorkspaceEnabled, isKubernetesPlatformFamily, isOpenshiftPlatformFamily, notifyCommandCompletedSuccessfully, wrapCommandError } from '../../util'

export default class Deploy extends Command {
static description = 'Deploy Eclipse Che server'
Expand Down Expand Up @@ -218,11 +217,7 @@ export default class Deploy extends Command {
cli.info(` ❕olm-suggested-namespace flag is turned on. Eclipse Che will be deployed in namespace: ${DEFAULT_OLM_SUGGESTED_NAMESPACE}.`)
}

if (!ctx.isChectl && flags.version) {
// Flavors of chectl should not use upstream repositories, so version flag is not applicable
this.error(`${getProjectName()} does not support '--version' flag.`)
}
if (!flags.templates && !flags.version) {
if (!flags.templates) {
// Use build-in templates if no custom templates nor version to deploy specified.
// All flavors should use embedded templates if not custom templates is given.
flags.templates = getEmbeddedTemplatesDirectory()
Expand Down Expand Up @@ -263,14 +258,6 @@ export default class Deploy extends Command {
if (flags[OLM.CATALOG_SOURCE_NAME] && flags[OLM.CATALOG_SOURCE_YAML]) {
this.error(`should be provided only one argument: "${OLM.CATALOG_SOURCE_NAME}" or "${OLM.CATALOG_SOURCE_YAML}"`)
}
if (flags.version) {
if (flags[OLM.STARTING_CSV]) {
this.error(`"${OLM.STARTING_CSV}" and "version" flags are mutually exclusive. Please specify only one of them.`)
}
if (flags[OLM.AUTO_UPDATE]) {
this.error(`enabled "${OLM.AUTO_UPDATE}" flag cannot be used with version flag. Deploy latest version instead.`)
}
}

if (!flags[OLM.PACKAGE_MANIFEST_NAME] && flags[OLM.CATALOG_SOURCE_YAML]) {
this.error(`you need to define "${OLM.PACKAGE_MANIFEST_NAME}" flag to use "${OLM.CATALOG_SOURCE_YAML}".`)
Expand Down Expand Up @@ -302,34 +289,6 @@ export default class Deploy extends Command {
this.error('"cluster-monitoring" flag should be used only with "olm" installer and "openshift" platform.')
}
}

if (flags.version) {
// Check minimal allowed version to install
let minAllowedVersion: string
switch (flags.installer) {
case 'olm':
minAllowedVersion = MIN_OLM_INSTALLER_VERSION
break
case 'operator':
minAllowedVersion = MIN_CHE_OPERATOR_INSTALLER_VERSION
break
default:
// Should never happen
minAllowedVersion = 'latest'
}

let isVersionAllowed = false
try {
isVersionAllowed = semver.gte(flags.version, minAllowedVersion)
} catch (error) {
// not to fail unexpectedly
cli.debug(`Failed to compare versions '${flags.version}' and '${minAllowedVersion}': ${error}`)
}

if (!isVersionAllowed) {
throw new Error(`This chectl version can deploy version ${minAllowedVersion} and higher. If you need to deploy ${flags.version} or lower, download the corresponding legacy chectl version.`)
}
}
}

async run() {
Expand All @@ -341,6 +300,11 @@ export default class Deploy extends Command {
await askForChectlUpdateIfNeeded()
}

if (flags.version) {
cli.info(getWarnVersionFlagMsg(flags))
this.exit(1)
}

await this.setPlaformDefaults(flags, ctx)
await this.config.runHook(DEFAULT_ANALYTIC_HOOK_NAME, { command: Deploy.id, flags })

Expand All @@ -362,8 +326,6 @@ export default class Deploy extends Command {
task: () => new Listr(cheTasks.checkIfCheIsInstalledTasks(flags)),
})
preInstallTasks.add(ensureOIDCProviderInstalled(flags))
preInstallTasks.add(checkChectlAndCheVersionCompatibility(flags))
preInstallTasks.add(downloadTemplates(flags))
preInstallTasks.add({
title: '🧪 DevWorkspace engine',
enabled: () => isDevWorkspaceEnabled(ctx) && !ctx.isOpenShift,
Expand Down
41 changes: 9 additions & 32 deletions src/commands/server/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import { CheHelper } from '../../api/che'
import { ChectlContext } from '../../api/context'
import { KubeHelper } from '../../api/kube'
import { assumeYes, batch, cheDeployment, cheDeployVersion, cheNamespace, cheOperatorCRPatchYaml, CHE_OPERATOR_CR_PATCH_YAML_KEY, CHE_TELEMETRY, DEPLOY_VERSION_KEY, listrRenderer, skipKubeHealthzCheck } from '../../common-flags'
import { DEFAULT_ANALYTIC_HOOK_NAME, DEFAULT_CHE_OPERATOR_IMAGE_NAME, MIN_CHE_OPERATOR_INSTALLER_VERSION, NEXT_TAG } from '../../constants'
import { checkChectlAndCheVersionCompatibility, downloadTemplates, getPrintHighlightedMessagesTask } from '../../tasks/installers/common-tasks'
import { DEFAULT_ANALYTIC_HOOK_NAME, DEFAULT_CHE_OPERATOR_IMAGE_NAME, NEXT_TAG } from '../../constants'
import { getPrintHighlightedMessagesTask } from '../../tasks/installers/common-tasks'
import { InstallerTasks } from '../../tasks/installers/installer'
import { ApiTasks } from '../../tasks/platforms/api'
import { askForChectlUpdateIfNeeded, findWorkingNamespace, getCommandSuccessMessage, getEmbeddedTemplatesDirectory, getProjectName, getProjectVersion, notifyCommandCompletedSuccessfully, wrapCommandError } from '../../util'
import { askForChectlUpdateIfNeeded, findWorkingNamespace, getCommandSuccessMessage, getEmbeddedTemplatesDirectory, getProjectName, getProjectVersion, getWarnVersionFlagMsg, notifyCommandCompletedSuccessfully, wrapCommandError } from '../../util'

export default class Update extends Command {
static description = 'Update Eclipse Che server.'
Expand Down Expand Up @@ -88,6 +88,11 @@ export default class Update extends Command {
await askForChectlUpdateIfNeeded()
}

if (flags.version) {
cli.info(getWarnVersionFlagMsg(flags))
this.exit(1)
}

await this.setDomainFlag(flags)
if (!flags.installer) {
await this.setDefaultInstaller(flags)
Expand All @@ -96,42 +101,18 @@ export default class Update extends Command {

await this.config.runHook(DEFAULT_ANALYTIC_HOOK_NAME, { command: Update.id, flags })

if (!flags.templates && !flags.version) {
if (!flags.templates) {
// Use build-in templates if no custom templates nor version to deploy specified.
// All flavors should use embedded templates if not custom templates is given.
flags.templates = getEmbeddedTemplatesDirectory()
}

if (flags.version) {
if (!ctx.isChectl) {
// Flavors of chectl should not use upstream repositories, so version flag is not appliable
this.error(`${getProjectName()} does not support '--version' flag.`)
}
if (flags.installer === 'olm') {
this.error(`'--${DEPLOY_VERSION_KEY}' flag is not supported for OLM installer. 'server:update' command automatically updates to the next available version.`)
}

let isVersionAllowed = false
try {
isVersionAllowed = semver.gte(flags.version, MIN_CHE_OPERATOR_INSTALLER_VERSION)
} catch (error) {
// not to fail unexpectedly
cli.debug(`Failed to compare versions '${flags.version}' and '${MIN_CHE_OPERATOR_INSTALLER_VERSION}': ${error}`)
}

if (flags.installer === 'operator' && !isVersionAllowed) {
throw new Error(this.getWrongVersionMessage(flags.version, MIN_CHE_OPERATOR_INSTALLER_VERSION))
}
}

const installerTasks = new InstallerTasks()

// pre update tasks
const apiTasks = new ApiTasks()
const preUpdateTasks = new Listr([], ctx.listrOptions)
preUpdateTasks.add(apiTasks.testApiTasks(flags))
preUpdateTasks.add(checkChectlAndCheVersionCompatibility(flags))
preUpdateTasks.add(downloadTemplates(flags))
preUpdateTasks.add(installerTasks.preUpdateTasks(flags, this))

// update tasks
Expand Down Expand Up @@ -372,8 +353,4 @@ export default class Update extends Command {
flags.installer = 'operator'
}
}

private getWrongVersionMessage(current: string, minimal: string): string {
return `This chectl version can deploy ${minimal} version and higher, but ${current} is provided. If you really need to deploy that old version, please download corresponding legacy chectl version.`
}
}
1 change: 1 addition & 0 deletions src/common-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export const cheDeployVersion = string({
char: 'v',
description: 'Version to deploy (e.g. 7.15.2). Defaults to the same as chectl.',
env: 'CHE_DEPLOY_VERSION',
hidden: true,
})

export const FOLLOW_LOGS = boolean({
Expand Down
72 changes: 1 addition & 71 deletions src/tasks/installers/common-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@ import * as os from 'os'
import * as Listr from 'listr'
import { isEmpty } from 'lodash'
import * as path from 'path'
import * as semver from 'semver'

import { CheHelper } from '../../api/che'
import { ChectlContext } from '../../api/context'
import { CheGithubClient } from '../../api/github-client'
import { KubeHelper } from '../../api/kube'
import { VersionHelper } from '../../api/version'
import { CHE_CLUSTER_CRD, DEFAULT_CA_CERT_FILE_NAME, DOCS_LINK_IMPORT_CA_CERT_INTO_BROWSER, OPERATOR_TEMPLATE_DIR } from '../../constants'
import { getProjectVersion } from '../../util'
import { CHE_CLUSTER_CRD, DEFAULT_CA_CERT_FILE_NAME, DOCS_LINK_IMPORT_CA_CERT_INTO_BROWSER } from '../../constants'

export const TASK_TITLE_CREATE_CHE_CLUSTER_CRD = `Create the Custom Resource of type ${CHE_CLUSTER_CRD}`
export const TASK_TITLE_PATCH_CHECLUSTER_CR = `Patching the Custom Resource of type ${CHE_CLUSTER_CRD}`
Expand All @@ -49,72 +45,6 @@ export function createNamespaceTask(namespaceName: string, labels: {}): Listr.Li
}
}

export function checkChectlAndCheVersionCompatibility(flags: any): Listr.ListrTask {
return {
title: 'Check versions compatibility',
enabled: ctx => ctx.isChectl && !flags.templates && flags.version && flags.installer !== 'olm',
task: async (ctx: any, task: any) => {
const githubClient = new CheGithubClient()
const verInfo = await githubClient.getTemplatesTagInfo(flags.installer, flags.version)
if (!verInfo) {
throw new Error(`Version ${flags.version} does not exist`)
}
ctx.versionInfo = verInfo
flags.version = VersionHelper.removeVPrefix(verInfo.name, true)

if (!ctx.isDevVersion && semver.lt(getProjectVersion(), flags.version)) {
throw new Error(`To deploy Eclipse Che ${flags.version}, please update your chectl first by running "chectl update".`)
}

task.title = `${task.title}... OK`
},
}
}

/**
* Sets flags.templates based on required version and installer.
* Does not support OLM.
*/
export function downloadTemplates(flags: any): Listr.ListrTask {
return {
title: 'Download templates',
enabled: ctx => ctx.isChectl && flags.version && !flags.templates && flags.installer !== 'olm',
task: async (ctx: any, task: any) => {
// All templates are stored in the cache directory
// Example path: ~/.cache/chectl/templates/7.15.1/
const templatesRootDir = path.join(ctx[ChectlContext.CACHE_DIR], 'templates')

let installerTemplatesSubDir: string
switch (flags.installer) {
case 'operator':
installerTemplatesSubDir = OPERATOR_TEMPLATE_DIR
break
case 'olm':
// Should be handled on install phase when catalog source is deployed
return
default:
throw new Error(`Unknow installer ${flags.installer}`)
}

const versionTemplatesDirPath = path.join(templatesRootDir, flags.version)
flags.templates = versionTemplatesDirPath

const installerTemplatesDirPath = path.join(versionTemplatesDirPath, installerTemplatesSubDir)
if (await fs.pathExists(installerTemplatesDirPath)) {
// Use cached templates
task.title = `${task.title}... found cached templates for version ${flags.version}`
return
}

// Download templates
task.title = `${task.title} for version ${flags.version}`
const cheHelper = new CheHelper(flags)
await cheHelper.downloadAndUnpackTemplates(flags.installer, ctx.versionInfo.zipball_url, versionTemplatesDirPath)
task.title = `${task.title} ... OK`
},
}
}

export function createEclipseCheCluster(flags: any, kube: KubeHelper): Listr.ListrTask {
return {
title: TASK_TITLE_CREATE_CHE_CLUSTER_CRD,
Expand Down
Loading

0 comments on commit 5c2a73e

Please sign in to comment.