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

Fix: CapRover Dashboard App: Details of Workers disappear after few seconds #3363

Merged
merged 18 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
f8aeaa2
chore: Build the grafana URL on mount.
Mahmoud-Emad Sep 3, 2024
2f54d6d
Merge branch 'development' of https://github.com/threefoldtech/tfgrid…
Mahmoud-Emad Sep 3, 2024
7cf41c2
fix: Fix an issue with loading Grafana URL
Mahmoud-Emad Sep 3, 2024
b70ee99
fix: Fix the listing issue:
Mahmoud-Emad Sep 3, 2024
ebd4a89
feat: Enhance Deletion of Caprover Cluster:
Mahmoud-Emad Sep 4, 2024
0f1d968
fix: Use `map.some()` instead of map.length.
Mahmoud-Emad Sep 4, 2024
6632441
Merge branch 'development' into development_caprover
Mahmoud-Emad Sep 16, 2024
52837dd
Merge branch 'development' into development_caprover
Mahmoud-Emad Sep 22, 2024
c0367be
fix: Fix listing Caprover:
Mahmoud-Emad Sep 22, 2024
cf7fc34
Merge branch 'development' into development_caprover
Mahmoud-Emad Sep 24, 2024
76a10fb
Merge branch 'development' of https://github.com/threefoldtech/tfgrid…
Mahmoud-Emad Sep 25, 2024
4336eb6
fix: Fix deleting Caprover cluster:
Mahmoud-Emad Sep 26, 2024
19dc37c
fix: Check if there is a project name before getting its data.
Mahmoud-Emad Sep 26, 2024
66764cf
Merge branch 'development' into development_caprover
Mahmoud-Emad Sep 29, 2024
546a9db
fix: Use console.error instead of console.log
Mahmoud-Emad Sep 29, 2024
d1a7abe
Merge branch 'development' of https://github.com/threefoldtech/tfgrid…
Mahmoud-Emad Oct 1, 2024
a1fc267
Merge branch 'development' into development_caprover
Mahmoud-Emad Oct 17, 2024
b781475
fix: Remove workers from the deployment list of the leader deleted
Mahmoud-Emad Oct 17, 2024
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 @@ -9,7 +9,6 @@
<v-btn> JSON</v-btn>
</v-btn-toggle>
</div>

<v-tabs v-model="activeTab" align-tabs="center" class="my-4 mx-auto" v-if="showType === 0">
<v-tab
v-for="(item, index) in contracts"
Expand Down Expand Up @@ -228,7 +227,8 @@ async function getGrafanaUrl() {
}
isLoading.value = false;
}
getGrafanaUrl();

onMounted(async () => await getGrafanaUrl());

async function getGPUInfo() {
loadingCard.value = true;
Expand Down Expand Up @@ -320,6 +320,7 @@ function getTooltipText(contract: any, index: number) {

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

import { ContractType } from "@/utils/contracts";
import { createCustomToast, ToastType } from "@/utils/custom_toast";
Expand All @@ -339,4 +340,3 @@ export default {
},
};
</script>
@/utils/get_metrics_url
131 changes: 100 additions & 31 deletions packages/playground/src/weblets/tf_deployment_list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,19 @@
<strong>Delete the following deployments?</strong>
</v-card-title>
<v-card-text>
<v-chip class="ma-1" v-for="item in selectedItems" :key="item.name">
{{ item.name }}
</v-chip>
<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-divider />
</v-card-text>
<v-card-actions class="justify-end my-1 mr-2">
Expand All @@ -414,7 +424,7 @@
</template>

<script lang="ts" setup>
import { getCurrentInstance, onUnmounted, type Ref, ref, watch } from "vue";
import { computed, 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 @@ -464,53 +474,112 @@ 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 _idx = tabs.findIndex(t => t.value === props.projectName);
const activeTab = ref(!props.projectName ? 0 : _idx) as Ref<number>;
watch(activeTab, () => (selectedItems.value = []));

async function onDelete(k8s = false) {
try {
prepareForDeletion();
await processSelectedItems(k8s);
refreshDeployments();
} catch (e) {
handleError(e);
} finally {
finalizeDeletion();
}
}

function prepareForDeletion() {
deletingDialog.value = false;
deleting.value = true;
}

async function processSelectedItems(k8s: boolean) {
const itemsToDelete = getAllItemsToDelete();

for (const item of itemsToDelete) {
await deleteItem(item, k8s);
}
}

function getAllItemsToDelete() {
const itemsToDelete = [...selectedItems.value];

selectedItems.value.forEach(item => {
if (item?.projectName.toLowerCase().includes(ProjectName.Caprover.toLowerCase())) {
itemsToDelete.push(...item.workers);
}
});

return itemsToDelete;
}

async function deleteItem(item: any, k8s: boolean) {
try {
for (const item of selectedItems.value) {
try {
if (props.projectName?.toLowerCase() === ProjectName.Domains.toLowerCase()) {
await deleteGatewayDeployment(
updateGrid(grid, { projectName: props.projectName.toLocaleLowerCase() }),
item[0].workloads[0].name as string,
);
} else {
await deleteDeployment(updateGrid(grid!, { projectName: item.projectName }), {
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.name}`, ToastType.danger);
console.log("Error while deleting deployment", e.message);
continue;
}
if (isDomainProject()) {
await deleteDomainProject(item);
} else {
await deleteStandardItem(item, k8s);
}
table.value?.loadDeployments();
} catch (e) {
createCustomToast((e as Error).message, ToastType.danger);
} finally {
selectedItems.value = [];
deleting.value = false;
} catch (e: any) {
logDeletionError(item.name, e);
}
}
zaelgohary marked this conversation as resolved.
Show resolved Hide resolved

function isDomainProject() {
return props.projectName?.toLowerCase() === ProjectName.Domains.toLowerCase();
}

async function deleteDomainProject(item: any) {
await deleteGatewayDeployment(
updateGrid(grid, { projectName: props.projectName!.toLowerCase() }),
item.workloads[0].name as string,
);
}

async function deleteStandardItem(item: any, k8s: boolean) {
await deleteDeployment(updateGrid(grid!, { projectName: item.projectName }), {
deploymentName: item.deploymentName,
name: k8s ? item.deploymentName : item.name,
projectName: item.projectName,
ip: item.interfaces?.[0]?.ip,
k8s,
});
}

function logDeletionError(itemName: string, error: any) {
createCustomToast(`Failed to delete deployment with name: ${itemName}`, ToastType.danger);
console.error("Error while deleting deployment", error.message);
}

function refreshDeployments() {
table.value?.loadDeployments();
}

function handleError(e: any) {
createCustomToast((e as Error).message, ToastType.danger);
}

function finalizeDeletion() {
selectedItems.value = [];
deleting.value = false;
}

const VMS: string[] = [ProjectName.Fullvm, ProjectName.VM, ProjectName.NodePilot];
function openDialog(project: string, item?: any): void {
const key: keyof typeof deploymentListEnvironments = VMS.includes(project)
? "vm"
: project === ProjectName.Kubernetes
? "k8s"
: (project.toLowerCase() as any);

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

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

Expand Down
Loading