Creating extension point for kubernetesObjectsProvider

Signed-off-by: Andres Mauricio Gomez P <andmagom@outlook.com>
This commit is contained in:
Andres Mauricio Gomez P
2023-09-15 09:39:48 -05:00
committed by blam
parent 8c73a617df
commit cbb0e3c3f4
12 changed files with 207 additions and 2 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'@backstage/plugin-kubernetes-node': minor
'@backstage/plugin-kubernetes-backend': patch
---
A new Package is introduced to house the backend plugin's extension points for Kubernetes plugin, at the moment only the KubernetesObjectsProviderExtensionPoint is present. The Kubernetes-backed package was modified to use this new extension point
+1
View File
@@ -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:^",
+35 -2
View File
@@ -21,15 +21,46 @@ import {
} from '@backstage/backend-plugin-api';
import { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha';
import { KubernetesBuilder } from '@backstage/plugin-kubernetes-backend';
import {
KubernetesBuilder,
KubernetesObjectsProvider,
} from '@backstage/plugin-kubernetes-backend';
import {
KubernetesObjectsProviderExtensionPoint,
kubernetesObjectsProviderExtensionPoint,
} 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 +77,9 @@ export const kubernetesPlugin = createBackendPlugin({
config,
catalogApi,
permissions,
}).build();
})
.setObjectsProvider(extensionPoint.getObjectsProvider())
.build();
http.use(router);
},
});
+1
View File
@@ -0,0 +1 @@
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
+5
View File
@@ -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_
+17
View File
@@ -0,0 +1,17 @@
## 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 { ExtensionPoint } from '@backstage/backend-plugin-api';
import { KubernetesObjectsProvider } from '@backstage/plugin-kubernetes-backend';
// @public
export interface KubernetesObjectsProviderExtensionPoint {
// (undocumented)
addObjectsProvider(provider: KubernetesObjectsProvider): void;
}
// @public
export const kubernetesObjectsProviderExtensionPoint: ExtensionPoint<KubernetesObjectsProviderExtensionPoint>;
```
+10
View File
@@ -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
+34
View File
@@ -0,0 +1,34 @@
{
"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/plugin-kubernetes-backend": "workspace:^"
}
}
+36
View File
@@ -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-backend';
/**
* 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',
});
+35
View File
@@ -0,0 +1,35 @@
/*
* 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';
+16
View File
@@ -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 {};
+11
View File
@@ -7570,6 +7570,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:^"
@@ -7702,6 +7703,16 @@ __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/cli": "workspace:^"
"@backstage/plugin-kubernetes-backend": "workspace:^"
languageName: unknown
linkType: soft
"@backstage/plugin-kubernetes@workspace:^, @backstage/plugin-kubernetes@workspace:plugins/kubernetes":
version: 0.0.0-use.local
resolution: "@backstage/plugin-kubernetes@workspace:plugins/kubernetes"