Skip to content

Commit e85aff4

Browse files
committed
OSDOCS-12022: Dynamic plugin updates
1 parent 023f0c2 commit e85aff4

7 files changed

+181
-15
lines changed

modules/build-image-docker.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[id="build-image-with-docker_{context}"]
77
= Build an image with Docker
88

9-
To deploy your plugin on a cluster, you need to build an image and push it to an image registry.
9+
To deploy your plugin on a cluster, you need to build an image and push it to an image registry first.
1010

1111
.Procedure
1212

modules/deployment-plug-in-cluster.adoc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66
[id="deploy-on-cluster_{context}"]
77
= Deploy your plugin on a cluster
88

9-
After pushing an image with your changes to a registry, you can deploy the plugin to a cluster.
9+
After pushing an image with your changes to a registry, you can deploy the plugin to a cluster using a Helm chart.
10+
11+
.Prerequisites
12+
* You must have the location of the image containing the plugin that was previously pushed.
13+
+
14+
[NOTE]
15+
====
16+
You can specify additional parameters based on the needs of your plugin. The link:https://github.com/openshift/console-plugin-template/blob/main/charts/openshift-console-plugin/values.yaml[`values.yaml`] file provides a full set of suported parameters.
17+
====
1018
1119
.Procedure
1220

@@ -25,6 +33,11 @@ Where:
2533
`--create-namespace`:: Optional: If deploying to a new namespace, use this parameter.
2634
`--set plugin.image=my-plugin-image-location`:: Specifies the location of the image within the `plugin.image` parameter.
2735
--
36+
+
37+
[NOTE]
38+
====
39+
If you are deploying on {product-title} 4.10 and later, it is recommended to exclude configurations related to pod security by adding the parameter `--set plugin.securityContext.enabled=false`.
40+
====
2841

2942
. Optional: You can specify any additional parameters by using the set of supported parameters in the `charts/openshift-console-plugin/values.yaml` file.
3043
+

modules/disabling-plug-in-browser.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ Console users can use the `disable-plugins` query parameter to disable specific
1616
1717
[NOTE]
1818
====
19-
Cluster administrators can disable plugins in the *Cluster Settings* page of the web console
19+
Cluster administrators can disable plugins in the *Cluster Settings* page of the web console.
2020
====

modules/dynamic-plug-in-development.adoc

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,22 @@
99
You can run the plugin using a local development environment. The {product-title} web console runs in a container connected to the cluster you have logged into.
1010

1111
.Prerequisites
12-
* You must have an OpenShift cluster running.
13-
* You must have the OpenShift CLI (`oc`) installed.
12+
* You must have cloned the link:https://github.com/openshift/console-plugin-template[`console-plugin-template`] repository, which contains a template for creating plugins.
13+
+
14+
[IMPORTANT]
15+
====
16+
Red{nbsp}Hat does not support custom plugin code. Only link:https://access.redhat.com/solutions/5893251[Cooperative community support] is available for your plugin.
17+
====
18+
* You must have an {product-title} cluster running.
19+
* You must have the {oc-first} installed.
1420
* You must have link:https://yarnpkg.com/[`yarn`] installed.
15-
* You must have link:https://www.docker.com/[Docker] v3.2.0 or newer or link:https://podman.io/[Podman] installed and running.
21+
* You must have link:https://www.docker.com/[Docker] v3.2.0 or later or link:https://podman.io/[Podman] v3.2.0 or later installed and running.
1622
1723
.Procedure
1824

19-
. In your terminal, run the following command to install the dependencies for your plugin using yarn.
25+
. Open two terminal windows.
26+
27+
. In one terminal window, run the following command to install the dependencies for your plugin using yarn.
2028

2129
+
2230
[source,terminal]
@@ -45,6 +53,19 @@ $ oc login
4553
----
4654
$ yarn run start-console
4755
----
56+
+
57+
[NOTE]
58+
====
59+
The `yarn run start-console` command runs an `amd64` image and might fail when run with Apple Silicon and Podman. You can work around it with `qemu-user-static` by running the following commands:
60+
61+
[source,terminal]
62+
----
63+
$ podman machine ssh
64+
$ sudo -i
65+
$ rpm-ostree install qemu-user-static
66+
$ systemctl reboot
67+
----
68+
====
4869

4970
.Verification
50-
* Visit link:http://localhost:9000/example[localhost:9000] to view the running plugin. Inspect the value of `window.SERVER_FLAGS.consolePlugins` to see the list of plugins which load at runtime.
71+
* Visit link:http://localhost:9000/example[localhost:9000] to view the running plugin. Inspect the value of `window.SERVER_FLAGS.consolePlugins` to see the list of plugins which load at runtime.

modules/dynamic-plugin-api.adoc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,49 @@ const Component: React.FC = (props) => {
16111611
.Returns
16121612
A tuple containing the current active namespace and setter callback.
16131613

1614+
[discrete]
1615+
== `useUserSettings`
1616+
1617+
Hook that provides a user setting value and a callback for setting the user setting value.
1618+
1619+
.Example
1620+
[source,tsx,subs="+quotes,+macros"]
1621+
----
1622+
const Component: React.FC = (props) ++=>++ {
1623+
const [state, setState, loaded] = useUserSettings(
1624+
++'devconsole.addPage.showDetails'++,
1625+
true,
1626+
true,
1627+
);
1628+
return loaded ++? (++
1629+
++<WrappedComponent {...props} userSettingState={state} setUserSettingState={setState} />++
1630+
) : null;
1631+
};
1632+
----
1633+
1634+
.Returns
1635+
A tuple containing the user setting vauel, a setter callback, and a loaded boolean.
1636+
1637+
[discrete]
1638+
== `useQuickStartContext`
1639+
1640+
Hook that provides the current quick start context values. This allows plugins to interoperate with console quick start functionality.
1641+
1642+
.Example
1643+
[source,tsx,subs="+quotes,+macros"]
1644+
----
1645+
const OpenQuickStartButton ++= ({ quickStartId }) => {++
1646+
const { setActiveQuickStart } = useQuickStartContext();
1647+
const ++onClick = React.useCallback(() => {++
1648+
setActiveQuickStart(quickStartId);
1649+
}, [quickStartId]);
1650+
++return <button onClick={onClick}>{t('Open Quick Start')}</button>++
1651+
};
1652+
----
1653+
1654+
.Reterns
1655+
Quick start context values object.
1656+
16141657
[discrete]
16151658
== `PerspectiveContext`
16161659

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * web_console/dynamic-plugin/overview-dynamic-plugin.adoc
4+
5+
:_mod-docs-content-type: PROCEDURE
6+
[id="dynamic-plugin-api_{context}"]
7+
= Translating messages with react-i18next
8+
9+
The link:https://github.com/openshift/console-plugin-template[plugin template] demonstrates how you can translate messages with link:https://www.i18next.com/[react-i18next].
10+
11+
.Prerequisites
12+
* You must have the plugin template cloned locally.
13+
* Optional: To test your plugin locally, run the {product-title} web console in a container. You can use either Docker or Podman 3.2.0 or later.
14+
15+
.Procedure
16+
17+
. Prefix the name with `plugin\__` to avoid any naming conflicts. The plugin template uses the `plugin__console-plugin-template` namespace by default, and you must update when you rename your plugin for example, `plugin__my-plugin`. You can use the `useTranslation` hook, for example:
18+
+
19+
[source,tsx,subs="+quotes,+macros"]
20+
----
21+
conster Header: React.FC = () ++=>++ {
22+
const ++{ t } = useTranslation('plugin__console-demo-plugin');++
23+
++return <h1>{t('Hello, World!')}</h1>;++
24+
++};++
25+
----
26+
+
27+
[IMPORTANT]
28+
====
29+
You must match the `i18n` namespace with the name of the `ConsolePlugin` resource.
30+
====
31+
32+
. Set the `spec.i18n.loadType` field based on needed behavior.
33+
+
34+
.`plugin__console-demo-plugin`
35+
[example]
36+
====
37+
[source,yaml,subs="+quotes,+macros"]
38+
----
39+
spec:
40+
backend:
41+
service:
42+
basePath: ++/++
43+
name: console-demo-plugin
44+
namespace: console-demo-plugin
45+
port: 9001
46+
type: Service
47+
displayName: OpenShift Console Demo Plugin
48+
i18n:
49+
loadType: Preload <1>
50+
----
51+
<1> Loads all the plugin's localization resources from the `i18n` namespace after the dynamic plugin during loading.
52+
====
53+
54+
. Use the format `++%plugin__console-plugin-template~My Label%++` for labels in `console-extensions.json`. The console replaces the value with the message for the current language from the `plugin__console-plugin-template` namespace. For example:
55+
+
56+
[source,json,subs="+quotes,+macros"]
57+
----
58+
{
59+
++"type": "console.navigation/section"++,
60+
++"properties": {++
61+
++"id": "admin-demo-section"++,
62+
++"perspective": "admin"++,
63+
++"name": "%plugin__console-plugin-template~Plugin Template%"++
64+
}
65+
}
66+
----
67+
68+
. Include a comment in a TypeScript file for link:https://github.com/i18next/i18next-parser[i18next-parser] to add the message from `console-extensions.json` to your message catalog. For example:
69+
+
70+
[source,tsx,subs="+quotes,+macros"]
71+
----
72+
++// t('plugin__console-demo-plugin~Demo Plugin')++
73+
----
74+
75+
. To update the JSON files in the `locales` folder of the plugin template when adding or changing a message, run the following command:
76+
+
77+
[source,terminal]
78+
----
79+
$ yarn i18n
80+
----

web_console/dynamic-plugin/overview-dynamic-plugin.adoc

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ toc::[]
99
[id="dynamic-plug-in-overview"]
1010
== About dynamic plugins
1111

12-
Dynamic plugins are deployed as workloads on the cluster. They allow you to add custom pages and other extensions to your console user interface at runtime. The `ConsolePlugin` custom resource registers plugins with the console, and a cluster administrator enables plugins in the `console-operator` configuration.
12+
Dynamic plugins are loaded and interpreted from remote sources at runtime. One way to deliver and expose dynamic plugins to the console is through OLM Operators. The Operator creates a deployment on the platform with an HTTP server to host the plugin and exposes it using a Kubernetes service.
13+
14+
Dynamic plugins allow you to add custom pages and other extensions to your console user interface at runtime. The `ConsolePlugin` custom resource registers plugins with the console, and a cluster administrator enables plugins in the console Operator configuration.
1315

1416
[id="dynamic-plugins-features"]
1517
== Key features
@@ -30,16 +32,21 @@ When creating your plugin, follow these general guidelines:
3032
* Maintain a consistent look, feel, and behavior with other console pages.
3133
* Follow link:https://www.i18next.com/[react-i18next] localization guidelines when creating your plugin. You can use the `useTranslation` hook like the one in the following example:
3234
+
33-
[source,typescript]
35+
[source,tsx,subs="+quotes,+macros"]
3436
----
35-
conster Header: React.FC = () => {
36-
const { t } = useTranslation('plugin__console-demo-plugin');
37-
return <h1>{t('Hello, World!')}</h1>;
38-
};
37+
conster Header: React.FC ++= () => {++
38+
++const { t } = useTranslation('plugin__console-demo-plugin');++
39+
++return <h1>{t('Hello, World!')}</h1>;++
40+
++};++
3941
----
4042

4143
* Avoid selectors that could affect markup outside of your plugins components, such as element selectors. These are not APIs and are subject to change. Using them might break your plugin. Avoid selectors like element selectors that could affect markup outside of your plugins components.
4244
* Provide valid JavaScript Multipurpose Internet Mail Extension (MIME) type using the `Content-Type` response header for all assets served by your plugin web server. Each plugin deployment should include a web server that hosts the generated assets of the given plugin.
45+
* You must build your plugin with Webpack using Webpack version 5 and later.
46+
* You should prefix CSS class names with your plugin name to avoid collisions. For example, `my-plugin_\_heading` and `my-plugin_\_icon`.
47+
* You should maintain a consistent look, feel, and behavior with other console pages.
48+
* You should avoid selectors that could affect markup outside of your plugin components, such as element selectors. These are not APIs and are subject to change.
49+
* You must provide a valid JavaScript Multipurpose Internet Mail Extension (MIME) type using the `Content-Type` response header for all assets served by your plugin web server. Each plugin deployment should include a web server that hosts the generated assets of the given plugin.
4350

4451
[discrete]
4552
== PatternFly guidelines
@@ -49,5 +56,7 @@ When creating your plugin, follow these guidelines for using PatternFly:
4956
** Use Patternfly 4.x if you are using {product-title} versions 4.14 and earlier.
5057
** Use Patternfly 5.x if you are using {product-title} 4.15 or later.
5158
* Make your plugin accessible by following link:https://www.patternfly.org/accessibility/accessibility-fundamentals/[PatternFly's accessibility fundamentals].
52-
* Avoid using other CSS libraries such as Bootstrap or Tailwind. They can conflict with PatternFly and will not match the console look and feel. Plugins should only include styles that are specific to their user interfaces to be evaluated on top of base PatternFly styles. Avoid importing styles such as `@patternfly/react-styles/**/*.css` or any styles from `@patternfly/patternfly` package in your plugin.
59+
* Avoid using other CSS libraries such as Bootstrap or Tailwind. They might conflict with PatternFly and not match the rest of the console. Plugins should only include styles that are specific to their user interfaces to be evaluated on top of base PatternFly styles. Avoid importing styles such as `@patternfly/react-styles/**/*.css` or any styles from the `@patternfly/patternfly` package in your plugin.
5360
* The console application is responsible for loading base styles for all supported PatternFly version(s).
61+
62+
include::modules/dynamic-plugin-localization.adoc[leveloffset=+2]

0 commit comments

Comments
 (0)