address review comments
Signed-off-by: Jonah Back <jonah@jonahback.com>
This commit is contained in:
@@ -40,7 +40,6 @@
|
||||
"@backstage/catalog-client": "^1.0.4-next.1",
|
||||
"@backstage/catalog-model": "^1.1.0-next.2",
|
||||
"@backstage/config": "^1.0.1",
|
||||
"@backstage/core-plugin-api": "^1.0.3-next.0",
|
||||
"@backstage/errors": "^1.1.0-next.0",
|
||||
"@backstage/plugin-auth-node": "^0.2.3-next.1",
|
||||
"@backstage/plugin-kubernetes-common": "^0.4.0-next.0",
|
||||
|
||||
@@ -41,12 +41,11 @@ export class CatalogClusterLocator implements KubernetesClustersSupplier {
|
||||
const filter: Record<string, symbol | string> = {
|
||||
kind: 'Resource',
|
||||
'spec.type': 'kubernetes-cluster',
|
||||
[apiServerKey]: CATALOG_FILTER_EXISTS,
|
||||
[apiServerCaKey]: CATALOG_FILTER_EXISTS,
|
||||
[authProviderKey]: CATALOG_FILTER_EXISTS,
|
||||
};
|
||||
|
||||
filter[apiServerKey] = CATALOG_FILTER_EXISTS;
|
||||
filter[apiServerCaKey] = CATALOG_FILTER_EXISTS;
|
||||
filter[authProviderKey] = CATALOG_FILTER_EXISTS;
|
||||
|
||||
const clusters = await this.catalogClient.getEntities({
|
||||
filter: [filter],
|
||||
});
|
||||
|
||||
@@ -16,9 +16,11 @@
|
||||
|
||||
import { Config, ConfigReader } from '@backstage/config';
|
||||
import { getCombinedClusterSupplier } from './index';
|
||||
import { PluginEndpointDiscovery } from '@backstage/backend-common';
|
||||
import { CatalogApi } from '@backstage/catalog-client';
|
||||
|
||||
describe('getCombinedClusterSupplier', () => {
|
||||
let catalogApi: CatalogApi;
|
||||
|
||||
it('should retrieve cluster details from config', async () => {
|
||||
const config: Config = new ConfigReader(
|
||||
{
|
||||
@@ -45,12 +47,8 @@ describe('getCombinedClusterSupplier', () => {
|
||||
},
|
||||
'ctx',
|
||||
);
|
||||
const discovery: PluginEndpointDiscovery = {
|
||||
getBaseUrl: jest.fn().mockResolvedValue('http://test-backend'),
|
||||
getExternalBaseUrl: jest.fn(),
|
||||
};
|
||||
|
||||
const clusterSupplier = getCombinedClusterSupplier(config, discovery);
|
||||
const clusterSupplier = getCombinedClusterSupplier(config, catalogApi);
|
||||
const result = await clusterSupplier.getClusters();
|
||||
|
||||
expect(result).toStrictEqual([
|
||||
@@ -104,12 +102,8 @@ describe('getCombinedClusterSupplier', () => {
|
||||
},
|
||||
'ctx',
|
||||
);
|
||||
const discovery: PluginEndpointDiscovery = {
|
||||
getBaseUrl: jest.fn().mockResolvedValue('http://test-backend'),
|
||||
getExternalBaseUrl: jest.fn(),
|
||||
};
|
||||
|
||||
expect(() => getCombinedClusterSupplier(config, discovery)).toThrowError(
|
||||
expect(() => getCombinedClusterSupplier(config, catalogApi)).toThrowError(
|
||||
new Error('Unsupported kubernetes.clusterLocatorMethods: "magic"'),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -20,8 +20,7 @@ import { ClusterDetails, KubernetesClustersSupplier } from '../types/types';
|
||||
import { ConfigClusterLocator } from './ConfigClusterLocator';
|
||||
import { GkeClusterLocator } from './GkeClusterLocator';
|
||||
import { CatalogClusterLocator } from './CatalogClusterLocator';
|
||||
import { PluginEndpointDiscovery } from '@backstage/backend-common';
|
||||
import { CatalogClient } from '@backstage/catalog-client';
|
||||
import { CatalogApi } from '@backstage/catalog-client';
|
||||
|
||||
class CombinedClustersSupplier implements KubernetesClustersSupplier {
|
||||
constructor(readonly clusterSuppliers: KubernetesClustersSupplier[]) {}
|
||||
@@ -41,10 +40,9 @@ class CombinedClustersSupplier implements KubernetesClustersSupplier {
|
||||
|
||||
export const getCombinedClusterSupplier = (
|
||||
rootConfig: Config,
|
||||
discovery: PluginEndpointDiscovery,
|
||||
catalogClient: CatalogApi,
|
||||
refreshInterval: Duration | undefined = undefined,
|
||||
): KubernetesClustersSupplier => {
|
||||
const catalogClient = new CatalogClient({ discoveryApi: discovery });
|
||||
const clusterSuppliers = rootConfig
|
||||
.getConfigArray('kubernetes.clusterLocatorMethods')
|
||||
.map(clusterLocatorMethod => {
|
||||
|
||||
@@ -14,10 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
getVoidLogger,
|
||||
PluginEndpointDiscovery,
|
||||
} from '@backstage/backend-common';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { Config, ConfigReader } from '@backstage/config';
|
||||
import { ObjectsByEntityResponse } from '@backstage/plugin-kubernetes-common';
|
||||
@@ -50,10 +47,6 @@ describe('KubernetesBuilder', () => {
|
||||
clusterLocatorMethods: [{ type: 'config', clusters: [] }],
|
||||
},
|
||||
});
|
||||
const discovery: PluginEndpointDiscovery = {
|
||||
getBaseUrl: jest.fn().mockResolvedValue('http://test-backend'),
|
||||
getExternalBaseUrl: jest.fn(),
|
||||
};
|
||||
|
||||
const clusters: ClusterDetails[] = [
|
||||
{
|
||||
@@ -81,7 +74,6 @@ describe('KubernetesBuilder', () => {
|
||||
const { router } = await KubernetesBuilder.createBuilder({
|
||||
config,
|
||||
logger,
|
||||
discovery,
|
||||
catalogApi,
|
||||
})
|
||||
.setObjectsProvider(kubernetesFanOutHandler)
|
||||
@@ -179,10 +171,6 @@ describe('KubernetesBuilder', () => {
|
||||
|
||||
it('custom service locator', async () => {
|
||||
const logger = getVoidLogger();
|
||||
const discovery: PluginEndpointDiscovery = {
|
||||
getBaseUrl: jest.fn().mockResolvedValue('http://test-backend'),
|
||||
getExternalBaseUrl: jest.fn(),
|
||||
};
|
||||
const someCluster: ClusterDetails = {
|
||||
name: 'some-cluster',
|
||||
authProvider: 'serviceAccount',
|
||||
@@ -258,7 +246,6 @@ describe('KubernetesBuilder', () => {
|
||||
const { router } = await KubernetesBuilder.createBuilder({
|
||||
logger,
|
||||
config,
|
||||
discovery,
|
||||
catalogApi,
|
||||
})
|
||||
.setClusterSupplier(clusterSupplier)
|
||||
|
||||
@@ -37,7 +37,6 @@ import {
|
||||
KubernetesFanOutHandler,
|
||||
} from './KubernetesFanOutHandler';
|
||||
import { KubernetesClientBasedFetcher } from './KubernetesFetcher';
|
||||
import { PluginEndpointDiscovery } from '@backstage/backend-common';
|
||||
import { addResourceRoutesToRouter } from '../routes/resourcesRoutes';
|
||||
import { CatalogApi } from '@backstage/catalog-client';
|
||||
|
||||
@@ -48,7 +47,6 @@ import { CatalogApi } from '@backstage/catalog-client';
|
||||
export interface KubernetesEnvironment {
|
||||
logger: Logger;
|
||||
config: Config;
|
||||
discovery: PluginEndpointDiscovery;
|
||||
catalogApi: CatalogApi;
|
||||
}
|
||||
|
||||
@@ -190,7 +188,7 @@ export class KubernetesBuilder {
|
||||
const config = this.env.config;
|
||||
return getCombinedClusterSupplier(
|
||||
config,
|
||||
this.env.discovery,
|
||||
this.env.catalogApi,
|
||||
refreshInterval,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user