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: Don't stick to eclipse-che as a CR name #725

Merged
merged 2 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/api/che.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import * as os from 'os'
import * as path from 'path'

import { OpenShiftHelper } from '../api/openshift'
import { CHE_CLUSTER_CR_NAME, CHE_ROOT_CA_SECRET_NAME, DEFAULT_CA_CERT_FILE_NAME } from '../constants'
import { CHE_ROOT_CA_SECRET_NAME, DEFAULT_CA_CERT_FILE_NAME } from '../constants'
import { base64Decode } from '../util'

import { Devfile } from './devfile'
Expand Down Expand Up @@ -150,7 +150,10 @@ export class CheHelper {
let adminUsername
let adminPassword

const cheCluster = await this.kube.getCheCluster(CHE_CLUSTER_CR_NAME, cheNamespace)
const cheCluster = await this.kube.getCheCluster(cheNamespace)
if (!cheCluster) {
return []
}
const keycloakCredentialsSecretName = cheCluster.spec.auth.identityProviderSecret
if (keycloakCredentialsSecretName) {
// Keycloak credentials are stored in secret
Expand Down
43 changes: 34 additions & 9 deletions src/api/kube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { merge } from 'lodash'
import * as net from 'net'
import { Writable } from 'stream'

import { DEFAULT_CHE_IMAGE } from '../constants'
import { CHE_CLUSTER_CRD, DEFAULT_CHE_IMAGE } from '../constants'
import { getClusterClientCommand } from '../util'

import { V1alpha2Certificate } from './typings/cert-manager'
Expand Down Expand Up @@ -1205,21 +1205,46 @@ export class KubeHelper {
}
}

async getCheCluster(name: string, namespace: string): Promise<any | undefined> {
/**
* Returns `checlusters.org.eclipse.che' in the given namespace.
*/
async getCheCluster(namespace: string): Promise<any | undefined> {
const customObjectsApi = KubeHelper.KUBE_CONFIG.makeApiClient(CustomObjectsApi)
try {
const { body } = await customObjectsApi.getNamespacedCustomObject('org.eclipse.che', 'v1', namespace, 'checlusters', name)
return body
} catch {
return
const { body } = await customObjectsApi.listNamespacedCustomObject('org.eclipse.che', 'v1', namespace, 'checlusters')
if (!body.items) {
return
}

const crs = body.items as any[]
if (crs.length === 0) {
return
} else if (crs.length !== 1) {
throw new Error(`Too many resources '${CHE_CLUSTER_CRD}' found in the namespace '${namespace}'`)
}

return crs[0]
} catch (e) {
throw this.wrapK8sClientError(e)
}
}

async deleteCheCluster(name = '', namespace = '') {
/**
* Deletes `checlusters.org.eclipse.che' resources in the given namespace.
*/
async deleteCheCluster(namespace: string) {
const customObjectsApi = KubeHelper.KUBE_CONFIG.makeApiClient(CustomObjectsApi)
try {
const options = new V1DeleteOptions()
await customObjectsApi.deleteNamespacedCustomObject('org.eclipse.che', 'v1', namespace, 'checlusters', name, options)
const { body } = await customObjectsApi.listNamespacedCustomObject('org.eclipse.che', 'v1', namespace, 'checlusters')
if (!body.items) {
return
}

const crs = body.items as any[]
for (const cr of crs) {
const options = new V1DeleteOptions()
await customObjectsApi.deleteNamespacedCustomObject('org.eclipse.che', 'v1', namespace, 'checlusters', cr.metadata.name, options)
}
} catch (e) {
throw this.wrapK8sClientError(e)
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/server/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as path from 'path'

import { KubeHelper } from '../../api/kube'
import { cheDeployment, cheNamespace, listrRenderer, skipKubeHealthzCheck } from '../../common-flags'
import { CHE_CLUSTER_CR_NAME, DEFAULT_CHE_OPERATOR_IMAGE } from '../../constants'
import { DEFAULT_CHE_OPERATOR_IMAGE } from '../../constants'
import { CheTasks } from '../../tasks/che'
import { getPrintHighlightedMessagesTask } from '../../tasks/installers/common-tasks'
import { InstallerTasks } from '../../tasks/installers/installer'
Expand Down Expand Up @@ -173,7 +173,7 @@ export default class Update extends Command {

async setDomainFlag(flags: any): Promise<void> {
const kubeHelper = new KubeHelper(flags)
const cheCluster = await kubeHelper.getCheCluster(CHE_CLUSTER_CR_NAME, flags.chenamespace)
const cheCluster = await kubeHelper.getCheCluster(flags.chenamespace)
if (cheCluster && cheCluster.spec.k8s && cheCluster.spec.k8s.ingressDomain) {
flags.domain = cheCluster.spec.k8s.ingressDomain
}
Expand Down
3 changes: 1 addition & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ export const CERT_MANAGER_NAMESPACE_NAME = 'cert-manager'
export const CHE_TLS_SECRET_NAME = 'che-tls'
export const CHE_ROOT_CA_SECRET_NAME = 'self-signed-certificate'
export const DEFAULT_CA_CERT_FILE_NAME = 'cheCA.crt'

export const operatorCheCluster = 'eclipse-che'
export const CHE_CLUSTER_CR_NAME = 'eclipse-che'
export const CHE_CLUSTER_CRD = 'checlusters.org.eclipse.che'

export const defaultOpenshiftMarketPlaceNamespace = 'openshift-marketplace'
export const defaultOLMKubernetesNamespace = 'olm'
Expand Down
6 changes: 3 additions & 3 deletions src/tasks/installers/common-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as path from 'path'

import { CheHelper } from '../../api/che'
import { KubeHelper } from '../../api/kube'
import { CHE_CLUSTER_CR_NAME, DOCS_LINK_IMPORT_CA_CERT_INTO_BROWSER } from '../../constants'
import { CHE_CLUSTER_CRD, DOCS_LINK_IMPORT_CA_CERT_INTO_BROWSER } from '../../constants'
import { isKubernetesPlatformFamily, isOpenshiftPlatformFamily } from '../../util'

export function createNamespaceTask(flags: any): Listr.ListrTask {
Expand Down Expand Up @@ -62,9 +62,9 @@ async function copyCheOperatorResources(templatesDir: string, cacheDir: string):

export function createEclipseCheCluster(flags: any, kube: KubeHelper): Listr.ListrTask {
return {
title: `Create Eclipse Che cluster ${CHE_CLUSTER_CR_NAME} in namespace ${flags.chenamespace}`,
title: `Create the Custom Resource of type ${CHE_CLUSTER_CRD} in the namespace ${flags.chenamespace}`,
task: async (ctx: any, task: any) => {
const cheCluster = await kube.getCheCluster(CHE_CLUSTER_CR_NAME, flags.chenamespace)
const cheCluster = await kube.getCheCluster(flags.chenamespace)
if (cheCluster) {
task.title = `${task.title}...It already exists.`
} else {
Expand Down
15 changes: 5 additions & 10 deletions src/tasks/installers/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as yaml from 'js-yaml'
import * as Listr from 'listr'

import { KubeHelper } from '../../api/kube'
import { CHE_CLUSTER_CR_NAME } from '../../constants'
import { CHE_CLUSTER_CRD } from '../../constants'
import { isStableVersion } from '../../util'

import { checkTlsCertificate, copyOperatorResources, createEclipseCheCluster, createNamespaceTask } from './common-tasks'
Expand Down Expand Up @@ -309,16 +309,11 @@ export class OperatorTasks {
deleteTasks(flags: any): ReadonlyArray<Listr.ListrTask> {
let kh = new KubeHelper(flags)
return [{
title: `Delete the CR ${CHE_CLUSTER_CR_NAME} of type ${this.cheClusterCrd}`,
title: `Delete the Custom Resource of type ${CHE_CLUSTER_CRD}`,
task: async (_ctx: any, task: any) => {
if (await kh.crdExist(this.cheClusterCrd) &&
await kh.getCheCluster(CHE_CLUSTER_CR_NAME, flags.chenamespace)) {
await kh.deleteCheCluster(CHE_CLUSTER_CR_NAME, flags.chenamespace)
await cli.wait(2000) //wait a couple of secs for the finalizers to be executed
task.title = await `${task.title}...OK`
} else {
task.title = await `${task.title}...CR not found`
}
await kh.deleteCheCluster(flags.chenamespace)
await cli.wait(2000) //wait a couple of secs for the finalizers to be executed
task.title = await `${task.title}...OK`
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ ecc-jsbn@~0.1.1:

"eclipse-che@git://github.com/eclipse/che#master":
version "0.0.0"
resolved "git://github.com/eclipse/che#fb063a970d0999915f18a8d4a19835a38a4a74b5"
resolved "git://github.com/eclipse/che#7bcf1d3e930ea4b993a09b3eae12a1bd22cdc351"

editorconfig@^0.15.0:
version "0.15.3"
Expand Down