Skip to content
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
19 changes: 8 additions & 11 deletions src/odo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class Command {
static listCatalogServicesJson () {
return `${Command.listCatalogServices()} -o json`;
}
static listStorageNames(project: string, app: string, component: string) {
static listStorageNames() {
return `odo storage list -o json`;
}
static printOcVersion() {
Expand Down Expand Up @@ -141,11 +141,11 @@ export class Command {
return `odo login ${clusterURL} --token=${ocToken} --insecure-skip-tls-verify`;
}
@verbose
static createStorage(project: string, app: string, component: string, storageName: string, mountPath: string, storageSize: string) {
return `odo storage create ${storageName} --path=${mountPath} --size=${storageSize} --project ${project} --app ${app} --component ${component}`;
static createStorage(storageName: string, mountPath: string, storageSize: string) {
return `odo storage create ${storageName} --path=${mountPath} --size=${storageSize}}`;
}
static deleteStorage(project: string, app: string, component: string, storage: string) {
return `odo storage delete ${storage} -f --project ${project} --app ${app} --component ${component}`;
static deleteStorage(storage: string) {
return `odo storage delete ${storage} -f`;
}
static waitForStorageToBeGone(project: string, app: string, storage: string) {
return `oc wait pvc/${storage}-${app}-pvc --for=delete --namespace ${project}`;
Expand Down Expand Up @@ -761,10 +761,7 @@ export class OdoImpl implements Odo {
}

public async _getStorageNames(component: OpenShiftObject): Promise<OpenShiftObject[]> {
const app = component.getParent();
const appName = app.getName();
const projName = app.getParent().getName();
const result: cliInstance.CliExitData = await this.execute(Command.listStorageNames(projName, appName, component.getName()), component.contextPath ? component.contextPath.fsPath : Platform.getUserHomePath());
const result: cliInstance.CliExitData = await this.execute(Command.listStorageNames(), component.contextPath ? component.contextPath.fsPath : Platform.getUserHomePath());
return this.loadItems(result).map<OpenShiftObject>((value) => new OpenShiftObjectImpl(component, value.metadata.name, ContextType.STORAGE, false, OdoImpl.instance, TreeItemCollapsibleState.None));
}

Expand Down Expand Up @@ -1022,13 +1019,13 @@ export class OdoImpl implements Odo {
}

public async createStorage(component: OpenShiftObject, name: string, mountPath: string, size: string): Promise<OpenShiftObject> {
await this.execute(Command.createStorage(component.getParent().getParent().getName(), component.getParent().getName(), component.getName(), name, mountPath, size), component.contextPath.fsPath);
await this.execute(Command.createStorage(name, mountPath, size), component.contextPath.fsPath);
return this.insertAndReveal(new OpenShiftObjectImpl(component, name, ContextType.STORAGE, false, this, TreeItemCollapsibleState.None));
}

public async deleteStorage(storage: OpenShiftObject): Promise<OpenShiftObject> {
const component = storage.getParent();
await this.execute(Command.deleteStorage(component.getParent().getParent().getName(), component.getParent().getName(), component.getName(), storage.getName()), component.contextPath.fsPath);
await this.execute(Command.deleteStorage(storage.getName()), component.contextPath.fsPath);
await this.execute(Command.waitForStorageToBeGone(storage.getParent().getParent().getParent().getName(), storage.getParent().getParent().getName(), storage.getName()), process.cwd(), false);
return this.deleteAndRefresh(storage);
}
Expand Down
2 changes: 1 addition & 1 deletion src/openshift/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ export class Component extends OpenShiftItem {
const pvcJson = JSON.parse(pvcResult.stdout);
const storageName = pvcJson.metadata.labels['app.kubernetes.io/storage-name'];
const size = pvcJson.spec.resources.requests.storage;
await Component.odo.execute(Command.createStorage(prjName, appName, compName, storageName, storage.mountPath, size), workspaceFolder.fsPath);
await Component.odo.execute(Command.createStorage(storageName, storage.mountPath, size), workspaceFolder.fsPath);
} catch (ignore) {
// means there is no storage attached to component
}
Expand Down
6 changes: 3 additions & 3 deletions test/unit/openshift/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ suite('OpenShift/Storage', () => {
const result = await Storage.create(componentItem);

expect(result).equals(`Storage '${storageItem.getName()}' successfully created for Component '${componentItem.getName()}'`);
expect(execStub).calledOnceWith(Command.createStorage(projectItem.getName(), appItem.getName(), componentItem.getName(), storageItem.getName(), mountPath, size));
expect(execStub).calledOnceWith(Command.createStorage(storageItem.getName(), mountPath, size));
});

test('returns null when no storage name selected', async () => {
Expand Down Expand Up @@ -306,15 +306,15 @@ suite('OpenShift/Storage', () => {
const result = await Storage.del(storageItem);

expect(result).equals(`Storage '${storageItem.getName()}' from Component '${componentItem.getName()}' successfully deleted`);
expect(execStub.getCall(0).args[0]).equals(Command.deleteStorage(projectItem.getName(), appItem.getName(), componentItem.getName(), storageItem.getName()));
expect(execStub.getCall(0).args[0]).equals(Command.deleteStorage(storageItem.getName()));
expect(execStub.getCall(1).args[0]).equals(Command.waitForStorageToBeGone(projectItem.getName(), appItem.getName(), storageItem.getName()));
});

test('works without set tree item', async () => {
const result = await Storage.del(null);

expect(result).equals(`Storage '${storageItem.getName()}' from Component '${componentItem.getName()}' successfully deleted`);
expect(execStub.getCall(0).args[0]).equals(Command.deleteStorage(projectItem.getName(), appItem.getName(), componentItem.getName(), storageItem.getName()));
expect(execStub.getCall(0).args[0]).equals(Command.deleteStorage(storageItem.getName()));
expect(execStub.getCall(1).args[0]).equals(Command.waitForStorageToBeGone(projectItem.getName(), appItem.getName(), storageItem.getName()));
});

Expand Down