-
Notifications
You must be signed in to change notification settings - Fork 65
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
Improve Eclipse Che deploy / update flow #1082
Changes from 11 commits
1ca8f9d
95b6cec
04ab07f
a8865cf
c165a67
7f17589
cc27e5d
d6093a2
192a53b
223bdfa
082e926
68acca4
7f10e46
c3207e1
d2d7fd1
ca23352
31d5148
7556a43
bd3047d
3e50be0
95d1ad2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,10 +20,12 @@ import * as yaml from 'js-yaml' | |
import * as nodeforge from 'node-forge' | ||
import * as os from 'os' | ||
import * as path from 'path' | ||
import * as rimraf from 'rimraf' | ||
import * as unzipper from 'unzipper' | ||
|
||
import { OpenShiftHelper } from '../api/openshift' | ||
import { CHE_ROOT_CA_SECRET_NAME, DEFAULT_CA_CERT_FILE_NAME } from '../constants' | ||
import { base64Decode } from '../util' | ||
import { base64Decode, downloadFile } from '../util' | ||
|
||
import { CheApiClient } from './che-api-client' | ||
import { ChectlContext } from './context' | ||
|
@@ -484,4 +486,69 @@ export class CheHelper { | |
return fileName | ||
} | ||
|
||
/** | ||
* Gets install templates for given installer. | ||
* @param installer Che installer | ||
* @param url link to zip archive with sources of Che operator | ||
* @param destDir destination directory into which the templates should be unpacked | ||
*/ | ||
async getAndPrepareInstallerTemplates(installer: string, url: string, destDir: string): Promise<void> { | ||
mmorhun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Add che-operator folder for operator templates | ||
if (installer === 'operator') { | ||
destDir = path.join(destDir, 'che-operator') | ||
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 don't get it. 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. This code is responsible for changing destination path for unpacked templates. The reason we need it is that the templates are located on different levels inside che (for helm) and che-operator repositories. And to have unzip process the same for both we have to correct the path for operator installer here. |
||
} | ||
// No need to add kubernetes folder for Helm installer as it already present in the archive | ||
|
||
const tempDir = path.join(os.tmpdir(), Date.now().toString()) | ||
await fs.mkdirp(tempDir) | ||
const zipFile = path.join(tempDir, `che-templates-${installer}.zip`) | ||
await downloadFile(url, zipFile) | ||
await this.unzipTemplates(zipFile, destDir) | ||
// Clean up zip. Do not wait when finishes. | ||
rimraf(tempDir, () => {}) | ||
} | ||
|
||
/** | ||
* Unpacks repository deploy templates into specified folder | ||
* @param zipFile path to zip archive with source code | ||
* @param destDir target directory into which templates should be unpacked | ||
*/ | ||
private async unzipTemplates(zipFile: string, destDir: string) { | ||
// Gets path from: repo-name/deploy/path | ||
const deployDirRegex = new RegExp('(?:^[\\\w-]*\\\/deploy\\\/)(.*)') | ||
|
||
const zip = fs.createReadStream(zipFile).pipe(unzipper.Parse({ forceStream: true })) | ||
for await (const entry of zip) { | ||
const entryPathInZip: string = entry.path | ||
const templatesPathMatch = entryPathInZip.match(deployDirRegex) | ||
if (templatesPathMatch && templatesPathMatch.length > 1 && templatesPathMatch[1]) { | ||
// Remove prefix from in-zip path | ||
const entryPathWhenExtracted = templatesPathMatch[1] | ||
// Path to the item in target location | ||
const dest = path.join(destDir, entryPathWhenExtracted) | ||
|
||
// Extract item | ||
if (entry.type === 'File') { | ||
const parentDirName = path.dirname(dest) | ||
if (!fs.existsSync(parentDirName)) { | ||
await fs.mkdirp(parentDirName) | ||
} | ||
entry.pipe(fs.createWriteStream(dest)) | ||
} else if (entry.type === 'Directory') { | ||
if (!fs.existsSync(dest)) { | ||
await fs.mkdirp(dest) | ||
} | ||
// The folder is created above | ||
entry.autodrain() | ||
} else { | ||
// Ignore the item as we do not need to handle links and etc. | ||
entry.autodrain() | ||
} | ||
} else { | ||
// No need to extract this item | ||
entry.autodrain() | ||
} | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ import * as os from 'os' | |
import * as path from 'path' | ||
|
||
import { CHE_OPERATOR_CR_PATCH_YAML_KEY, CHE_OPERATOR_CR_YAML_KEY, LOG_DIRECTORY_KEY } from '../common-flags' | ||
import { readCRFile } from '../util' | ||
import { getProjectName, getProjectVersion, readCRFile } from '../util' | ||
|
||
import { KubeHelper } from './kube' | ||
|
||
|
@@ -28,13 +28,14 @@ export namespace ChectlContext { | |
export const START_TIME = 'startTime' | ||
export const END_TIME = 'endTime' | ||
export const CONFIG_DIR = 'configDir' | ||
export const CACHE_DIR = 'cacheDir' | ||
export const ERROR_LOG = 'errorLog' | ||
export const COMMAND_ID = 'commandId' | ||
|
||
// command specific attributes | ||
export const CUSTOM_CR = 'customCR' | ||
export const CR_PATCH = 'crPatch' | ||
export const LOGS_DIRECTORY = 'directory' | ||
export const LOGS_DIR = 'directory' | ||
|
||
const ctx: any = {} | ||
|
||
|
@@ -43,6 +44,9 @@ export namespace ChectlContext { | |
ctx[IS_OPENSHIFT] = await kube.isOpenShift() | ||
ctx[IS_OPENSHIFT4] = await kube.isOpenShift4() | ||
|
||
ctx.isChectl = getProjectName() === 'chectl' | ||
ctx.isNightly = getProjectVersion().includes('next') || getProjectVersion() === '0.0.2' | ||
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. it looks strange to have nightly when version is 0.0.2 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. Well, we still have version |
||
|
||
if (flags['listr-renderer'] as any) { | ||
ctx.listrOptions = { renderer: (flags['listr-renderer'] as any), collapse: false } as Listr.ListrOptions | ||
} | ||
|
@@ -51,9 +55,10 @@ export namespace ChectlContext { | |
ctx[START_TIME] = Date.now() | ||
|
||
ctx[CONFIG_DIR] = command.config.configDir | ||
ctx[CACHE_DIR] = command.config.cacheDir | ||
ctx[ERROR_LOG] = command.config.errlog | ||
ctx[COMMAND_ID] = command.id | ||
ctx[LOGS_DIRECTORY] = path.resolve(flags[LOG_DIRECTORY_KEY] ? flags[LOG_DIRECTORY_KEY] : path.resolve(os.tmpdir(), 'chectl-logs', Date.now().toString())) | ||
ctx[LOGS_DIR] = path.resolve(flags[LOG_DIRECTORY_KEY] ? flags[LOG_DIRECTORY_KEY] : path.resolve(os.tmpdir(), 'chectl-logs', Date.now().toString())) | ||
|
||
ctx[CUSTOM_CR] = readCRFile(flags, CHE_OPERATOR_CR_YAML_KEY) | ||
ctx[CR_PATCH] = readCRFile(flags, CHE_OPERATOR_CR_PATCH_YAML_KEY) | ||
|
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.
I think it's odd because I might expect that -v or --version will display the current version of the cli
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.
The flag is used as an argument for
server:deploy
command, so it will not collide with-v
flag ofchectl
itself.