Git Product home page Git Product logo

console-plugin-template's Introduction

OpenShift Console Plugin Template

This project is a minimal template for writing a new OpenShift Console dynamic plugin.

Dynamic plugins allow you to extend the OpenShift UI at runtime, adding custom pages and other extensions. They are based on webpack module federation. Plugins are registered with console using the ConsolePlugin custom resource and enabled in the console operator config by a cluster administrator.

Using the latest v1 API version of ConsolePlugin CRD, requires OpenShift 4.12 and higher. For using old v1alpha1 API version us OpenShift version 4.10 or 4.11.

For an example of a plugin that works with OpenShift 4.11, see the release-4.11 branch. For a plugin that works with OpenShift 4.10, see the release-4.10 branch.

Node.js and yarn are required to build and run the example. To run OpenShift console in a container, either Docker or podman 3.2.0+ and oc are required.

Getting started

After cloning this repo, you should update the plugin metadata such as the plugin name in the consolePlugin declaration of package.json.

"consolePlugin": {
  "name": "console-plugin-template",
  "version": "0.0.1",
  "displayName": "My Plugin",
  "description": "Enjoy this shiny, new console plugin!",
  "exposedModules": {
    "ExamplePage": "./components/ExamplePage"
  },
  "dependencies": {
    "@console/pluginAPI": "*"
  }
}

The template adds a single example page in the Home navigation section. The extension is declared in the console-extensions.json file and the React component is declared in src/components/ExamplePage.tsx.

You can run the plugin using a local development environment or build an image to deploy it to a cluster.

Development

Option 1: Local

In one terminal window, run:

  1. yarn install
  2. yarn run start

In another terminal window, run:

  1. oc login (requires oc and an OpenShift cluster)
  2. yarn run start-console (requires Docker or podman 3.2.0+)

This will run the OpenShift console in a container connected to the cluster you've logged into. The plugin HTTP server runs on port 9001 with CORS enabled. Navigate to http://localhost:9000/example to see the running plugin.

Running start-console with Apple silicon and podman

If you are using podman on a Mac with Apple silicon, yarn run start-console might fail since it runs an amd64 image. You can workaround the problem with qemu-user-static by running these commands:

podman machine ssh
sudo -i
rpm-ostree install qemu-user-static
systemctl reboot

Option 2: Docker + VSCode Remote Container

Make sure the Remote Containers extension is installed. This method uses Docker Compose where one container is the OpenShift console and the second container is the plugin. It requires that you have access to an existing OpenShift cluster. After the initial build, the cached containers will help you start developing in seconds.

  1. Create a dev.env file inside the .devcontainer folder with the correct values for your cluster:
OC_PLUGIN_NAME=console-plugin-template
OC_URL=https://api.example.com:6443
OC_USER=kubeadmin
OC_PASS=<password>
  1. (Ctrl+Shift+P) => Remote Containers: Open Folder in Container...
  2. yarn run start
  3. Navigate to http://localhost:9000/example

Docker image

Before you can deploy your plugin on a cluster, you must build an image and push it to an image registry.

  1. Build the image:

    docker build -t quay.io/my-repository/my-plugin:latest .
  2. Run the image:

    docker run -it --rm -d -p 9001:80 quay.io/my-repository/my-plugin:latest
  3. Push the image:

    docker push quay.io/my-repository/my-plugin:latest

NOTE: If you have a Mac with Apple silicon, you will need to add the flag --platform=linux/amd64 when building the image to target the correct platform to run in-cluster.

Deployment on cluster

A Helm chart is available to deploy the plugin to an OpenShift environment.

The following Helm parameters are required:

plugin.image: The location of the image containing the plugin that was previously pushed

Additional parameters can be specified if desired. Consult the chart values file for the full set of supported parameters.

Installing the Helm Chart

Install the chart using the name of the plugin as the Helm release name into a new namespace or an existing namespace as specified by the plugin_console-plugin-template parameter and providing the location of the image within the plugin.image parameter by using the following command:

helm upgrade -i  my-plugin charts/openshift-console-plugin -n plugin__console-plugin-template --create-namespace --set plugin.image=my-plugin-image-location

NOTE: When deploying on OpenShift 4.10, it is recommended to add the parameter --set plugin.securityContext.enabled=false which will omit configurations related to Pod Security.

NOTE: When defining i18n namespace, adhere plugin__<name-of-the-plugin> format. The name of the plugin should be extracted from the consolePlugin declaration within the package.json file.

i18n

The plugin template demonstrates how you can translate messages in with react-i18next. The i18n namespace must match the name of the ConsolePlugin resource with the plugin__ prefix to avoid naming conflicts. For example, the plugin template uses the plugin__console-plugin-template namespace. You can use the useTranslation hook with this namespace as follows:

conster Header: React.FC = () => {
  const { t } = useTranslation('plugin__console-plugin-template');
  return <h1>{t('Hello, World!')}</h1>;
};

For labels in console-extensions.json, you can use the format %plugin__console-plugin-template~My Label%. Console will replace the value with the message for the current language from the plugin__console-plugin-template namespace. For example:

  {
    "type": "console.navigation/section",
    "properties": {
      "id": "admin-demo-section",
      "perspective": "admin",
      "name": "%plugin__console-plugin-template~Plugin Template%"
    }
  }

Running yarn i18n updates the JSON files in the locales folder of the plugin template when adding or changing messages.

Linting

This project adds prettier, eslint, and stylelint. Linting can be run with yarn run lint.

The stylelint config disallows hex colors since these cause problems with dark mode (starting in OpenShift console 4.11). You should use the PatternFly global CSS variables for colors instead.

The stylelint config also disallows naked element selectors like table and .pf- or .co- prefixed classes. This prevents plugins from accidentally overwriting default console styles, breaking the layout of existing pages. The best practice is to prefix your CSS classnames with your plugin name to avoid conflicts. Please don't disable these rules without understanding how they can break console styles!

Reporting

Steps to generate reports

  1. In command prompt, navigate to root folder and execute the command yarn run cypress-merge
  2. Then execute command yarn run cypress-generate The cypress-report.html file is generated and should be in (/integration-tests/screenshots) directory

References

console-plugin-template's People

Contributors

batzionb avatar caponetto avatar cyril-ui-developer avatar glekner avatar jgbernalp avatar jhadvig avatar kyoto avatar lavocatt avatar mikaello avatar mylanos avatar nitin-dhevar avatar openshift-merge-bot[bot] avatar openshift-merge-robot avatar rhamilto avatar sabre1041 avatar sg00dwin avatar spadgett avatar therealjon avatar vojtechszocs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

console-plugin-template's Issues

Local dev instructions aren't working (Option 1)

Following the instructions in the README for local development under "Option 1: Local", it instructs me to run the plugin via yarn run start in one terminal and start the console in a container via yarn run start-console. In the console output, when I open the console in my browser I am seeing this error:

E0222 22:29:55.352596       1 handlers.go:165] GET request for "console-plugin-template" plugin failed: Get "http://host.docker.internal:9001/locales/en/plugin__console-plugin-template.json": dial tcp: lookup host.docker.internal on 192.168.5.3:53: no such host

It seems like the console wants to load from port 9001 in its docker environment rather than on my actual local machine where the plugin is running. (Note: I'm using Rancher Desktop to provide my dockerd runtime, maybe that's my issue? I'd expect it to work like any other Docker environment.)

We may want to add a third option in these instructions to describe running the console locally (not in a container) with ./bin/bridge, as described here: https://github.com/openshift/console/tree/master/frontend/packages/console-dynamic-plugin-sdk#plugin-development

Run Bridge locally and instruct it to proxy e.g. /api/plugins/console-demo-plugin requests directly
to your local plugin asset server (web server hosting the plugin's generated assets):

./bin/bridge -plugins console-demo-plugin=http://localhost:9001/

Your plugin should start loading automatically upon Console application startup. Inspect the value of
window.SERVER_FLAGS.consolePlugins to see the list of plugins which Console loads upon its startup.

This is useful in case you can't (or don't want to) set up a container runtime on your development machine, or if you need to develop changes to the console itself alongside changes to a plugin.

`yarn run start-console` fails on Apple silicon

Attempting to follow the getting started guide for the first time using Apple M2 and a ROSA cluster. I have followed the instructions for qemu-user-static but still receive an architecture-related error running yarn run start-console. What am I missing? We are a Red Hat partner exploring the console plugin system. Thanks!

(This looks different from #10.)

$ yarn run start-console
yarn run v1.22.21
$ ./start-console.sh
Starting local OpenShift console...
API Server: https://api.XXX.YYY.ZZZ.openshiftapps.com:6443
Console Image: quay.io/openshift/origin-console:latest
Console URL: http://localhost:9000
Trying to pull quay.io/openshift/origin-console:latest...
Error: choosing an image from manifest list docker://quay.io/openshift/origin-console:latest: no image found in manifest list for architecture arm64, variant "v8", OS linux
error Command failed with exit code 125.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

System info:

$ podman version
Client:       Podman Engine
Version:      4.6.0
API Version:  4.6.0
Go Version:   go1.20.6
Git Commit:   38e6fab9664c6e59b66e73523b307a56130316ae
Built:        Thu Jul 20 16:13:05 2023
OS/Arch:      darwin/arm64

Server:       Podman Engine
Version:      4.7.2
API Version:  4.7.2
Go Version:   go1.21.1
Built:        Tue Oct 31 10:30:33 2023
OS/Arch:      linux/arm64
$ podman machine info
Host:
  Arch: arm64
  CurrentMachine: podman-machine-default
  DefaultMachine: podman-machine-default
  EventsDir: /var/folders/x3/jdkpfq_s301fv3208971rx080000gn/T/podman-run--1/podman
  MachineConfigDir: /Users/estoner/.config/containers/podman/machine/qemu
  MachineImageDir: /Users/estoner/.local/share/containers/podman/machine/qemu
  MachineState: Running
  NumberOfMachines: 1
  OS: darwin
  VMType: qemu
Version:
  APIVersion: 4.6.0
  Built: 1689883985
  BuiltTime: Thu Jul 20 16:13:05 2023
  GitCommit: 38e6fab9664c6e59b66e73523b307a56130316ae
  GoVersion: go1.20.6
  Os: darwin
  OsArch: darwin/arm64
  Version: 4.6.0
$ podman machine ssh    
Connecting to vm podman-machine-default. To close connection, use `~.` or `exit`
Fedora CoreOS 39.20231204.2.1
Tracker: https://github.com/coreos/fedora-coreos-tracker
Discuss: https://discussion.fedoraproject.org/tag/coreos

Last login: Fri Dec 29 09:37:21 2023 from 192.168.127.1
core@localhost:~$ rpm-ostree status
State: idle
Deployments:
โ— fedora:fedora/aarch64/coreos/testing
                  Version: 39.20231204.2.1 (2023-12-05T16:40:37Z)
               BaseCommit: c35b380d7da8041330c89473791e935d2472004c4ee5a1e4f2f685ae6b558abc
             GPGSignature: Valid signature by E8F23996F23218640CB44CBE75CF5AC418B8E74C
      RemovedBasePackages: moby-engine 24.0.5-1.fc39
          LayeredPackages: qemu-user-static

  fedora:fedora/aarch64/coreos/testing
                  Version: 39.20231204.2.1 (2023-12-05T16:40:37Z)
               BaseCommit: c35b380d7da8041330c89473791e935d2472004c4ee5a1e4f2f685ae6b558abc
             GPGSignature: Valid signature by E8F23996F23218640CB44CBE75CF5AC418B8E74C
      RemovedBasePackages: moby-engine 24.0.5-1.fc39

`./start-console` won't work with non-admin user

getting the following error trying to run ./start-console.sh

Starting local OpenShift console...
Error from server (Forbidden): configmaps "monitoring-shared-config" is forbidden: User "test" cannot get resource "configmaps" in API group "" in the namespace "openshift-config-managed"

Dev Environment support

I am having trouble getting started on a Windows box with these instructions. What is the preferred dev environment for this?

Hot reload of plugin is broken in 4.14

After 4.14 release of OpenShift I started experiencing issues with hot reloading of console plugin when developing.
After any change in my plugin code, I was getting a 404 when trying to access the plugin, so I had to do the full (yarn run start and yarn run start-console thing again).

Logs seems clear with no indication of a problem. After exploring the browser console I noticed that the second time browser tries to fetch the console manifest (e.g. http://localhost:9000/api/plugins/quarkus-openshift-console-plugin/plugin-manifest.json) it gets a blank response back.

After rolling back to 4.13 (by changing the start-console.sh script to use 4.13 instead of latest) the issue seems fixed.

How to develop with other console plugins

Hi, I'm a Red Hat ISV partner developing a plugin that will add a horizontal nav tab to the VirtualMachine page. However, the kubevirt-plugin that is loaded and enabled in my OpenShift cluster is not enabled in the local OKD console. How do I load both the plugins that are enabled on the remote cluster, as well as my local plugin in development?

Add more regular updates of dependencies

This is a template repository, so many will start off of this. I think you, therefore, have an extra responsibility to have your dependencies up to date so others don't start off with out-of-date dependencies.

There are some great tools to help you keep your dependencies up to date with pretty low effort, here are a couple of examples:

Both of these support auto-merge of pull requests (either by GitHub actions or by Renovatebot App), so you can for example auto-merge all minor and patch versions to keep the maintenance low. You seem to have good testing in this project, so you can be confident you don't break the project.

Use ENVs during Runtime on OpenShift

Hi there

I want to use ENVs during Runtime on OpenShift. At first sight I could not place a runtime-config.json on the Webserver which serves the Plugin.

Does anyone have experience with this and can place a hint?

Thanks and regards

`yarn run start-console` fails in mac M1 with http proxy error

Our team is using the console-plugin-template as a base for the project:https://github.com/artemiscloud/activemq-artemis-self-provisioning-plugin

We are using the M1 chip MacBooks and when we run yarn run start-console and access http://locahost:9000, the following error comes up.

More information

  • macOS M1
  • Hypervisor: Podman(qemu)
  • Did you run crc setup before starting it (Yes)
  • Running CRC on: Laptop

CRC version

CRC version: 2.10.2+065f0741
OpenShift version: 4.11.7
Podman version: 4.2.0

CRC status

DEBU CRC version: 2.10.2+065f0741
DEBU OpenShift version: 4.11.7
DEBU Podman version: 4.2.0
DEBU Running 'crc status'
CRC VM:          Running
OpenShift:       Running (v4.11.7)
RAM Usage:       8.943GB of 16.34GB
Disk Usage:      15.18GB of 32.74GB (Inside the CRC VM)
Cache Usage:     73.53GB
Cache Directory: /Users/ajay/.crc/cache

CRC config

- consent-telemetry                     : no

Host Operating System

ProductName:		macOS
ProductVersion:		13.0.1
BuildVersion:		22A400

Steps to reproduce

  1. clone https://github.com/artemiscloud/activemq-artemis-self-provisioning-plugin.git
  2. cd activemq-artemis-self-provisioning-plugin
  3. run yarn run build (should have yarn installed)
  4. run yarn run start in a separate terminal
  5. run yarn run start-console in another terminal

Expected

The UI should be accessible at http://localhost:9000

Actual

The logs fail with a HTTP proxy error and UI is not accessible.

Logs

Starting local OpenShift console...
API Server: https://api.crc.testing:6443
Console Image: quay.io/openshift/origin-console:latest
Console URL: http://localhost:9000
Trying to pull quay.io/openshift/origin-console:latest...
Getting image source signatures
Copying blob sha256:b1a581a9885c08c968f83a70f6d6940564f288cb9fc4b039e4743e7be8c9c8cc
Copying blob sha256:69788635f90cb66139f7d62ff431c784b4fd7b98632bb18e7cc10bebab55205e
Copying blob sha256:9578bde7a5452e36c2da7dca455705194e76d896b3d3371358fc3fc027e203d4
Copying blob sha256:dfaf6e5198c10186790f5f02d3d4e18941704c0f29b0dda3e7a1df12563a5c5a
Copying blob sha256:230a4f53a4a69f1aed929af369883fd1563117b0643f0c8bf1ad1578d41a895e
Copying config sha256:e47e7f353b8fa136ba24f53037156b0b6a5c735c5f9a638f575ca66f686becca
Writing manifest to image destination
Storing signatures
WARNING: image platform ({amd64 linux [] }) does not match the expected platform ({arm64 linux [] })
W1121 05:28:19.153195 1 main.go:228] Flag inactivity-timeout is set to less then 300 seconds and will be ignored!
I1121 05:28:19.155403 1 main.go:238] The following console plugins are enabled:
I1121 05:28:19.155896 1 main.go:240] - activemq-artemis-self-provisioning-plugin
W1121 05:28:19.156592 1 main.go:351] cookies are not secure because base-address is not https!
W1121 05:28:19.158006 1 main.go:682] running with AUTHENTICATION DISABLED!
I1121 05:28:19.168760 1 main.go:798] Binding to 0.0.0.0:9000...
I1121 05:28:19.169235 1 main.go:803] not using TLS
2022/11/21 05:28:45 http: proxy error: dial tcp: lookup api.crc.testing on 192.168.127.1:53: no such host
2022/11/21 05:28:45 http: proxy error: dial tcp: lookup api.crc.testing on 192.168.127.1:53: no such host
2022/11/21 05:28:45 http: proxy error: dial tcp: lookup api.crc.testing on 192.168.127.1:53: no such host
2022/11/21 05:28:45 http: proxy error: dial tcp: lookup api.crc.testing on 192.168.127.1:53: no such host
2022/11/21 05:28:45 http: proxy error: dial tcp: lookup api.crc.testing on 192.168.127.1:53: no such host
2022/11/21 05:28:45 http: proxy error: dial tcp: lookup api.crc.testing on 192.168.127.1:53: no such host
2022/11/21 05:28:45 http: proxy error: dial tcp: lookup api.crc.testing on 192.168.127.1:53: no such host

I would be great if you could assist us in finding the exact issue. Thanks in advance.

`yarn run start-console` doesn't work with docker

When I start the console using podman the plugin are loaded and works.
However if I force it to use docker the console gets 'no such host' error.
The following shows the output of yarn run start-console:

$ yarn run start-console
yarn run v1.22.19
$ ./start-console.sh
Starting local OpenShift console...
API Server: https://api.crc.testing:6443
Console Image: quay.io/openshift/origin-console:latest
Console URL: http://localhost:9000
============docker
latest: Pulling from openshift/origin-console
Digest: sha256:bcdfadf39f45ea2f35bdff6e6db92b4ea2bd9237a67fc4d96be08b6855641255
Status: Image is up to date for quay.io/openshift/origin-console:latest
I0219 12:02:57.784894       1 main.go:204] The following console plugins are enabled:
I0219 12:02:57.784908       1 main.go:206]  - console-plugin-template
W0219 12:02:57.784913       1 authoptions.go:85] Flag inactivity-timeout is set to less then 300 seconds and will be ignored!
W0219 12:02:57.784937       1 authoptions.go:205] running with AUTHENTICATION DISABLED!
I0219 12:02:57.785915       1 main.go:625] Binding to 0.0.0.0:9000...
I0219 12:02:57.785931       1 main.go:630] not using TLS
I0219 12:03:00.786050       1 metrics.go:138] serverconfig.Metrics: Update ConsolePlugin metrics...
E0219 12:03:00.841627       1 metrics.go:143] serverconfig.Metrics: Failed to get all installed ConsolePlugins: Get "https://api.crc.testing:6443/apis/console.openshift.io/v1/consoleplugins": dial tcp: lookup api.crc.testing on 10.72.17.5:53: no such host
I0219 12:03:00.841656       1 metrics.go:148] serverconfig.Metrics: Update ConsolePlugin metrics: &map[demo:map[notfound:1]] (took 55.585986ms)
2024/02/19 12:03:02 Failed to dial backend: 'Internal Server Error'
I0219 12:03:02.786252       1 metrics.go:88] usage.Metrics: Count console users...
E0219 12:03:02.805072       1 metrics.go:105] usage.Metrics: Failed to get user-settings RoleBindings: Get "https://api.crc.testing:6443/apis/rbac.authorization.k8s.io/v1/namespaces/openshift-console-user-settings/rolebindings": dial tcp: lookup api.crc.testing on 10.72.17.5:53: no such host
E0219 12:03:03.406491       1 handlers.go:164] failed to send GET request for "console-plugin-template" plugin: Get "http://host.docker.internal:9001/plugin-manifest.json": dial tcp: lookup host.docker.internal on 10.72.17.5:53: no such host
^C

Looks like it has problems accessing api.crc.testing and host.docker.internal from inside the container?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.