Merge pull request #6782 from livetocode/feature/k8s-dashboard-links
provide access to the Kubernetes dashboard when viewing a specific resource
This commit is contained in:
@@ -3,10 +3,11 @@
|
||||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
||||
|
||||
```ts
|
||||
import { ClusterObjects } from '@backstage/plugin-kubernetes-common';
|
||||
import { Config } from '@backstage/config';
|
||||
import express from 'express';
|
||||
import { FetchResponse } from '@backstage/plugin-kubernetes-common';
|
||||
import { KubernetesFetchError } from '@backstage/plugin-kubernetes-common';
|
||||
import type { FetchResponse } from '@backstage/plugin-kubernetes-common';
|
||||
import type { KubernetesFetchError } from '@backstage/plugin-kubernetes-common';
|
||||
import { KubernetesRequestBody } from '@backstage/plugin-kubernetes-common';
|
||||
import { Logger as Logger_2 } from 'winston';
|
||||
|
||||
@@ -26,7 +27,8 @@ export interface AWSClusterDetails extends ClusterDetails {
|
||||
export interface ClusterDetails {
|
||||
// (undocumented)
|
||||
authProvider: string;
|
||||
// (undocumented)
|
||||
dashboardApp?: string;
|
||||
dashboardUrl?: string;
|
||||
name: string;
|
||||
// (undocumented)
|
||||
serviceAccountToken?: string | undefined;
|
||||
|
||||
@@ -66,6 +66,7 @@ describe('ConfigClusterLocator', () => {
|
||||
url: 'http://localhost:8080',
|
||||
authProvider: 'serviceAccount',
|
||||
skipTLSVerify: false,
|
||||
dashboardUrl: 'https://k8s.foo.com',
|
||||
},
|
||||
{
|
||||
name: 'cluster2',
|
||||
@@ -83,6 +84,7 @@ describe('ConfigClusterLocator', () => {
|
||||
expect(result).toStrictEqual([
|
||||
{
|
||||
name: 'cluster1',
|
||||
dashboardUrl: 'https://k8s.foo.com',
|
||||
serviceAccountToken: 'token',
|
||||
url: 'http://localhost:8080',
|
||||
authProvider: 'serviceAccount',
|
||||
|
||||
@@ -30,13 +30,21 @@ export class ConfigClusterLocator implements KubernetesClustersSupplier {
|
||||
return new ConfigClusterLocator(
|
||||
config.getConfigArray('clusters').map(c => {
|
||||
const authProvider = c.getString('authProvider');
|
||||
const clusterDetails = {
|
||||
const clusterDetails: ClusterDetails = {
|
||||
name: c.getString('name'),
|
||||
url: c.getString('url'),
|
||||
serviceAccountToken: c.getOptionalString('serviceAccountToken'),
|
||||
skipTLSVerify: c.getOptionalBoolean('skipTLSVerify') ?? false,
|
||||
authProvider: authProvider,
|
||||
};
|
||||
const dashboardUrl = c.getOptionalString('dashboardUrl');
|
||||
if (dashboardUrl) {
|
||||
clusterDetails.dashboardUrl = dashboardUrl;
|
||||
}
|
||||
const dashboardApp = c.getOptionalString('dashboardApp');
|
||||
if (dashboardApp) {
|
||||
clusterDetails.dashboardApp = dashboardApp;
|
||||
}
|
||||
|
||||
switch (authProvider) {
|
||||
case 'google': {
|
||||
|
||||
@@ -211,6 +211,7 @@ describe('handleGetKubernetesObjectsForService', () => {
|
||||
{
|
||||
name: 'test-cluster',
|
||||
authProvider: 'serviceAccount',
|
||||
dashboardUrl: 'https://k8s.foo.coom',
|
||||
},
|
||||
{
|
||||
name: 'other-cluster',
|
||||
@@ -260,6 +261,7 @@ describe('handleGetKubernetesObjectsForService', () => {
|
||||
items: [
|
||||
{
|
||||
cluster: {
|
||||
dashboardUrl: 'https://k8s.foo.coom',
|
||||
name: 'test-cluster',
|
||||
},
|
||||
errors: [],
|
||||
|
||||
@@ -22,7 +22,10 @@ import {
|
||||
KubernetesObjectTypes,
|
||||
KubernetesServiceLocator,
|
||||
} from '../types/types';
|
||||
import { KubernetesRequestBody } from '@backstage/plugin-kubernetes-common';
|
||||
import {
|
||||
ClusterObjects,
|
||||
KubernetesRequestBody,
|
||||
} from '@backstage/plugin-kubernetes-common';
|
||||
import { KubernetesAuthTranslator } from '../kubernetes-auth-translator/types';
|
||||
import { KubernetesAuthTranslatorGenerator } from '../kubernetes-auth-translator/KubernetesAuthTranslatorGenerator';
|
||||
|
||||
@@ -111,13 +114,20 @@ export class KubernetesFanOutHandler {
|
||||
customResources: this.customResources,
|
||||
})
|
||||
.then(result => {
|
||||
return {
|
||||
const objects: ClusterObjects = {
|
||||
cluster: {
|
||||
name: clusterDetailsItem.name,
|
||||
},
|
||||
resources: result.responses,
|
||||
errors: result.errors,
|
||||
};
|
||||
if (clusterDetailsItem.dashboardUrl) {
|
||||
objects.cluster.dashboardUrl = clusterDetailsItem.dashboardUrl;
|
||||
}
|
||||
if (clusterDetailsItem.dashboardApp) {
|
||||
objects.cluster.dashboardApp = clusterDetailsItem.dashboardApp;
|
||||
}
|
||||
return objects;
|
||||
});
|
||||
}),
|
||||
).then(r => ({
|
||||
|
||||
@@ -86,6 +86,7 @@ export const makeRouter = (
|
||||
res.json({
|
||||
items: clusterDetails.map(cd => ({
|
||||
name: cd.name,
|
||||
dashboardUrl: cd.dashboardUrl,
|
||||
authProvider: cd.authProvider,
|
||||
})),
|
||||
});
|
||||
|
||||
@@ -75,11 +75,39 @@ export interface KubernetesServiceLocator {
|
||||
export type ServiceLocatorMethod = 'multiTenant' | 'http'; // TODO implement http
|
||||
|
||||
export interface ClusterDetails {
|
||||
/**
|
||||
* Specifies the name of the Kubernetes cluster.
|
||||
*/
|
||||
name: string;
|
||||
url: string;
|
||||
authProvider: string;
|
||||
serviceAccountToken?: string | undefined;
|
||||
skipTLSVerify?: boolean;
|
||||
/**
|
||||
* Specifies the link to the Kubernetes dashboard managing this cluster.
|
||||
* @remarks
|
||||
* Note that you should specify the app used for the dashboard
|
||||
* using the dashboardApp property, in order to properly format
|
||||
* links to kubernetes resources, otherwise it will assume that you're running the standard one.
|
||||
* @see dashboardApp
|
||||
*/
|
||||
dashboardUrl?: string;
|
||||
/**
|
||||
* Specifies the app that provides the Kubernetes dashboard.
|
||||
* This will be used for formatting links to kubernetes objects inside the dashboard.
|
||||
* @remarks
|
||||
* The existing apps are: standard, rancher, openshift, gke, aks, eks
|
||||
* Note that it will default to the regular dashboard provided by the Kubernetes project (standard).
|
||||
* Note that you can add your own formatter by registering it to the clusterLinksFormatters dictionary.
|
||||
* @defaultValue standard
|
||||
* @see dashboardUrl
|
||||
* @example
|
||||
* ```ts
|
||||
* import { clusterLinksFormatters } from '@backstage/plugin-kubernetes';
|
||||
* clusterLinksFormatters.myDashboard = (options) => ...;
|
||||
* ```
|
||||
*/
|
||||
dashboardApp?: string;
|
||||
}
|
||||
|
||||
export interface GKEClusterDetails extends ClusterDetails {}
|
||||
|
||||
Reference in New Issue
Block a user