Skip to content

Commit d0b4a58

Browse files
committed
Allow getting previous logs
Signed-off-by: adameska <[email protected]>
1 parent ecb0927 commit d0b4a58

File tree

11 files changed

+209
-65
lines changed

11 files changed

+209
-65
lines changed

packages/channels/src/channels.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
***********************************************************************/
1818

19+
import { createRpcChannel } from '@kubernetes-dashboard/rpc';
1920
import type { ContextsApi } from './interface/contexts-api';
2021
import type { NavigationApi } from './interface/navigation-api';
2122
import type { PodLogsApi } from './interface/pod-logs-api';
@@ -28,6 +29,7 @@ import type { AvailableContextsInfo } from './model/available-contexts-info';
2829
import type { ContextsHealthsInfo } from './model/contexts-healths-info';
2930
import type { ContextsPermissionsInfo } from './model/contexts-permissions-info';
3031
import type { CurrentContextInfo } from './model/current-context-info';
32+
import type { EditorSettings } from './model/editor-settings';
3133
import type { EndpointsInfo } from './model/endpoints-info';
3234
import type { KubernetesProvidersInfo } from './model/kubernetes-providers-info';
3335
import type { PodLogsChunk } from './model/pod-logs-chunk';
@@ -37,7 +39,6 @@ import type { ResourceDetailsInfo } from './model/resource-details-info';
3739
import type { ResourceEventsInfo } from './model/resource-events-info';
3840
import type { ResourcesCountInfo } from './model/resources-count-info';
3941
import type { UpdateResourceInfo } from './model/update-resource-info';
40-
import { createRpcChannel } from '@kubernetes-dashboard/rpc';
4142

4243
// RPC channels (used by the webview to send requests to the extension)
4344
export const API_CONTEXTS = createRpcChannel<ContextsApi>('ContextsApi');
@@ -66,3 +67,5 @@ export const POD_LOGS = createRpcChannel<PodLogsChunk>('PodLogs');
6667

6768
export const API_POD_TERMINALS = createRpcChannel<PodTerminalsApi>('PodTerminalsApi');
6869
export const POD_TERMINAL_DATA = createRpcChannel<PodTerminalChunk>('PodTerminalData');
70+
71+
export const EDITOR_SETTINGS = createRpcChannel<EditorSettings>('EditorSettings');
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**********************************************************************
2+
* Copyright (C) 2025 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
export interface EditorSettings {
20+
fontSize: number;
21+
}

packages/channels/src/model/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export * from './context-resources-items';
2424
export * from './contexts-healths-info';
2525
export * from './contexts-permissions-info';
2626
export * from './current-context-info';
27+
export * from './editor-settings';
2728
export * from './endpoint';
2829
export * from './endpoints-info';
2930
export * from './endpoints-options';
@@ -36,8 +37,8 @@ export * from './openshift-types';
3637
export * from './pod-logs-chunk';
3738
export * from './pod-logs-options';
3839
export * from './pod-terminal-chunk';
39-
export * from './port-forward-info';
4040
export * from './port-forward';
41+
export * from './port-forward-info';
4142
export * from './resource-details-info';
4243
export * from './resource-details-options';
4344
export * from './resource-events-info';
@@ -46,3 +47,4 @@ export * from './resources-count-info';
4647
export * from './target-ref';
4748
export * from './update-resource-info';
4849
export * from './update-resource-options';
50+

packages/extension/src/dispatcher/_dispatcher-module.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@
1818

1919
import { ContainerModule } from 'inversify';
2020
import { ActiveResourcesCountDispatcher } from './active-resources-count-dispatcher';
21+
import { AvailableContextsDispatcher } from './available-contexts-dispatcher';
2122
import { ContextsHealthsDispatcher } from './contexts-healths-dispatcher';
2223
import { ContextsPermissionsDispatcher } from './contexts-permissions-dispatcher';
23-
import { ResourcesCountDispatcher } from './resources-count-dispatcher';
24-
import { DispatcherObject } from './util/dispatcher-object';
2524
import { CurrentContextDispatcher } from './current-context-dispatcher';
26-
import { UpdateResourceDispatcher } from './update-resource-dispatcher';
27-
import { ResourceDetailsDispatcher } from './resource-details-dispatcher';
28-
import { ResourceEventsDispatcher } from './resource-events-dispatcher';
29-
import { PortForwardsDispatcher } from './port-forwards-dispatcher';
25+
import { EditorSettingsDispatcher } from './editor-settings-dispatcher';
3026
import { EndpointsDispatcher } from './endpoints-dispatcher';
31-
import { AvailableContextsDispatcher } from './available-contexts-dispatcher';
3227
import { KubernetesProvidersDispatcher } from './kubernetes-providers-dispatcher';
28+
import { PortForwardsDispatcher } from './port-forwards-dispatcher';
29+
import { ResourceDetailsDispatcher } from './resource-details-dispatcher';
30+
import { ResourceEventsDispatcher } from './resource-events-dispatcher';
31+
import { ResourcesCountDispatcher } from './resources-count-dispatcher';
32+
import { UpdateResourceDispatcher } from './update-resource-dispatcher';
33+
import { DispatcherObject } from './util/dispatcher-object';
3334

3435
const dispatchersModule = new ContainerModule(options => {
3536
options.bind<ActiveResourcesCountDispatcher>(ActiveResourcesCountDispatcher).toSelf().inSingletonScope();
@@ -50,6 +51,9 @@ const dispatchersModule = new ContainerModule(options => {
5051
options.bind<AvailableContextsDispatcher>(AvailableContextsDispatcher).toSelf().inSingletonScope();
5152
options.bind(DispatcherObject).toService(AvailableContextsDispatcher);
5253

54+
options.bind<EditorSettingsDispatcher>(EditorSettingsDispatcher).toSelf().inSingletonScope();
55+
options.bind(DispatcherObject).toService(EditorSettingsDispatcher);
56+
5357
options.bind<UpdateResourceDispatcher>(UpdateResourceDispatcher).toSelf().inSingletonScope();
5458
options.bind(DispatcherObject).toService(UpdateResourceDispatcher);
5559

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**********************************************************************
2+
* Copyright (C) 2025 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
import { EDITOR_SETTINGS, type EditorSettings } from '@kubernetes-dashboard/channels';
20+
import { RpcExtension } from '@kubernetes-dashboard/rpc';
21+
import { configuration } from '@podman-desktop/api';
22+
import { inject, injectable } from 'inversify';
23+
import type { DispatcherObject } from '/@/dispatcher/util/dispatcher-object';
24+
import { AbsDispatcherObjectImpl } from '/@/dispatcher/util/dispatcher-object';
25+
26+
@injectable()
27+
export class EditorSettingsDispatcher
28+
extends AbsDispatcherObjectImpl<void, EditorSettings>
29+
implements DispatcherObject<void>
30+
{
31+
constructor(@inject(RpcExtension) rpcExtension: RpcExtension) {
32+
super(rpcExtension, EDITOR_SETTINGS);
33+
}
34+
35+
getData(): EditorSettings {
36+
//TODO probably would be nice to expose these keys in the podman-desktop api spec
37+
const fontSize = configuration.getConfiguration('editor').get<number>('integrated.fontSize') ?? 10;
38+
return {
39+
fontSize,
40+
};
41+
}
42+
}

packages/extension/src/manager/contexts-states-dispatcher.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,33 @@
1717
***********************************************************************/
1818

1919
import {
20-
KubernetesTroubleshootingInformation,
2120
ACTIVE_RESOURCES_COUNT,
2221
AVAILABLE_CONTEXTS,
2322
CONTEXTS_HEALTHS,
2423
CONTEXTS_PERMISSIONS,
2524
CURRENT_CONTEXT,
25+
EDITOR_SETTINGS,
2626
ENDPOINTS,
27+
KUBERNETES_PROVIDERS,
28+
KubernetesTroubleshootingInformation,
2729
PORT_FORWARDS,
2830
RESOURCE_DETAILS,
2931
RESOURCE_EVENTS,
3032
RESOURCES_COUNT,
31-
UPDATE_RESOURCE,
3233
SubscribeApi,
33-
KUBERNETES_PROVIDERS,
34+
UPDATE_RESOURCE,
3435
} from '@kubernetes-dashboard/channels';
3536

37+
import { RpcChannel } from '@kubernetes-dashboard/rpc';
38+
import { inject, injectable, multiInject } from 'inversify';
3639
import type { ContextHealthState } from './context-health-checker.js';
3740
import type { ContextPermissionResult } from './context-permissions-checker.js';
3841
import type { DispatcherEvent } from './contexts-dispatcher.js';
3942
import { ContextsManager } from './contexts-manager.js';
40-
import { RpcChannel } from '@kubernetes-dashboard/rpc';
41-
import { inject, injectable, multiInject } from 'inversify';
4243
import { DispatcherObject } from '/@/dispatcher/util/dispatcher-object.js';
43-
import { ChannelSubscriber } from '/@/types/channel-subscriber.js';
44-
import { PortForwardServiceProvider } from '/@/port-forward/port-forward-service.js';
4544
import { KubernetesProvidersManager } from '/@/manager/kubernetes-providers.js';
45+
import { PortForwardServiceProvider } from '/@/port-forward/port-forward-service.js';
46+
import { ChannelSubscriber } from '/@/types/channel-subscriber.js';
4647

4748
@injectable()
4849
export class ContextsStatesDispatcher extends ChannelSubscriber implements SubscribeApi {
@@ -107,6 +108,8 @@ export class ContextsStatesDispatcher extends ChannelSubscriber implements Subsc
107108
this.kubernetesProvidersManager.onKubernetesProvidersChange(async () => {
108109
await this.dispatch(KUBERNETES_PROVIDERS);
109110
});
111+
112+
this.dispatch(EDITOR_SETTINGS).catch(console.error);
110113
}
111114

112115
// TODO replace this with an event

packages/webview/src/component/pods/PodLogs.svelte

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,44 @@
11
<script lang="ts">
2-
import type { V1Pod } from '@kubernetes/client-node';
3-
import { getContext, onDestroy, onMount, tick } from 'svelte';
4-
import { Streams } from '/@/stream/streams';
5-
import type { IDisposable, PodLogsOptions } from '@kubernetes-dashboard/channels';
6-
import { EmptyScreen, Button, Input } from '@podman-desktop/ui-svelte';
7-
import NoLogIcon from '/@/component/icons/NoLogIcon.svelte';
8-
import type { Terminal } from '@xterm/xterm';
9-
import TerminalWindow from '/@/component/terminal/TerminalWindow.svelte';
10-
import { SvelteMap } from 'svelte/reactivity';
11-
import { ansi256Colours, colourizedANSIContainerName } from '/@/component/terminal/terminal-colors';
12-
13-
interface Props {
14-
object: V1Pod;
15-
}
16-
let { object }: Props = $props();
17-
18-
// Logs has been initialized
19-
let noLogs = $state(true);
20-
21-
let logsTerminal = $state<Terminal>();
2+
import type { IDisposable, PodLogsOptions } from '@kubernetes-dashboard/channels';
3+
import type { V1Pod } from '@kubernetes/client-node';
4+
import { Button, EmptyScreen, Input } from '@podman-desktop/ui-svelte';
5+
import type { Terminal } from '@xterm/xterm';
6+
import { getContext, onDestroy, onMount, tick } from 'svelte';
7+
import { SvelteMap } from 'svelte/reactivity';
8+
import type { Unsubscriber } from 'svelte/store';
9+
import NoLogIcon from '/@/component/icons/NoLogIcon.svelte';
10+
import { ansi256Colours, colourizedANSIContainerName } from '/@/component/terminal/terminal-colors';
11+
import TerminalWindow from '/@/component/terminal/TerminalWindow.svelte';
12+
import { States } from '/@/state/states';
13+
import { Streams } from '/@/stream/streams';
14+
15+
interface Props {
16+
object: V1Pod;
17+
}
18+
let { object }: Props = $props();
19+
20+
const states = getContext<States>(States);
21+
const editorSettingsState = states.stateEditorSettingsInfoUI;
22+
23+
// Logs has been initialized
24+
let noLogs = $state(true);
25+
26+
let logsTerminal = $state<Terminal>();
2227
2328
// Log retrieval mode and options
2429
let isStreaming = $state(true);
2530
let previous = $state(false);
2631
let tailLines = $state<number | undefined>(undefined);
2732
let sinceSeconds = $state<number | undefined>(undefined);
2833
let timestamps = $state(false);
29-
let fontSize = $state(10);
34+
let fontSize = $state(editorSettingsState.data?.fontSize ?? 10);
35+
36+
// Update fontSize when editor settings change
37+
$effect(() => {
38+
if (editorSettingsState.data?.fontSize !== undefined) {
39+
fontSize = editorSettingsState.data.fontSize;
40+
}
41+
});
3042
3143
let disposables: IDisposable[] = [];
3244
const streams = getContext<Streams>(Streams);
@@ -38,7 +50,7 @@
3850
async function loadLogs() {
3951
logsTerminal?.clear();
4052
noLogs = true;
41-
53+
4254
disposables.forEach(disposable => disposable.dispose());
4355
disposables = [];
4456
@@ -73,16 +85,16 @@
7385
}
7486
: (_name: string, data: string, callback: (data: string) => void): void => {
7587
callback(data);
76-
};
77-
88+
};
89+
7890
const options: PodLogsOptions = {
7991
stream: isStreaming,
8092
previous,
8193
tailLines,
8294
sinceSeconds,
8395
timestamps,
8496
};
85-
97+
8698
for (const containerName of object.spec?.containers.map(c => c.name) ?? []) {
8799
disposables.push(
88100
await streams.streamPodLogs.subscribe(
@@ -105,11 +117,15 @@
105117
}
106118
}
107119
120+
let unsubscribers: Unsubscriber[] = [];
121+
108122
onMount(async () => {
123+
unsubscribers.push(editorSettingsState.subscribe());
109124
await loadLogs();
110125
});
111126
112127
onDestroy(() => {
128+
unsubscribers.forEach(unsubscriber => unsubscriber());
113129
disposables.forEach(disposable => disposable.dispose());
114130
disposables = [];
115131
});

packages/webview/src/component/pods/PodTerminal.svelte

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<script lang="ts">
2+
import { API_POD_TERMINALS, Disposable } from '@kubernetes-dashboard/channels';
23
import type { V1Pod } from '@kubernetes/client-node';
3-
import { getContext, onDestroy, onMount } from 'svelte';
4-
import { Streams } from '/@/stream/streams';
5-
import type { IDisposable } from 'monaco-editor';
6-
import { Terminal } from '@xterm/xterm';
7-
import { getTerminalTheme } from '/@/component/terminal/terminal-theme';
84
import { FitAddon } from '@xterm/addon-fit';
95
import { SerializeAddon } from '@xterm/addon-serialize';
6+
import { Terminal } from '@xterm/xterm';
7+
import type { IDisposable } from 'monaco-editor';
8+
import { getContext, onDestroy, onMount } from 'svelte';
9+
import { getTerminalTheme } from '/@/component/terminal/terminal-theme';
1010
import { Remote } from '/@/remote/remote';
11-
import { API_POD_TERMINALS, Disposable } from '@kubernetes-dashboard/channels';
11+
import { Streams } from '/@/stream/streams';
1212
1313
interface Props {
1414
object: V1Pod;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**********************************************************************
2+
* Copyright (C) 2025 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
import { inject, injectable } from 'inversify';
20+
21+
import { EDITOR_SETTINGS } from '@kubernetes-dashboard/channels';
22+
import { RpcBrowser } from '@kubernetes-dashboard/rpc';
23+
24+
import type { EditorSettings } from '@kubernetes-dashboard/channels';
25+
import { AbsStateObjectImpl, type StateObject } from './util/state-object.svelte';
26+
27+
// Define a state for the EditorSettings
28+
@injectable()
29+
export class StateEditorSettingsInfo
30+
extends AbsStateObjectImpl<EditorSettings, void>
31+
implements StateObject<EditorSettings, void>
32+
{
33+
constructor(@inject(RpcBrowser) rpcBrowser: RpcBrowser) {
34+
super(rpcBrowser);
35+
}
36+
37+
async init(): Promise<void> {
38+
await this.initChannel(EDITOR_SETTINGS);
39+
}
40+
}

0 commit comments

Comments
 (0)