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

feat(ui): adding cluster ops resource quotas view #81

Merged
merged 6 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions pkg/api/resources/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Cache struct {
HPAs *ResourceList
PriorityClasses *ResourceList
RuntimeClasses *ResourceList
ResourceQuotas *ResourceList

// Network resources
Services *ResourceList
Expand Down Expand Up @@ -166,12 +167,14 @@ func (c *Cache) bindClusterOpsResources() {
hpaGVK := autoScalingV2.SchemeGroupVersion.WithKind("HorizontalPodAutoscaler")
runtimeClassGVK := nodeV1.SchemeGroupVersion.WithKind("RuntimeClass")
priorityClassGVK := schedulingV1.SchemeGroupVersion.WithKind("PriorityClass")
resourceQuotaGVK := coreV1.SchemeGroupVersion.WithKind("ResourceQuotas")

c.MutatingWebhooks = NewResourceList(c.factory.Admissionregistration().V1().MutatingWebhookConfigurations().Informer(), mutatingWebhookGVK)
c.ValidatingWebhooks = NewResourceList(c.factory.Admissionregistration().V1().ValidatingWebhookConfigurations().Informer(), validatingWebhookGVK)
c.HPAs = NewResourceList(c.factory.Autoscaling().V2().HorizontalPodAutoscalers().Informer(), hpaGVK)
c.RuntimeClasses = NewResourceList(c.factory.Node().V1().RuntimeClasses().Informer(), runtimeClassGVK)
c.PriorityClasses = NewResourceList(c.factory.Scheduling().V1().PriorityClasses().Informer(), priorityClassGVK)
c.ResourceQuotas = NewResourceList(c.factory.Core().V1().ResourceQuotas().Informer(), resourceQuotaGVK)
}

func (c *Cache) bindNetworkResources() {
Expand Down
3 changes: 3 additions & 0 deletions pkg/api/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ func Start(assets embed.FS) error {

r.Get("/runtime-classes", sse.Bind(cache.RuntimeClasses))
r.Get("/runtime-classes/{uid}", sse.Bind(cache.RuntimeClasses))

r.Get("/resource-quotas", sse.Bind(cache.ResourceQuotas))
r.Get("/resource-quotas/{uid}", sse.Bind(cache.ResourceQuotas))
})

// Network resources
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'], ['namespace'], ['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('ResourceQuotasTable Component', () => {
beforeEach(() => {
vi.clearAllMocks()
})

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

testK8sTableWithCustomColumns(Component, { createStore })
})
21 changes: 21 additions & 0 deletions ui/src/lib/features/k8s/cluster-ops/resource-quotas/store.ts
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 type { V1ResourceQuota as Resource } from '@kubernetes/client-node'

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

export function createStore(): ResourceStoreInterface<Resource, CommonRow> {
const url = `/api/v1/resources/cluster-ops/resource-quotas`

const transform = transformResource<Resource, CommonRow>(() => ({}))

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

return {
...store,
start: () => store.start(url, transform),
sortByKey: store.sortByKey.bind(store),
}
}
1 change: 1 addition & 0 deletions ui/src/lib/features/k8s/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export { default as UDSPackageTable } from './configs/uds-packages/component.sve
// Cluster ops resources
export { default as MutatingWebhooksTable } from './cluster-ops/mutatingwebhooks/component.svelte'
export { default as PriorityClassesTable } from './cluster-ops/priority-classes/component.svelte'
export { default as ResourceQuotasTable } from './cluster-ops/resource-quotas/component.svelte'
export { default as RuntimeClassesTable } from './cluster-ops/runtime-classes/component.svelte'

// Network resources
Expand Down
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">Resource Quotas</h1>
<script>
import { ResourceQuotasTable } from '$features/k8s'
</script>

<ResourceQuotasTable />
Loading