Skip to content

Commit 934ae1d

Browse files
committed
Option in UI to annotations on resources. fixes Show annotations? #124
1 parent f66e381 commit 934ae1d

File tree

5 files changed

+48
-13
lines changed

5 files changed

+48
-13
lines changed

public/css/main.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,7 @@ pre {
126126
font-size: 1rem;
127127
font-weight: 500;
128128
}
129+
130+
.clickable {
131+
cursor: pointer;
132+
}

public/index.html

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,37 +217,51 @@
217217
<span x-text="panelData.kind" class="valign-middle"></span>
218218
</p>
219219
<section>
220-
<div class="panel-block">
221-
<button class="button is-small is-primary" :class="{'is-outlined':!showLabels}"
222-
@click="showLabels=!showLabels">Labels</button>
220+
<div class="panel-block is-flex">
221+
<button class="button is-small is-primary mr-1" :class="{'is-outlined':!showLabels}"
222+
@click="showLabels=!showLabels; showAnno=false">Labels</button>
223+
<button class="button is-small is-primary" :class="{'is-outlined':!showAnno}"
224+
@click="showAnno=!showAnno; showLabels=false">Annotations</button>
223225
</div>
224-
<!-- Labels -->
226+
<!-- Labels & Annotations -->
225227
<template x-for="(value, label) in panelData.labels" :key="label">
226228
<div class="panel-block py-0" x-show="showLabels">
227229
<div class="py-1 has-text-weight-bold" x-text="label"></div>
228230
<div class="py-1" x-text="`: ${value}`"></div>
229231
</div>
230232
</template>
233+
<template x-for="(value, label) in panelData.annotations" :key="label">
234+
<div class="panel-block py-0" x-show="showAnno">
235+
<div class="py-1 has-text-weight-bold" x-text="label"></div>
236+
<div class="py-1" x-text="`: ${value}`"></div>
237+
</div>
238+
</template>
231239
<!-- Properties -->
232-
<div class="panel-block has-background-dark py-1">
233-
<label class="label">Properties</label>
240+
<div
241+
class="panel-block has-background-dark py-0 is-flex is-justify-content-space-around is-align-items-center clickable"
242+
@click="showProps=!showProps">
243+
<label class="label is-flex-grow-1 pt-1 mr-3 clickable">Properties</label>
244+
<i class="fas" :class="showProps ? 'fa-angles-up' : 'fa-angles-down'"></i>
234245
</div>
235246
<template x-for="(value, prop) in panelData.props" :key="prop">
236-
<div class="panel-block py-0">
247+
<div class="panel-block py-0" x-show="showProps" x-transition.scale.origin.top>
237248
<div class="py-1 has-text-weight-bold property" x-text="prop"></div>
238249
<div class="py-1" x-text="value"></div>
239250
</div>
240251
</template>
241252
<!-- Containers (pods only) -->
242253
<template x-for="(cont, name) in panelData.containers" :key="name">
243254
<div>
244-
<div class="panel-block has-background-dark py-1">
245-
<label class="label" x-text="`Container: ${name}`"></label>
255+
<div
256+
class="panel-block has-background-dark py-0 is-flex is-justify-content-space-around is-align-items-center clickable"
257+
@click="showContainers=!showContainers" style="cursor: pointer">
258+
<label class="label is-flex-grow-1 pt-1 mr-3 clickable" x-text="`Container: ${name}`"></label>
259+
<i class="fas" :class="showContainers ? 'fa-angles-up' : 'fa-angles-down'"></i>
246260
</div>
247261
<template x-for="(value, prop) in cont" :key="prop">
248-
<div class="panel-block py-0">
262+
<div class="panel-block py-0" x-show="showContainers" x-transition.scale.origin.top>
249263
<div class="py-1 has-text-weight-bold property" x-text="prop"></div>
250-
<div class="py-1" x-text="value"></div>
264+
<div class="py-1=" x-text="value"></div>
251265
</div>
252266
</template>
253267
</div>

public/js/side-panel.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import { getResource } from './graph.js'
1212
export default () => ({
1313
open: false,
1414
showLabels: false,
15+
showAnno: false,
16+
showProps: true,
17+
showContainers: true,
18+
1519
/** @type {PanelData} */
1620
panelData: {
1721
id: '',
@@ -20,6 +24,7 @@ export default () => ({
2024
props: {},
2125
containers: {},
2226
labels: {},
27+
annotations: {},
2328
},
2429

2530
init() {
@@ -147,6 +152,15 @@ export default () => ({
147152
}
148153
}
149154

155+
// Annotations
156+
/** @type {Record<string, string>} */
157+
const annotations = {}
158+
if (res.metadata?.annotations) {
159+
for (const [key, value] of Object.entries(res.metadata.annotations)) {
160+
annotations[key] = value
161+
}
162+
}
163+
150164
/** @type {Record<string, any>} */
151165
const containers = {}
152166
if (res.status?.containerStatuses) {
@@ -170,6 +184,7 @@ export default () => ({
170184
props,
171185
containers,
172186
labels,
187+
annotations,
173188
}
174189
},
175190
})

public/js/types/custom.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ declare type Resource = {
3030
creationTimestamp: string
3131
deletionTimestamp: string | null
3232
labels: Record<string, string>
33+
annotations: Record<string, string>
3334
ownerReferences: Array<{
3435
uid: string
3536
}>
@@ -48,4 +49,5 @@ declare type PanelData = {
4849
props: Record<string, string>
4950
containers: Record<string, any>
5051
labels: Record<string, string>
52+
annotations: Record<string, string>
5153
}

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ Note: This is a v2 and complete rewrite the original KubeView project [see below
2626

2727
## 🏗️ Architecture & Design
2828

29-
KubeView is built using Go for the backend, exposing a REST API that provides the data for the frontend, and serves static HTML/JS. The frontend is a static web application that uses HTML, CSS, and JavaScript to render the user interface. It uses [Cytoscape.js](https://js.cytoscape.org/) for graph visualization, [Alpine.js](https://alpinejs.dev/) for client-side interactivity, and [Bulma](https://bulma.io/) for styling.
29+
KubeView is built using Go for the backend, exposing a REST API that provides the data for the frontend, and serves static HTML/JS. The frontend is a static web application that uses HTML, CSS, and plain modern JavaScript (ES6) to render the user interface. It uses [Cytoscape.js](https://js.cytoscape.org/) for graph visualization, [Alpine.js](https://alpinejs.dev/) for client-side interactivity, and [Bulma](https://bulma.io/) for styling.
3030

31-
The backend uses the Go client for Kubernetes to interact with the cluster and retrieve resource information, including setting up watchers for real-time updates streamed using SSE. The data is then processed and sent to the frontend as JSON, which the frontend uses to render the graph and update the UI.
31+
The backend uses the Go client for Kubernetes to retrieve resource information, including setting up watchers for real-time updates streamed using SSE. The data is then processed and sent to the frontend as JSON, which the frontend uses to render the graph and update the UI.
3232

3333
![diagram of system](./docs/diagram.drawio.png)
3434

0 commit comments

Comments
 (0)