diff --git a/packages/main/src/plugin/kubernetes/contexts-manager.spec.ts b/packages/main/src/plugin/kubernetes/contexts-manager.spec.ts index 28d456c29e77a..de3e1744a58ff 100644 --- a/packages/main/src/plugin/kubernetes/contexts-manager.spec.ts +++ b/packages/main/src/plugin/kubernetes/contexts-manager.spec.ts @@ -235,8 +235,13 @@ describe('update', async () => { deployments: DEPLOYMENTS_NS1, }, }); - expect(dispatchCurrentContextResourceSpy).toHaveBeenCalledWith('pods', Array(PODS_NS1).fill({})); - expect(dispatchCurrentContextResourceSpy).toHaveBeenCalledWith('deployments', Array(DEPLOYMENTS_NS1).fill({})); + expect(dispatchCurrentContextResourceSpy).toHaveBeenCalledWith('pods', [{ metadata: { uid: '0' } }]); + expect(dispatchCurrentContextResourceSpy).toHaveBeenCalledWith('deployments', [ + { metadata: { uid: '0' } }, + { metadata: { uid: '1' } }, + { metadata: { uid: '2' } }, + { metadata: { uid: '3' } }, + ]); const expectedCheckMap = new Map(); expectedCheckMap.set('context1', { state: 'waiting' }); @@ -329,8 +334,13 @@ describe('update', async () => { deployments: DEPLOYMENTS_NS1, }, }); - expect(dispatchCurrentContextResourceSpy).toHaveBeenCalledWith('pods', Array(PODS_NS1).fill({})); - expect(dispatchCurrentContextResourceSpy).toHaveBeenCalledWith('deployments', Array(DEPLOYMENTS_NS1).fill({})); + expect(dispatchCurrentContextResourceSpy).toHaveBeenCalledWith('pods', [{ metadata: { uid: '0' } }]); + expect(dispatchCurrentContextResourceSpy).toHaveBeenCalledWith('deployments', [ + { metadata: { uid: '0' } }, + { metadata: { uid: '1' } }, + { metadata: { uid: '2' } }, + { metadata: { uid: '3' } }, + ]); }); test('should check current context if contexts are > 10', async () => { @@ -860,7 +870,10 @@ describe('update', async () => { }, }); expect(dispatchCurrentContextResourceSpy).toHaveBeenCalledWith('pods', []); - expect(dispatchCurrentContextResourceSpy).toHaveBeenCalledWith('deployments', [{}, {}]); + expect(dispatchCurrentContextResourceSpy).toHaveBeenCalledWith('deployments', [ + { metadata: { uid: '0' } }, + { metadata: { uid: '1' } }, + ]); vi.advanceTimersToNextTimer(); // error event vi.advanceTimersToNextTimer(); // dispatches @@ -1038,7 +1051,7 @@ describe('update', async () => { deployments: 0, }, }); - expect(dispatchCurrentContextResourceSpy).toHaveBeenCalledWith(resource, [{}]); + expect(dispatchCurrentContextResourceSpy).toHaveBeenCalledWith(resource, [{ metadata: { uid: '0' } }]); }); test('createInformer should send data for deleted and updated resource', async () => { diff --git a/packages/main/src/plugin/kubernetes/contexts-manager.ts b/packages/main/src/plugin/kubernetes/contexts-manager.ts index f27eb6c65b29d..72678b680e83e 100644 --- a/packages/main/src/plugin/kubernetes/contexts-manager.ts +++ b/packages/main/src/plugin/kubernetes/contexts-manager.ts @@ -391,7 +391,13 @@ export class ContextsManager { sendGeneral: true, currentContext: this.kubeConfig.currentContext, resources: { pods: true }, - update: state => state.resources.pods.push(obj), + update: state => { + if (state.resources.pods.some(o => o.metadata?.uid !== obj.metadata?.uid)) { + console.debug(`pod ${obj.metadata?.name} already added in context ${this.kubeConfig.currentContext}`); + } + state.resources.pods = state.resources.pods.filter(o => o.metadata?.uid !== obj.metadata?.uid); + state.resources.pods.push(obj); + }, }); }, onUpdate: obj => { diff --git a/packages/main/src/plugin/kubernetes/test-informer.ts b/packages/main/src/plugin/kubernetes/test-informer.ts index 319cd50d4fbc6..bfaf26c8e7d27 100644 --- a/packages/main/src/plugin/kubernetes/test-informer.ts +++ b/packages/main/src/plugin/kubernetes/test-informer.ts @@ -57,7 +57,7 @@ export class TestInformer { } if (this.connectResponse === undefined) { for (let i = 0; i < this.resourcesCount; i++) { - this.onCb.get('add')?.({}); + this.onCb.get('add')?.({ metadata: { uid: i.toString() } }); } this.events.forEach(event => { setTimeout(() => {