Skip to content

Commit cd3c7b3

Browse files
feloybenoitf
andauthoredJan 27, 2025
feat: display pods and deployments counts in experimental mode (podman-desktop#10748)
* feat: display pods and deployments counts in experimental mode Signed-off-by: Philippe Martin <phmartin@redhat.com> * fix: apply suggestions from code review Co-authored-by: Florent BENOIT <fbenoit@redhat.com> Signed-off-by: Philippe Martin <feloy1@gmail.com> * feat: do not display undefined counts Signed-off-by: Philippe Martin <phmartin@redhat.com> --------- Signed-off-by: Philippe Martin <feloy1@gmail.com> Co-authored-by: Florent BENOIT <fbenoit@redhat.com>
1 parent dde2b22 commit cd3c7b3

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed
 

‎packages/renderer/src/lib/preferences/PreferencesKubernetesContextsRendering.spec.ts

+34-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest';
2525
import { kubernetesContextsHealths } from '/@/stores/kubernetes-context-health';
2626
import { kubernetesContexts } from '/@/stores/kubernetes-contexts';
2727
import * as kubernetesContextsState from '/@/stores/kubernetes-contexts-state';
28+
import { kubernetesResourcesCount } from '/@/stores/kubernetes-resources-count';
2829
import type { KubeContext } from '/@api/kubernetes-context';
2930
import type { ContextGeneralState } from '/@api/kubernetes-contexts-states';
3031

@@ -171,7 +172,8 @@ describe.each([
171172
name: 'experimental states',
172173
implemented: {
173174
health: true,
174-
resourcesCount: false,
175+
resourcesCount: true,
176+
undefinedCounts: true,
175177
},
176178
initMocks: (): void => {
177179
Object.defineProperty(global, 'window', {
@@ -181,6 +183,18 @@ describe.each([
181183
kubernetesRefreshContextState: vi.fn(),
182184
},
183185
});
186+
kubernetesResourcesCount.set([
187+
{
188+
contextName: 'context-name',
189+
resourceName: 'pods',
190+
count: 1,
191+
},
192+
{
193+
contextName: 'context-name',
194+
resourceName: 'deployments',
195+
count: 2,
196+
},
197+
]);
184198
vi.mocked(window.getConfigurationValue<boolean>).mockResolvedValue(true);
185199
kubernetesContextsHealths.set([
186200
{
@@ -193,6 +207,11 @@ describe.each([
193207
reachable: false,
194208
checking: false,
195209
},
210+
{
211+
contextName: 'context-name3',
212+
reachable: true,
213+
checking: false,
214+
},
196215
]);
197216
},
198217
},
@@ -201,6 +220,7 @@ describe.each([
201220
implemented: {
202221
health: true,
203222
resourcesCount: true,
223+
undefinedCounts: false,
204224
},
205225
initMocks: (): void => {
206226
const state: Map<string, ContextGeneralState> = new Map();
@@ -230,6 +250,7 @@ describe.each([
230250
render(PreferencesKubernetesContextsRendering, {});
231251
const context1 = screen.getAllByRole('row')[0];
232252
const context2 = screen.getAllByRole('row')[1];
253+
const context3 = screen.getAllByRole('row')[2];
233254
if (implemented.health) {
234255
await vi.waitFor(() => {
235256
expect(within(context1).queryByText('REACHABLE')).toBeInTheDocument();
@@ -258,6 +279,18 @@ describe.each([
258279
expect(podsCountContext2).not.toBeInTheDocument();
259280
const deploymentsCountContext2 = within(context2).queryByLabelText('Context Deployments Count');
260281
expect(deploymentsCountContext2).not.toBeInTheDocument();
282+
283+
if (implemented.undefinedCounts) {
284+
const checkNoCount = (el: HTMLElement, label: string): void => {
285+
const countEl = within(el).getByLabelText(label);
286+
expect(countEl).toBeInTheDocument();
287+
expect(countEl).toBeEmptyDOMElement();
288+
};
289+
expect(within(context3).queryByText('PODS')).toBeInTheDocument();
290+
expect(within(context3).queryByText('DEPLOYMENTS')).toBeInTheDocument();
291+
checkNoCount(context3, 'Context Pods Count');
292+
checkNoCount(context3, 'Context Deployments Count');
293+
}
261294
});
262295
});
263296

‎packages/renderer/src/lib/preferences/PreferencesKubernetesContextsRendering.svelte

+21-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import { router } from 'tinro';
66
77
import { kubernetesContextsHealths } from '/@/stores/kubernetes-context-health';
88
import { kubernetesContextsCheckingStateDelayed, kubernetesContextsState } from '/@/stores/kubernetes-contexts-state';
9+
import { kubernetesResourcesCount } from '/@/stores/kubernetes-resources-count';
910
import type { KubeContext } from '/@api/kubernetes-context';
11+
import type { SelectedResourceName } from '/@api/kubernetes-contexts-states';
1012
1113
import { kubernetesContexts } from '../../stores/kubernetes-contexts';
1214
import { clearKubeUIContextErrors, setKubeUIContextError } from '../kube/KubeContextUI';
@@ -18,6 +20,8 @@ interface KubeContextWithStates extends KubeContext {
1820
isReachable: boolean;
1921
isKnown: boolean;
2022
isBeingChecked: boolean;
23+
podsCount?: number;
24+
deploymentsCount?: number;
2125
}
2226
2327
const currentContextName = $derived($kubernetesContexts.find(c => c.currentContext)?.name);
@@ -31,6 +35,8 @@ const kubernetesContextsWithStates: KubeContextWithStates[] = $derived(
3135
isReachable: isContextReachable(kubeContext.name, experimentalStates),
3236
isKnown: isContextKnown(kubeContext.name, experimentalStates),
3337
isBeingChecked: isContextBeingChecked(kubeContext.name, experimentalStates),
38+
podsCount: getResourcesCount(kubeContext.name, 'pods', experimentalStates),
39+
deploymentsCount: getResourcesCount(kubeContext.name, 'deployments', experimentalStates),
3440
})),
3541
);
3642
@@ -111,6 +117,19 @@ function isContextBeingChecked(contextName: string, experimental: boolean): bool
111117
return !!$kubernetesContextsCheckingStateDelayed?.get(contextName);
112118
}
113119
120+
function getResourcesCount(
121+
contextName: string,
122+
resourceName: SelectedResourceName,
123+
experimental: boolean,
124+
): number | undefined {
125+
if (experimental) {
126+
return $kubernetesResourcesCount.find(
127+
resourcesCount => resourcesCount.contextName === contextName && resourcesCount.resourceName === resourceName,
128+
)?.count;
129+
}
130+
return $kubernetesContextsState.get(contextName)?.resources[resourceName];
131+
}
132+
114133
async function connect(contextName: string): Promise<void> {
115134
await window.telemetryTrack('kubernetes.monitoring.start.non-current');
116135
$kubernetesContexts = clearKubeUIContextErrors($kubernetesContexts, contextName);
@@ -197,15 +216,15 @@ async function connect(contextName: string): Promise<void> {
197216
<div class="text-center">
198217
<div class="font-bold text-[9px] text-[var(--pd-invert-content-card-text)]">PODS</div>
199218
<div class="text-[16px] text-[var(--pd-invert-content-card-text)]" aria-label="Context Pods Count">
200-
{$kubernetesContextsState.get(context.name)?.resources.pods}
219+
{#if context.podsCount !== undefined}{context.podsCount}{/if}
201220
</div>
202221
</div>
203222
<div class="text-center">
204223
<div class="font-bold text-[9px] text-[var(--pd-invert-content-card-text)]">DEPLOYMENTS</div>
205224
<div
206225
class="text-[16px] text-[var(--pd-invert-content-card-text)]"
207226
aria-label="Context Deployments Count">
208-
{$kubernetesContextsState.get(context.name)?.resources.deployments}
227+
{#if context.deploymentsCount !== undefined}{context.deploymentsCount}{/if}
209228
</div>
210229
</div>
211230
</div>

0 commit comments

Comments
 (0)
Please sign in to comment.