kubernets: migrate to new composability API

This commit is contained in:
Patrik Oldsberg
2021-02-02 23:51:30 +01:00
parent 7716d1d709
commit 64b9efac2e
7 changed files with 36 additions and 8 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-kubernetes': patch
---
Migrate to new composability API, exporting the plugin instance as `kubernetesPlugin` and entity content as `EntityKubernetesContent`.
+2 -2
View File
@@ -14,6 +14,6 @@
* limitations under the License.
*/
import { createDevApp } from '@backstage/dev-utils';
import { plugin } from '../src';
import { kubernetesPlugin } from '../src';
createDevApp().registerPlugin(plugin).render();
createDevApp().registerPlugin(kubernetesPlugin).render();
+1
View File
@@ -32,6 +32,7 @@
},
"dependencies": {
"@backstage/catalog-model": "^0.7.0",
"@backstage/plugin-catalog-react": "^0.0.1",
"@backstage/config": "^0.1.2",
"@backstage/core": "^0.5.0",
"@backstage/plugin-kubernetes-backend": "^0.2.6",
+9 -2
View File
@@ -16,15 +16,22 @@
import React from 'react';
import { Entity } from '@backstage/catalog-model';
import { useEntity } from '@backstage/plugin-catalog-react';
import { Route, Routes } from 'react-router-dom';
import { rootCatalogKubernetesRouteRef } from './plugin';
import { KubernetesContent } from './components/KubernetesContent';
import { MissingAnnotationEmptyState } from '@backstage/core';
const KUBERNETES_ANNOTATION = 'backstage.io/kubernetes-id';
export const Router = ({ entity }: { entity: Entity }) => {
type Props = {
/** @deprecated The entity is now grabbed from context instead */
entity?: Entity;
};
export const Router = (_props: Props) => {
const { entity } = useEntity();
const kubernetesAnnotationValue =
entity.metadata.annotations?.[KUBERNETES_ANNOTATION];
+5 -1
View File
@@ -13,5 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { plugin } from './plugin';
export {
kubernetesPlugin,
kubernetesPlugin as plugin,
EntityKubernetesContent,
} from './plugin';
export { Router } from './Router';
+2 -2
View File
@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { plugin } from './plugin';
import { kubernetesPlugin } from './plugin';
describe('kubernetes', () => {
it('should export plugin', () => {
expect(plugin).toBeDefined();
expect(kubernetesPlugin).toBeDefined();
});
});
+12 -1
View File
@@ -19,6 +19,7 @@ import {
createRouteRef,
discoveryApiRef,
googleAuthApiRef,
createRoutableExtension,
} from '@backstage/core';
import { KubernetesBackendClient } from './api/KubernetesBackendClient';
import { kubernetesApiRef } from './api/types';
@@ -30,7 +31,7 @@ export const rootCatalogKubernetesRouteRef = createRouteRef({
title: 'Kubernetes',
});
export const plugin = createPlugin({
export const kubernetesPlugin = createPlugin({
id: 'kubernetes',
apis: [
createApiFactory({
@@ -47,4 +48,14 @@ export const plugin = createPlugin({
},
}),
],
routes: {
entityContent: rootCatalogKubernetesRouteRef,
},
});
export const EntityKubernetesContent = kubernetesPlugin.provide(
createRoutableExtension({
component: () => import('./Router').then(m => m.Router),
mountPoint: rootCatalogKubernetesRouteRef,
}),
);