Skip to content

Commit

Permalink
feat(ui): adding cluster ops resource quotas view (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyFigueroa authored Jul 29, 2024
1 parent a2f17b3 commit 5370bf9
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/api/resources/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Cache struct {
RuntimeClasses *ResourceList
PodDisruptionBudgets *ResourceList
LimitRanges *ResourceList
ResourceQuotas *ResourceList

// Network resources
Services *ResourceList
Expand Down Expand Up @@ -171,6 +172,7 @@ func (c *Cache) bindClusterOpsResources() {
priorityClassGVK := schedulingV1.SchemeGroupVersion.WithKind("PriorityClass")
podDisruptionBudgetGVK := policyV1.SchemeGroupVersion.WithKind("PodDisruptionBudget")
limitRangesGVK := coreV1.SchemeGroupVersion.WithKind("LimitRange")
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)
Expand All @@ -179,6 +181,7 @@ func (c *Cache) bindClusterOpsResources() {
c.PriorityClasses = NewResourceList(c.factory.Scheduling().V1().PriorityClasses().Informer(), priorityClassGVK)
c.PodDisruptionBudgets = NewResourceList(c.factory.Policy().V1().PodDisruptionBudgets().Informer(), podDisruptionBudgetGVK)
c.LimitRanges = NewResourceList(c.factory.Core().V1().LimitRanges().Informer(), limitRangesGVK)
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 @@ -112,6 +112,9 @@ func Start(assets embed.FS) error {

r.Get("/limit-ranges", sse.Bind(cache.LimitRanges))
r.Get("/limit-ranges/{uid}", sse.Bind(cache.LimitRanges))

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 @@ -25,6 +25,7 @@ export { default as LimitRangesTable } from './cluster-ops/limit-ranges/componen
export { default as MutatingWebhooksTable } from './cluster-ops/mutatingwebhooks/component.svelte'
export { default as PodDisruptionBudgetsTable } from './cluster-ops/pod-disruption-budgets/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 />

0 comments on commit 5370bf9

Please sign in to comment.