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

Ignore default components when a devfile references a parent #773

Merged
merged 1 commit into from
Apr 11, 2023
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
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