Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

fix: properly calculate servers capacity #120

Merged
merged 1 commit into from
Mar 25, 2022
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
fix: properly calculate servers capacity
Before `getAllocated` was returning just the count of servers, use
filter to count the amount of the servers `inUse`.
Also fix wording on the Kubernetes Upgrades page, when the list is
empty.

Signed-off-by: Artem Chernyshev <artem.chernyshev@talos-systems.com>
  • Loading branch information
Unix4ever committed Mar 25, 2022
commit 14ce0838845c92393be1530e626c56297b4ebcdf
13 changes: 10 additions & 3 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.

<script lang="ts">
import { ref, onMounted, watch } from "vue";
import { useRouter } from "vue-router";
import { useRouter, useRoute } from "vue-router";
// import Shell from "./components/Shell.vue";
// import SidebarChangeContext from "./views/SidebarChangeContext.vue";
// import Sidebar from "./views/Sidebar.vue";
Expand Down Expand Up @@ -78,6 +78,7 @@ export default {
const currentContext = ref("");
const selectContext = ref(false);
const router = useRouter();
const route = useRoute();

const updateTheme = (mode: string) => {
dark.value = isDark(mode);
Expand All @@ -99,7 +100,7 @@ export default {

connected.value = true;

await detectCapabilities();
await detectCapabilities(route);
});

updateTheme(theme.value);
Expand All @@ -108,8 +109,14 @@ export default {
updateTheme(val);
});

watch(() => route.query, (val, old) => {
if (val.cluster != old.cluster) {
detectCapabilities(route);
}
})

watch(context.current, (val, old) => {
if (val != old) detectCapabilities();
if (val != old) detectCapabilities(route);
});

watch(systemTheme, (val) => {
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export function changeContext(c: Object) {
context.current.value = c;
}

export function getContext() {
const route = useRoute();
export function getContext(route: any = null) {
route = route || useRoute();

const name = contextName();

Expand All @@ -56,7 +56,7 @@ export function contextName(): string | null {
return context.current.value ? context.current.value.name : null;
}

export async function detectCapabilities() {
export async function detectCapabilities(route) {
context.capabilities.capi.value = false;
context.capabilities.sidero.value = false;
context.capabilities.packet.value = false;
Expand All @@ -67,6 +67,8 @@ export async function detectCapabilities() {
await ResourceService.Get({
type: kubernetes.crd,
id: id,
}, {
context: getContext(route),
});

return true;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/Kubernetes/TKubernetesContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<div class="info__wrapper">
<t-icon class="info__icon" icon="upgrade-empty-state" />
<h3 class="info__title">
You have not yet updated the Kubernetes for this cluster
No kubernetes upgrades have yet been done
</h3>
<p class="info__subtitle">
After the update, information about it will appear here
Expand Down
22 changes: 11 additions & 11 deletions frontend/src/views/Servers/components/TServersContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ export default {
inputValue.value = data;
};

const getAllocated = () => {
return items?.value?.length;
};

const filteredItems = computed(() => {
const arr =
serversFilterOption.value !== TServersServersFilterOptions.ALL
Expand All @@ -109,21 +105,25 @@ export default {
return elem?.metadata?.uid?.includes(inputValue.value);
});
});

const allocated = computed(() => {
return (items?.value || []).filter((elem) => elem?.status?.inUse).length;
});

return {
setServersFilterOption,
setStatusesFilterOption,
setInputValue,
filteredItems,
TServersServersFilterOptions,
TServersStatusesFilterOptions,
allocated: computed(() => {
if (items.value.length === 0) return null;

return getAllocated();
}),
allocated: allocated,
capacity: computed(() => {
if (items.value.length === 0) return null;
return 100 - (getAllocated() / items.value.length) * 100 + "%";
if (items?.value?.length === 0) {
return null;
}

return 100 - (allocated.value / items.value.length) * 100 + "%";
}),
};
},
Expand Down