diff --git a/packages/api/src/kubernetes-port-forward-model.ts b/packages/api/src/kubernetes-port-forward-model.ts index f1863c8c5402d..2867067ae2acd 100644 --- a/packages/api/src/kubernetes-port-forward-model.ts +++ b/packages/api/src/kubernetes-port-forward-model.ts @@ -60,10 +60,6 @@ export interface ForwardOptions { * The forward to create */ forward: PortMapping; - /** - * The display name for the forward configuration. - */ - displayName: string; } /** @@ -96,15 +92,3 @@ export interface ForwardConfig { */ forward: PortMapping; } - -/** - * Interface representing a user-specific forward configuration. - * Extends the base {@link ForwardConfig} interface. - * @see ForwardConfig - */ -export interface UserForwardConfig extends ForwardConfig { - /** - * The display name for the forward configuration. - */ - displayName: string; -} diff --git a/packages/main/src/plugin/index.ts b/packages/main/src/plugin/index.ts index 2dee46ad0ca40..8e60a1a507d53 100644 --- a/packages/main/src/plugin/index.ts +++ b/packages/main/src/plugin/index.ts @@ -87,7 +87,7 @@ import type { ImageInspectInfo } from '/@api/image-inspect-info.js'; import type { ImageSearchOptions, ImageSearchResult, ImageTagsListOptions } from '/@api/image-registry.js'; import type { KubeContext } from '/@api/kubernetes-context.js'; import type { ContextGeneralState, ResourceName } from '/@api/kubernetes-contexts-states.js'; -import type { ForwardOptions, UserForwardConfig } from '/@api/kubernetes-port-forward-model.js'; +import type { ForwardConfig, ForwardOptions } from '/@api/kubernetes-port-forward-model.js'; import type { ManifestCreateOptions, ManifestInspectInfo, ManifestPushOptions } from '/@api/manifest-info.js'; import type { NetworkInspectInfo } from '/@api/network-info.js'; import type { NotificationCard, NotificationCardOptions } from '/@api/notification.js'; @@ -2464,23 +2464,20 @@ export class PluginSystem { }, ); - this.ipcHandle('kubernetes-client:getPortForwards', async (_listener): Promise => { + this.ipcHandle('kubernetes-client:getPortForwards', async (_listener): Promise => { return kubernetesClient.getPortForwards(); }); this.ipcHandle( 'kubernetes-client:createPortForward', - async (_listener, options: ForwardOptions): Promise => { + async (_listener, options: ForwardOptions): Promise => { return kubernetesClient.createPortForward(options); }, ); - this.ipcHandle( - 'kubernetes-client:deletePortForward', - async (_listener, config: UserForwardConfig): Promise => { - return kubernetesClient.deletePortForward(config); - }, - ); + this.ipcHandle('kubernetes-client:deletePortForward', async (_listener, config: ForwardConfig): Promise => { + return kubernetesClient.deletePortForward(config); + }); this.ipcHandle( 'openshift-client:createRoute', diff --git a/packages/main/src/plugin/kubernetes/kubernetes-client.ts b/packages/main/src/plugin/kubernetes/kubernetes-client.ts index ce2458263c212..8f1dc64c5dec4 100644 --- a/packages/main/src/plugin/kubernetes/kubernetes-client.ts +++ b/packages/main/src/plugin/kubernetes/kubernetes-client.ts @@ -71,7 +71,7 @@ import type { KubernetesPortForwardService } from '/@/plugin/kubernetes/kubernet import { KubernetesPortForwardServiceProvider } from '/@/plugin/kubernetes/kubernetes-port-forward-service.js'; import type { KubeContext } from '/@api/kubernetes-context.js'; import type { ContextGeneralState, ResourceName } from '/@api/kubernetes-contexts-states.js'; -import type { ForwardOptions, UserForwardConfig } from '/@api/kubernetes-port-forward-model.js'; +import type { ForwardConfig, ForwardOptions } from '/@api/kubernetes-port-forward-model.js'; import type { V1Route } from '/@api/openshift-types.js'; import type { ApiSenderType } from '../api.js'; @@ -1761,18 +1761,18 @@ export class KubernetesClient { return this.#portForwardService; } - public async getPortForwards(): Promise { + public async getPortForwards(): Promise { return this.ensurePortForwardService().listForwards(); } - public async createPortForward(config: ForwardOptions): Promise { + public async createPortForward(config: ForwardOptions): Promise { const service = this.ensurePortForwardService(); const newConfig = await service.createForward(config); await service.startForward(newConfig); return newConfig; } - public async deletePortForward(config: UserForwardConfig): Promise { + public async deletePortForward(config: ForwardConfig): Promise { return this.ensurePortForwardService().deleteForward(config); } } diff --git a/packages/main/src/plugin/kubernetes/kubernetes-port-forward-service.spec.ts b/packages/main/src/plugin/kubernetes/kubernetes-port-forward-service.spec.ts index 27601fda834ab..502b74083e1f3 100644 --- a/packages/main/src/plugin/kubernetes/kubernetes-port-forward-service.spec.ts +++ b/packages/main/src/plugin/kubernetes/kubernetes-port-forward-service.spec.ts @@ -30,7 +30,7 @@ import { } from '/@/plugin/kubernetes/kubernetes-port-forward-service.js'; import type { ConfigManagementService } from '/@/plugin/kubernetes/kubernetes-port-forward-storage.js'; import type { IDisposable } from '/@/plugin/types/disposable.js'; -import type { ForwardConfig, UserForwardConfig } from '/@api/kubernetes-port-forward-model.js'; +import type { ForwardConfig } from '/@api/kubernetes-port-forward-model.js'; import { WorkloadKind } from '/@api/kubernetes-port-forward-model.js'; vi.mock('/@/plugin/kubernetes/kubernetes-port-forward-connection.js'); @@ -79,18 +79,13 @@ describe('KubernetesPortForwardService', () => { forward: { localPort: 8080, remotePort: 80 }, }; - const sampleUserForwardConfig: UserForwardConfig = { - ...sampleForwardConfig, - displayName: 'test-display-name', - }; - beforeEach(() => { vi.clearAllMocks(); mockConfigManagementService = { - createForward: vi.fn().mockResolvedValue(sampleUserForwardConfig), + createForward: vi.fn().mockResolvedValue(sampleForwardConfig), deleteForward: vi.fn().mockResolvedValue(undefined), - updateForward: vi.fn().mockResolvedValue(sampleUserForwardConfig), - listForwards: vi.fn().mockResolvedValue([sampleUserForwardConfig]), + updateForward: vi.fn().mockResolvedValue(sampleForwardConfig), + listForwards: vi.fn().mockResolvedValue([sampleForwardConfig]), } as unknown as ConfigManagementService; mockForwardingConnectionService = { @@ -107,30 +102,29 @@ describe('KubernetesPortForwardService', () => { test('should create a forward configuration', async () => { vi.mocked(mockConfigManagementService.listForwards).mockResolvedValue([]); - const forward = sampleUserForwardConfig.forward; + const forward = sampleForwardConfig.forward; if (!forward) throw new Error('undefined forward'); const result = await service.createForward({ - name: sampleUserForwardConfig.name, - kind: sampleUserForwardConfig.kind, - namespace: sampleUserForwardConfig.namespace, + name: sampleForwardConfig.name, + kind: sampleForwardConfig.kind, + namespace: sampleForwardConfig.namespace, forward: forward, - displayName: sampleUserForwardConfig.displayName, }); - expect(result).toEqual(sampleUserForwardConfig); - expect(mockConfigManagementService.createForward).toHaveBeenCalledWith(sampleUserForwardConfig); + expect(result).toEqual(sampleForwardConfig); + expect(mockConfigManagementService.createForward).toHaveBeenCalledWith(sampleForwardConfig); expect(apiSenderMock.send).toHaveBeenCalledWith('kubernetes-port-forwards-update', []); }); test('should delete a forward configuration', async () => { - await service.deleteForward(sampleUserForwardConfig); - expect(mockConfigManagementService.deleteForward).toHaveBeenCalledWith(sampleUserForwardConfig); + await service.deleteForward(sampleForwardConfig); + expect(mockConfigManagementService.deleteForward).toHaveBeenCalledWith(sampleForwardConfig); expect(apiSenderMock.send).toHaveBeenCalledWith('kubernetes-port-forwards-update', []); }); test('should list all forward configurations', async () => { const result = await service.listForwards(); - expect(result).toEqual([sampleUserForwardConfig]); + expect(result).toEqual([sampleForwardConfig]); expect(mockConfigManagementService.listForwards).toHaveBeenCalled(); }); diff --git a/packages/main/src/plugin/kubernetes/kubernetes-port-forward-service.ts b/packages/main/src/plugin/kubernetes/kubernetes-port-forward-service.ts index 9a6c5454a6059..ad9cd22c722a2 100644 --- a/packages/main/src/plugin/kubernetes/kubernetes-port-forward-service.ts +++ b/packages/main/src/plugin/kubernetes/kubernetes-port-forward-service.ts @@ -27,7 +27,7 @@ import { ForwardConfigRequirements } from '/@/plugin/kubernetes/kubernetes-port- import type { IDisposable } from '/@/plugin/types/disposable.js'; import { Disposable } from '/@/plugin/types/disposable.js'; import { isFreePort } from '/@/plugin/util/port.js'; -import type { ForwardConfig, ForwardOptions, UserForwardConfig } from '/@api/kubernetes-port-forward-model.js'; +import type { ForwardConfig, ForwardOptions } from '/@api/kubernetes-port-forward-model.js'; /** * Service provider for Kubernetes port forwarding. @@ -94,14 +94,13 @@ export class KubernetesPortForwardService implements IDisposable { * @returns The created forward configuration. * @param options */ - async createForward(options: ForwardOptions): Promise { - const result: UserForwardConfig = await this.configManagementService.createForward({ + async createForward(options: ForwardOptions): Promise { + const result: ForwardConfig = await this.configManagementService.createForward({ id: randomUUID(), name: options.name, forward: options.forward, namespace: options.namespace, kind: options.kind, - displayName: options.displayName, }); this.apiSender.send('kubernetes-port-forwards-update', await this.listForwards()); @@ -112,9 +111,9 @@ export class KubernetesPortForwardService implements IDisposable { * Deletes an existing forward configuration. * @param config - The forward configuration to delete. * @returns Void if the operation successful. - * @see UserForwardConfig + * @see ForwardConfig */ - async deleteForward(config: UserForwardConfig): Promise { + async deleteForward(config: ForwardConfig): Promise { const disposable = this.#disposables.get(config.id); disposable?.dispose(); this.#disposables.delete(config.id); @@ -127,9 +126,9 @@ export class KubernetesPortForwardService implements IDisposable { /** * Lists all forward configurations. * @returns A list of forward configurations. - * @see UserForwardConfig + * @see ForwardConfig */ - async listForwards(): Promise { + async listForwards(): Promise { return this.configManagementService.listForwards(); } diff --git a/packages/main/src/plugin/kubernetes/kubernetes-port-forward-storage.spec.ts b/packages/main/src/plugin/kubernetes/kubernetes-port-forward-storage.spec.ts index 55ec5dbf04d7c..892a0b0900c38 100644 --- a/packages/main/src/plugin/kubernetes/kubernetes-port-forward-storage.spec.ts +++ b/packages/main/src/plugin/kubernetes/kubernetes-port-forward-storage.spec.ts @@ -30,7 +30,7 @@ import { MemoryBasedStorage, PreferenceFolderBasedStorage, } from '/@/plugin/kubernetes/kubernetes-port-forward-storage.js'; -import type { UserForwardConfig } from '/@api/kubernetes-port-forward-model.js'; +import type { ForwardConfig } from '/@api/kubernetes-port-forward-model.js'; import { WorkloadKind } from '/@api/kubernetes-port-forward-model.js'; vi.mock('node:fs/promises', () => ({ @@ -45,15 +45,15 @@ class TestFileBasedConfigStorage extends FileBasedConfigStorage { return super.ensureStorageInitialized(); } - public override _createForward(config: UserForwardConfig): void { + public override _createForward(config: ForwardConfig): void { super._createForward(config); } - public override _deleteForward(config: UserForwardConfig): void { + public override _deleteForward(config: ForwardConfig): void { super._deleteForward(config); } - public override _updateForward(config: UserForwardConfig, newConfig: UserForwardConfig): void { + public override _updateForward(config: ForwardConfig, newConfig: ForwardConfig): void { super._updateForward(config, newConfig); } } @@ -134,13 +134,12 @@ describe('FileBasedConfigStorage', () => { getStoragePath: vi.fn().mockReturnValue('/mock/storage/path'), }; - const sampleConfig: UserForwardConfig = { + const sampleConfig: ForwardConfig = { id: 'fake-id', name: 'test-name', namespace: 'test-namespace', kind: WorkloadKind.POD, forward: { localPort: 8080, remotePort: 80 }, - displayName: 'test-display-name', }; beforeEach(() => { @@ -206,16 +205,14 @@ describe('FileBasedConfigStorage', () => { const storage = new TestFileBasedConfigStorage(mockFileStorage, 'test-key'); storage['configs'] = [sampleConfig]; - expect(() => storage._createForward(sampleConfig)).toThrow( - 'Found existed forward configuration with the same display name.', - ); + expect(() => storage._createForward(sampleConfig)).toThrow('Found existed forward configuration with the same id.'); }); test('should throw an error if deleting a non-existing forward configuration', () => { const storage = new TestFileBasedConfigStorage(mockFileStorage, 'test-key'); expect(() => storage._deleteForward(sampleConfig)).toThrow( - `Forward configuration with display name ${sampleConfig.displayName} not found.`, + `Forward configuration with id ${sampleConfig.id} not found.`, ); }); @@ -224,7 +221,7 @@ describe('FileBasedConfigStorage', () => { const newConfig = { ...sampleConfig, displayName: 'new-display-name' }; expect(() => storage._updateForward(sampleConfig, newConfig)).toThrow( - `Forward configuration with display name ${sampleConfig.displayName} not found.`, + `Forward configuration with id ${sampleConfig.id} not found.`, ); }); @@ -257,13 +254,12 @@ describe('FileBasedConfigStorage', () => { }); describe('MemoryBasedConfigStorage', () => { - const sampleConfig: UserForwardConfig = { + const sampleConfig: ForwardConfig = { id: 'fake-id', name: 'test-name', namespace: 'test-namespace', kind: WorkloadKind.POD, forward: { localPort: 8080, remotePort: 80 }, - displayName: 'test-display-name', }; beforeEach(() => { @@ -286,7 +282,7 @@ describe('MemoryBasedConfigStorage', () => { }); test('should update forward configuration', async () => { - const newConfig = { ...sampleConfig, displayName: 'new-display-name' }; + const newConfig: ForwardConfig = { ...sampleConfig, namespace: 'new-ns' }; const storage = new MemoryBasedStorage(); storage['configs'] = [sampleConfig]; await storage.updateForward(sampleConfig, newConfig); @@ -302,29 +298,27 @@ describe('MemoryBasedConfigStorage', () => { expect(result).toContainEqual(sampleConfig); }); - test('should throw an error if creating forward configuration with existing display name', () => { + test('should throw an error if creating forward configuration with existing id', () => { const storage = new MemoryBasedStorage(); storage['configs'] = [sampleConfig]; - expect(() => storage.createForward(sampleConfig)).toThrow( - 'Found existed forward configuration with the same display name.', - ); + expect(() => storage.createForward(sampleConfig)).toThrow('Found existed forward configuration with the same id.'); }); test('should throw an error if deleting a non-existing forward configuration', () => { const storage = new MemoryBasedStorage(); expect(() => storage.deleteForward(sampleConfig)).toThrow( - `Forward configuration with display name ${sampleConfig.displayName} not found.`, + `Forward configuration with id ${sampleConfig.id} not found.`, ); }); test('should throw an error if updating a non-existing forward configuration', () => { const storage = new MemoryBasedStorage(); - const newConfig = { ...sampleConfig, displayName: 'new-display-name' }; + const newConfig: ForwardConfig = { ...sampleConfig, namespace: 'new-ns' }; expect(() => storage.updateForward(sampleConfig, newConfig)).toThrow( - `Forward configuration with display name ${sampleConfig.displayName} not found.`, + `Forward configuration with id ${sampleConfig.id} not found.`, ); }); }); @@ -337,13 +331,12 @@ describe('ConfigManagementService', () => { listForwards: vi.fn(), } as unknown as ForwardConfigStorage; - const sampleConfig: UserForwardConfig = { + const sampleConfig: ForwardConfig = { id: 'fake-id', name: 'test-name', namespace: 'test-namespace', kind: WorkloadKind.POD, forward: { localPort: 8080, remotePort: 80 }, - displayName: 'test-display-name', }; test('should create forward configuration', async () => { @@ -378,9 +371,8 @@ describe('ConfigManagementService', () => { mockConfigStorage.listForwards = vi.fn().mockResolvedValue([sampleConfig]); const service = new ConfigManagementService(mockConfigStorage); - const old: UserForwardConfig = { + const old: ForwardConfig = { forward: { localPort: 8080, remotePort: 80 }, - displayName: 'dummy', namespace: 'default', kind: WorkloadKind.POD, name: 'hihi', diff --git a/packages/main/src/plugin/kubernetes/kubernetes-port-forward-storage.ts b/packages/main/src/plugin/kubernetes/kubernetes-port-forward-storage.ts index d74a55cb8741a..5577f1b329c52 100644 --- a/packages/main/src/plugin/kubernetes/kubernetes-port-forward-storage.ts +++ b/packages/main/src/plugin/kubernetes/kubernetes-port-forward-storage.ts @@ -19,7 +19,7 @@ import * as fs from 'node:fs/promises'; import path from 'node:path'; import type { Directories } from '/@/plugin/directories.js'; -import type { UserForwardConfig } from '/@api/kubernetes-port-forward-model.js'; +import type { ForwardConfig } from '/@api/kubernetes-port-forward-model.js'; /** * Interface for forward configuration storage. @@ -29,33 +29,33 @@ export interface ForwardConfigStorage { * Creates a new forward configuration. * @param config - The forward configuration to create. * @returns The created forward configuration. - * @see UserForwardConfig + * @see ForwardConfig */ - createForward(config: UserForwardConfig): Promise; + createForward(config: ForwardConfig): Promise; /** * Deletes an existing forward configuration. * @param config - The forward configuration to delete. * @returns Void if the operation successful. - * @see UserForwardConfig + * @see ForwardConfig */ - deleteForward(config: UserForwardConfig): Promise; + deleteForward(config: ForwardConfig): Promise; /** * Updates an existing forward configuration. * @param config - The existing forward configuration. * @param newConfig - The new forward configuration. * @returns The updated forward configuration. - * @see UserForwardConfig + * @see ForwardConfig */ - updateForward(config: UserForwardConfig, newConfig: UserForwardConfig): Promise; + updateForward(config: ForwardConfig, newConfig: ForwardConfig): Promise; /** * Lists all forward configurations. * @returns A list of forward configurations. - * @see UserForwardConfig + * @see ForwardConfig */ - listForwards(): Promise; + listForwards(): Promise; } /** @@ -158,7 +158,7 @@ export class PreferenceFolderBasedStorage implements FileBasedStorage { * @see ForwardConfigStorage */ export class FileBasedConfigStorage implements ForwardConfigStorage { - private configs: UserForwardConfig[] = []; + private configs: ForwardConfig[] = []; /** * Creates an instance of FileBasedConfigStorage. @@ -176,9 +176,9 @@ export class FileBasedConfigStorage implements ForwardConfigStorage { * @param config - The forward configuration to create. * @returns The created forward configuration. * @throws If the storage is not initialized or creation fails. - * @see UserForwardConfig + * @see ForwardConfig */ - async createForward(config: UserForwardConfig): Promise { + async createForward(config: ForwardConfig): Promise { await this.ensureStorageInitialized(); this._createForward(config); await this.flushStorage(); @@ -191,9 +191,9 @@ export class FileBasedConfigStorage implements ForwardConfigStorage { * @param config - The forward configuration to delete. * @returns Void if the operation successful. * @throws If the storage is not initialized or deletion fails. - * @see UserForwardConfig + * @see ForwardConfig */ - async deleteForward(config: UserForwardConfig): Promise { + async deleteForward(config: ForwardConfig): Promise { await this.ensureStorageInitialized(); this._deleteForward(config); await this.flushStorage(); @@ -205,9 +205,9 @@ export class FileBasedConfigStorage implements ForwardConfigStorage { * @param newConfig - The new forward configuration. * @returns The updated forward configuration. * @throws If the storage is not initialized or update fails. - * @see UserForwardConfig + * @see ForwardConfig */ - async updateForward(config: UserForwardConfig, newConfig: UserForwardConfig): Promise { + async updateForward(config: ForwardConfig, newConfig: ForwardConfig): Promise { await this.ensureStorageInitialized(); this._updateForward(config, newConfig); await this.flushStorage(); @@ -218,9 +218,9 @@ export class FileBasedConfigStorage implements ForwardConfigStorage { * Lists all forward configurations. * @returns A list of forward configurations. * @throws If the storage is not initialized. - * @see UserForwardConfig + * @see ForwardConfig */ - async listForwards(): Promise { + async listForwards(): Promise { await this.ensureStorageInitialized(); return [...this.configs]; } @@ -235,7 +235,7 @@ export class FileBasedConfigStorage implements ForwardConfigStorage { await this.fileStorage.initStorage(); const storagePath = this.fileStorage.getStoragePath(); const fileContent = await fs.readFile(storagePath, 'utf-8'); - const configMap: Map = new Map(Object.entries(JSON.parse(fileContent))); + const configMap: Map = new Map(Object.entries(JSON.parse(fileContent))); if (configMap.has(this.configKey)) { this.configs = configMap.get(this.configKey) ?? []; @@ -253,7 +253,7 @@ export class FileBasedConfigStorage implements ForwardConfigStorage { protected async flushStorage(): Promise { const storagePath = this.fileStorage.getStoragePath(); const fileContent = await fs.readFile(storagePath, 'utf-8'); - const configMap: Map = new Map(Object.entries(JSON.parse(fileContent))); + const configMap: Map = new Map(Object.entries(JSON.parse(fileContent))); configMap.set(this.configKey, this.configs); @@ -265,12 +265,12 @@ export class FileBasedConfigStorage implements ForwardConfigStorage { * Creates a new forward configuration in memory. * @param config - The forward configuration to create. * @throws If a configuration with the same display name already exists. - * @see UserForwardConfig + * @see ForwardConfig */ - protected _createForward(config: UserForwardConfig): void { - const index = this.configs.findIndex(c => c.displayName === config.displayName); + protected _createForward(config: ForwardConfig): void { + const index = this.configs.findIndex(c => c.id === config.id); if (index > -1) { - throw new Error('Found existed forward configuration with the same display name.'); + throw new Error('Found existed forward configuration with the same id.'); } this.configs.push(config); @@ -280,12 +280,12 @@ export class FileBasedConfigStorage implements ForwardConfigStorage { * Deletes an existing forward configuration in memory. * @param config - The forward configuration to delete. * @throws If the configuration is not found. - * @see UserForwardConfig + * @see ForwardConfig */ - protected _deleteForward(config: UserForwardConfig): void { - const index = this.configs.findIndex(c => c.displayName === config.displayName); + protected _deleteForward(config: ForwardConfig): void { + const index = this.configs.findIndex(c => c.id === config.id); if (index === -1) { - throw new Error(`Forward configuration with display name ${config.displayName} not found.`); + throw new Error(`Forward configuration with id ${config.id} not found.`); } this.configs.splice(index, 1); @@ -296,12 +296,12 @@ export class FileBasedConfigStorage implements ForwardConfigStorage { * @param config - The existing forward configuration. * @param newConfig - The new forward configuration. * @throws If the configuration is not found. - * @see UserForwardConfig + * @see ForwardConfig */ - protected _updateForward(config: UserForwardConfig, newConfig: UserForwardConfig): void { - const index = this.configs.findIndex(c => c.displayName === config.displayName); + protected _updateForward(config: ForwardConfig, newConfig: ForwardConfig): void { + const index = this.configs.findIndex(c => c.id === config.id); if (index === -1) { - throw new Error(`Forward configuration with display name ${config.displayName} not found.`); + throw new Error(`Forward configuration with id ${config.id} not found.`); } this.configs[index] = newConfig; @@ -309,36 +309,36 @@ export class FileBasedConfigStorage implements ForwardConfigStorage { } export class MemoryBasedStorage implements ForwardConfigStorage { - private configs: UserForwardConfig[] = []; + private configs: ForwardConfig[] = []; - createForward(config: UserForwardConfig): Promise { - const index = this.configs.findIndex(c => c.displayName === config.displayName); + createForward(config: ForwardConfig): Promise { + const index = this.configs.findIndex(c => c.id === config.id); if (index > -1) { - throw new Error('Found existed forward configuration with the same display name.'); + throw new Error('Found existed forward configuration with the same id.'); } this.configs.push(config); return Promise.resolve(config); } - deleteForward(config: UserForwardConfig): Promise { - const index = this.configs.findIndex(c => c.displayName === config.displayName); + deleteForward(config: ForwardConfig): Promise { + const index = this.configs.findIndex(c => c.id === config.id); if (index === -1) { - throw new Error(`Forward configuration with display name ${config.displayName} not found.`); + throw new Error(`Forward configuration with id ${config.id} not found.`); } this.configs.splice(index, 1); return Promise.resolve(); } - listForwards(): Promise { + listForwards(): Promise { return Promise.resolve(this.configs); } - updateForward(config: UserForwardConfig, newConfig: UserForwardConfig): Promise { - const index = this.configs.findIndex(c => c.displayName === config.displayName); + updateForward(config: ForwardConfig, newConfig: ForwardConfig): Promise { + const index = this.configs.findIndex(c => c.id === config.id); if (index === -1) { - throw new Error(`Forward configuration with display name ${config.displayName} not found.`); + throw new Error(`Forward configuration with id ${config.id} not found.`); } this.configs[index] = newConfig; @@ -362,9 +362,9 @@ export class ConfigManagementService { * Creates a new forward configuration. * @param config - The forward configuration to create. * @returns The created forward configuration. - * @see UserForwardConfig + * @see ForwardConfig */ - async createForward(config: UserForwardConfig): Promise { + async createForward(config: ForwardConfig): Promise { return this.configStorage.createForward(config); } @@ -372,9 +372,9 @@ export class ConfigManagementService { * Deletes an existing forward configuration. * @param config - The forward configuration to delete. * @returns Void if the operation successful. - * @see UserForwardConfig + * @see ForwardConfig */ - async deleteForward(config: UserForwardConfig): Promise { + async deleteForward(config: ForwardConfig): Promise { return this.configStorage.deleteForward(config); } @@ -383,18 +383,18 @@ export class ConfigManagementService { * @param oldConfig - The forward configuration to update * @param newConfig - The * @returns The updated configuration - * @see UserForwardConfig + * @see ForwardConfig */ - async updateForward(oldConfig: UserForwardConfig, newConfig: UserForwardConfig): Promise { + async updateForward(oldConfig: ForwardConfig, newConfig: ForwardConfig): Promise { return this.configStorage.updateForward(oldConfig, newConfig); } /** * Lists all forward configurations. * @returns A list of forward configurations. - * @see UserForwardConfig + * @see ForwardConfig */ - async listForwards(): Promise { + async listForwards(): Promise { return this.configStorage.listForwards(); } } diff --git a/packages/preload/src/index.spec.ts b/packages/preload/src/index.spec.ts index 35cb57239caa8..cf724967707df 100644 --- a/packages/preload/src/index.spec.ts +++ b/packages/preload/src/index.spec.ts @@ -23,7 +23,7 @@ import type { IpcRenderer, IpcRendererEvent } from 'electron'; import { contextBridge, ipcRenderer } from 'electron'; import { beforeEach, expect, test, vi } from 'vitest'; -import type { UserForwardConfig } from '/@api/kubernetes-port-forward-model'; +import type { ForwardConfig } from '/@api/kubernetes-port-forward-model'; import { WorkloadKind } from '/@api/kubernetes-port-forward-model'; import { buildApiSender, initExposure } from '.'; @@ -223,9 +223,8 @@ test('createKubernetesPortForward', async () => { }, ); - const userPortForward: UserForwardConfig = { + const userPortForward: ForwardConfig = { id: 'fake-id', - displayName: 'My port forward', namespace: 'kubernetes', name: 'service', kind: WorkloadKind.SERVICE, @@ -262,9 +261,8 @@ test('deleteKubernetesPortForward', async () => { }, ); - const userPortForward: UserForwardConfig = { + const userPortForward: ForwardConfig = { id: 'fake-id', - displayName: 'My port forward', namespace: 'kubernetes', name: 'service', kind: WorkloadKind.SERVICE, diff --git a/packages/preload/src/index.ts b/packages/preload/src/index.ts index 1a301141a0eab..599f0dc5e89b2 100644 --- a/packages/preload/src/index.ts +++ b/packages/preload/src/index.ts @@ -68,7 +68,7 @@ import type { ImageInspectInfo } from '/@api/image-inspect-info'; import type { ImageSearchOptions, ImageSearchResult, ImageTagsListOptions } from '/@api/image-registry'; import type { KubeContext } from '/@api/kubernetes-context'; import type { ContextGeneralState, ResourceName } from '/@api/kubernetes-contexts-states'; -import type { ForwardOptions, PortMapping, UserForwardConfig } from '/@api/kubernetes-port-forward-model'; +import type { ForwardConfig, ForwardOptions } from '/@api/kubernetes-port-forward-model'; import type { ManifestCreateOptions, ManifestInspectInfo, ManifestPushOptions } from '/@api/manifest-info'; import type { NetworkInspectInfo } from '/@api/network-info'; import type { NotificationCard, NotificationCardOptions } from '/@api/notification'; @@ -2114,23 +2114,20 @@ export function initExposure(): void { return ipcInvoke('kubernetes-client:refreshContextState', context); }); - contextBridge.exposeInMainWorld('getKubernetesPortForwards', async (): Promise => { + contextBridge.exposeInMainWorld('getKubernetesPortForwards', async (): Promise => { return ipcInvoke('kubernetes-client:getPortForwards'); }); contextBridge.exposeInMainWorld( 'createKubernetesPortForward', - async (options: ForwardOptions): Promise => { + async (options: ForwardOptions): Promise => { return ipcInvoke('kubernetes-client:createPortForward', options); }, ); - contextBridge.exposeInMainWorld( - 'deleteKubernetesPortForward', - async (config: UserForwardConfig, mapping?: PortMapping): Promise => { - return ipcInvoke('kubernetes-client:deletePortForward', config, mapping); - }, - ); + contextBridge.exposeInMainWorld('deleteKubernetesPortForward', async (config: ForwardConfig): Promise => { + return ipcInvoke('kubernetes-client:deletePortForward', config); + }); contextBridge.exposeInMainWorld( 'openshiftCreateRoute', diff --git a/packages/renderer/src/AppNavigation.spec.ts b/packages/renderer/src/AppNavigation.spec.ts index ba3d71652aa72..530671591cd02 100644 --- a/packages/renderer/src/AppNavigation.spec.ts +++ b/packages/renderer/src/AppNavigation.spec.ts @@ -27,7 +27,7 @@ import { beforeAll, expect, test, vi } from 'vitest'; import * as kubeContextStore from '/@/stores/kubernetes-contexts-state'; import type { ContributionInfo } from '/@api/contribution-info'; import type { ContextGeneralState } from '/@api/kubernetes-contexts-states'; -import type { UserForwardConfig } from '/@api/kubernetes-port-forward-model'; +import type { ForwardConfig } from '/@api/kubernetes-port-forward-model'; import AppNavigation from './AppNavigation.svelte'; import { contributions } from './stores/contribs'; @@ -60,7 +60,7 @@ test('Test rendering of the navigation bar with empty items', async () => { vi.mocked(kubeContextStore).kubernetesCurrentContextConfigMaps = readable([]); vi.mocked(kubeContextStore).kubernetesCurrentContextSecrets = readable([]); vi.mocked(kubeContextStore).kubernetesCurrentContextPersistentVolumeClaims = readable([]); - vi.mocked(kubeContextStore).kubernetesCurrentContextPortForwards = readable([]); + vi.mocked(kubeContextStore).kubernetesCurrentContextPortForwards = readable([]); vi.mocked(kubeContextStore).kubernetesCurrentContextState = readable({} as ContextGeneralState); // init navigation registry diff --git a/packages/renderer/src/lib/kube/details/KubePort.spec.ts b/packages/renderer/src/lib/kube/details/KubePort.spec.ts index cd4dcf48f3a48..600d7b009f377 100644 --- a/packages/renderer/src/lib/kube/details/KubePort.spec.ts +++ b/packages/renderer/src/lib/kube/details/KubePort.spec.ts @@ -21,7 +21,7 @@ import '@testing-library/jest-dom/vitest'; import { fireEvent, render } from '@testing-library/svelte'; import { beforeEach, describe, expect, test, vi } from 'vitest'; -import { type UserForwardConfig, WorkloadKind } from '/@api/kubernetes-port-forward-model'; +import { type ForwardConfig, WorkloadKind } from '/@api/kubernetes-port-forward-model'; import KubePort from './KubePort.svelte'; @@ -34,7 +34,7 @@ beforeEach(() => { (window.deleteKubernetesPortForward as unknown) = vi.fn(); }); -const DUMMY_FORWARD_CONFIG: UserForwardConfig = { +const DUMMY_FORWARD_CONFIG: ForwardConfig = { id: 'fake-id', name: 'dummy-pod-name', namespace: 'dummy-ns', @@ -43,7 +43,6 @@ const DUMMY_FORWARD_CONFIG: UserForwardConfig = { localPort: 55_076, remotePort: 80, }, - displayName: 'dummy name', }; describe('port forwarding', () => { @@ -83,7 +82,6 @@ describe('port forwarding', () => { await vi.waitFor(() => { expect(window.getFreePort).toHaveBeenCalled(); expect(window.createKubernetesPortForward).toHaveBeenCalledWith({ - displayName: 'dummy-pod-name/undefined', forward: { localPort: 55001, remotePort: 80, diff --git a/packages/renderer/src/lib/kube/details/KubePort.svelte b/packages/renderer/src/lib/kube/details/KubePort.svelte index c6bb0787206b4..0f8994fb62f9f 100644 --- a/packages/renderer/src/lib/kube/details/KubePort.svelte +++ b/packages/renderer/src/lib/kube/details/KubePort.svelte @@ -3,13 +3,13 @@ import { faQuestionCircle, faSquareUpRight, faTrash } from '@fortawesome/free-so import { Button, ErrorMessage, Tooltip } from '@podman-desktop/ui-svelte'; import Fa from 'svelte-fa'; -import type { PortMapping, UserForwardConfig, WorkloadKind } from '/@api/kubernetes-port-forward-model'; +import type { ForwardConfig, PortMapping, WorkloadKind } from '/@api/kubernetes-port-forward-model'; import type { KubePortInfo } from './kube-port'; interface Props { port: KubePortInfo; - forwardConfig?: UserForwardConfig; + forwardConfig?: ForwardConfig; resourceName?: string; namespace?: string; kind: WorkloadKind; @@ -33,7 +33,6 @@ async function onForwardRequest(port: KubePortInfo): Promise { const snapshot: KubePortInfo = $state.snapshot(port); try { await window.createKubernetesPortForward({ - displayName: `${resourceName}/${snapshot.name}`, name: resourceName, kind: kind, namespace: namespace ?? 'default', diff --git a/packages/renderer/src/lib/kube/details/KubePortsList.svelte b/packages/renderer/src/lib/kube/details/KubePortsList.svelte index 24bb3ef381b0b..2f911ffc82631 100644 --- a/packages/renderer/src/lib/kube/details/KubePortsList.svelte +++ b/packages/renderer/src/lib/kube/details/KubePortsList.svelte @@ -1,7 +1,7 @@