From 61c9c0ba0e0595272c7e69a5009b77244df1e39a Mon Sep 17 00:00:00 2001 From: Remi Date: Thu, 4 Mar 2021 01:01:48 +0100 Subject: [PATCH 1/3] fix(kubernetes-plugin): read cluster config from api Signed-off-by: Remi --- plugins/kubernetes/src/api/KubernetesBackendClient.ts | 10 +++++++++- plugins/kubernetes/src/api/types.ts | 2 ++ .../KubernetesContent/KubernetesContent.tsx | 4 +--- plugins/kubernetes/src/plugin.ts | 11 ++++++++--- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/plugins/kubernetes/src/api/KubernetesBackendClient.ts b/plugins/kubernetes/src/api/KubernetesBackendClient.ts index dcb2cca142..353f5e8800 100644 --- a/plugins/kubernetes/src/api/KubernetesBackendClient.ts +++ b/plugins/kubernetes/src/api/KubernetesBackendClient.ts @@ -14,23 +14,27 @@ * limitations under the License. */ -import { DiscoveryApi, IdentityApi } from '@backstage/core'; +import { ConfigApi, DiscoveryApi, IdentityApi } from '@backstage/core'; import { KubernetesApi } from './types'; import { KubernetesRequestBody, ObjectsByEntityResponse, } from '@backstage/plugin-kubernetes-backend'; +import { Config } from '@backstage/config'; export class KubernetesBackendClient implements KubernetesApi { private readonly discoveryApi: DiscoveryApi; private readonly identityApi: IdentityApi; + private readonly configApi: ConfigApi; constructor(options: { discoveryApi: DiscoveryApi; identityApi: IdentityApi; + configApi: ConfigApi; }) { this.discoveryApi = options.discoveryApi; this.identityApi = options.identityApi; + this.configApi = options.configApi; } private async getRequired( @@ -73,4 +77,8 @@ export class KubernetesBackendClient implements KubernetesApi { requestBody, ); } + + getClusters(): Config[] { + return this.configApi.getConfigArray('kubernetes.clusters'); + } } diff --git a/plugins/kubernetes/src/api/types.ts b/plugins/kubernetes/src/api/types.ts index 498e74a626..d9ed79e720 100644 --- a/plugins/kubernetes/src/api/types.ts +++ b/plugins/kubernetes/src/api/types.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Config } from '@backstage/config'; import { createApiRef } from '@backstage/core'; import { KubernetesRequestBody, @@ -30,4 +31,5 @@ export interface KubernetesApi { getObjectsByEntity( requestBody: KubernetesRequestBody, ): Promise; + getClusters(): Config[]; } diff --git a/plugins/kubernetes/src/components/KubernetesContent/KubernetesContent.tsx b/plugins/kubernetes/src/components/KubernetesContent/KubernetesContent.tsx index 18351c7455..ec08267579 100644 --- a/plugins/kubernetes/src/components/KubernetesContent/KubernetesContent.tsx +++ b/plugins/kubernetes/src/components/KubernetesContent/KubernetesContent.tsx @@ -25,7 +25,6 @@ import { } from '@material-ui/core'; import { Config } from '@backstage/config'; import { - configApiRef, Content, Page, Progress, @@ -169,8 +168,7 @@ export const KubernetesContent = ({ entity }: KubernetesContentProps) => { >(undefined); const [error, setError] = useState(undefined); - const configApi = useApi(configApiRef); - const clusters: Config[] = configApi.getConfigArray('kubernetes.clusters'); + const clusters: Config[] = kubernetesApi.getClusters(); const allAuthProviders: string[] = clusters.map(c => c.getString('authProvider'), ); diff --git a/plugins/kubernetes/src/plugin.ts b/plugins/kubernetes/src/plugin.ts index 24f51fe64a..6da1abb4b6 100644 --- a/plugins/kubernetes/src/plugin.ts +++ b/plugins/kubernetes/src/plugin.ts @@ -21,6 +21,7 @@ import { identityApiRef, googleAuthApiRef, createRoutableExtension, + configApiRef, } from '@backstage/core'; import { KubernetesBackendClient } from './api/KubernetesBackendClient'; import { kubernetesApiRef } from './api/types'; @@ -37,9 +38,13 @@ export const kubernetesPlugin = createPlugin({ apis: [ createApiFactory({ api: kubernetesApiRef, - deps: { discoveryApi: discoveryApiRef, identityApi: identityApiRef }, - factory: ({ discoveryApi, identityApi }) => - new KubernetesBackendClient({ discoveryApi, identityApi }), + deps: { + discoveryApi: discoveryApiRef, + identityApi: identityApiRef, + configApi: configApiRef, + }, + factory: ({ discoveryApi, identityApi, configApi }) => + new KubernetesBackendClient({ discoveryApi, identityApi, configApi }), }), createApiFactory({ api: kubernetesAuthProvidersApiRef, From 763926bc1812738b9feb5a3ff6aeec1bededc56b Mon Sep 17 00:00:00 2001 From: Ben Lambert Date: Thu, 4 Mar 2021 16:58:59 +0100 Subject: [PATCH 2/3] Create twelve-seahorses-flow.md Signed-off-by: blam --- .changeset/twelve-seahorses-flow.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/twelve-seahorses-flow.md diff --git a/.changeset/twelve-seahorses-flow.md b/.changeset/twelve-seahorses-flow.md new file mode 100644 index 0000000000..2e2fd1e803 --- /dev/null +++ b/.changeset/twelve-seahorses-flow.md @@ -0,0 +1,5 @@ +--- +"@backstage/plugin-kubernetes": patch +--- + +Adds a new method `getClusters` to grab cluster configuration in the frontend From 4d8d54f561cc5e4d5f108a91f1515c3282828e16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Doreau?= Date: Thu, 4 Mar 2021 17:13:19 +0100 Subject: [PATCH 3/3] fix(changeset): prettier MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémi Doreau --- .changeset/twelve-seahorses-flow.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/twelve-seahorses-flow.md b/.changeset/twelve-seahorses-flow.md index 2e2fd1e803..5bd6dd2111 100644 --- a/.changeset/twelve-seahorses-flow.md +++ b/.changeset/twelve-seahorses-flow.md @@ -1,5 +1,5 @@ --- -"@backstage/plugin-kubernetes": patch +'@backstage/plugin-kubernetes': patch --- Adds a new method `getClusters` to grab cluster configuration in the frontend