Skip to content
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

fix: Improve chectl KubeHelper class and context #1085

Merged
merged 14 commits into from
Feb 25, 2021
13 changes: 5 additions & 8 deletions src/api/che.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { CHE_ROOT_CA_SECRET_NAME, DEFAULT_CA_CERT_FILE_NAME, OPERATOR_TEMPLATE_D
import { base64Decode, downloadFile } from '../util'

import { CheApiClient } from './che-api-client'
import { ChectlContext } from './context'
import { Devfile } from './devfile'
import { KubeHelper } from './kube'

Expand Down Expand Up @@ -56,7 +55,7 @@ export class CheHelper {
* or if workspace ID wasn't specified but more than one workspace is found.
*/
async getWorkspacePodName(namespace: string, cheWorkspaceId: string): Promise<string> {
const k8sApi = KubeHelper.KUBE_CONFIG.makeApiClient(CoreV1Api)
const k8sApi = this.kube.kubeConfig.makeApiClient(CoreV1Api)

const res = await k8sApi.listNamespacedPod(namespace)
const pods = res.body.items
Expand All @@ -80,7 +79,7 @@ export class CheHelper {
}

async getWorkspacePodContainers(namespace: string, cheWorkspaceId?: string): Promise<string[]> {
const k8sApi = KubeHelper.KUBE_CONFIG.makeApiClient(CoreV1Api)
const k8sApi = this.kube.kubeConfig.makeApiClient(CoreV1Api)

const res = await k8sApi.listNamespacedPod(namespace)
const pods = res.body.items
Expand Down Expand Up @@ -108,8 +107,7 @@ export class CheHelper {
throw new Error(`ERR_NAMESPACE_NO_EXIST - No namespace ${namespace} is found`)
}

const ctx = ChectlContext.get()
if (ctx.isOpenShift) {
if (await this.kube.isOpenShift()) {
return this.cheOpenShiftURL(namespace)
} else {
return this.cheK8sURL(namespace)
Expand All @@ -127,8 +125,7 @@ export class CheHelper {
}

// grab URL
const ctx = ChectlContext.get()
if (ctx.isOpenShift) {
if (await this.kube.isOpenShift()) {
return this.chePluginRegistryOpenShiftURL(namespace)
} else {
return this.chePluginRegistryK8sURL(namespace)
Expand Down Expand Up @@ -391,7 +388,7 @@ export class CheHelper {
async watchNamespacedPods(namespace: string, podLabelSelector: string | undefined, directory: string): Promise<void> {
const processedContainers = new Map<string, Set<string>>()

const watcher = new Watch(KubeHelper.KUBE_CONFIG)
const watcher = new Watch(this.kube.kubeConfig)
return watcher.watch(`/api/v1/namespaces/${namespace}/pods`, {},
async (_phase: string, obj: any) => {
const pod = obj as V1Pod
Expand Down
5 changes: 0 additions & 5 deletions src/api/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { CHE_OPERATOR_CR_PATCH_YAML_KEY, CHE_OPERATOR_CR_YAML_KEY, LOG_DIRECTORY
import { CHECTL_PROJECT_NAME } from '../constants'
import { getProjectName, getProjectVersion, readCRFile } from '../util'

import { KubeHelper } from './kube'
import { CHECTL_DEVELOPMENT_VERSION } from './version'

/**
Expand All @@ -42,10 +41,6 @@ export namespace ChectlContext {
const ctx: any = {}

export async function init(flags: any, command: Command): Promise<void> {
const kube = new KubeHelper(flags)
ctx[IS_OPENSHIFT] = await kube.isOpenShift()
ctx[IS_OPENSHIFT4] = await kube.isOpenShift4()

ctx.isChectl = getProjectName() === CHECTL_PROJECT_NAME
ctx.isNightly = getProjectVersion().includes('next') || getProjectVersion() === CHECTL_DEVELOPMENT_VERSION

Expand Down