From b3ff37bf5ef35e03c4d3b117ce7815fba29545c7 Mon Sep 17 00:00:00 2001 From: Brad McCoy Date: Mon, 28 Nov 2022 20:36:51 +1000 Subject: [PATCH] feat: add backstage annotations for service discovery Signed-off-by: Brad McCoy --- README.md | 11 ++--- app-config.production.yaml | 45 +++++++++++++++++-- chart/backstage/Chart.yaml | 4 +- .../templates/backend/deployment.yaml | 10 +++++ examples/template/content/catalog-info.yaml | 23 ++++++++++ .../app/src/components/catalog/EntityPage.tsx | 7 ++- packages/backend/src/index.ts | 17 ++----- packages/backend/src/plugins/kubernetes.ts | 16 +++++++ 8 files changed, 102 insertions(+), 31 deletions(-) create mode 100644 packages/backend/src/plugins/kubernetes.ts diff --git a/README.md b/README.md index 8c7c437..e921187 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,7 @@ -# [Backstage](https://backstage.io) +# [Ortelius Backstage Portal](https://backstage.ortelius.io) -This is your newly scaffolded Backstage App, Good Luck! +This repo is for the Ortelius Backstage Portal. -To start the app, run: +## Disclaimer 🚧 -```sh -yarn install -yarn dev -``` +This portal is work in work in progress the first release will be on 15-Dec-22 diff --git a/app-config.production.yaml b/app-config.production.yaml index e20a026..67d8af6 100644 --- a/app-config.production.yaml +++ b/app-config.production.yaml @@ -46,6 +46,16 @@ backend: createRetryIntervalMillis: 200 propagateCreateError: false +kubernetes: + serviceLocatorMethod: 'multiTenant' + clusterLocatorMethods: + - 'config' + clusters: + - url: ${KUBERNETES_URL} + name: aks + serviceAccountToken: ${KUBERNETES_TOKEN} + authProvider: 'serviceAccount' + # plugin: # auth: # connection: @@ -58,7 +68,34 @@ backend: # $file: /ca/server.crt catalog: - # Overrides the default list locations from app-config.yaml as these contain example data. - # See https://backstage.io/docs/features/software-catalog/software-catalog-overview#adding-components-to-the-catalog for more details - # on how to get entities into the catalog. - locations: [] + import: + entityFilename: catalog-info.yaml + pullRequestBranchName: backstage-integration + rules: + - allow: [Component, System, API, Resource, Location] + locations: + # Local example data, file locations are relative to the backend process, typically `packages/backend` + - type: file + target: ../../examples/entities.yaml + + # Local example template + - type: file + target: ../../examples/template/template.yaml + rules: + - allow: [Template] + + # Local example organizational data + - type: file + target: ../../examples/org.yaml + rules: + - allow: [User, Group] + + # # Uncomment these lines to add more example data + # - type: url + # target: https://github.com/backstage/backstage/blob/master/packages/catalog-model/examples/all.yaml + + # # Uncomment these lines to add an example org + # - type: url + # target: https://github.com/backstage/backstage/blob/master/packages/catalog-model/examples/acme-corp.yaml + # rules: + # - allow: [User, Group] diff --git a/chart/backstage/Chart.yaml b/chart/backstage/Chart.yaml index 45a81cf..0439e80 100644 --- a/chart/backstage/Chart.yaml +++ b/chart/backstage/Chart.yaml @@ -4,8 +4,8 @@ description: A Helm chart for the Ortelius Backstage Instance type: application -version: 0.0.13 -appVersion: "0.0.13" +version: 0.0.14 +appVersion: "0.0.14" home: "https://ortelius.io" icon: https://backstage.io/img/twitter-summary.png diff --git a/chart/backstage/templates/backend/deployment.yaml b/chart/backstage/templates/backend/deployment.yaml index d4c2b98..4e64259 100644 --- a/chart/backstage/templates/backend/deployment.yaml +++ b/chart/backstage/templates/backend/deployment.yaml @@ -74,6 +74,16 @@ spec: secretKeyRef: name: backstage-secrets key: GITHUB_CLIENT_SECRET + - name: KUBERNETES_URL + valueFrom: + secretKeyRef: + name: backstage-secrets + key: KUBERNETES_URL + - name: KUBERNETES_TOKEN + valueFrom: + secretKeyRef: + name: backstage-secrets + key: KUBERNETES_TOKEN {{- with .Values.backend.env }} {{- toYaml . | nindent 12 }} {{- end }} diff --git a/examples/template/content/catalog-info.yaml b/examples/template/content/catalog-info.yaml index a8975de..1528873 100644 --- a/examples/template/content/catalog-info.yaml +++ b/examples/template/content/catalog-info.yaml @@ -17,3 +17,26 @@ spec: email: brad.mccoy@basiq.io picture: https://avatars.githubusercontent.com/u/25817813?v=4 memberOf: [devsecops] +--- +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: ortelius-www + annotations: + 'backstage.io/kubernetes-id': ortelius-www +spec: + type: service + owner: user:guest + lifecycle: experimental +--- +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: ortelius-docs + annotations: + 'backstage.io/kubernetes-id': ortelius-docs +spec: + type: service + owner: user:guest + lifecycle: experimental +--- diff --git a/packages/app/src/components/catalog/EntityPage.tsx b/packages/app/src/components/catalog/EntityPage.tsx index f0075b3..c67b210 100644 --- a/packages/app/src/components/catalog/EntityPage.tsx +++ b/packages/app/src/components/catalog/EntityPage.tsx @@ -55,8 +55,7 @@ import { import { TechDocsAddons } from '@backstage/plugin-techdocs-react'; import { ReportIssue } from '@backstage/plugin-techdocs-module-addons-contrib'; -// TODO BM uncomment -// import { EntityKubernetesContent } from '@backstage/plugin-kubernetes'; +import { EntityKubernetesContent } from '@backstage/plugin-kubernetes'; const techdocsContent = ( @@ -168,9 +167,9 @@ const serviceEntityPage = ( {techdocsContent} - {/* + - */} + ); diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts index 3f1c04b..121ea09 100644 --- a/packages/backend/src/index.ts +++ b/packages/backend/src/index.ts @@ -1,11 +1,3 @@ -/* - * Hi! - * - * Note that this is an EXAMPLE Backstage backend. Please check the README. - * - * Happy hacking! - */ - import Router from 'express-promise-router'; import { createServiceBuilder, @@ -31,8 +23,7 @@ import search from './plugins/search'; import { PluginEnvironment } from './types'; import { ServerPermissionClient } from '@backstage/plugin-permission-node'; import { DefaultIdentityClient } from '@backstage/plugin-auth-node'; -// TODO BM: uncomment -//import kubernetes from './plugins/kubernetes'; +import kubernetes from './plugins/kubernetes'; function makeCreateEnv(config: Config) { const root = getRootLogger(); @@ -87,8 +78,7 @@ async function main() { const techdocsEnv = useHotMemoize(module, () => createEnv('techdocs')); const searchEnv = useHotMemoize(module, () => createEnv('search')); const appEnv = useHotMemoize(module, () => createEnv('app')); - // TODO BM: add k8s config https://backstage.io/docs/features/kubernetes/configuration - //const kubernetesEnv = useHotMemoize(module, () => createEnv('kubernetes')); + const kubernetesEnv = useHotMemoize(module, () => createEnv('kubernetes')); const apiRouter = Router(); apiRouter.use('/catalog', await catalog(catalogEnv)); @@ -97,8 +87,7 @@ async function main() { apiRouter.use('/techdocs', await techdocs(techdocsEnv)); apiRouter.use('/proxy', await proxy(proxyEnv)); apiRouter.use('/search', await search(searchEnv)); - // TODO BM: uncomment once k8s config done - //apiRouter.use('/kubernetes', await kubernetes(kubernetesEnv)); + apiRouter.use('/kubernetes', await kubernetes(kubernetesEnv)); // Add backends ABOVE this line; this 404 handler is the catch-all fallback apiRouter.use(notFoundHandler()); diff --git a/packages/backend/src/plugins/kubernetes.ts b/packages/backend/src/plugins/kubernetes.ts new file mode 100644 index 0000000..8bf1d42 --- /dev/null +++ b/packages/backend/src/plugins/kubernetes.ts @@ -0,0 +1,16 @@ +import { KubernetesBuilder } from '@backstage/plugin-kubernetes-backend'; +import { Router } from 'express'; +import { PluginEnvironment } from '../types'; +import { CatalogClient } from '@backstage/catalog-client'; + +export default async function createPlugin( + env: PluginEnvironment, +): Promise { + const catalogApi = new CatalogClient({ discoveryApi: env.discovery }); + const { router } = await KubernetesBuilder.createBuilder({ + logger: env.logger, + config: env.config, + catalogApi, + }).build(); + return router; +}