Skip to content

Commit

Permalink
Replaced flow_refresh.sh w flow_refresh.py script (#239)
Browse files Browse the repository at this point in the history
* Replaced flow_refresh.sh w flow_refresh.py script

Signed-off-by: Henrich Hubbe <h.hubbe@ndr.de>

* Update Chart.yaml

---------

Signed-off-by: Henrich Hubbe <h.hubbe@ndr.de>
Co-authored-by: Henrich Hubbe <h.hubbe@ndr.de>
Co-authored-by: Engin Diri <engin.diri@ediri.de>
Signed-off-by: Engin Diri <engin.diri@ediri.de>
  • Loading branch information
3 people authored Jun 2, 2023
1 parent 9b872bc commit 021786c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
4 changes: 2 additions & 2 deletions charts/node-red/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ icon: https://nodered.org/about/resources/media/node-red-icon-2.png

type: application

version: 0.23.2
version: 0.24.0
appVersion: 3.0.2

keywords:
Expand All @@ -29,7 +29,7 @@ maintainers:
annotations:
artifacthub.io/containsSecurityUpdates: "false"
artifacthub.io/changes: |
- update quay.io/kiwigrid/k8s-sidecar to 1.24.0
- change flow_refresh.sh to flow_refresh.py, this is a breaking change.
artifacthub.io/images: |
- name: node-red
image: docker.io/nodered/node-red:3.0.2
Expand Down
45 changes: 45 additions & 0 deletions charts/node-red/scripts/flow_refresh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python

import time
import os
import requests
import json
import sys
import re

# SET VARIABLES FROM CONTAINER ENVIRONMENT
SLEEP_TIME_SIDECAR = 5 if os.getenv("SLEEP_TIME_SIDECAR") is None else int(re.sub('[A-z]', "",os.getenv("SLEEP_TIME_SIDECAR")))
USERNAME = os.getenv("USERNAME")
PASSWORD = os.getenv("PASSWORD")
URL = os.getenv("URL")

print('node-red flow refresh api call via k8s-sidecar')
print('sidecar sleeping for', SLEEP_TIME_SIDECAR, 'seconds...')
time.sleep(SLEEP_TIME_SIDECAR)

# GET NODE RED BEARER TOKEN
PAYLOAD_TOKEN = {"client_id": "node-red-admin", "grant_type": "password", "scope": "*", "username": USERNAME, "password": PASSWORD}
r_token = requests.post(URL + '/auth/token', data=PAYLOAD_TOKEN, timeout=30)
if r_token.status_code == requests.codes.ok:
print('node-red bearer token successfully created -', r_token.status_code)
token = (json.loads(r_token.text)["access_token"])
else:
print('could not create bearer token....', r_token.status_code)
sys.exit('Error-Code -', r_token.status_code)

# FLOW REFRESH/RELOAD FLOWS FROM SECRET/CONFIGMAP
PAYLOAD_FLOW_REFRESH = "{\"flows\": [{\"type\": \"tab\"}]}"
HEADERS_FLOW_REFRESH={
'Authorization': 'Bearer' + ' ' + token,
'content-type': 'application/json; charset=utf-8',
'Node-RED-Deployment-Type': 'reload',
'Node-RED-API-Version': 'v2'
}

r_flow_refresh = requests.post(URL + '/flows', headers=HEADERS_FLOW_REFRESH, data=PAYLOAD_FLOW_REFRESH, timeout=30)

if r_flow_refresh.status_code == requests.codes.ok:
print('node-red flows successfully reloaded -', r_flow_refresh.status_code)
sys.exit(0)
else:
sys.exit('Error-Code', r_flow_refresh.status_code)
5 changes: 0 additions & 5 deletions charts/node-red/scripts/flow_refresh.sh

This file was deleted.

2 changes: 1 addition & 1 deletion charts/node-red/templates/sidecar-cm.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- if .Values.sidecar.enabled }}
apiVersion: v1
data:
flow_refresh.sh: | {{ range $.Files.Lines "scripts/flow_refresh.sh" }}
flow_refresh.py: | {{ range $.Files.Lines "scripts/flow_refresh.py" }}
{{ . }}{{ end }}
kind: ConfigMap
metadata:
Expand Down
2 changes: 1 addition & 1 deletion charts/node-red/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ sidecar:
# -- The value for the label you want to filter your resources on. Don't set a value to filter by any value
label_value: "1"
# -- Absolute path to shell script to execute after a configmap got reloaded.
script: flow_refresh.sh
script: flow_refresh.py
# The username for the API Call, check node-red documentation for more information
username: ""
# -- Password as key value pair
Expand Down

0 comments on commit 021786c

Please sign in to comment.