Skip to content

jhadvig/dbaaS-dynamic-plugin

 
 

Repository files navigation

DBaaS Dynamic Plugin

This project emulates a standalone repository hosting a sample dynamic plugin for OpenShift Console.

Local development

  1. yarn build to build the plugin, generating output to dist directory
  2. yarn http-server to start an HTTP server hosting the generated assets
Starting up http-server, serving ./dist
Available on:
  http://127.0.0.1:9001
  http://192.168.1.190:9001
  http://10.40.192.80:9001
Hit CTRL-C to stop the server

The server runs on port 9001 with caching disabled and CORS enabled. Additional server options can be passed to the script, for example:

yarn http-server -a 127.0.0.1

See the plugin development section in Console Dynamic Plugins README for details on how to run Bridge using local plugins.

Using Console's API

OpenShift Console exposes API via global window object in runtime. In order to use the API you need to configure webpack externals.

  1. in webpack.config.js add externals configuration
externals: {
  '@openshift-console/dynamic-plugin-sdk/api': 'api',
}
  1. Add path mapping to tsconfig.json - this step is needed because TS does not yet support node's package exports
"paths": {
  "@openshift-console/dynamic-plugin-sdk/api": ["node_modules/@openshift-console/dynamic-plugin-sdk/lib/api/api"],
}

After following the steps above you will be able to import API in your components/functions like

import { useK8sWatchResource } from '@openshift-console/dynamic-plugin-sdk/api';

See the usage in Foo component

Every imported component/function from @openshift-console/dynamic-plugin-sdk/api will be replaced in runtime by an actual implementation.

Deployment on cluster

Console dynamic plugins are supposed to be deployed via OLM operators. In case of demo plugin, we just apply a minimal OpenShift manifest which adds the necessary resources.

oc apply -f oc-manifest.yaml

Note that the Service exposing the HTTP server is annotated to have a signed service serving certificate generated and mounted into the image. This allows us to run the server with HTTP/TLS enabled, using a trusted CA certificate.

Enabling the plugin

Once deployed on the cluster, demo plugin must be enabled before it can be loaded by Console.

To enable the plugin manually, edit Console operator config and make sure the plugin's name is listed in the spec.plugins sequence (add one if missing):

oc edit console.operator.openshift.io cluster
# ...
spec:
  plugins:
    - console-dynamic-foo
# ...

Docker image

Following commands should be executed in Console repository root.

  1. Build the image:
    docker build -f Dockerfile.plugins.demo -t quay.io/$USER/console-dynamic-foo .
  2. Run the image:
    docker run -it -p 9001:9001 quay.io/$USER/console-dynamic-foo
  3. Push the image to image registry:
    docker push quay.io/$USER/console-dynamic-foo

Update and apply oc-manifest.yaml to use a custom plugin image.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 61.6%
  • TypeScript 27.9%
  • CSS 9.7%
  • Other 0.8%