Skip to content

Commit

Permalink
feat: ignore default components when a devfile references a parent
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <oorel@redhat.com>
  • Loading branch information
olexii4 committed Apr 10, 2023
1 parent 5475ca2 commit f68ae41
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down

0 comments on commit f68ae41

Please sign in to comment.