Skip to content

Commit

Permalink
fix: managePvcStrategy method
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <[email protected]>
  • Loading branch information
olexii4 committed Nov 24, 2023
1 parent 249c8ef commit 6589ae6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,30 @@ describe('DevWorkspace client, managePvcStrategy', () => {
]);
});

it('should add attributes with devWorkspace config', async () => {
const devWorkspace = devWorkspaceBuilder
.withSpec({
template: {},
})
.build();
const config = {
defaults: {},
cheNamespace: namespace,
} as api.IServerConfig;

await client.managePvcStrategy(devWorkspace, config);

expect(spyPatchWorkspace).toHaveBeenCalledWith(namespace, name, [
{
op: 'add',
path: '/spec/template/attributes',
value: {
[DEVWORKSPACE_CONFIG_ATTR]: { name: 'devworkspace-config', namespace: 'user-che' },
},
},
]);
});

it('should update devWorkspace storage type', async () => {
const devWorkspace = devWorkspaceBuilder
.withSpec({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,15 +458,19 @@ export class DevWorkspaceClient {
const cheNamespace = config.cheNamespace;
let attributes = workspace.spec.template.attributes;
if (cheNamespace) {
if (attributes?.[DEVWORKSPACE_CONFIG_ATTR] === undefined) {
const devworkspaceConfig = { name: 'devworkspace-config', namespace: cheNamespace };
const devworkspaceConfigPath = `/spec/template/attributes/${this.escape(
DEVWORKSPACE_CONFIG_ATTR,
)}`;
const devworkspaceConfig = { name: 'devworkspace-config', namespace: cheNamespace };
const devworkspaceConfigPath = `/spec/template/attributes/${this.escape(
DEVWORKSPACE_CONFIG_ATTR,
)}`;
if (attributes) {
if (!attributes[DEVWORKSPACE_CONFIG_ATTR]) {
patch.push({ op: 'add', path: devworkspaceConfigPath, value: devworkspaceConfig });
}
} else {
patch.push({
op: 'add',
path: devworkspaceConfigPath,
value: devworkspaceConfig,
path: '/spec/template/attributes',
value: { [DEVWORKSPACE_CONFIG_ATTR]: devworkspaceConfig },
});
attributes = {};
}
Expand Down

0 comments on commit 6589ae6

Please sign in to comment.