Skip to content

Commit

Permalink
TMP Refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Sergii Leshchenko <sleshche@redhat.com>
  • Loading branch information
sleshchenko committed Sep 6, 2019
1 parent 1f32ff6 commit f654110
Show file tree
Hide file tree
Showing 45 changed files with 1,310 additions and 924 deletions.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
"axios": "^0.19.0",
"cli-ux": "^5.3.2",
"command-exists": "^1.2.8",
"debug": "^4.1.1",
"eclipse-che": "git://github.com/eclipse/che#master",
"eclipse-che-minishift": "git://github.com/minishift/minishift#master",
"eclipse-che-minishift": "git://github.com/sleshchenko/minishift#updateChe",
"eclipse-che-operator": "git://github.com/eclipse/che-operator#master",
"esprima": "^4.0.1",
"execa": "^2.0.0",
Expand Down Expand Up @@ -120,21 +121,21 @@
},
"repository": "che-incubator/chectl",
"scripts": {
"version": "oclif-dev readme && git add README.md",
"postinstall-helm": "rimraf templates/kubernetes && cpx 'node_modules/eclipse-che/deploy/kubernetes/**' 'templates/kubernetes'",
"postinstall-minishift-addon": "rimraf templates/minishift-addon && cpx 'node_modules/eclipse-che-minishift/addons/che/**' 'templates/minishift-addon/che'",
"postinstall-operator": "rimraf templates/che-operator && cpx 'node_modules/eclipse-che-operator/deploy/**' 'templates/che-operator'",
"postinstall-repositories": "yarn upgrade eclipse-che eclipse-che-operator eclipse-che-minishift",
"postinstall": "npm run -s postinstall-repositories && npm run -s postinstall-helm && npm run -s postinstall-operator && npm run -s postinstall-minishift-addon && npm run -s postinstall-cleanup",
"postinstall-cleanup": "rimraf node_modules/eclipse-che && rimraf node_modules/eclipse-che-operator && rimraf node_modules/eclipse-che-minishift",
"postpack": "rm -f oclif.manifest.json",
"posttest": "tslint -p test -t stylish",
"tslint-fix": "tslint --fix -p test -t stylish",
"prepack": "rm -rf lib && rm -rf tsconfig.tsbuildinfo && tsc -b && oclif-dev manifest && oclif-dev readme",
"pack-binaries": "oclif-dev pack",
"postpack": "rm -f oclif.manifest.json",
"test": "jest",
"test-watch": "jest --watchAll",
"version": "oclif-dev readme && git add README.md",
"format": "tsfmt -r --useTsfmt tsfmt.json"
"posttest": "tslint -p test -t stylish",
"format": "tsfmt -r",
"tslint-fix": "tslint --fix -p test -t stylish"
},
"types": "lib/index.d.ts",
"jest": {
Expand Down
11 changes: 6 additions & 5 deletions src/api/che.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
// tslint:disable:object-curly-spacing
// tslint:disable-next-line:no-http-string

import { Core_v1Api, KubeConfig } from '@kubernetes/client-node'
import axios from 'axios'
import { cli } from 'cli-ux'
import * as fs from 'fs'
import * as yaml from 'js-yaml'

import { KubeHelper } from '../api/kube'
import { OpenShiftHelper } from '../api/openshift'

import { Devfile } from './devfile'
import { KubeHelper } from './kube'

export class CheHelper {
defaultCheResponseTimeoutMs = 3000
kc = new KubeConfig()
kube = new KubeHelper()
kube: KubeHelper
oc = new OpenShiftHelper()

constructor(flags: any) {
this.kube = new KubeHelper(flags)
}

async cheServerPodExist(namespace: string): Promise<boolean> {
const kc = new KubeConfig()
kc.loadFromDefault()
Expand Down
29 changes: 26 additions & 3 deletions src/api/kube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
// tslint:disable:object-curly-spacing

import { Apiextensions_v1beta1Api, ApisApi, Apps_v1Api, Core_v1Api, Custom_objectsApi, Extensions_v1beta1Api, KubeConfig, RbacAuthorization_v1Api, V1beta1CustomResourceDefinition, V1beta1IngressList, V1ClusterRole, V1ClusterRoleBinding, V1ConfigMap, V1ConfigMapEnvSource, V1Container, V1DeleteOptions, V1Deployment, V1DeploymentList, V1DeploymentSpec, V1EnvFromSource, V1LabelSelector, V1ObjectMeta, V1PersistentVolumeClaimList, V1Pod, V1PodSpec, V1PodTemplateSpec, V1Role, V1RoleBinding, V1RoleRef, V1Secret, V1ServiceAccount, V1ServiceList, V1Subject } from '@kubernetes/client-node'
import axios from 'axios'
import { cli } from 'cli-ux'
Expand All @@ -21,7 +19,7 @@ export class KubeHelper {
podWaitTimeout: number
podReadyTimeout: number

constructor(flags?: any, context?: string) {
constructor(flags: any, context?: string) {
if (!context) {
this.kc.loadFromDefault()
} else {
Expand Down Expand Up @@ -525,6 +523,31 @@ export class KubeHelper {
}
}

async deploymentReady(name = '', namespace = ''): Promise<boolean> {
const k8sApi = this.kc.makeApiClient(Apps_v1Api)
try {
const res = await k8sApi.readNamespacedDeployment(name, namespace)
return ((res && res.body &&
res.body.status && res.body.status.readyReplicas
&& res.body.status.readyReplicas > 0) as boolean)
} catch {
return false
}
}

async deploymentStopped(name = '', namespace = ''): Promise<boolean> {
const k8sApi = this.kc.makeApiClient(Apps_v1Api)
try {
const res = await k8sApi.readNamespacedDeployment(name, namespace)
if (res && res.body && res.body.spec && res.body.spec.replicas) {
throw new Error(`Deployment '${name}' without replicas in spec is fetched`)
}
return res.body.spec.replicas === 0
} catch {
return false
}
}

async isDeploymentPaused(name = '', namespace = ''): Promise<boolean> {
const k8sApi = this.kc.makeApiClient(Apps_v1Api)
try {
Expand Down
13 changes: 0 additions & 13 deletions src/api/openshift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
// tslint:disable:object-curly-spacing

import execa = require('execa')

export class OpenShiftHelper {
Expand Down Expand Up @@ -46,17 +44,6 @@ export class OpenShiftHelper {
const args = ['delete', 'route', '--all', '--namespace', namespace]
await execa(command, args, { timeout: 60000 })
}
async deploymentConfigExist(name = '', namespace = ''): Promise<boolean> {
const command = 'oc'
const args = ['get', 'deploymentconfig', '--namespace', namespace, '-o', `jsonpath={range.items[?(.metadata.name=='${name}')]}{.metadata.name}{end}`]
const { stdout } = await execa(command, args, { timeout: 60000 })
return stdout.trim().includes(name)
}
async scaleDeploymentConfig(name = '', namespace = '', replicas: number) {
const command = 'oc'
const args = ['scale', 'deploymentconfig', '--namespace', namespace, name, `--replicas=${replicas}`]
await execa(command, args, { timeout: 60000 })
}
async deleteAllDeploymentConfigs(namespace = '') {
const command = 'oc'
const args = ['delete', 'deploymentconfig', '--all', '--namespace', namespace]
Expand Down
1 change: 0 additions & 1 deletion src/commands/devfile/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
// tslint:disable:object-curly-spacing

import { V1beta1Ingress, V1Deployment, V1DeploymentSpec, V1ObjectMeta, V1PersistentVolumeClaim, V1PersistentVolumeClaimSpec, V1PodTemplateSpec, V1Service, V1ServicePort, V1ServiceSpec } from '@kubernetes/client-node'
import { Command, flags } from '@oclif/command'
Expand Down
Loading

0 comments on commit f654110

Please sign in to comment.