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

delete vm deployment with its all gateway #3541

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 3 additions & 3 deletions packages/playground/src/utils/delete_deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface DeleteDeploymentOptions {
deploymentName?: string;
name: string;
projectName: ProjectName;
ip?: string;
ip?: string[];
k8s?: boolean;
}

Expand Down Expand Up @@ -117,9 +117,9 @@ function isVm(projectName: string) {
return false;
}

async function deleteVmGateways(grid: GridClient, ip?: string) {
async function deleteVmGateways(grid: GridClient, ips?: string[]) {
const { gateways } = await loadDeploymentGateways(grid, {
filter: ip ? gw => gw.backends.some(bk => bk.includes(ip)) : undefined,
filter: ips ? gw => gw.backends.some(bk => ips.some(ip => bk.includes(ip))) : undefined,
});
for (const gateway of gateways) {
try {
Expand Down
83 changes: 34 additions & 49 deletions packages/playground/src/weblets/tf_deployment_list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,12 @@
@click="openDialog(tabs[activeTab].value, item)"
/>
<IconActionBtn
v-if="isCaproverLeader(item)"
tooltip="Admin Panel"
color="anchor"
icon="mdi-view-dashboard"
:href="'http://captain.' + item.env.CAPROVER_ROOT_DOMAIN"
/>
<IconActionBtn
v-if="isCaproverLeader(item)"
icon="mdi-cog"
tooltip="Manage Workers"
@click="dialog = item.name"
/>
<IconActionBtn icon="mdi-cog" tooltip="Manage Workers" @click="dialog = item.name" />

<ManageCaproverWorkerDialog
v-if="dialog === item.name"
Expand Down Expand Up @@ -416,19 +410,9 @@
<strong>Delete the following deployments?</strong>
</v-card-title>
<v-card-text>
<template v-if="hasWorkers">
<v-alert type="warning">Please note that: This deployment contains workers workloads.</v-alert>
</template>
<template v-for="item in selectedItems" :key="item.name">
<template v-if="item.workers">
<v-chip class="ma-3" v-for="worker in item.workers" :key="worker.name">
{{ worker.name }}
</v-chip>
</template>
<v-chip class="ma-3">
{{ item.name }}
</v-chip>
</template>
<v-chip class="ma-1" v-for="item in selectedItems" :key="item.name">
{{ item.name }}
</v-chip>
<v-divider />
</v-card-text>
<v-card-actions class="justify-end my-1 mr-2">
Expand All @@ -440,7 +424,7 @@
</template>

<script lang="ts" setup>
import { computed, getCurrentInstance, onUnmounted, type Ref, ref, watch } from "vue";
import { getCurrentInstance, onUnmounted, type Ref, ref, watch } from "vue";

import type { Tab } from "../components/dynamic_tabs.vue";
import { useLayout } from "../components/weblet_layout.vue";
Expand Down Expand Up @@ -492,8 +476,6 @@ const deletingDialog = ref(false);
const table = ref() as Ref<{ loadDeployments(): void }>;
const gridStore = useGrid();
const grid = gridStore.client as GridClient;
const hasWorkers = computed(() => selectedItems.value.map(item => item.workers && item.workers.length).some(i => i));
const isCaproverLeader = (vm: ZmachineData) => vm.env["SWM_NODE_MODE"] === "leader";

const _idx = tabs.findIndex(t => t.value === props.projectName);
const activeTab = ref(!props.projectName ? 0 : _idx) as Ref<number>;
Expand All @@ -502,22 +484,12 @@ watch(activeTab, () => (selectedItems.value = []));
async function onDelete(k8s = false) {
deletingDialog.value = false;
deleting.value = true;

try {
const projectNameLower = props.projectName?.toLowerCase();
const allSelectedItems = [...selectedItems.value];
selectedItems.value.forEach(item => {
if (item.projectName.toLowerCase().includes(ProjectName.Caprover.toLowerCase()) && item.workers) {
allSelectedItems.push(...item.workers);
}
});

await allSelectedItems.reduce(async (acc, item) => {
await acc;
for (const item of selectedItems.value) {
try {
if (projectNameLower === ProjectName.Domains.toLowerCase()) {
if (props.projectName?.toLowerCase() === ProjectName.Domains.toLowerCase()) {
await deleteGatewayDeployment(
updateGrid(grid, { projectName: projectNameLower }),
updateGrid(grid, { projectName: props.projectName.toLocaleLowerCase() }),
item[0].workloads[0].name as string,
);
} else {
Expand All @@ -531,10 +503,10 @@ async function onDelete(k8s = false) {
}
} catch (e: any) {
createCustomToast(`Failed to delete deployment with name: ${item.name}`, ToastType.danger);
console.error("Error while deleting deployment", e.message);
console.log("Error while deleting deployment", e.message);
continue;
}
}, Promise.resolve());

}
table.value?.loadDeployments();
} catch (e) {
createCustomToast((e as Error).message, ToastType.danger);
Expand All @@ -551,15 +523,6 @@ function openDialog(project: string, item?: any): void {
: project === ProjectName.Kubernetes
? "k8s"
: (project.toLowerCase() as any);

if (item && item.projectName && item.projectName.includes(ProjectName.Caprover.toLocaleLowerCase())) {
if (!item.workers) {
item = [item];
} else {
item = [item, ...item.workers];
}
}

layout.value.openDialog(item, deploymentListEnvironments[key]);
}

Expand All @@ -576,10 +539,32 @@ deploymentListManager?.register(uid, () => {
});

onUnmounted(() => deploymentListManager?.unregister(uid));
/**
* Collect the deployment interfaces ips
* @param item deployment data
* @returns {string[]} list of strings
*/
function getDeploymentIps(item: any): string[] {
const ips = [];
// wg ip
if (item.interfaces) {
for (const iface of item.interfaces) {
if (iface.ip) ips.push(iface.ip);
}
}
// public ip, ipv6
if (item.publicIP) {
if (item.publicIP.ip) ips.push(item.publicIP.ip.split("/")[0]);
if (item.publicIP.ip6) ips.push(item.publicIP.ip6.split("/")[0]);
}
if (item.planetary) ips.push(item.planetary);
if (item.myceliumIP) ips.push(item.myceliumIP);
return ips;
}
</script>

<script lang="ts">
import type { GridClient, ZmachineData } from "@threefold/grid_client";
import type { GridClient } from "@threefold/grid_client";

import { useDeploymentListManager } from "../components/deployment_list_manager.vue";
import IconActionBtn from "../components/icon_action_btn.vue";
Expand Down
Loading