-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds pods to pvc view, make swagger more discoverable (#271)
Co-authored-by: Tristan Holaday <40547442+TristanHoladay@users.noreply.github.com>
- Loading branch information
1 parent
9875e62
commit d6e5eba
Showing
15 changed files
with
163 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ vite.config.ts.timestamp-* | |
|
||
# # Playwright/ Vitest | ||
/ui/test-results | ||
screenshot.png | ||
|
||
# Dev | ||
zarf-sbom | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
['namespace'], | ||
['storage_class'], | ||
['capacity'], | ||
['pods'], | ||
['age'], | ||
['status'], | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
ui/src/lib/features/k8s/storage/persistentvolumeclaims/status/component.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!-- SPDX-License-Identifier: Apache-2.0 --> | ||
<!-- SPDX-FileCopyrightText: 2024-Present The UDS Authors --> | ||
|
||
<script lang="ts"> | ||
import { type PVCStatus } from '$features/k8s/types' | ||
import { getColorAndStatus } from '$lib/features/k8s/helpers' | ||
export let status: PVCStatus | ||
$: statusClass = getColorAndStatus('PersistentVolumeClaims', status) | ||
</script> | ||
|
||
{#if status} | ||
<span class={statusClass}> | ||
{status} | ||
</span> | ||
{:else} | ||
- | ||
{/if} |
61 changes: 55 additions & 6 deletions
61
ui/src/lib/features/k8s/storage/persistentvolumeclaims/store.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,84 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2024-Present The UDS Authors | ||
|
||
import type { V1PersistentVolumeClaim as Resource } from '@kubernetes/client-node' | ||
import type { V1PersistentVolumeClaim as Resource, V1Pod } from '@kubernetes/client-node' | ||
|
||
import { apiAuthEnabled } from '$features/api-auth/store' | ||
import { ResourceStore, transformResource } from '$features/k8s/store' | ||
import { type ColumnWrapper, type CommonRow, type ResourceStoreInterface } from '$features/k8s/types' | ||
import { get, writable } from 'svelte/store' | ||
import Status from './status/component.svelte' | ||
|
||
interface Row extends CommonRow { | ||
storage_class: string | ||
capacity: string | ||
pods: string[] | ||
status: string | ||
status: { component: typeof Status; props: { status: string } } | ||
} | ||
|
||
export type Columns = ColumnWrapper<Row> | ||
|
||
export function createStore(): ResourceStoreInterface<Resource, Row> { | ||
const url = `/api/v1/resources/storage/persistentvolumeclaims?dense=true` | ||
|
||
// correlate pods with pvcs | ||
const pods = new Map<string, string[]>() // map of pvc name -> pod names | ||
const podStore = writable<number>() | ||
const jsonPathFields = 'metadata.name,spec.volumes,status.phase' | ||
let podEvents: EventSource | ||
const podEventsPath = `/api/v1/resources/workloads/pods?fields=${jsonPathFields}` | ||
|
||
if (get(apiAuthEnabled)) { | ||
const apiToken: string = sessionStorage.getItem('token') ?? '' | ||
podEvents = new EventSource(`${podEventsPath}&token=${apiToken}`) | ||
} else { | ||
podEvents = new EventSource(podEventsPath) | ||
} | ||
|
||
podEvents.onmessage = (event) => { | ||
const data = JSON.parse(event.data) as V1Pod[] | ||
data.forEach((p) => { | ||
// find the pvcs for each pod | ||
p.spec?.volumes?.forEach((v) => { | ||
const claimName = `${v.persistentVolumeClaim?.claimName}` || '' | ||
let podNames = pods.get(claimName) ?? [] | ||
if (claimName && p.status?.phase === 'Running') { | ||
// add pod to state | ||
podNames.push(p.metadata?.name ?? '') | ||
podNames = Array.from(new Set(podNames)) // de-dup | ||
pods.set(claimName, podNames) | ||
} else if (claimName && p.status?.phase !== 'Running') { | ||
// remove terminated pods from state | ||
podNames = podNames.filter((n) => n !== p.metadata?.name) | ||
pods.set(claimName, podNames) | ||
} | ||
}) | ||
}) | ||
|
||
// trigger an update | ||
podStore.set(event.timeStamp) | ||
} | ||
|
||
const transform = transformResource<Resource, Row>((r) => ({ | ||
storage_class: r.spec?.storageClassName ?? '', | ||
capacity: r.spec?.resources?.requests?.storage ?? '', | ||
status: r.status?.phase ?? '', | ||
status: { component: Status, props: { status: r.status?.phase ?? '' } }, | ||
})) | ||
|
||
const store = new ResourceStore<Resource, Row>(url, transform, 'name') | ||
|
||
const store = new ResourceStore<Resource, Row>(url, transform, 'name', true, [podStore]) | ||
store.stopCallback = podEvents.close.bind(podEvents) | ||
store.filterCallback = (data) => { | ||
return data.map((d) => { | ||
const pvcName = d.table.name | ||
if (pods.has(pvcName)) { | ||
d.table.pods = pods.get(pvcName) ?? [] | ||
} | ||
return d | ||
}) | ||
} | ||
return { | ||
...store, | ||
start: store.start.bind(store), | ||
|
||
sortByKey: store.sortByKey.bind(store), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.