Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Flavius Lacatusu <flacatus@redhat.com>
  • Loading branch information
flacatus committed Feb 22, 2021
1 parent 192dd2c commit 400c99d
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 164 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/e2e-minikube-devworkspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- name: Install minikube kubernetes cluster
run: minikube start --memory=6000
- name: Provision minikube cluster
run: |
minikube start --memory=6000
minikube addons enable ingress
- name: Install chectl dependencies
run: yarn
- name: Run workspace-engine tests in minikube
run: |
minikube addons enable ingress
./bin/run server:deploy --telemetry=off --workspace-engine=dev-workspace -p minikube
7 changes: 4 additions & 3 deletions .github/workflows/e2e-minikube-helm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- name: Install minikube kubernetes cluster
run: minikube start --memory=6000
- name: Provision minikube cluster
run: |
minikube start --memory=6000
minikube addons enable ingress
- name: Install chectl dependencies
run: yarn
- name: Run e2e tests minikube
run: |
export PLATFORM=minikube
export INSTALLER=helm
minikube addons enable ingress
yarn test --coverage=false --forceExit --testRegex=test/e2e/e2e.test.ts
10 changes: 5 additions & 5 deletions .github/workflows/e2e-minikube-olm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- name: Install minikube kubernetes cluster
run: minikube start --memory=6000
- name: Provision minikube cluster
run: |
minikube start --memory=6000
minikube addons enable ingress
minikube addons enable olm
- name: Install chectl dependencies
run: yarn
- name: Run olm e2e tests minikube
run: |
export PLATFORM=minikube
export INSTALLER=olm
minikube addons enable olm
minikube addons enable ingress
sleep 60
yarn test --coverage=false --forceExit --testRegex=test/e2e/e2e.test.ts
7 changes: 4 additions & 3 deletions .github/workflows/e2e-minikube-operator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- name: Install minikube kubernetes cluster
run: minikube start --memory=6000
- name: Provision minikube cluster
run: |
minikube start --memory=6000
minikube addons enable ingress
- name: Install chectl dependencies
run: yarn
- name: Run e2e tests minikube
run: |
export PLATFORM=minikube
export INSTALLER=operator
minikube addons enable ingress
yarn test --coverage=false --forceExit --testRegex=test/e2e/e2e.test.ts
2 changes: 1 addition & 1 deletion .github/workflows/happy-path.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
id: deploy-che
uses: che-incubator/che-deploy-action@next
with:
# use custom image built by this PR
# use custom chectl built by this PR
skip-chectl-install: true
- name: Run Happy Path tests
id: run-happy-path-tests
Expand Down
8 changes: 3 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
"name": "Debug Openshift Install",
"program": "${workspaceFolder}/bin/run",
"args": [
"server:deploy",
"--platform",
"openshift",
"--installer",
"operator"
"server:delete",
"-n",
"flacatus-qe"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
Expand Down
33 changes: 9 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,32 +406,21 @@ USAGE
$ chectl server:delete
OPTIONS
-h, --help show CLI help
-n, --chenamespace=chenamespace Eclipse Che Kubernetes namespace. Default to
'eclipse-che'
-y, --yes Automatic yes to prompts; assume "yes" as
answer to all prompts and run
non-interactively
-h, --help show CLI help
-n, --chenamespace=chenamespace Eclipse Che Kubernetes namespace. Default to 'eclipse-che'
--batch Batch mode. Running a command without end
user interaction.
-y, --yes Automatic yes to prompts; assume "yes" as answer to all prompts and run
non-interactively
--delete-namespace Indicates that a Eclipse Che namespace will
be deleted as well
--batch Batch mode. Running a command without end user interaction.
--deployment-name=deployment-name [default: che] Eclipse Che deployment name
--delete-namespace Indicates that a Eclipse Che namespace will be deleted as well
--dev-workspace-controller-namespace=dev-workspace-controller-namespace [default: devworkspace-controller] Namespace
for the DevWorkspace controller. This
parameter is used only when the workspace
engine is the DevWorkspace
--deployment-name=deployment-name [default: che] Eclipse Che deployment name
--skip-kubernetes-health-check Skip Kubernetes health check
--skip-kubernetes-health-check Skip Kubernetes health check
--telemetry=on|off Enable or disable telemetry. This flag skips
a prompt and enable/disable telemetry
--telemetry=on|off Enable or disable telemetry. This flag skips a prompt and enable/disable telemetry
```

_See code: [src/commands/server/delete.ts](https://github.com/che-incubator/chectl/blob/v0.0.2/src/commands/server/delete.ts)_
Expand Down Expand Up @@ -698,10 +687,6 @@ OPTIONS
--deployment-name=deployment-name
[default: che] Eclipse Che deployment name
--dev-workspace-controller-namespace=dev-workspace-controller-namespace
[default: devworkspace-controller] Namespace for the DevWorkspace controller. This parameter is used only when the
workspace engine is the DevWorkspace
--skip-kubernetes-health-check
Skip Kubernetes health check
Expand Down
30 changes: 20 additions & 10 deletions src/api/kube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import { AdmissionregistrationV1Api, ApiextensionsV1Api, ApiextensionsV1beta1Api, ApisApi, AppsV1Api, AuthorizationV1Api, BatchV1Api, CoreV1Api, CustomObjectsApi, ExtensionsV1beta1Api, ExtensionsV1beta1IngressList, KubeConfig, Log, PortForward, RbacAuthorizationV1Api, V1beta1CustomResourceDefinition, V1ClusterRole, V1ClusterRoleBinding, V1ClusterRoleBindingList, V1ConfigMap, V1ConfigMapEnvSource, V1Container, V1ContainerStateTerminated, V1ContainerStateWaiting, V1CustomResourceDefinition, V1Deployment, V1DeploymentList, V1DeploymentSpec, V1EnvFromSource, V1Job, V1JobSpec, V1LabelSelector, V1Namespace, V1NamespaceList, V1ObjectMeta, V1PersistentVolumeClaimList, V1Pod, V1PodCondition, V1PodList, V1PodSpec, V1PodTemplateSpec, V1PolicyRule, V1Role, V1RoleBinding, V1RoleBindingList, V1RoleList, V1RoleRef, V1Secret, V1SelfSubjectAccessReview, V1SelfSubjectAccessReviewSpec, V1Service, V1ServiceAccount, V1ServiceList, V1Status, V1Subject, Watch } from '@kubernetes/client-node'
import { AdmissionregistrationV1Api, ApiextensionsV1Api, ApiextensionsV1beta1Api, ApisApi, AppsV1Api, AuthorizationV1Api, BatchV1Api, CoreV1Api, CustomObjectsApi, ExtensionsV1beta1Api, ExtensionsV1beta1IngressList, KubeConfig, Log, PortForward, RbacAuthorizationV1Api, V1beta1CustomResourceDefinition, V1ClusterRole, V1ClusterRoleBinding, V1ClusterRoleBindingList, V1ConfigMap, V1ConfigMapEnvSource, V1Container, V1ContainerStateTerminated, V1ContainerStateWaiting, V1CustomResourceDefinition, V1Deployment, V1DeploymentList, V1DeploymentSpec, V1EnvFromSource, V1Job, V1JobSpec, V1LabelSelector, V1MutatingWebhookConfiguration, V1Namespace, V1NamespaceList, V1ObjectMeta, V1PersistentVolumeClaimList, V1Pod, V1PodCondition, V1PodList, V1PodSpec, V1PodTemplateSpec, V1PolicyRule, V1Role, V1RoleBinding, V1RoleBindingList, V1RoleList, V1RoleRef, V1Secret, V1SelfSubjectAccessReview, V1SelfSubjectAccessReviewSpec, V1Service, V1ServiceAccount, V1ServiceList, V1Status, V1Subject, Watch } from '@kubernetes/client-node'
import { Cluster, Context } from '@kubernetes/client-node/dist/config_types'
import axios, { AxiosRequestConfig } from 'axios'
import { cli } from 'cli-ux'
Expand Down Expand Up @@ -454,6 +454,16 @@ export class KubeHelper {
}
}

async getMutatingWebhookConfiguration(name: string): Promise<V1MutatingWebhookConfiguration> {
const k8sAdmissionApi = KubeHelper.KUBE_CONFIG.makeApiClient(AdmissionregistrationV1Api)
try {
const res = await k8sAdmissionApi.readMutatingWebhookConfiguration(name)
return res.body
} catch (e) {
throw this.wrapK8sClientError(e)
}
}

async isValidatingWebhookConfigurationExists(name: string): Promise<boolean> {
const k8sAdmissionApi = KubeHelper.KUBE_CONFIG.makeApiClient(AdmissionregistrationV1Api)
try {
Expand Down Expand Up @@ -1409,7 +1419,7 @@ export class KubeHelper {
}
}

async createCrdFromFile(filePath: string) {
async createCrdV1Beta1FromFile(filePath: string) {
const yamlCrd = this.safeLoadFromYamlFile(filePath) as V1beta1CustomResourceDefinition
const k8sApiextensionsApi = KubeHelper.KUBE_CONFIG.makeApiClient(ApiextensionsV1beta1Api)
try {
Expand All @@ -1419,7 +1429,7 @@ export class KubeHelper {
}
}

async createCRDV1FromFile(filePath: string) {
async createCrdV1FromFile(filePath: string) {
const yamlCrd = this.safeLoadFromYamlFile(filePath) as V1CustomResourceDefinition
const k8sApiextensionsApi = KubeHelper.KUBE_CONFIG.makeApiClient(ApiextensionsV1Api)
try {
Expand All @@ -1443,7 +1453,7 @@ export class KubeHelper {
}
}

async crdExist(name = ''): Promise<boolean> {
async isCrdV1Beta1Exists(name = ''): Promise<boolean> {
const k8sApiextensionsApi = KubeHelper.KUBE_CONFIG.makeApiClient(ApiextensionsV1beta1Api)
try {
const { body } = await k8sApiextensionsApi.readCustomResourceDefinition(name)
Expand All @@ -1453,7 +1463,7 @@ export class KubeHelper {
}
}

async isCRDV1Exists(name: string): Promise<boolean> {
async isCrdV1Exists(name: string): Promise<boolean> {
const k8sApiextensionsApi = KubeHelper.KUBE_CONFIG.makeApiClient(ApiextensionsV1Api)
try {
await k8sApiextensionsApi.readCustomResourceDefinition(name)
Expand Down Expand Up @@ -1488,7 +1498,7 @@ export class KubeHelper {
return crdv ? crdv.name : 'v1'
}

async deleteCrd(name: string): Promise<void> {
async deleteCrdV1Beta1(name: string): Promise<void> {
const k8sApiextensionsApi = KubeHelper.KUBE_CONFIG.makeApiClient(ApiextensionsV1beta1Api)
try {
await k8sApiextensionsApi.deleteCustomResourceDefinition(name)
Expand All @@ -1497,7 +1507,7 @@ export class KubeHelper {
}
}

async deleteCRDV1(name: string): Promise<void> {
async deleteCrdV1(name: string): Promise<void> {
const k8sApiextensionsApi = KubeHelper.KUBE_CONFIG.makeApiClient(ApiextensionsV1Api)
try {
await k8sApiextensionsApi.deleteCustomResourceDefinition(name)
Expand Down Expand Up @@ -2100,7 +2110,7 @@ export class KubeHelper {
const customObjectsApi = KubeHelper.KUBE_CONFIG.makeApiClient(CustomObjectsApi)

try {
// If cluster issuers doesn't exist an exception will be thrown
// If cluster certificates doesn't exist an exception will be thrown
await customObjectsApi.deleteNamespacedCustomObject('cert-manager.io', version, namespace, 'certificates', name)
} catch (e) {
throw this.wrapK8sClientError(e)
Expand Down Expand Up @@ -2174,11 +2184,11 @@ export class KubeHelper {
}
}

async createCheClusterCertificate(certificateYaml: V1Certificate, version: string): Promise<void> {
async createCheClusterCertificate(certificate: V1Certificate, version: string): Promise<void> {
const customObjectsApi = KubeHelper.KUBE_CONFIG.makeApiClient(CustomObjectsApi)

try {
await customObjectsApi.createNamespacedCustomObject('cert-manager.io', version, certificateYaml.metadata.namespace, 'certificates', certificateYaml)
await customObjectsApi.createNamespacedCustomObject('cert-manager.io', version, certificate.metadata.namespace, 'certificates', certificate)
} catch (e) {
throw this.wrapK8sClientError(e)
}
Expand Down
19 changes: 15 additions & 4 deletions src/commands/server/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import { Command, flags } from '@oclif/command'
import { boolean } from '@oclif/command/lib/flags'
import { cli } from 'cli-ux'
import * as Listrq from 'listr'
import Listr = require('listr')

import { ChectlContext } from '../../api/context'
import { KubeHelper } from '../../api/kube'
import { assumeYes, batch, cheDeployment, cheNamespace, CHE_TELEMETRY, devWorkspaceControllerNamespace, listrRenderer, skipKubeHealthzCheck } from '../../common-flags'
import { assumeYes, batch, cheDeployment, cheNamespace, CHE_TELEMETRY, listrRenderer, skipKubeHealthzCheck } from '../../common-flags'
import { DEFAULT_ANALYTIC_HOOK_NAME } from '../../constants'
import { CheTasks } from '../../tasks/che'
import { DevWorkspaceTasks } from '../../tasks/component-installers/devfile-workspace-operator-installer'
Expand All @@ -32,7 +33,6 @@ export default class Delete extends Command {
help: flags.help({ char: 'h' }),
chenamespace: cheNamespace,
batch,
'dev-workspace-controller-namespace': devWorkspaceControllerNamespace,
'delete-namespace': boolean({
description: 'Indicates that a Eclipse Che namespace will be deleted as well',
default: false
Expand Down Expand Up @@ -62,21 +62,32 @@ export default class Delete extends Command {
}

const apiTasks = new ApiTasks()
const kube = new KubeHelper(flags)
const helmTasks = new HelmTasks(flags)
const operatorTasks = new OperatorTasks()
const olmTasks = new OLMTasks()
const cheTasks = new CheTasks(flags)
const devWorkspaceTasks = new DevWorkspaceTasks(flags)

const tasks = new Listrq([], ctx.listrOptions)

tasks.add(apiTasks.testApiTasks(flags, this))
tasks.add(operatorTasks.deleteTasks(flags))
tasks.add(olmTasks.deleteTasks(flags))
tasks.add(cheTasks.deleteTasks(flags))
tasks.add(devWorkspaceTasks.getUninstallTasks())
tasks.add(helmTasks.deleteTasks(flags))
tasks.add(cheTasks.waitPodsDeletedTasks())

// Remove devworkspace controller only if there are no more cheClusters after olm/operator tasks
tasks.add({
title: 'Uninstall DevWorkspace Controller',
task: async (_ctx: any, task: any) => {
const checlusters = await kube.getAllCheClusters()
if (checlusters.length === 0) {
return new Listr(devWorkspaceTasks.getUninstallTasks())
}
task.title = `${task.title}...Skipped: another Eclipse Che deployment found.`
}})

if (flags['delete-namespace']) {
tasks.add(cheTasks.deleteNamespace(flags))
}
Expand Down
3 changes: 1 addition & 2 deletions src/commands/server/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { string } from '@oclif/parser/lib/flags'
import { cli } from 'cli-ux'

import { ChectlContext } from '../../api/context'
import { accessToken, cheDeployment, cheNamespace, CHE_TELEMETRY, devWorkspaceControllerNamespace, listrRenderer, skipKubeHealthzCheck } from '../../common-flags'
import { accessToken, cheDeployment, cheNamespace, CHE_TELEMETRY, listrRenderer, skipKubeHealthzCheck } from '../../common-flags'
import { DEFAULT_ANALYTIC_HOOK_NAME } from '../../constants'
import { CheTasks } from '../../tasks/che'
import { ApiTasks } from '../../tasks/platforms/api'
Expand All @@ -25,7 +25,6 @@ export default class Stop extends Command {
static flags: flags.Input<any> = {
help: flags.help({ char: 'h' }),
chenamespace: cheNamespace,
'dev-workspace-controller-namespace': devWorkspaceControllerNamespace,
'deployment-name': cheDeployment,
'che-selector': string({
description: 'Selector for Eclipse Che server resources',
Expand Down
10 changes: 5 additions & 5 deletions src/tasks/component-installers/cert-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ export class CertManagerTasks {
this.cheHelper = new CheHelper(flags)
}
/**
* Verify if cert-manager it is installed in cluster
* Verify if cert-manager is installed in cluster
*/
verifyCertManagerDeployment(flags: any): ReadonlyArray<Listr.ListrTask> {
getDeployCertManagerTasks(flags: any): ReadonlyArray<Listr.ListrTask> {
return [
{
title: 'Check Cert Manager deployment',
task: async (ctx: any, task: any) => {
// Check only one CRD of cert-manager assuming that it is installed or not.
ctx.certManagerInstalled = await this.kubeHelper.getNamespace(CERT_MANAGER_NAMESPACE_NAME) && await this.kubeHelper.crdExist('certificates.cert-manager.io')
ctx.certManagerInstalled = await this.kubeHelper.getNamespace(CERT_MANAGER_NAMESPACE_NAME) && await this.kubeHelper.isCrdV1Exists('certificates.cert-manager.io')
if (ctx.certManagerInstalled) {
task.title = `${task.title}...already deployed`
} else {
Expand Down Expand Up @@ -85,9 +85,9 @@ export class CertManagerTasks {
]
}
/**
* Returns list of tasks which perform cert-manager checks and deploy and requests self-signed certificate for Che.
* Returns list of tasks which perform cert-manager checks and requests self-signed certificate for Che.
*/
getTasks(flags: any): ReadonlyArray<Listr.ListrTask> {
getGenerateCertificatesTasks(flags: any): ReadonlyArray<Listr.ListrTask> {
return [
{
title: 'Check Cert Manager CA certificate',
Expand Down
Loading

0 comments on commit 400c99d

Please sign in to comment.