Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to specify a certain version for extra node modules instead of latest every time #318

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
8 changes: 4 additions & 4 deletions charts/node-red/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# node-red ⚙
****# node-red ⚙

![Version: 0.32.0](https://img.shields.io/badge/Version-0.32.0-informational?style=for-the-badge) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=for-the-badge) ![AppVersion: 3.1.9](https://img.shields.io/badge/AppVersion-3.1.9-informational?style=for-the-badge)

Expand Down Expand Up @@ -131,7 +131,7 @@ The command removes all the Kubernetes components associated with the chart and
| sidecar.env.sleep_time_sidecar | string | `"5s"` | Set the sleep time for refresh script |
| sidecar.env.username | string | `""` | |
| sidecar.extraEnv | list | `[]` | Extra Environments for the sidecar |
| sidecar.extraNodeModules | list | `[]` | Extra Node-Modules that will be installed from the sidecar script |
| sidecar.extraNodeModules | list | `[]` | Extra Node-Modules that will be installed from the sidecar script (specifying a version like [email protected] is supported) |
| sidecar.image.pullPolicy | string | `"IfNotPresent"` | The image pull policy, default: `IfNotPresent` |
| sidecar.image.registry | string | `"quay.io"` | The image registry to pull the sidecar from |
| sidecar.image.repository | string | `"kiwigrid/k8s-sidecar"` | The image repository to pull from |
Expand Down Expand Up @@ -179,15 +179,15 @@ Default values are: `node-red-settings:1`.
The `k8s-sidecar` will then call the `node-red` api to reload the flows. This will be done via a script. To run this script successfully you need to provide the `username` and `password`
of your admin user. The admin user needs to have the right to use the `node-red` API.

The `k8s-sidecar` can also call the `node-red` api to install additional node modules (npm packages) before refreshing or importing the flow.json.
The `k8s-sidecar` can also call the `node-red` api to install additional node modules (npm packages) before refreshing or importing the flow.json. Specifying a version for a module is supported (s. example below).
You need to list your flows required 'NODE_MODULES' in the `sidecar.extraNodeModules`: e.g.

```yaml
sidecar:
extraNodeModules:
- node-red-contrib-xkeys_setunitid
- node-red-contrib-microsoft-teams-tasks
- node-red-contrib-json
- node-red-contrib-json@0.2.0
```
To install the node modules successfully, the node red pod needs access to the `npmrc.registry` to download the declaired modules/packages.

Expand Down
2 changes: 1 addition & 1 deletion charts/node-red/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Default values are: `node-red-settings:1`.
The `k8s-sidecar` will then call the `node-red` api to reload the flows. This will be done via a script. To run this script successfully you need to provide the `username` and `password`
of your admin user. The admin user needs to have the right to use the `node-red` API.

The `k8s-sidecar` can also call the `node-red` api to install additional node modules (npm packages) before refreshing or importing the flow.json.
The `k8s-sidecar` can also call the `node-red` api to install additional node modules (npm packages) before refreshing or importing the flow.json. Specifying a version for a module is supported (s. example below).
You need to list your flows required 'NODE_MODULES' in the `sidecar.extraNodeModules`: e.g.

```yaml
Expand Down
10 changes: 9 additions & 1 deletion charts/node-red/scripts/flow_refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,15 @@ def main():

for module in EXTRA_NODE_MODULES:
if module not in modules_installed:
payload_node_module = '{"module": "' + module + '"}'
try:
module_name, version = module.rsplit('/', 1)[-1].split('@', 1) if '@' in module else (module, None)
except:
module_name, version = module, None
payload_node_module = ''
if version is not None:
payload_node_module = '{"module": "' + module_name + '", "version": "' + version + '"}'
else:
payload_node_module = '{"module": "' + module_name + '"}'
headers_node_module = {
"Content-type": "application/json",
}
Expand Down