NAS-122777 / 23.10 / Add node-red to community train (#1323)

* add node-red - initial commit

* add templtes

* add ci values and questions

* run single test

* all but one

* add trace logging

* hmmmm

* root

* add tests

* no 18 for now

* update questions and chart.yaml

* fix tests

* bump common
This commit is contained in:
Stavros Kois
2023-07-06 15:16:27 +03:00
committed by GitHub
parent 33f5e9bad1
commit df01fb3304
25 changed files with 659 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
dependencies:
- name: common
repository: file://../../../common
version: 1.0.10
digest: sha256:06709bd6d9a8dbb721eec437a52f8c24aeecefbbc57e6f8617e53b29570d5512
generated: "2023-07-05T19:34:00.610088429+03:00"

View File

@@ -0,0 +1,25 @@
name: node-red
description: Node-RED is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways.
annotations:
title: Node-RED
type: application
version: 1.0.0
apiVersion: v2
appVersion: '3.0.2'
kubeVersion: '>=1.16.0-0'
maintainers:
- name: truenas
url: https://www.truenas.com/
email: dev@ixsystems.com
dependencies:
- name: common
repository: file://../../../common
version: 1.0.10
home: https://nodered.org
icon: https://avatars.githubusercontent.com/u/5375661
sources:
- https://github.com/node-red/node-red-docker
- https://github.com/truenas/charts/tree/master/community/node-red
- https://nodered.org
keywords:
- automation

View File

@@ -0,0 +1,8 @@
# Node-RED
[Node-RED](https://nodered.org) is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways.
> When application is installed, a container will be launched with **root** privileges.
> This is required in order to apply the correct permissions to the `Node-RED` directories.
> Afterward, the `Node-RED` container will run as a **non**-root user (`1000`).
> All mounted storage(s) will be `chown`ed only if the parent directory does not match the configured user.

View File

@@ -0,0 +1,8 @@
# Node-RED
[Node-RED](https://nodered.org) is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways.
> When application is installed, a container will be launched with **root** privileges.
> This is required in order to apply the correct permissions to the `Node-RED` directories.
> Afterward, the `Node-RED` container will run as a **non**-root user (`1000`).
> All mounted storage(s) will be `chown`ed only if the parent directory does not match the configured user.

View File

@@ -0,0 +1,10 @@
noderedConfig:
imageSelector: node14Image
noderedNetwork:
webPort: 31000
noderedStorage:
data:
type: hostPath
hostPath: /mnt/{{ .Release.Namespace }}/data

View File

@@ -0,0 +1,10 @@
noderedConfig:
imageSelector: node14MinimalImage
noderedNetwork:
webPort: 31000
noderedStorage:
data:
type: hostPath
hostPath: /mnt/{{ .Release.Namespace }}/data

View File

@@ -0,0 +1,10 @@
noderedConfig:
imageSelector: node16Image
noderedNetwork:
webPort: 31000
noderedStorage:
data:
type: hostPath
hostPath: /mnt/{{ .Release.Namespace }}/data

View File

@@ -0,0 +1,10 @@
noderedConfig:
imageSelector: node16MinimalImage
noderedNetwork:
webPort: 31000
noderedStorage:
data:
type: hostPath
hostPath: /mnt/{{ .Release.Namespace }}/data

View File

@@ -0,0 +1,10 @@
noderedConfig:
imageSelector: node18Image
noderedNetwork:
webPort: 31000
noderedStorage:
data:
type: hostPath
hostPath: /mnt/{{ .Release.Namespace }}/data

View File

@@ -0,0 +1,10 @@
noderedConfig:
imageSelector: node18MinimalImage
noderedNetwork:
webPort: 31000
noderedStorage:
data:
type: hostPath
hostPath: /mnt/{{ .Release.Namespace }}/data

View File

@@ -0,0 +1,21 @@
noderedConfig:
safeMode: true
enableProjects: true
additionalEnvs:
- name: NODE_OPTIONS
value: --max-old-space-size=256
noderedNetwork:
webPort: 31000
noderedStorage:
data:
type: hostPath
hostPath: /mnt/{{ .Release.Namespace }}/data
additionalStorages:
- type: hostPath
hostPath: /mnt/{{ .Release.Namespace }}/customData
mountPath: /customData
- type: hostPath
hostPath: /mnt/{{ .Release.Namespace }}/customFiles
mountPath: /customFiles

View File

@@ -0,0 +1,8 @@
noderedNetwork:
webPort: 30000
hostNetwork: true
noderedStorage:
data:
type: hostPath
hostPath: /mnt/{{ .Release.Namespace }}/data

View File

@@ -0,0 +1,7 @@
icon_url: https://avatars.githubusercontent.com/u/5375661
categories:
- productivity
screenshots:
- https://camo.githubusercontent.com/c7b6e0b937295c4d2c852130814050eb0caffac5b700ead6de21df6dbf83aa82/687474703a2f2f6e6f64657265642e6f72672f696d616765732f6e6f64652d7265642d73637265656e73686f742e706e67
tags:
- automation

View File

@@ -0,0 +1,8 @@
runAsContext:
- userName: node-red
groupName: node-red
gid: 1000
uid: 1000
description: Node-RED runs as a non-root user.
capabilities: []
hostMounts: []

View File

@@ -0,0 +1,248 @@
groups:
- name: Node-RED Configuration
description: Configure Node-RED
- name: User and Group Configuration
description: Configure User and Group for Node-RED
- name: Network Configuration
description: Configure Network for Node-RED
- name: Storage Configuration
description: Configure Storage for Node-RED
- name: Resources Configuration
description: Configure Resources for Node-RED
portals:
web_portal:
protocols:
- "$kubernetes-resource_configmap_portal_protocol"
host:
- "$kubernetes-resource_configmap_portal_host"
ports:
- "$kubernetes-resource_configmap_portal_port"
path: "$kubernetes-resource_configmap_portal_path"
questions:
- variable: noderedConfig
label: ""
group: Node-RED Configuration
schema:
type: dict
attrs:
- variable: imageSelector
label: Node-RED Image
description: The Node-RED image to use.
schema:
type: string
default: "node16Image"
required: true
enum:
- value: node14Image
description: Node-RED on Node.js 14
- value: node14MinimalImage
description: Node-RED Minimal on Node.js 14
- value: node16Image
description: Node-RED on Node.js 16
- value: node16MinimalImage
description: Node-RED Minimal on Node.js 16
- value: node18Image
description: Node-RED on Node.js 18
- value: node18MinimalImage
description: Node-RED Minimal on Node.js 18
- variable: safeMode
label: Safe Mode
description: |
Starts Node-RED without starting the flows.</br>
This allows you to open the flows in the editor and
make changes without the flows running.</br>
When you deploy your changes, the flows are then started.
schema:
type: boolean
default: false
- variable: enableProjects
label: Enable Projects
description: |
Enable projects in Node-RED.</br>
This allows you to use the projects feature in Node-RED.
schema:
type: boolean
default: false
- variable: additionalEnvs
label: Additional Environment Variables
description: Configure additional environment variables for Node-RED.
schema:
type: list
default: []
items:
- variable: env
label: Environment Variable
schema:
type: dict
attrs:
- variable: name
label: Name
schema:
type: string
required: true
- variable: value
label: Value
schema:
type: string
required: true
- variable: noderedNetwork
label: ""
group: Network Configuration
schema:
type: dict
attrs:
- variable: webPort
label: Web Port
description: The port for the Node-RED Web UI.
schema:
type: int
default: 30049
min: 9000
max: 65535
required: true
- variable: hostNetwork
label: Host Network
description: |
Bind to the host network. It's recommended to keep this disabled.</br>
schema:
type: boolean
default: false
- variable: noderedStorage
label: ""
group: Storage Configuration
schema:
type: dict
attrs:
- variable: data
label: Node-RED Data Storage
description: The path to store Node-RED Data.
schema:
type: dict
attrs:
- variable: type
label: Type
description: |
ixVolume: Is dataset created automatically by the system.</br>
Host Path: Is a path that already exists on the system.
schema:
type: string
required: true
default: "ixVolume"
enum:
- value: "hostPath"
description: Host Path (Path that already exists on the system)
- value: "ixVolume"
description: ixVolume (Dataset created automatically by the system)
- variable: datasetName
label: Dataset Name
schema:
type: string
show_if: [["type", "=", "ixVolume"]]
required: true
hidden: true
immutable: true
default: "data"
$ref:
- "normalize/ixVolume"
- variable: hostPath
label: Host Path
schema:
type: hostpath
show_if: [["type", "=", "hostPath"]]
immutable: true
required: true
- variable: additionalStorages
label: Additional Storage
description: Additional storage for Node-RED.
schema:
type: list
default: []
items:
- variable: storageEntry
label: Storage Entry
schema:
type: dict
attrs:
- variable: type
label: Type
description: |
ixVolume: Is dataset created automatically by the system.</br>
Host Path: Is a path that already exists on the system.
schema:
type: string
required: true
default: "ixVolume"
enum:
- value: "hostPath"
description: Host Path (Path that already exists on the system)
- value: "ixVolume"
description: ixVolume (Dataset created automatically by the system)
- variable: mountPath
label: Mount Path
description: The path inside the container to mount the storage.
schema:
type: path
required: true
- variable: hostPath
label: Host Path
description: The host path to use for storage.
schema:
type: hostpath
show_if: [["type", "=", "hostPath"]]
required: true
- variable: datasetName
label: Dataset Name
description: The name of the dataset to use for storage.
schema:
type: string
show_if: [["type", "=", "ixVolume"]]
required: true
immutable: true
default: "storage_entry"
$ref:
- "normalize/ixVolume"
- variable: resources
group: Resources Configuration
label: ""
schema:
type: dict
attrs:
- variable: limits
label: Limits
schema:
type: dict
attrs:
- variable: cpu
label: CPU
description: CPU limit for Node-RED.
schema:
type: string
max_length: 6
valid_chars: '^(0\.[1-9]|[1-9][0-9]*)(\.[0-9]|m?)$'
valid_chars_error: |
Valid CPU limit formats are</br>
- Plain Integer - eg. 1</br>
- Float - eg. 0.5</br>
- Milicpu - eg. 500m
default: "4000m"
required: true
- variable: memory
label: Memory
description: Memory limit for Node-RED.
schema:
type: string
max_length: 12
valid_chars: '^[1-9][0-9]*([EPTGMK]i?|e[0-9]+)?$'
valid_chars_error: |
Valid Memory limit formats are</br>
- Suffixed with E/P/T/G/M/K - eg. 1G</br>
- Suffixed with Ei/Pi/Ti/Gi/Mi/Ki - eg. 1Gi</br>
- Plain Integer in bytes - eg. 1024</br>
- Exponent - eg. 134e6
default: "8Gi"
required: true

View File

@@ -0,0 +1 @@
{{ include "ix.v1.common.lib.chart.notes" $ }}

View File

@@ -0,0 +1,60 @@
{{- define "nodered.workload" -}}
workload:
nodered:
enabled: true
primary: true
type: Deployment
podSpec:
hostNetwork: {{ .Values.noderedNetwork.hostNetwork }}
containers:
nodered:
enabled: true
primary: true
imageSelector: {{ .Values.noderedConfig.imageSelector }}
# https://github.com/node-red/node-red-docker/wiki/Permissions-and-Persistence
securityContext:
runAsUser: 1000
runAsGroup: 1000
env:
PORT: {{ .Values.noderedNetwork.webPort }}
NODE_RED_ENABLE_SAFE_MODE: {{ .Values.noderedConfig.safeMode }}
NODE_RED_ENABLE_PROJECTS: {{ .Values.noderedConfig.enableProjects }}
{{ with .Values.noderedConfig.additionalEnvs }}
envList:
{{ range $env := . }}
- name: {{ $env.name }}
value: {{ $env.value }}
{{ end }}
{{ end }}
probes:
liveness:
enabled: true
type: exec
command:
- /bin/sh
- -c
- |
NODE_OPTIONS=--dns-result-order=ipv4first node /healthcheck.js
readiness:
enabled: true
type: exec
command:
- /bin/sh
- -c
- |
NODE_OPTIONS=--dns-result-order=ipv4first node /healthcheck.js
startup:
enabled: true
type: exec
command:
- /bin/sh
- -c
- |
NODE_OPTIONS=--dns-result-order=ipv4first node /healthcheck.js
initContainers:
{{- include "ix.v1.common.app.permissions" (dict "containerName" "01-permissions"
"UID" 1000
"GID" 1000
"mode" "check"
"type" "init") | nindent 8 }}
{{- end -}}

View File

@@ -0,0 +1,34 @@
{{- define "nodered.persistence" -}}
persistence:
data:
enabled: true
type: {{ .Values.noderedStorage.data.type }}
datasetName: {{ .Values.noderedStorage.data.datasetName | default "" }}
hostPath: {{ .Values.noderedStorage.data.hostPath | default "" }}
targetSelector:
nodered:
nodered:
mountPath: /data
01-permissions:
mountPath: /mnt/directories/data
tmp:
enabled: true
type: emptyDir
targetSelector:
nodered:
nodered:
mountPath: /tmp
{{- range $idx, $storage := .Values.noderedStorage.additionalStorages }}
{{ printf "nodered-%v" (int $idx) }}:
enabled: true
type: {{ $storage.type }}
datasetName: {{ $storage.datasetName | default "" }}
hostPath: {{ $storage.hostPath | default "" }}
targetSelector:
nodered:
nodered:
mountPath: {{ $storage.mountPath }}
01-permissions:
mountPath: /mnt/directories{{ $storage.mountPath }}
{{- end }}
{{- end -}}

View File

@@ -0,0 +1,12 @@
{{- define "nodered.portal" -}}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: portal
data:
path: "/"
port: {{ .Values.noderedNetwork.webPort | quote }}
protocol: http
host: $node_ip
{{- end -}}

View File

@@ -0,0 +1,15 @@
{{- define "nodered.service" -}}
service:
nodered:
enabled: true
primary: true
type: NodePort
targetSelector: nodered
ports:
webui:
enabled: true
primary: true
port: {{ .Values.noderedNetwork.webPort }}
nodePort: {{ .Values.noderedNetwork.webPort }}
targetSelector: nodered
{{- end -}}

View File

@@ -0,0 +1,11 @@
{{- include "ix.v1.common.loader.init" . -}}
{{/* Merge the templates with Values */}}
{{- $_ := mustMergeOverwrite .Values (include "nodered.workload" $ | fromYaml) -}}
{{- $_ := mustMergeOverwrite .Values (include "nodered.service" $ | fromYaml) -}}
{{- $_ := mustMergeOverwrite .Values (include "nodered.persistence" $ | fromYaml) -}}
{{/* Create the configmap for portal manually*/}}
{{- include "nodered.portal" $ -}}
{{- include "ix.v1.common.loader.apply" . -}}

View File

@@ -0,0 +1,11 @@
{
"filename": "values.yaml",
"keys": [
"node18Image",
"node18MinimalImage",
"node16Image",
"node16MinimalImage",
"node14Image",
"node14MinimalImage"
]
}

View File

@@ -0,0 +1,71 @@
#!/usr/bin/python3
import json
import re
import sys
from catalog_update.upgrade_strategy import semantic_versioning
RE_STABLE_VERSION_BASE = r'\d+\.\d+\.\d+'
ENUMS = {
'node18Image': {
'RE_STABLE_VERSION': re.compile(rf'{RE_STABLE_VERSION_BASE}-18'),
'STRIP_TEXT': '-18'
},
'node18MinimalImage': {
'RE_STABLE_VERSION': re.compile(rf'{RE_STABLE_VERSION_BASE}-18-minimal'),
'STRIP_TEXT': '-18-minimal'
},
'node16Image': {
'RE_STABLE_VERSION': re.compile(rf'{RE_STABLE_VERSION_BASE}-16'),
'STRIP_TEXT': '-16'
},
'node16MinimalImage': {
'RE_STABLE_VERSION': re.compile(rf'{RE_STABLE_VERSION_BASE}-16-minimal'),
'STRIP_TEXT': '-16-minimal'
},
'node14Image': {
'RE_STABLE_VERSION': re.compile(rf'{RE_STABLE_VERSION_BASE}-14'),
'STRIP_TEXT': '-14'
},
'node14MinimalImage': {
'RE_STABLE_VERSION': re.compile(rf'{RE_STABLE_VERSION_BASE}-14-minimal'),
'STRIP_TEXT': '-14-minimal'
}
}
def newer_mapping(image_tags):
output = {
"tags": {},
"app_version": ""
}
for key in image_tags.keys():
STRIP_TEXT = ENUMS[key].get('STRIP_TEXT', None) if key in ENUMS else None
RE_STABLE_VERSION = ENUMS[key].get('RE_STABLE_VERSION', None) if key in ENUMS else None
if (STRIP_TEXT is None) or (RE_STABLE_VERSION is None):
continue
tags = {t.strip(STRIP_TEXT): t for t in image_tags[key] if RE_STABLE_VERSION.fullmatch(t)}
version = semantic_versioning(list(tags))
if not version:
continue
# 16 is the "default" (Also tied to latest tag)
if key == 'node16Image':
output['app_version'] = version
output['tags'][key] = tags[version]
return output
if __name__ == '__main__':
try:
versions_json = json.loads(sys.stdin.read())
except ValueError:
raise ValueError('Invalid json specified')
print(json.dumps(newer_mapping(versions_json)))

View File

@@ -0,0 +1,45 @@
node18Image:
repository: nodered/node-red
pullPolicy: IfNotPresent
tag: '3.0.2-18'
node18MinimalImage:
repository: nodered/node-red
pullPolicy: IfNotPresent
tag: '3.0.2-18-minimal'
node16Image:
repository: nodered/node-red
pullPolicy: IfNotPresent
tag: '3.0.2-16'
node16MinimalImage:
repository: nodered/node-red
pullPolicy: IfNotPresent
tag: '3.0.2-16-minimal'
node14Image:
repository: nodered/node-red
pullPolicy: IfNotPresent
tag: '3.0.2-14'
node14MinimalImage:
repository: nodered/node-red
pullPolicy: IfNotPresent
tag: '3.0.2-14-minimal'
resources:
limits:
cpu: 4000m
memory: 8Gi
noderedConfig:
imageSelector: node16Image
safeMode: false
enableProjects: false
additionalEnvs: []
noderedNetwork:
webPort: 30049
hostNetwork: false
noderedStorage:
data:
type: ixVolume
datasetName: data
additionalStorages: []