Merge pull request #19969 from andmagom/kubernetes/ObjectsProviderExtensionPoint
Extension point for kubernetesObjectsProvider
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@backstage/plugin-kubernetes-node': minor
|
||||
'@backstage/plugin-kubernetes-backend': patch
|
||||
---
|
||||
|
||||
A new plugin has been introduced to house the extension points for Kubernetes backend plugin; at the moment only the `KubernetesObjectsProviderExtensionPoint` is present. The `kubernetes-backend` plugin was modified to use this new extension point.
|
||||
@@ -6,16 +6,18 @@
|
||||
import { CatalogApi } from '@backstage/catalog-client';
|
||||
import { Config } from '@backstage/config';
|
||||
import type { CustomResourceMatcher } from '@backstage/plugin-kubernetes-common';
|
||||
import { CustomResourcesByEntity } from '@backstage/plugin-kubernetes-node';
|
||||
import { Duration } from 'luxon';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import express from 'express';
|
||||
import type { FetchResponse } from '@backstage/plugin-kubernetes-common';
|
||||
import type { JsonObject } from '@backstage/types';
|
||||
import type { KubernetesFetchError } from '@backstage/plugin-kubernetes-common';
|
||||
import { KubernetesObjectsByEntity } from '@backstage/plugin-kubernetes-node';
|
||||
import { KubernetesObjectsProvider } from '@backstage/plugin-kubernetes-node';
|
||||
import { KubernetesRequestAuth } from '@backstage/plugin-kubernetes-common';
|
||||
import type { KubernetesRequestBody } from '@backstage/plugin-kubernetes-common';
|
||||
import { Logger } from 'winston';
|
||||
import type { ObjectsByEntityResponse } from '@backstage/plugin-kubernetes-common';
|
||||
import { PermissionEvaluator } from '@backstage/plugin-permission-common';
|
||||
import { PluginEndpointDiscovery } from '@backstage/backend-common';
|
||||
import { RequestHandler } from 'http-proxy-middleware';
|
||||
@@ -101,11 +103,7 @@ export interface CustomResource extends ObjectToFetch {
|
||||
objectType: 'customresources';
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
export interface CustomResourcesByEntity extends KubernetesObjectsByEntity {
|
||||
// (undocumented)
|
||||
customResources: CustomResourceMatcher[];
|
||||
}
|
||||
export { CustomResourcesByEntity };
|
||||
|
||||
// @public (undocumented)
|
||||
export const DEFAULT_OBJECTS: ObjectToFetch[];
|
||||
@@ -316,25 +314,9 @@ export interface KubernetesFetcher {
|
||||
): Promise<FetchResponseWrapper>;
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
export interface KubernetesObjectsByEntity {
|
||||
// (undocumented)
|
||||
auth: KubernetesRequestAuth;
|
||||
// (undocumented)
|
||||
entity: Entity;
|
||||
}
|
||||
export { KubernetesObjectsByEntity };
|
||||
|
||||
// @public (undocumented)
|
||||
export interface KubernetesObjectsProvider {
|
||||
// (undocumented)
|
||||
getCustomResourcesByEntity(
|
||||
customResourcesByEntity: CustomResourcesByEntity,
|
||||
): Promise<ObjectsByEntityResponse>;
|
||||
// (undocumented)
|
||||
getKubernetesObjectsByEntity(
|
||||
kubernetesObjectsByEntity: KubernetesObjectsByEntity,
|
||||
): Promise<ObjectsByEntityResponse>;
|
||||
}
|
||||
export { KubernetesObjectsProvider };
|
||||
|
||||
// @public (undocumented)
|
||||
export interface KubernetesObjectsProviderOptions {
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
"@backstage/plugin-auth-node": "workspace:^",
|
||||
"@backstage/plugin-catalog-node": "workspace:^",
|
||||
"@backstage/plugin-kubernetes-common": "workspace:^",
|
||||
"@backstage/plugin-kubernetes-node": "workspace:^",
|
||||
"@backstage/plugin-permission-common": "workspace:^",
|
||||
"@backstage/plugin-permission-node": "workspace:^",
|
||||
"@backstage/types": "workspace:^",
|
||||
@@ -86,6 +87,7 @@
|
||||
"yn": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/backend-app-api": "workspace:^",
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@types/aws4": "^1.5.1",
|
||||
|
||||
@@ -22,14 +22,43 @@ import {
|
||||
import { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha';
|
||||
|
||||
import { KubernetesBuilder } from '@backstage/plugin-kubernetes-backend';
|
||||
import {
|
||||
KubernetesObjectsProviderExtensionPoint,
|
||||
kubernetesObjectsProviderExtensionPoint,
|
||||
KubernetesObjectsProvider,
|
||||
} from '@backstage/plugin-kubernetes-node';
|
||||
|
||||
class ObjectsProvider implements KubernetesObjectsProviderExtensionPoint {
|
||||
private objectsProvider: KubernetesObjectsProvider | undefined;
|
||||
|
||||
getObjectsProvider() {
|
||||
return this.objectsProvider;
|
||||
}
|
||||
|
||||
addObjectsProvider(provider: KubernetesObjectsProvider) {
|
||||
if (this.objectsProvider) {
|
||||
throw new Error(
|
||||
'Multiple Kubernetes objects provider is not supported at this time',
|
||||
);
|
||||
}
|
||||
this.objectsProvider = provider;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the backend plugin that provides the Kubernetes integration.
|
||||
* @alpha
|
||||
*/
|
||||
|
||||
export const kubernetesPlugin = createBackendPlugin({
|
||||
pluginId: 'kubernetes',
|
||||
register(env) {
|
||||
const extensionPoint = new ObjectsProvider();
|
||||
env.registerExtensionPoint(
|
||||
kubernetesObjectsProviderExtensionPoint,
|
||||
extensionPoint,
|
||||
);
|
||||
|
||||
env.registerInit({
|
||||
deps: {
|
||||
http: coreServices.httpRouter,
|
||||
@@ -46,7 +75,9 @@ export const kubernetesPlugin = createBackendPlugin({
|
||||
config,
|
||||
catalogApi,
|
||||
permissions,
|
||||
}).build();
|
||||
})
|
||||
.setObjectsProvider(extensionPoint.getObjectsProvider())
|
||||
.build();
|
||||
http.use(router);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -14,23 +14,64 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { errorHandler } from '@backstage/backend-common';
|
||||
import express from 'express';
|
||||
import request from 'supertest';
|
||||
import Router from 'express-promise-router';
|
||||
import { addResourceRoutesToRouter } from './resourcesRoutes';
|
||||
import { mockServices, startTestBackend } from '@backstage/backend-test-utils';
|
||||
import { ExtendedHttpServer } from '@backstage/backend-app-api';
|
||||
import { kubernetesObjectsProviderExtensionPoint } from '@backstage/plugin-kubernetes-node';
|
||||
import { createBackendModule } from '@backstage/backend-plugin-api';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
|
||||
describe('resourcesRoutes', () => {
|
||||
let app: express.Express;
|
||||
let app: ExtendedHttpServer;
|
||||
|
||||
beforeAll(() => {
|
||||
app = express();
|
||||
app.use(express.json());
|
||||
const router = Router();
|
||||
addResourceRoutesToRouter(
|
||||
router,
|
||||
{
|
||||
beforeAll(async () => {
|
||||
const objectsProviderMock = {
|
||||
getKubernetesObjectsByEntity: jest.fn().mockImplementation(args => {
|
||||
if (args.entity.metadata.name === 'inject500') {
|
||||
return Promise.reject(new Error('some internal error'));
|
||||
}
|
||||
|
||||
return Promise.resolve({
|
||||
items: [
|
||||
{
|
||||
clusterOne: {
|
||||
pods: [
|
||||
{
|
||||
metadata: {
|
||||
name: 'pod1',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
}),
|
||||
getCustomResourcesByEntity: jest.fn().mockImplementation(args => {
|
||||
if (args.entity.metadata.name === 'inject500') {
|
||||
return Promise.reject(new Error('some internal error'));
|
||||
}
|
||||
|
||||
return Promise.resolve({
|
||||
items: [
|
||||
{
|
||||
clusterOne: {
|
||||
pods: [
|
||||
{
|
||||
metadata: {
|
||||
name: 'pod1',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
}),
|
||||
};
|
||||
|
||||
jest.mock('@backstage/catalog-client', () => ({
|
||||
CatalogClient: jest.fn().mockImplementation(() => ({
|
||||
getEntityByRef: jest.fn().mockImplementation(entityRef => {
|
||||
if (entityRef.name === 'noentity') {
|
||||
return Promise.resolve(undefined);
|
||||
@@ -43,61 +84,50 @@ describe('resourcesRoutes', () => {
|
||||
},
|
||||
} as Entity);
|
||||
}),
|
||||
} as any,
|
||||
{
|
||||
getKubernetesObjectsByEntity: jest.fn().mockImplementation(args => {
|
||||
if (args.entity.metadata.name === 'inject500') {
|
||||
return Promise.reject(new Error('some internal error'));
|
||||
}
|
||||
})),
|
||||
}));
|
||||
|
||||
return Promise.resolve({
|
||||
items: [
|
||||
{
|
||||
clusterOne: {
|
||||
pods: [
|
||||
{
|
||||
metadata: {
|
||||
name: 'pod1',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
const { server } = await startTestBackend({
|
||||
features: [
|
||||
mockServices.rootConfig.factory({
|
||||
data: {
|
||||
kubernetes: {
|
||||
serviceLocatorMethod: {
|
||||
type: 'multiTenant',
|
||||
},
|
||||
],
|
||||
});
|
||||
clusterLocatorMethods: [
|
||||
{
|
||||
type: 'config',
|
||||
clusters: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}),
|
||||
getCustomResourcesByEntity: jest.fn().mockImplementation(args => {
|
||||
if (args.entity.metadata.name === 'inject500') {
|
||||
return Promise.reject(new Error('some internal error'));
|
||||
}
|
||||
import('@backstage/plugin-kubernetes-backend/alpha'),
|
||||
createBackendModule({
|
||||
pluginId: 'kubernetes',
|
||||
moduleId: 'testObjectsProvider',
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: { extension: kubernetesObjectsProviderExtensionPoint },
|
||||
async init({ extension }) {
|
||||
extension.addObjectsProvider(objectsProviderMock);
|
||||
},
|
||||
});
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
return Promise.resolve({
|
||||
items: [
|
||||
{
|
||||
clusterOne: {
|
||||
pods: [
|
||||
{
|
||||
metadata: {
|
||||
name: 'pod1',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
}),
|
||||
} as any,
|
||||
);
|
||||
app.use('/', router);
|
||||
app.use(errorHandler());
|
||||
app = server;
|
||||
});
|
||||
|
||||
describe('POST /resources/workloads/query', () => {
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it('200 happy path', async () => {
|
||||
await request(app)
|
||||
.post('/resources/workloads/query')
|
||||
.post('/api/kubernetes/resources/workloads/query')
|
||||
.send({
|
||||
entityRef: 'kind:namespacec/someComponent',
|
||||
auth: {
|
||||
@@ -125,7 +155,7 @@ describe('resourcesRoutes', () => {
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it('400 when missing entity ref', async () => {
|
||||
await request(app)
|
||||
.post('/resources/workloads/query')
|
||||
.post('/api/kubernetes/resources/workloads/query')
|
||||
.send({
|
||||
auth: {
|
||||
google: 'something',
|
||||
@@ -137,7 +167,7 @@ describe('resourcesRoutes', () => {
|
||||
error: { name: 'InputError', message: 'entity is a required field' },
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '/resources/workloads/query',
|
||||
url: '/api/kubernetes/resources/workloads/query',
|
||||
},
|
||||
response: { statusCode: 400 },
|
||||
});
|
||||
@@ -145,7 +175,7 @@ describe('resourcesRoutes', () => {
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it('400 when bad entity ref', async () => {
|
||||
await request(app)
|
||||
.post('/resources/workloads/query')
|
||||
.post('/api/kubernetes/resources/workloads/query')
|
||||
.send({
|
||||
entityRef: 'ffff',
|
||||
auth: {
|
||||
@@ -162,7 +192,7 @@ describe('resourcesRoutes', () => {
|
||||
},
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '/resources/workloads/query',
|
||||
url: '/api/kubernetes/resources/workloads/query',
|
||||
},
|
||||
response: { statusCode: 400 },
|
||||
});
|
||||
@@ -170,7 +200,7 @@ describe('resourcesRoutes', () => {
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it('400 when no entity in catalog', async () => {
|
||||
await request(app)
|
||||
.post('/resources/workloads/query')
|
||||
.post('/api/kubernetes/resources/workloads/query')
|
||||
.send({
|
||||
entityRef: 'noentity:noentity',
|
||||
auth: {
|
||||
@@ -186,7 +216,7 @@ describe('resourcesRoutes', () => {
|
||||
},
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '/resources/workloads/query',
|
||||
url: '/api/kubernetes/resources/workloads/query',
|
||||
},
|
||||
response: { statusCode: 400 },
|
||||
});
|
||||
@@ -194,7 +224,7 @@ describe('resourcesRoutes', () => {
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it('401 when no Auth header', async () => {
|
||||
await request(app)
|
||||
.post('/resources/workloads/query')
|
||||
.post('/api/kubernetes/resources/workloads/query')
|
||||
.send({
|
||||
entityRef: 'component:someComponent',
|
||||
auth: {
|
||||
@@ -206,7 +236,7 @@ describe('resourcesRoutes', () => {
|
||||
error: { name: 'AuthenticationError', message: 'No Backstage token' },
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '/resources/workloads/query',
|
||||
url: '/api/kubernetes/resources/workloads/query',
|
||||
},
|
||||
response: { statusCode: 401 },
|
||||
});
|
||||
@@ -214,7 +244,7 @@ describe('resourcesRoutes', () => {
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it('401 when invalid Auth header', async () => {
|
||||
await request(app)
|
||||
.post('/resources/workloads/query')
|
||||
.post('/api/kubernetes/resources/workloads/query')
|
||||
.send({
|
||||
entityRef: 'component:someComponent',
|
||||
auth: {
|
||||
@@ -227,7 +257,7 @@ describe('resourcesRoutes', () => {
|
||||
error: { name: 'AuthenticationError', message: 'No Backstage token' },
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '/resources/workloads/query',
|
||||
url: '/api/kubernetes/resources/workloads/query',
|
||||
},
|
||||
response: { statusCode: 401 },
|
||||
});
|
||||
@@ -235,7 +265,7 @@ describe('resourcesRoutes', () => {
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it('500 handle gracefully', async () => {
|
||||
await request(app)
|
||||
.post('/resources/workloads/query')
|
||||
.post('/api/kubernetes/resources/workloads/query')
|
||||
.send({
|
||||
entityRef: 'inject500:inject500/inject500',
|
||||
auth: {
|
||||
@@ -249,7 +279,10 @@ describe('resourcesRoutes', () => {
|
||||
name: 'Error',
|
||||
message: 'some internal error',
|
||||
},
|
||||
request: { method: 'POST', url: '/resources/workloads/query' },
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '/api/kubernetes/resources/workloads/query',
|
||||
},
|
||||
response: { statusCode: 500 },
|
||||
});
|
||||
});
|
||||
@@ -258,7 +291,7 @@ describe('resourcesRoutes', () => {
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it('200 happy path', async () => {
|
||||
await request(app)
|
||||
.post('/resources/custom/query')
|
||||
.post('/api/kubernetes/resources/custom/query')
|
||||
.send({
|
||||
entityRef: 'component:someComponent',
|
||||
auth: {
|
||||
@@ -293,7 +326,7 @@ describe('resourcesRoutes', () => {
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it('400 when missing custom resources', async () => {
|
||||
await request(app)
|
||||
.post('/resources/custom/query')
|
||||
.post('/api/kubernetes/resources/custom/query')
|
||||
.send({
|
||||
entityRef: 'component:someComponent',
|
||||
auth: {
|
||||
@@ -309,7 +342,7 @@ describe('resourcesRoutes', () => {
|
||||
},
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '/resources/custom/query',
|
||||
url: '/api/kubernetes/resources/custom/query',
|
||||
},
|
||||
response: { statusCode: 400 },
|
||||
});
|
||||
@@ -317,7 +350,7 @@ describe('resourcesRoutes', () => {
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it('400 when custom resources not array', async () => {
|
||||
await request(app)
|
||||
.post('/resources/custom/query')
|
||||
.post('/api/kubernetes/resources/custom/query')
|
||||
.send({
|
||||
entityRef: 'component:someComponent',
|
||||
auth: {
|
||||
@@ -334,7 +367,7 @@ describe('resourcesRoutes', () => {
|
||||
},
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '/resources/custom/query',
|
||||
url: '/api/kubernetes/resources/custom/query',
|
||||
},
|
||||
response: { statusCode: 400 },
|
||||
});
|
||||
@@ -342,7 +375,7 @@ describe('resourcesRoutes', () => {
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it('400 when custom resources empty', async () => {
|
||||
await request(app)
|
||||
.post('/resources/custom/query')
|
||||
.post('/api/kubernetes/resources/custom/query')
|
||||
.send({
|
||||
entityRef: 'component:someComponent',
|
||||
auth: {
|
||||
@@ -359,7 +392,7 @@ describe('resourcesRoutes', () => {
|
||||
},
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '/resources/custom/query',
|
||||
url: '/api/kubernetes/resources/custom/query',
|
||||
},
|
||||
response: { statusCode: 400 },
|
||||
});
|
||||
@@ -367,7 +400,7 @@ describe('resourcesRoutes', () => {
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it('400 when missing entity ref', async () => {
|
||||
await request(app)
|
||||
.post('/resources/custom/query')
|
||||
.post('/api/kubernetes/resources/custom/query')
|
||||
.send({
|
||||
auth: {
|
||||
google: 'something',
|
||||
@@ -386,7 +419,7 @@ describe('resourcesRoutes', () => {
|
||||
error: { name: 'InputError', message: 'entity is a required field' },
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '/resources/custom/query',
|
||||
url: '/api/kubernetes/resources/custom/query',
|
||||
},
|
||||
response: { statusCode: 400 },
|
||||
});
|
||||
@@ -394,7 +427,7 @@ describe('resourcesRoutes', () => {
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it('400 when bad entity ref', async () => {
|
||||
await request(app)
|
||||
.post('/resources/custom/query')
|
||||
.post('/api/kubernetes/resources/custom/query')
|
||||
.send({
|
||||
entityRef: 'ffff',
|
||||
auth: {
|
||||
@@ -418,7 +451,7 @@ describe('resourcesRoutes', () => {
|
||||
},
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '/resources/custom/query',
|
||||
url: '/api/kubernetes/resources/custom/query',
|
||||
},
|
||||
response: { statusCode: 400 },
|
||||
});
|
||||
@@ -426,7 +459,7 @@ describe('resourcesRoutes', () => {
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it('400 when no entity in catalog', async () => {
|
||||
await request(app)
|
||||
.post('/resources/custom/query')
|
||||
.post('/api/kubernetes/resources/custom/query')
|
||||
.send({
|
||||
entityRef: 'noentity:noentity',
|
||||
auth: {
|
||||
@@ -449,7 +482,7 @@ describe('resourcesRoutes', () => {
|
||||
},
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '/resources/custom/query',
|
||||
url: '/api/kubernetes/resources/custom/query',
|
||||
},
|
||||
response: { statusCode: 400 },
|
||||
});
|
||||
@@ -457,7 +490,7 @@ describe('resourcesRoutes', () => {
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it('401 when no Auth header', async () => {
|
||||
await request(app)
|
||||
.post('/resources/custom/query')
|
||||
.post('/api/kubernetes/resources/custom/query')
|
||||
.send({
|
||||
entityRef: 'component:someComponent',
|
||||
auth: {
|
||||
@@ -476,7 +509,7 @@ describe('resourcesRoutes', () => {
|
||||
error: { name: 'AuthenticationError', message: 'No Backstage token' },
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '/resources/custom/query',
|
||||
url: '/api/kubernetes/resources/custom/query',
|
||||
},
|
||||
response: { statusCode: 401 },
|
||||
});
|
||||
@@ -484,7 +517,7 @@ describe('resourcesRoutes', () => {
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it('401 when invalid Auth header', async () => {
|
||||
await request(app)
|
||||
.post('/resources/custom/query')
|
||||
.post('/api/kubernetes/resources/custom/query')
|
||||
.send({
|
||||
entityRef: 'component:someComponent',
|
||||
auth: {
|
||||
@@ -504,7 +537,7 @@ describe('resourcesRoutes', () => {
|
||||
error: { name: 'AuthenticationError', message: 'No Backstage token' },
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '/resources/custom/query',
|
||||
url: '/api/kubernetes/resources/custom/query',
|
||||
},
|
||||
response: { statusCode: 401 },
|
||||
});
|
||||
@@ -512,7 +545,7 @@ describe('resourcesRoutes', () => {
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it('500 handle gracefully', async () => {
|
||||
await request(app)
|
||||
.post('/resources/custom/query')
|
||||
.post('/api/kubernetes/resources/custom/query')
|
||||
.send({
|
||||
entityRef: 'inject500:inject500/inject500',
|
||||
auth: {
|
||||
@@ -533,7 +566,10 @@ describe('resourcesRoutes', () => {
|
||||
name: 'Error',
|
||||
message: 'some internal error',
|
||||
},
|
||||
request: { method: 'POST', url: '/resources/custom/query' },
|
||||
request: {
|
||||
method: 'POST',
|
||||
url: '/api/kubernetes/resources/custom/query',
|
||||
},
|
||||
response: { statusCode: 500 },
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
import { CatalogApi } from '@backstage/catalog-client';
|
||||
import { InputError, AuthenticationError } from '@backstage/errors';
|
||||
import express, { Request } from 'express';
|
||||
import { KubernetesObjectsProvider } from '../types/types';
|
||||
import { KubernetesObjectsProvider } from '@backstage/plugin-kubernetes-node';
|
||||
import { getBearerTokenFromAuthorizationHeader } from '@backstage/plugin-auth-node';
|
||||
|
||||
export const addResourceRoutesToRouter = (
|
||||
|
||||
@@ -47,13 +47,13 @@ import {
|
||||
CustomResource,
|
||||
KubernetesClustersSupplier,
|
||||
KubernetesFetcher,
|
||||
KubernetesObjectsProvider,
|
||||
KubernetesObjectsProviderOptions,
|
||||
KubernetesObjectTypes,
|
||||
KubernetesServiceLocator,
|
||||
ObjectsByEntityRequest,
|
||||
ServiceLocatorMethod,
|
||||
} from '../types/types';
|
||||
import { KubernetesObjectsProvider } from '@backstage/plugin-kubernetes-node';
|
||||
import {
|
||||
DEFAULT_OBJECTS,
|
||||
KubernetesFanOutHandler,
|
||||
|
||||
@@ -25,8 +25,6 @@ import {
|
||||
FetchResponseWrapper,
|
||||
ObjectToFetch,
|
||||
CustomResource,
|
||||
CustomResourcesByEntity,
|
||||
KubernetesObjectsByEntity,
|
||||
} from '../types/types';
|
||||
import { AuthenticationStrategy, KubernetesCredential } from '../auth/types';
|
||||
import {
|
||||
@@ -46,6 +44,10 @@ import {
|
||||
CurrentResourceUsage,
|
||||
PodStatus,
|
||||
} from '@kubernetes/client-node';
|
||||
import {
|
||||
CustomResourcesByEntity,
|
||||
KubernetesObjectsByEntity,
|
||||
} from '@backstage/plugin-kubernetes-node';
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -15,3 +15,9 @@
|
||||
*/
|
||||
|
||||
export * from './types';
|
||||
|
||||
export type {
|
||||
CustomResourcesByEntity,
|
||||
KubernetesObjectsByEntity,
|
||||
KubernetesObjectsProvider,
|
||||
} from '@backstage/plugin-kubernetes-node';
|
||||
|
||||
@@ -21,9 +21,7 @@ import type {
|
||||
CustomResourceMatcher,
|
||||
FetchResponse,
|
||||
KubernetesFetchError,
|
||||
KubernetesRequestAuth,
|
||||
KubernetesRequestBody,
|
||||
ObjectsByEntityResponse,
|
||||
} from '@backstage/plugin-kubernetes-common';
|
||||
import { Config } from '@backstage/config';
|
||||
import { KubernetesCredential } from '../auth/types';
|
||||
@@ -229,33 +227,3 @@ export interface KubernetesObjectsProviderOptions {
|
||||
* @public
|
||||
*/
|
||||
export type ObjectsByEntityRequest = KubernetesRequestBody;
|
||||
|
||||
/**
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface KubernetesObjectsByEntity {
|
||||
entity: Entity;
|
||||
auth: KubernetesRequestAuth;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface CustomResourcesByEntity extends KubernetesObjectsByEntity {
|
||||
customResources: CustomResourceMatcher[];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface KubernetesObjectsProvider {
|
||||
getKubernetesObjectsByEntity(
|
||||
kubernetesObjectsByEntity: KubernetesObjectsByEntity,
|
||||
): Promise<ObjectsByEntityResponse>;
|
||||
getCustomResourcesByEntity(
|
||||
customResourcesByEntity: CustomResourcesByEntity,
|
||||
): Promise<ObjectsByEntityResponse>;
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
|
||||
@@ -0,0 +1,5 @@
|
||||
# @backstage/plugin-kubernetes-node
|
||||
|
||||
Welcome to the Node.js library package for the kubernetes plugin!
|
||||
|
||||
_This plugin was created through the Backstage CLI_
|
||||
@@ -0,0 +1,47 @@
|
||||
## API Report File for "@backstage/plugin-kubernetes-node"
|
||||
|
||||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
||||
|
||||
```ts
|
||||
import { CustomResourceMatcher } from '@backstage/plugin-kubernetes-common';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { ExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
import { KubernetesObjectsProvider as KubernetesObjectsProvider_2 } from '@backstage/plugin-kubernetes-node';
|
||||
import { KubernetesRequestAuth } from '@backstage/plugin-kubernetes-common';
|
||||
import { ObjectsByEntityResponse } from '@backstage/plugin-kubernetes-common';
|
||||
|
||||
// @public (undocumented)
|
||||
export interface CustomResourcesByEntity extends KubernetesObjectsByEntity {
|
||||
// (undocumented)
|
||||
customResources: CustomResourceMatcher[];
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
export interface KubernetesObjectsByEntity {
|
||||
// (undocumented)
|
||||
auth: KubernetesRequestAuth;
|
||||
// (undocumented)
|
||||
entity: Entity;
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
export interface KubernetesObjectsProvider {
|
||||
// (undocumented)
|
||||
getCustomResourcesByEntity(
|
||||
customResourcesByEntity: CustomResourcesByEntity,
|
||||
): Promise<ObjectsByEntityResponse>;
|
||||
// (undocumented)
|
||||
getKubernetesObjectsByEntity(
|
||||
kubernetesObjectsByEntity: KubernetesObjectsByEntity,
|
||||
): Promise<ObjectsByEntityResponse>;
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface KubernetesObjectsProviderExtensionPoint {
|
||||
// (undocumented)
|
||||
addObjectsProvider(provider: KubernetesObjectsProvider_2): void;
|
||||
}
|
||||
|
||||
// @public
|
||||
export const kubernetesObjectsProviderExtensionPoint: ExtensionPoint<KubernetesObjectsProviderExtensionPoint>;
|
||||
```
|
||||
@@ -0,0 +1,10 @@
|
||||
apiVersion: backstage.io/v1alpha1
|
||||
kind: Component
|
||||
metadata:
|
||||
name: backstage-plugin-kubernetes-node
|
||||
title: '@backstage/plugin-kubernetes-node'
|
||||
description: Node.js library for the kubernetes plugin
|
||||
spec:
|
||||
lifecycle: experimental
|
||||
type: backstage-node-library
|
||||
owner: kubernetes-maintainers
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "@backstage/plugin-kubernetes-node",
|
||||
"description": "Node.js library for the kubernetes plugin",
|
||||
"version": "0.0.0",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"license": "Apache-2.0",
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"main": "dist/index.cjs.js",
|
||||
"types": "dist/index.d.ts"
|
||||
},
|
||||
"backstage": {
|
||||
"role": "node-library"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "backstage-cli package build",
|
||||
"lint": "backstage-cli package lint",
|
||||
"test": "backstage-cli package test",
|
||||
"clean": "backstage-cli package clean",
|
||||
"prepack": "backstage-cli package prepack",
|
||||
"postpack": "backstage-cli package postpack"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/cli": "workspace:^"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"dependencies": {
|
||||
"@backstage/backend-plugin-api": "workspace:^",
|
||||
"@backstage/catalog-model": "workspace:^",
|
||||
"@backstage/plugin-kubernetes-common": "workspace:^"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2023 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { createExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
import { KubernetesObjectsProvider } from '@backstage/plugin-kubernetes-node';
|
||||
|
||||
/**
|
||||
* The interface for {@link kubernetesObjectsProviderExtensionPoint}.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface KubernetesObjectsProviderExtensionPoint {
|
||||
addObjectsProvider(provider: KubernetesObjectsProvider): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* An extension point the exposes the ability to configure a objects provider.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const kubernetesObjectsProviderExtensionPoint =
|
||||
createExtensionPoint<KubernetesObjectsProviderExtensionPoint>({
|
||||
id: 'kubernetes.objects-provider',
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2023 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Node.js library for the kubernetes plugin.
|
||||
*
|
||||
* @packageDocumentation
|
||||
*/
|
||||
|
||||
// In this package you might for example export functions that
|
||||
// help other plugins or modules interact with your plugin.
|
||||
|
||||
/**
|
||||
* Node.js library for the kubernetes plugin.
|
||||
*
|
||||
* @packageDocumentation
|
||||
*/
|
||||
|
||||
export {
|
||||
kubernetesObjectsProviderExtensionPoint,
|
||||
type KubernetesObjectsProviderExtensionPoint,
|
||||
} from './extensions';
|
||||
|
||||
export * from './types';
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2023 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export {};
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2023 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './types';
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2023 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import {
|
||||
CustomResourceMatcher,
|
||||
KubernetesRequestAuth,
|
||||
ObjectsByEntityResponse,
|
||||
} from '@backstage/plugin-kubernetes-common';
|
||||
|
||||
/**
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
|
||||
export interface KubernetesObjectsProvider {
|
||||
getKubernetesObjectsByEntity(
|
||||
kubernetesObjectsByEntity: KubernetesObjectsByEntity,
|
||||
): Promise<ObjectsByEntityResponse>;
|
||||
getCustomResourcesByEntity(
|
||||
customResourcesByEntity: CustomResourcesByEntity,
|
||||
): Promise<ObjectsByEntityResponse>;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
|
||||
export interface KubernetesObjectsByEntity {
|
||||
entity: Entity;
|
||||
auth: KubernetesRequestAuth;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
|
||||
export interface CustomResourcesByEntity extends KubernetesObjectsByEntity {
|
||||
customResources: CustomResourceMatcher[];
|
||||
}
|
||||
@@ -7558,6 +7558,7 @@ __metadata:
|
||||
"@aws-sdk/credential-providers": ^3.350.0
|
||||
"@aws-sdk/signature-v4": ^3.347.0
|
||||
"@azure/identity": ^3.2.1
|
||||
"@backstage/backend-app-api": "workspace:^"
|
||||
"@backstage/backend-common": "workspace:^"
|
||||
"@backstage/backend-plugin-api": "workspace:^"
|
||||
"@backstage/backend-test-utils": "workspace:^"
|
||||
@@ -7570,6 +7571,7 @@ __metadata:
|
||||
"@backstage/plugin-auth-node": "workspace:^"
|
||||
"@backstage/plugin-catalog-node": "workspace:^"
|
||||
"@backstage/plugin-kubernetes-common": "workspace:^"
|
||||
"@backstage/plugin-kubernetes-node": "workspace:^"
|
||||
"@backstage/plugin-permission-common": "workspace:^"
|
||||
"@backstage/plugin-permission-node": "workspace:^"
|
||||
"@backstage/types": "workspace:^"
|
||||
@@ -7663,6 +7665,17 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@backstage/plugin-kubernetes-node@workspace:^, @backstage/plugin-kubernetes-node@workspace:plugins/kubernetes-node":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@backstage/plugin-kubernetes-node@workspace:plugins/kubernetes-node"
|
||||
dependencies:
|
||||
"@backstage/backend-plugin-api": "workspace:^"
|
||||
"@backstage/catalog-model": "workspace:^"
|
||||
"@backstage/cli": "workspace:^"
|
||||
"@backstage/plugin-kubernetes-common": "workspace:^"
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@backstage/plugin-kubernetes-react@workspace:^, @backstage/plugin-kubernetes-react@workspace:plugins/kubernetes-react":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@backstage/plugin-kubernetes-react@workspace:plugins/kubernetes-react"
|
||||
|
||||
Reference in New Issue
Block a user