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 runtime classes view #68

Merged
merged 8 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ vite.config.ts.timestamp-*

# # Playwright/ Vitest
/ui/test-results

/zarf-sbom
4 changes: 4 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"
nodeV1 "k8s.io/api/node/v1"
storageV1 "k8s.io/api/storage/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand All @@ -33,6 +34,8 @@ type Cache struct {
factory informers.SharedInformerFactory
dynamicFactory dynamicInformer.DynamicSharedInformerFactory

RuntimeClasses *ResourceList[*nodeV1.RuntimeClass]

// Core resources
Events *ResourceList[*v1.Event]
Namespaces *ResourceList[*v1.Namespace]
Expand Down Expand Up @@ -148,6 +151,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.RuntimeClasses = NewResourceList[*nodeV1.RuntimeClass](c.factory.Node().V1().RuntimeClasses().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("/runtime-classes", sse.Bind(cache.RuntimeClasses))
})

// 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'], ['handler'], ['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('RuntimeClassesTable Component', () => {
beforeEach(() => {
vi.clearAllMocks()
})

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

testK8sTableWithCustomColumns(Component, { createStore })
})
29 changes: 29 additions & 0 deletions ui/src/lib/features/k8s/cluster-ops/runtime-classes/store.ts
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 type { V1RuntimeClass 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 {
handler: string
}

export type Columns = ColumnWrapper<Row>

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

const transform = transformResource<Resource, Row>((r) => ({
handler: r.handler ?? '',
}))

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

return {
...store,
start: () => store.start(url, transform),
sortByKey: store.sortByKey.bind(store),
}
}
6 changes: 6 additions & 0 deletions ui/src/lib/features/k8s/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2024-Present The UDS Authors

// Resources
export { default as EventTable } from './events/component.svelte'
export { default as NamespaceTable } from './namespaces/component.svelte'
export { default as NodeTable } from './nodes/component.svelte'

// Workload resources
export { default as CronJobTable } from './workloads/cronjobs/component.svelte'
export { default as DaemonSetsTable } from './workloads/daemonsets/component.svelte'
export { default as DeploymentTable } from './workloads/deployments/component.svelte'
export { default as JobTable } from './workloads/jobs/component.svelte'
export { default as PodTable } from './workloads/pods/component.svelte'
export { default as StatefulsetTable } from './workloads/statefulsets/component.svelte'

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

// Cluster ops resources
export { default as RuntimeClassesTable } from './cluster-ops/runtime-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">Runtime Classes</h1>
<script>
import { RuntimeClassesTable } from '$features/k8s'
</script>

<RuntimeClassesTable />
Loading