From f68ae41542da2b2d8465272c31b14014e14ad4ff Mon Sep 17 00:00:00 2001 From: Oleksii Orel Date: Mon, 10 Apr 2023 16:12:02 +0300 Subject: [PATCH] feat: ignore default components when a devfile references a parent Signed-off-by: Oleksii Orel --- .../__tests__/normalizeDevfileV2.spec.ts | 46 +++++++++++++++---- .../FactoryResolver/normalizeDevfileV2.ts | 24 +++++----- 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/packages/dashboard-frontend/src/store/FactoryResolver/__tests__/normalizeDevfileV2.spec.ts b/packages/dashboard-frontend/src/store/FactoryResolver/__tests__/normalizeDevfileV2.spec.ts index 23928321a..d6d94f4c4 100644 --- a/packages/dashboard-frontend/src/store/FactoryResolver/__tests__/normalizeDevfileV2.spec.ts +++ b/packages/dashboard-frontend/src/store/FactoryResolver/__tests__/normalizeDevfileV2.spec.ts @@ -29,7 +29,7 @@ describe('Normalize Devfile V2', () => { ]; }); - it('should not apply defaultComponents', () => { + it('should not apply defaultComponents if components exist', () => { const devfileLike = { schemaVersion: '2.1.0', metadata: { @@ -66,21 +66,49 @@ describe('Normalize Devfile V2', () => { ); }); - it('should apply defaultComponents', () => { + it('should not apply defaultComponents if parent exist', () => { const devfileLike = { schemaVersion: '2.1.0', metadata: { generateName: 'empty', }, + parent: { + id: 'java-maven', + registryUrl: 'https://registry.devfile.io/', + version: '1.2.0', + }, + components: [], } as devfileApi.DevfileLike; - const defaultComponents = [ - { - container: { - image: 'quay.io/devfile/universal-developer-image:latest', - }, - name: 'universal-developer-image', + + const targetDevfile = normalizeDevfileV2( + devfileLike, + {} as FactoryResolver, + 'http://dummy-registry/devfiles/empty.yaml', + defaultComponents, + 'che', + {}, + ); + + expect(targetDevfile).not.toEqual( + expect.objectContaining({ + components: defaultComponents, + }), + ); + expect(targetDevfile).toEqual( + expect.objectContaining({ + components: devfileLike.components, + }), + ); + }); + + it('should apply defaultComponents', () => { + const devfileLike = { + schemaVersion: '2.1.0', + metadata: { + generateName: 'empty', }, - ] as V220DevfileComponents[]; + components: [], + } as devfileApi.DevfileLike; const targetDevfile = normalizeDevfileV2( devfileLike, diff --git a/packages/dashboard-frontend/src/store/FactoryResolver/normalizeDevfileV2.ts b/packages/dashboard-frontend/src/store/FactoryResolver/normalizeDevfileV2.ts index fc5e24f1a..80a42b09b 100644 --- a/packages/dashboard-frontend/src/store/FactoryResolver/normalizeDevfileV2.ts +++ b/packages/dashboard-frontend/src/store/FactoryResolver/normalizeDevfileV2.ts @@ -59,21 +59,23 @@ export default function normalizeDevfileV2( devfile.metadata.namespace = namespace; // propagate default components - if (!devfile.components || devfile.components.length === 0) { + if (!devfile.parent && (!devfile.components || devfile.components.length === 0)) { devfile.components = cloneDeep(defaultComponents); } - // apply the custom image from factory params - if (factoryParams.image && devfile.components[0].container?.image) { - devfile.components[0].container.image = factoryParams.image; - } - - // temporary solution for fix che-server serialization bug with empty volume - devfile.components.forEach(component => { - if (Object.keys(component).length === 1 && component.name) { - component.volume = {}; + if (devfile.components && devfile.components.length > 0) { + // apply the custom image from factory params + if (factoryParams.image && devfile.components[0].container?.image) { + devfile.components[0].container.image = factoryParams.image; } - }); + + // temporary solution for fix che-server serialization bug with empty volume + devfile.components.forEach(component => { + if (Object.keys(component).length === 1 && component.name) { + component.volume = {}; + } + }); + } // add a default project const projects: DevfileV2ProjectSource[] = [];