Skip to content

Commit

Permalink
Merge pull request #2944 from threefoldtech/development_fix_manage_mu…
Browse files Browse the repository at this point in the history
…ltiple_vms_deployment

Fix manage multiple vms deployment
  • Loading branch information
MohamedElmdary authored Jun 11, 2024
2 parents ad4143f + c83d078 commit 9fd76a5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 20 deletions.
4 changes: 3 additions & 1 deletion packages/playground/src/components/manage_gateway_dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ export default {
loadingGateways.value = true;
updateGrid(grid, { projectName: props.vm.projectName });
const { gateways: gws, failedToList } = await loadDeploymentGateways(grid!);
const { gateways: gws, failedToList } = await loadDeploymentGateways(grid!, {
filter: gw => gw.backends.some(bk => bk.includes(ip)),
});
gateways.value = gws;
failedToListGws.value = failedToList;
} catch (error) {
Expand Down
20 changes: 16 additions & 4 deletions packages/playground/src/utils/delete_deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { getSubdomain, loadDeploymentGateways } from "./gateway";
import { updateGrid } from "./grid";

export interface DeleteDeploymentOptions {
deploymentName?: string;
name: string;
projectName: ProjectName;
ip?: string;
k8s?: boolean;
}

Expand All @@ -25,7 +27,7 @@ export async function deleteDeployment(grid: GridClient, options: DeleteDeployme

/* For fvm/vm */
if (isVm(options.projectName)) {
await deleteVmGateways(grid);
await deleteVmGateways(grid, options.ip);
}

/* For solutions */
Expand All @@ -36,7 +38,15 @@ export async function deleteDeployment(grid: GridClient, options: DeleteDeployme
/* End Delete gateway */

/* Delete deployment */
return options.k8s ? grid.k8s.delete({ name: options.name }) : grid.machines.delete({ name: options.name });
if (options.k8s) {
return grid.k8s.delete({ name: options.name });
}

if (options.deploymentName) {
return grid.machines.delete_machine({ deployment_name: options.deploymentName, name: options.name });
}

return grid.machines.delete({ name: options.name });
}

export async function deleteDeploymentGateway(grid: GridClient, options: DeleteDeploymentOptions) {
Expand Down Expand Up @@ -93,8 +103,10 @@ function isVm(projectName: string) {
return false;
}

async function deleteVmGateways(grid: GridClient) {
const { gateways } = await loadDeploymentGateways(grid);
async function deleteVmGateways(grid: GridClient, ip?: string) {
const { gateways } = await loadDeploymentGateways(grid, {
filter: ip ? gw => gw.backends.some(bk => bk.includes(ip)) : undefined,
});
for (const gateway of gateways) {
try {
if (gateway.type.includes("name")) {
Expand Down
16 changes: 14 additions & 2 deletions packages/playground/src/utils/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ export async function rollbackDeployment(grid: GridClient, name: string) {
}

export type GridGateway = Awaited<ReturnType<GridClient["gateway"]["getObj"]>>[0];
export async function loadDeploymentGateways(grid: GridClient) {
interface LoadDeploymentGatewaysOptions {
filter?: (gateway: GridGateway) => boolean;
}

export async function loadDeploymentGateways(grid: GridClient, options?: LoadDeploymentGatewaysOptions) {
const failedToList: string[] = [];
const gws = await grid.gateway.list();
const items = await Promise.all(
Expand All @@ -97,5 +101,13 @@ export async function loadDeploymentGateways(grid: GridClient) {
.finally(() => timeout && clearTimeout(timeout));
}),
);
return { gateways: items.flat().filter(Boolean) as GridGateway[], failedToList };

const filter = options?.filter ?? (() => true);
return {
gateways: items
.flat()
.filter(Boolean)
.filter(filter as any) as GridGateway[],
failedToList,
};
}
28 changes: 15 additions & 13 deletions packages/playground/src/weblets/tf_deployment_list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
@click="openDialog(tabs[activeTab].value, item)"
/>

<IconActionBtn icon="mdi-cog" tooltip="Manage Domains" @click="dialog = item.deploymentName" />
<IconActionBtn icon="mdi-cog" tooltip="Manage Domains" @click="dialog = item.name" />

<ManageGatewayDialog v-if="dialog === item.deploymentName" :vm="item" @close="dialog = undefined" />
<ManageGatewayDialog v-if="dialog === item.name" :vm="item" @close="dialog = undefined" />
</template>

<template #VM-actions="{ item }">
Expand All @@ -42,10 +42,10 @@
icon="mdi-cog"
tooltip="Manage Domains"
:disabled="item.fromAnotherClient"
@click="dialog = item.deploymentName"
@click="dialog = item.name"
/>

<ManageGatewayDialog v-if="dialog === item.deploymentName" :vm="item" @close="dialog = undefined" />
<ManageGatewayDialog v-if="dialog === item.name" :vm="item" @close="dialog = undefined" />
</template>

<template #CapRover-actions="{ item, update }">
Expand All @@ -60,10 +60,10 @@
icon="mdi-view-dashboard"
:href="'http://captain.' + item.env.CAPROVER_ROOT_DOMAIN"
/>
<IconActionBtn icon="mdi-cog" tooltip="Manage Workers" @click="dialog = item.deploymentName" />
<IconActionBtn icon="mdi-cog" tooltip="Manage Workers" @click="dialog = item.name" />

<ManageCaproverWorkerDialog
v-if="dialog === item.deploymentName"
v-if="dialog === item.name"
:master="item"
:data="item.workers || []"
:project-name="item.projectName"
Expand Down Expand Up @@ -317,11 +317,11 @@
icon="mdi-cog"
:disabled="item.fromAnotherClient"
tooltip="Manage Workers"
@click="dialog = item.deploymentName"
@click="dialog = item.name"
/>
<ManageK8SWorkerDialog
v-if="dialog === item.deploymentName"
v-if="dialog === item.name"
:data="item"
@close="dialog = undefined"
@update:k8s="item.workers = $event.workers"
Expand Down Expand Up @@ -349,8 +349,8 @@
<strong>Delete the following deployments?</strong>
</v-card-title>
<v-card-text>
<v-chip class="ma-1" v-for="item in selectedItems" :key="item.deploymentName">
{{ item.deploymentName }}
<v-chip class="ma-1" v-for="item in selectedItems" :key="item.name">
{{ item.name }}
</v-chip>
<v-divider />
</v-card-text>
Expand Down Expand Up @@ -421,17 +421,19 @@ async function onDelete(k8s = false) {
for (const item of selectedItems.value) {
try {
await deleteDeployment(updateGrid(grid!, { projectName: item.projectName }), {
name: item.deploymentName,
deploymentName: item.deploymentName,
name: k8s ? item.deploymentName : item.name,
projectName: item.projectName,
ip: item.interfaces?.[0]?.ip,
k8s,
});
} catch (e: any) {
createCustomToast(`Failed to delete deployment with name: ${item.deploymentName}`, ToastType.danger);
createCustomToast(`Failed to delete deployment with name: ${item.name}`, ToastType.danger);
console.log("Error while deleting deployment", e.message);
continue;
}
table.value?.loadDeployments();
}
table.value?.loadDeployments();
} catch (e) {
createCustomToast((e as Error).message, ToastType.danger);
} finally {
Expand Down

0 comments on commit 9fd76a5

Please sign in to comment.