Dynamic plugin example

Before working through the example, verify that the plugin is working by following the steps in Dynamic plugin development

Adding a tab to the pods page

There are different customizations you can make to the OKD web console. The following procedure adds a tab to the Pod details page as an example extension to your plugin.

The OKD web console runs in a container connected to the cluster you have logged into. See “Dynamic plugin development” for information to test the plugin before creating your own.

Procedure

  1. Visit the console-plugin-template repository containing a template for creating plugins in a new tab.

    Custom plugin code is not supported by Red Hat. Only Cooperative community support is available for your plugin.

  2. Select the Use this template dropdown button and select Create new repository from the dropdown list to create a GitHub repository.

  3. Re-name the new repository with the name of your plugin.

  4. Clone your copied repositury to your local machine so you can edit the code.

  5. Edit the plugin metadata in the consolePlugin declaration of package.json.

    1. "consolePlugin": {
    2. "name": "my-plugin", (1)
    3. "version": "0.0.1", (2)
    4. "displayName": "My Plugin", (3)
    5. "description": "Enjoy this shiny, new console plugin!", (4)
    6. "exposedModules": {
    7. "ExamplePage": "./components/ExamplePage"
    8. },
    9. "dependencies": {
    10. "@console/pluginAPI": "/*"
    11. }
    12. }
    1Update the name of your plugin.
    2Update the version.
    3Update the display name for your plugin.
    4Update the description with a synopsis about your plugin.
  6. Add the following to the console-extensions.json file:

    1. {
    2. "type": "console.tab/horizontalNav",
    3. "properties": {
    4. "page": {
    5. "name": "Example Tab",
    6. "href": "example"
    7. },
    8. "model": {
    9. "group": "core",
    10. "version": "v1",
    11. "kind": "Pod"
    12. },
    13. "component": { "$codeRef": "ExampleTab" }
    14. }
    15. }
  7. Edit the package.json file to include the following changes:

    1. "exposedModules": {
    2. "ExamplePage": "./components/ExamplePage",
    3. "ExampleTab": "./components/ExampleTab"
    4. }
  8. Write a message to display on a new custom tab on the Pods page by creating a new file src/components/ExampleTab.tsx and adding the following script:

    1. import * as React from 'react';
    2. export default function ExampleTab() {
    3. return (
    4. <p>This is a custom tab added to a resource using a dynamic plugin.</p>
    5. );
    6. }

Verification

  • Visit a Pod page to view the added tab.