Skip to content

Commit 7a1e79d

Browse files
ci: [sync] Push chectl @ main to devspaces-chectl @ devspaces-3-rhel-8
Signed-off-by: devstudio-release <[email protected]>
1 parent da62580 commit 7a1e79d

File tree

5 files changed

+75
-3
lines changed

5 files changed

+75
-3
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dsc",
3-
"version": "3.6.0-CI-6d1f-redhat",
3+
"version": "3.6.0-CI-redhat",
44
"description": "Red Hat OpenShift Dev Spaces CLI",
55
"keywords": [
66
"oclif"

src/commands/server/deploy.ts

+31-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import { Command, flags } from '@oclif/command'
1414
import { cli } from 'cli-ux'
1515
import { CertManagerInstaller } from '../../tasks/installers/cert-manager-installer'
16-
import {CheCtlContext, InfrastructureContext } from '../../context'
16+
import {CheCtlContext, InfrastructureContext} from '../../context'
1717
import { KubeClient } from '../../api/kube-client'
1818
import { DEFAULT_ANALYTIC_HOOK_NAME } from '../../constants'
1919
import { DexInstaller } from '../../tasks/installers/dex-installer'
@@ -92,6 +92,7 @@ import {
9292
import {CommonTasks} from '../../tasks/common-tasks'
9393
import {CheTasks} from '../../tasks/che-tasks'
9494
import {newListr} from '../../utils/utls'
95+
import {Che} from '../../utils/che'
9596

9697
export default class Deploy extends Command {
9798
static description = `Deploy ${EclipseChe.PRODUCT_NAME} server`
@@ -143,6 +144,19 @@ export default class Deploy extends Command {
143144
}
144145

145146
if (!ctx[InfrastructureContext.IS_OPENSHIFT]) {
147+
// Ensure required CheCluster fields are set (k8s platforms)
148+
if (flags[PLATFORM_FLAG] !== 'minikube') {
149+
for (const field of [
150+
'spec.networking.auth.identityProviderURL',
151+
'spec.networking.auth.oAuthSecret',
152+
'spec.networking.auth.oAuthClientName',
153+
]) {
154+
if (!Che.getCheClusterFieldConfigured(field)) {
155+
this.error(getMissedOIDCConfigClusterFieldErrorMsg())
156+
}
157+
}
158+
}
159+
146160
// Not OLM installer
147161
if (flags[STARTING_CSV_FLAG]) {
148162
this.error(`--${STARTING_CSV_FLAG} flag should be used only for OpenShift platform.`)
@@ -241,3 +255,19 @@ function getNamespaceLabels(flags: any): any {
241255
return {}
242256
}
243257

258+
function getMissedOIDCConfigClusterFieldErrorMsg(): string {
259+
return `Some required configuration is not specifed in order to deploy ${EclipseChe.PRODUCT_NAME}
260+
on a Kubernetes cluster with an OIDC provider configured. Use the flag '--${CHE_OPERATOR_CR_PATCH_YAML_FLAG} <PATH_TO_PATCH_FILE>' to
261+
provide a CheCluster Custom Resource patch with the needed configuration. Find an example of such a configuration below:
262+
263+
kind: CheCluster
264+
apiVersion: org.eclipse.che/v2
265+
spec:
266+
networking:
267+
auth:
268+
oAuthClientName: "<CLIENT_ID>"
269+
oAuthSecret: "<CLIENT_SECRET>"
270+
identityProviderURL: "<ISSUER_URL>"
271+
272+
`
273+
}

src/utils/che.ts

+17
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ export namespace Che {
4747
return EclipseChe.CHE_TLS_SECRET_NAME
4848
}
4949

50+
export function getCheClusterFieldConfigured(fieldPath: string): any | undefined {
51+
const ctx = CheCtlContext.get()
52+
53+
const cheClusterPatch = ctx[EclipseCheContext.CR_PATCH]
54+
const cheCluster = ctx[EclipseCheContext.CUSTOM_CR] || ctx[EclipseCheContext.DEFAULT_CR]
55+
56+
for (const cr of [cheClusterPatch, cheCluster]) {
57+
const fieldValue = fieldPath.split('.').reduce((acc, prop) => {
58+
return acc?.[prop]
59+
}, cr)
60+
61+
if (fieldValue !== undefined) {
62+
return fieldValue
63+
}
64+
}
65+
}
66+
5067
export async function getCheVersion(): Promise<string> {
5168
const kubeHelper = KubeClient.getInstance()
5269
const flags = CheCtlContext.getFlags()

test/other/util.test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import { expect, fancy } from 'fancy-test'
1414
import {getImageNameAndTag} from '../../src/utils/utls'
15+
import {Che} from '../../src/utils/che'
16+
import {CheCtlContext, EclipseCheContext} from '../../src/context'
1517

1618
describe('Util tests', () => {
1719
describe('Test getImageNameAndTag', () => {
@@ -40,4 +42,27 @@ describe('Util tests', () => {
4042
})
4143
})
4244

45+
describe('Test getCheClusterFieldConfigured', () => {
46+
// test data format: full image reference, image repository, tag
47+
const data = [
48+
[{spec: {networking: {auth: {identityProviderURL: 'url'}}}}, 'spec.networking.auth.identityProviderURL', 'url'],
49+
[{spec: {networking: {auth: {identityProviderURL: ''}}}}, 'spec.networking.auth.identityProviderURL', ''],
50+
[{spec: {networking: {auth: {}}}}, 'spec.networking.auth.identityProviderURL', undefined],
51+
]
52+
fancy.it('Should get field value', async () => {
53+
for (const testCaseData of data) {
54+
const crPatch = testCaseData[0]
55+
const fieldPath = testCaseData[1] as string
56+
const expectedFieldValue = testCaseData[2]
57+
58+
const ctx = await CheCtlContext.get()
59+
ctx[EclipseCheContext.CR_PATCH] = crPatch
60+
61+
const actualFieldValue = Che.getCheClusterFieldConfigured(fieldPath)
62+
63+
expect(actualFieldValue).to.equal(expectedFieldValue)
64+
}
65+
})
66+
})
67+
4368
})

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -2456,7 +2456,7 @@ detect-newline@^3.0.0:
24562456

24572457
"devspaces-operator@https://github.com/redhat-developer/devspaces-images#devspaces-3-rhel-8":
24582458
version "0.0.0"
2459-
resolved "https://github.com/redhat-developer/devspaces-images#9139b4206a2c845dd805814f658ab9f0f66673d5"
2459+
resolved "https://github.com/redhat-developer/devspaces-images#dd0d403dacb9dd3f10559b7edc836c419e90f35f"
24602460

24612461
"devworkspace-operator@https://github.com/devfile/devworkspace-operator#main":
24622462
version "0.0.0"

0 commit comments

Comments
 (0)