Skip to content

Commit

Permalink
feat(ui): adding cluster ops priority classes view (#62)
Browse files Browse the repository at this point in the history
## Description
Adding Priority Classes view

##### UDS
<img width="1589" alt="Screenshot 2024-07-24 at 2 55 42 PM"
src="https://github.com/user-attachments/assets/66971667-ac68-4981-8bcd-71277b71ae2c">

##### OpenLens
<img width="1704" alt="Screenshot 2024-07-24 at 3 06 19 PM"
src="https://github.com/user-attachments/assets/1a1a21f0-c730-4d5e-98bc-23562cfe35f6">

## Related Issue

- #32

---------

Co-authored-by: Jeff McCoy <code@jeffm.us>
  • Loading branch information
BillyFigueroa and jeff-mccoy authored Jul 25, 2024
1 parent 2995497 commit f52ea3d
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pkg/api/resources/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
batchV1 "k8s.io/api/batch/v1"
v1 "k8s.io/api/core/v1"
networkingV1 "k8s.io/api/networking/v1"
schedulingV1 "k8s.io/api/scheduling/v1"
storageV1 "k8s.io/api/storage/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -58,6 +59,7 @@ type Cache struct {
MutatingWebhooks *ResourceList[*admissionRegV1.MutatingWebhookConfiguration]
ValidatingWebhooks *ResourceList[*admissionRegV1.ValidatingWebhookConfiguration]
HPAs *ResourceList[*autoscalingV2.HorizontalPodAutoscaler]
PriorityClasses *ResourceList[*schedulingV1.PriorityClass]

// Network resources
Services *ResourceList[*v1.Service]
Expand Down Expand Up @@ -148,6 +150,7 @@ func (c *Cache) bindClusterOpsResources() {
c.MutatingWebhooks = NewResourceList[*admissionRegV1.MutatingWebhookConfiguration](c.factory.Admissionregistration().V1().MutatingWebhookConfigurations().Informer())
c.ValidatingWebhooks = NewResourceList[*admissionRegV1.ValidatingWebhookConfiguration](c.factory.Admissionregistration().V1().ValidatingWebhookConfigurations().Informer())
c.HPAs = NewResourceList[*autoscalingV2.HorizontalPodAutoscaler](c.factory.Autoscaling().V2().HorizontalPodAutoscalers().Informer())
c.PriorityClasses = NewResourceList[*schedulingV1.PriorityClass](c.factory.Scheduling().V1().PriorityClasses().Informer())
}

func (c *Cache) bindNetworkResources() {
Expand Down
1 change: 1 addition & 0 deletions pkg/api/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func Start(assets embed.FS) error {
r.Get("/mutatingwebhooks", sse.Bind(cache.MutatingWebhooks))
r.Get("/validatingwebhooks", sse.Bind(cache.ValidatingWebhooks))
r.Get("/hpas", sse.Bind(cache.HPAs))
r.Get("/priority-classes", sse.Bind(cache.PriorityClasses))
})

// Network resources
Expand Down
3 changes: 2 additions & 1 deletion ui/src/lib/components/DataTable/component.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
{#each $rows as row}
<tr>
{#each columns as [key, style]}
{@const value = row.table[key] || {}}
<!-- Check object to avoid issues with `false` values -->
{@const value = Object.hasOwn(row.table, key) ? row.table[key] : ''}
{#if value.component}
<td class={style || ''}>
<svelte:component this={value.component} {...value.props} />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- SPDX-License-Identifier: Apache-2.0 -->
<!-- SPDX-FileCopyrightText: 2024-Present The UDS Authors -->

<script lang="ts">
import { DataTable } from '$components'
import { createStore, type Columns } from './store'
export let columns: Columns = [['name', 'emphasize'], ['value'], ['global_default'], ['description'], ['age']]
</script>

<DataTable {columns} {createStore} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2024-Present The UDS Authors

import '@testing-library/jest-dom'

import { testK8sTableWithCustomColumns, testK8sTableWithDefaults } from '$features/k8s/test-helper'
import Component from './component.svelte'
import { createStore } from './store'

suite('PriorityClassesTable Component', () => {
beforeEach(() => {
vi.clearAllMocks()
})

testK8sTableWithDefaults(Component, {
createStore,
columns: [['name', 'emphasize'], ['value'], ['global_default'], ['description'], ['age']],
})

testK8sTableWithCustomColumns(Component, { createStore })
})
33 changes: 33 additions & 0 deletions ui/src/lib/features/k8s/cluster-ops/priority-classes/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2024-Present The UDS Authors

import type { V1PriorityClass as Resource } from '@kubernetes/client-node'

import { ResourceStore, transformResource } from '$features/k8s/store'
import { type ColumnWrapper, type CommonRow, type ResourceStoreInterface } from '$features/k8s/types'

interface Row extends CommonRow {
description: string
global_default: boolean
value: number
}

export type Columns = ColumnWrapper<Row>

export function createStore(): ResourceStoreInterface<Resource, Row> {
const url = `/api/v1/resources/cluster-ops/priority-classes`

const transform = transformResource<Resource, Row>((r) => ({
description: r.description ?? '',
global_default: r.globalDefault ?? false,
value: r.value ?? 0,
}))

const store = new ResourceStore<Resource, Row>('name')

return {
...store,
start: () => store.start(url, transform),
sortByKey: store.sortByKey.bind(store),
}
}
2 changes: 2 additions & 0 deletions ui/src/lib/features/k8s/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export { default as StatefulsetTable } from './workloads/statefulsets/component.

export { default as UDSExemptionTable } from './configs/uds-exemptions/component.svelte'
export { default as UDSPackageTable } from './configs/uds-packages/component.svelte'

export { default as PriorityClassesTable } from './cluster-ops/priority-classes/component.svelte'
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<!-- SPDX-License-Identifier: Apache-2.0 -->
<!-- SPDX-FileCopyrightText: 2024-Present The UDS Authors -->

<h1 class="text-white text-5xl">Priority Classes</h1>
<script>
import { PriorityClassesTable } from '$features/k8s'
</script>

<PriorityClassesTable />

0 comments on commit f52ea3d

Please sign in to comment.