npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@antoinedao/backstage-provider-kubernetes

v0.1.2

Published

A Backstage catalog provider and processor for Kubernetes

Downloads

26

Readme

Backstage Provider Kubernetes

A Backstage plugin with entity providers to read Kubernetes objects as Backstage Entities.

Getting started

Installing The Plugin

You will have to add the provider in the catalog initialization code of your backend. They are not installed by default, therefore you have to add a dependency on @antoinedao/backstage-provider-kubernetes to your backend package.

yarn add --cwd packages/backend @antoinedao/backstage-provider-kubernetes

And then add the entity provider to your catalog builder:

/* highlight-add-next-line */
import { KubernetesEntityProvider } from '@antoinedao/backstage-provider-kubernetes';

export default async function createPlugin(
  env: PluginEnvironment,
): Promise<Router> {
  const builder = await CatalogBuilder.create(env);

  builder.addEntityProvider([
    ... await KubernetesEntityProvider.fromConfig(env, {
      logger: env.logger,
      scheduler: env.scheduler,
    })
  ])

  // ..
}

Configuration

Configuring the Backstage Kubernetes provider is managed in Backstage's app-config.yaml file and involves two steps:

  1. Defining remote Kubernetes cluster configuration and authentication methods. This re-uses the config definition for the Backstage Kubernetes Plugin which is documented here.

    ⚠️ clusterLocatorMethod of type config is the only tests method for no, other methods might not work or produce unexpected results

    kubernetes:
     serviceLocatorMethod:
       type: 'multiTenant'
     clusterLocatorMethods:
       - type: 'config'
         clusters:
           - url: https://127.0.0.1:6443
             name: docker-desktop
             authProvider: 'serviceAccount'
             skipTLSVerify: false
             skipMetricsLookup: true
             serviceAccountToken: ${K8S_DOCKER_DESKTOP_SA_TOKEN}
             caData: ${K8S_DOCKER_DESKTOP_CONFIG_CA_DATA}
    
           - url: https://33.33.33.33
             name: k8s-staging
             authProvider: googleServiceAccount
             skipTLSVerify: false
             skipMetricsLookup: true    
             caData: ${K8S_STAGING_CONFIG_CA_DATA}
  2. Adding kubernetes configurations to the catalog providers configuration
    catalog:
      rules:
        - allow: [Component, System, API, Resource, Location]
      providers:
        kubernetes:
          local-cluster:
            cluster: docker-desktop
            processor:
              namespaceOverride: default
              defaultOwner: guests
            schedule:
              frequency:
                seconds: 30
              timeout:
                seconds: 5
    
          staging:
            cluster: k8s-staging
            processor:
              namespaceOverride: default
              defaultOwner: guests
            filters:
              resources:
              - group: serving.knative.dev
                apiVersion: v1
                plural: services
                objectType: Service 
            schedule:
              frequency:
                minutes: 30
              timeout:
                minutes: 1

Catalog Provider Configuration

This section covers in detail the configuration options for the catalog provider section.

The Catalog Providers are defined in configuration file at the following path: catalog.providers.kubernetes.<name-of-provider-config>. Multiple concurrent providers are supported so you can import data from multiple clusters or within the same cluster with different processor overrides.

The values for each key are objects with the following properties:

  • cluster (required): a string that specifies the name of the Kubernetes cluster. It should match the name of the cluster inside the cluster locator methods defined in the global config at kubernetes.clusterLocatorMethods.clusters.name

  • filters (optional): an optional object that contains properties for filtering resources.

    • resources (optional): property is an optional array of any type of data. The default configuration fetches [deployments, jobs, cronjobs, statefulsets, daemonsets]
    • namespace (optional): property is an optional string that specifies a namespace to filter for
    • labelSelector (optional): property is an optional string that specifies a label selector.
  • processor (optional): an optional object that contains properties to populate required fields in the provided Backtstage Components

    • namespaceOverride (optional): set this to the Backstage Namespace the Component should be assigned to. This will default to the Kubernetes object's namespace if left blank
    • lifecyle (optional): set this to specify the Backstage Component Lifecycle property (defaults to production)
    • defaultOwner (optional): set this to specify the Backstage Component Owner property (defaults to unknown)
  • schedule (optional): an optional object that contains properties for the schedule. The TaskScheduleDefinitionConfig interface is used to define the properties.

    • frequency: How often you want the task to run. The system does its best to avoid overlapping invocations.
    • timeout: The maximum amount of time that a single task invocation can take.
    • initialDelay (optional): The amount of time that should pass before the first invocation happens.
    • scope (optional): 'global' or 'local'. Sets the scope of concurrency control.

Example

Here is a full example config for local development with Docker Desktop as a source:

app:
  title: Scaffolded Backstage App
  baseUrl: http://localhost:3000

organization:
  name: My Company

backend:
  baseUrl: http://localhost:7007
  listen:
    port: 7007
  csp:
    connect-src: ["'self'", 'http:', 'https:']
  cors:
    origin: http://localhost:3000
    methods: [GET, HEAD, PATCH, POST, PUT, DELETE]
    credentials: true
  database:
    client: better-sqlite3
    connection: ':memory:'
  cache:
    store: memory

integrations:
  github:
    - host: github.com
      token: ${GITHUB_TOKEN}

techdocs:
  builder: 'local' # Alternatives - 'external'
  generator:
    runIn: 'docker' # Alternatives - 'local'
  publisher:
    type: 'local' # Alternatives - 'googleGcs' or 'awsS3'. Read documentation for using alternatives.

auth:
  providers: {}

scaffolder: {}

catalog:
  import:
    entityFilename: catalog-info.yaml
    pullRequestBranchName: backstage-integration
  rules:
    - allow: [Component, System, API, Resource, Location]
  providers:
    kubernetes:
      local-cluster:
        cluster: docker-desktop
        processor:
          namespaceOverride: default
          defaultOwner: guests
        schedule:
          frequency:
            seconds: 30
          timeout:
            seconds: 5
          
  locations: []

kubernetes:
  serviceLocatorMethod:
    type: 'multiTenant'
  clusterLocatorMethods:
    - type: 'config'
      clusters:
        - url: https://127.0.0.1:6443
          name: docker-desktop
          authProvider: 'serviceAccount'
          skipT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