项目作者: juanmanuel-tirado

项目描述 :
Juju deployable charm for NodeRED for K8s
高级语言: Python
项目地址: git://github.com/juanmanuel-tirado/nodered-charm-k8s.git
创建时间: 2021-08-05T11:40:14Z
项目社区:https://github.com/juanmanuel-tirado/nodered-charm-k8s

开源协议:Apache License 2.0

下载


nodered-charm-k8s

Description

Node-RED is a programming tool for wiring together
hardware devices, APIs and online services in new and interesting ways. It
provides a browser-based editor that makes it easy to wire together flows
using the wide range of nodes in the palette that can be deployed to its
runtime in a single-click.

This charm deploys a basic Node-Red server on the desired port. It provides
an HTTP interface with
basic configuration options.

Development setup

For a local deployment set a MicroK8s environment:

  1. # Install MicroK8s
  2. $ sudo snap install --classic microk8s
  3. # Wait for MicroK8s to be ready
  4. $ sudo microk8s status --wait-ready
  5. # Enable features required by Juju controller & charm
  6. $ sudo microk8s enable storage dns ingress
  7. # (Optional) Alias kubectl bundled with MicroK8s package
  8. $ sudo snap alias microk8s.kubectl kubectl
  9. # (Optional) Add current user to 'microk8s' group
  10. # This avoid needing to use 'sudo' with the 'microk8s' command
  11. $ sudo usermod -aG microk8s $(whoami)
  12. # Activate the new group (in the current shell only)
  13. # Log out and log back in to make the change system-wide
  14. $ newgrp microk8s
  15. # Install Charmcraft
  16. $ sudo snap install charmcraft
  17. # Install juju
  18. $ sudo snap install --classic juju
  19. # Bootstrap the Juju controller on MicroK8s
  20. $ juju bootstrap microk8s micro
  21. # Add a new model to Juju
  22. $ juju add-model test

Usage

First, get a package with charmcraft.

  1. $ charmcraft pack

Now a .charm file should have been generated. Now juju can deploy the charm.

  1. $ juju deploy ./nodered_ubuntu-20.04-amd64.charm --resource nodered-image=nodered/node-red:latest

Our charm waits for a ingress point. We can provide one using the
nginx-ingress-integrator charm.

  1. $ juju deploy nginx-ingress-integrator
  2. $ juju relate nodered nginx-ingress-integrator

Check the current juju status.

  1. $ juju status --color
  2. Model Controller Cloud/Region Version SLA Timestamp
  3. test micro microk8s/localhost 2.9.10 unsupported 13:23:01+02:00
  4. App Version Status Scale Charm Store Channel Rev OS Address Message
  5. nginx-ingress-integrator active 1 nginx-ingress-integrator charmhub stable 22 kubernetes 10.152.183.254
  6. nodered active 1 nodered local 9 kubernetes 10.152.183.9
  7. Unit Workload Agent Address Ports Message
  8. nginx-ingress-integrator/0* active idle 10.1.250.244 Ingress with service IP(s): 10.152.183.115
  9. nodered/0* active idle 10.1.250.243

When both applications are ready, NodeRED will be available on the ingress IP and the port indicated in
the configuration file.

Actions

This charm uses the node-red-admin API to offer the following actions.

Install-package

Install a node-red package. For example, to install the node-red-dashboard package:

  1. $ juju run-action nodered/0 install-package package=node-red-dashboard
  2. Action queued with id: "14"
  3. $ juju show-action-output 14
  4. UnitId: nodered/0
  5. id: "14"
  6. log:
  7. - 2021-08-16 12:23:01 +0200 CEST Module node-red-dashboard installed
  8. results: {}
  9. status: completed
  10. timing:
  11. completed: 2021-08-16 10:23:01 +0000 UTC
  12. enqueued: 2021-08-16 10:22:54 +0000 UTC
  13. started: 2021-08-16 10:22:54 +0000 UTC

Uninstall-package

Uninstall a node-red package.

  1. $ juju run-action nodered/0 uninstall-package package=node-red-dashboard
  2. Action queued with id: "26"
  3. $ juju show-action-output 26
  4. UnitId: nodered/0
  5. id: "26"
  6. log:
  7. - 2021-08-16 12:37:02 +0200 CEST Module node-red-dashboard uninstalled
  8. results: {}
  9. status: completed
  10. timing:
  11. completed: 2021-08-16 10:37:02 +0000 UTC
  12. enqueued: 2021-08-16 10:36:57 +0000 UTC
  13. started: 2021-08-16 10:36:59 +0000 UTC

Developing

Create and activate a virtualenv with the development requirements:

  1. virtualenv -p python3 venv
  2. source venv/bin/activate
  3. pip install -r requirements-dev.txt

Testing

The Python operator framework includes a very nice harness for testing
operator behaviour without full deployment. Just run_tests:

  1. ./run_tests