Skip to content

Commit

Permalink
feat: add pod disruption budgets view (#79)
Browse files Browse the repository at this point in the history
## Description
Add api and view for pod disruption budgets

## Related Issue

- #48
  • Loading branch information
TristanHoladay authored Jul 27, 2024
1 parent d04d50b commit a2f17b3
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 7 deletions.
16 changes: 10 additions & 6 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"
coreV1 "k8s.io/api/core/v1"
nodeV1 "k8s.io/api/node/v1"
policyV1 "k8s.io/api/policy/v1"
schedulingV1 "k8s.io/api/scheduling/v1"
storageV1 "k8s.io/api/storage/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -55,12 +56,13 @@ type Cache struct {
Secrets *ResourceList

// Cluster ops resources
MutatingWebhooks *ResourceList
ValidatingWebhooks *ResourceList
HPAs *ResourceList
PriorityClasses *ResourceList
RuntimeClasses *ResourceList
LimitRanges *ResourceList
MutatingWebhooks *ResourceList
ValidatingWebhooks *ResourceList
HPAs *ResourceList
PriorityClasses *ResourceList
RuntimeClasses *ResourceList
PodDisruptionBudgets *ResourceList
LimitRanges *ResourceList

// Network resources
Services *ResourceList
Expand Down Expand Up @@ -167,13 +169,15 @@ func (c *Cache) bindClusterOpsResources() {
hpaGVK := autoScalingV2.SchemeGroupVersion.WithKind("HorizontalPodAutoscaler")
runtimeClassGVK := nodeV1.SchemeGroupVersion.WithKind("RuntimeClass")
priorityClassGVK := schedulingV1.SchemeGroupVersion.WithKind("PriorityClass")
podDisruptionBudgetGVK := policyV1.SchemeGroupVersion.WithKind("PodDisruptionBudget")
limitRangesGVK := coreV1.SchemeGroupVersion.WithKind("LimitRange")

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.PodDisruptionBudgets = NewResourceList(c.factory.Policy().V1().PodDisruptionBudgets().Informer(), podDisruptionBudgetGVK)
c.LimitRanges = NewResourceList(c.factory.Core().V1().LimitRanges().Informer(), limitRangesGVK)
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/api/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,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("/poddisruptionbudgets", sse.Bind(cache.PodDisruptionBudgets))
r.Get("/poddisruptionbudgets/{uid}", sse.Bind(cache.PodDisruptionBudgets))

r.Get("/limit-ranges", sse.Bind(cache.LimitRanges))
r.Get("/limit-ranges/{uid}", sse.Bind(cache.LimitRanges))
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- 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'],
['min_available'],
['max_unavailable'],
['current_healthy'],
['desired_healthy'],
['age'],
]
</script>

<DataTable {columns} {createStore} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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'],
['namespace'],
['min_available'],
['max_unavailable'],
['current_healthy'],
['desired_healthy'],
['age'],
],
})

testK8sTableWithCustomColumns(Component, { createStore })
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2024-Present The UDS Authors

import type { V1PodDisruptionBudget 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 {
min_available: number | string
max_unavailable: number | string
current_healthy: number
desired_healthy: number
}

export type Columns = ColumnWrapper<Row>

export function createStore(): ResourceStoreInterface<Resource, Row> {
// needs dense=true to get the min_available and max_unavailable fields from spec
const url = `/api/v1/resources/cluster-ops/poddisruptionbudgets?dense=true`

const transform = transformResource<Resource, Row>((r) => ({
min_available: r.spec?.minAvailable ?? 'N/A',
max_unavailable: r.spec?.maxUnavailable ?? 'N/A',
desired_healthy: r.status?.desiredHealthy ?? 0,
current_healthy: r.status?.currentHealthy ?? 0,
}))

const store = new ResourceStore<Resource, Row>('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 LimitRangesTable } from './cluster-ops/limit-ranges/component.svelte'
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 RuntimeClassesTable } from './cluster-ops/runtime-classes/component.svelte'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<!-- SPDX-License-Identifier: Apache-2.0 -->
<!-- SPDX-FileCopyrightText: 2024-Present The UDS Authors -->
<script>
import { PodDisruptionBudgetsTable } from '$features/k8s'
</script>

<h1 class="text-white text-5xl">Pod Disruption Budgets</h1>
<PodDisruptionBudgetsTable />

0 comments on commit a2f17b3

Please sign in to comment.