diff --git a/.changeset/nice-ghosts-build.md b/.changeset/nice-ghosts-build.md new file mode 100644 index 0000000000..a0f22aa63f --- /dev/null +++ b/.changeset/nice-ghosts-build.md @@ -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 diff --git a/plugins/kubernetes-backend/package.json b/plugins/kubernetes-backend/package.json index bb39a01c6c..dc16ebc1c9 100644 --- a/plugins/kubernetes-backend/package.json +++ b/plugins/kubernetes-backend/package.json @@ -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:^", diff --git a/plugins/kubernetes-backend/src/plugin.ts b/plugins/kubernetes-backend/src/plugin.ts index e2523b4ecd..2ec7500741 100644 --- a/plugins/kubernetes-backend/src/plugin.ts +++ b/plugins/kubernetes-backend/src/plugin.ts @@ -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); }, }); diff --git a/plugins/kubernetes-node/.eslintrc.js b/plugins/kubernetes-node/.eslintrc.js new file mode 100644 index 0000000000..e2a53a6ad2 --- /dev/null +++ b/plugins/kubernetes-node/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require('@backstage/cli/config/eslint-factory')(__dirname); diff --git a/plugins/kubernetes-node/README.md b/plugins/kubernetes-node/README.md new file mode 100644 index 0000000000..afdc299bce --- /dev/null +++ b/plugins/kubernetes-node/README.md @@ -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_ diff --git a/plugins/kubernetes-node/api-report.md b/plugins/kubernetes-node/api-report.md new file mode 100644 index 0000000000..127a360496 --- /dev/null +++ b/plugins/kubernetes-node/api-report.md @@ -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; +``` diff --git a/plugins/kubernetes-node/catalog-info.yaml b/plugins/kubernetes-node/catalog-info.yaml new file mode 100644 index 0000000000..ad04818e49 --- /dev/null +++ b/plugins/kubernetes-node/catalog-info.yaml @@ -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 diff --git a/plugins/kubernetes-node/package.json b/plugins/kubernetes-node/package.json new file mode 100644 index 0000000000..c0dad70e21 --- /dev/null +++ b/plugins/kubernetes-node/package.json @@ -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:^" + } +} diff --git a/plugins/kubernetes-node/src/extensions.ts b/plugins/kubernetes-node/src/extensions.ts new file mode 100644 index 0000000000..927ff8a32f --- /dev/null +++ b/plugins/kubernetes-node/src/extensions.ts @@ -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({ + id: 'kubernetes.objects-provider', + }); diff --git a/plugins/kubernetes-node/src/index.ts b/plugins/kubernetes-node/src/index.ts new file mode 100644 index 0000000000..eb38e591da --- /dev/null +++ b/plugins/kubernetes-node/src/index.ts @@ -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'; diff --git a/plugins/kubernetes-node/src/setupTests.ts b/plugins/kubernetes-node/src/setupTests.ts new file mode 100644 index 0000000000..4b9026cde5 --- /dev/null +++ b/plugins/kubernetes-node/src/setupTests.ts @@ -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 {}; diff --git a/yarn.lock b/yarn.lock index b029e6280f..6da141bf2c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"