Merge pull request #4791 from ayshiff/feature/kubernetes-clusters-config
Kubernetes plugin: Read cluster config from api
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-kubernetes': patch
|
||||
---
|
||||
|
||||
Adds a new method `getClusters` to grab cluster configuration in the frontend
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ObjectsByEntityResponse>;
|
||||
getClusters(): Config[];
|
||||
}
|
||||
|
||||
@@ -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<string | undefined>(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'),
|
||||
);
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user