From 0dab3848267f0aa29c2314f3388df0af3af306c0 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Thu, 13 Feb 2025 18:55:36 +0300 Subject: [PATCH] K8s/Frontend: Update watch support (#100631) use watch from gitsync --- public/app/features/apiserver/client.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/public/app/features/apiserver/client.ts b/public/app/features/apiserver/client.ts index 90a5004b8b0..f631aca175a 100644 --- a/public/app/features/apiserver/client.ts +++ b/public/app/features/apiserver/client.ts @@ -1,6 +1,6 @@ import { Observable, from, retry, catchError, filter, map, mergeMap } from 'rxjs'; -import { config, getBackendSrv } from '@grafana/runtime'; +import { BackendSrvRequest, config, getBackendSrv } from '@grafana/runtime'; import { contextSrv } from 'app/core/core'; import { getAPINamespace } from '../../api/utils'; @@ -40,18 +40,26 @@ export class ScopedResourceClient implements return getBackendSrv().get>(`${this.url}/${name}`); } - public watch(opts?: WatchOptions): Observable> { + public watch( + params?: WatchOptions, + config?: Pick + ): Observable> { const decoder = new TextDecoder(); - const params = { - ...opts, + const { name, ...rest } = params ?? {}; // name needs to be added to fieldSelector + const requestParams = { + ...rest, watch: true, - labelSelector: this.parseListOptionsSelector(opts?.labelSelector), - fieldSelector: this.parseListOptionsSelector(opts?.fieldSelector), + labelSelector: this.parseListOptionsSelector(params?.labelSelector), + fieldSelector: this.parseListOptionsSelector(params?.fieldSelector), }; + if (name) { + requestParams.fieldSelector = `metadata.name=${name}`; + } return getBackendSrv() .chunked({ - url: params.name ? `${this.url}/${params.name}` : this.url, - params, + url: this.url, + params: requestParams, + ...config, }) .pipe( filter((response) => response.ok && response.data instanceof Uint8Array),