This codebase is an example charm - based on the Canonical training for the Python Operator Framework. The code in its current form is a scaffolded charm, with no customization.
Follow these instructions to configure your environment:
Most up to date instruction can be found at https://juju.is/docs/microk8s-cloud
But a quick summary can be found here:
$ sudo snap install microk8s --classic
$ sudo usermod -a -G microk8s $USER
$ sudo su - $USER
$ microk8s status --wait-ready
$ microk8s.enable dns storage
$ sudo snap install juju --classic
$ juju bootstrap microk8s micro
$ juju add-model training
Charmcraft is our build and publish tool for Operators.
$ sudo snap install charmcraft --beta
This project is intended as a training aid, to learn how to quick start an Operator with the Python Operator Framework.
For each step in this project, you'll find numbered directories inside the stages directory, which contains a complete version of the training operator. Example: stages/01podspec/src/charm.py - which contains an updated version of the TrainingCharm class for Section 01.
After reviewing each step of the tutorial, you can build and deploy the charm from within the stages directory:
$ cd stages/01podspec
$ charmcraft build
Done, charm left in 'training.charm'
$ juju deploy ./training.charm
Deploying charm "local:kubernetes/training-0".
$
$ charmcraft init --project-dir training-charm --name training
This command will scaffold a charm into the training-charm directory, and the contents should be identical to the staged 00init directory.
To view the changes for src/charm.py
$ diff stages/00init/src/charm.py stages/01podspec/src/charm.py
Build and deploy.
View the changes for config.yaml
$ diff stages/01podspec/config.yaml stages/02newconfigs/config.yaml
View the changes for src/charm.py
$ diff stages/01podspec/src/charm.py stages/02newconfigs/src/charm.py
Build and deploy. At this stage, you can use upgrade-charm instead of deploy.
$ juju upgrade-charm training --path=./training.charm
Added charm "local:kubernetes/training-1" to the model.
View the changes for metadata.yaml
$ diff stages/02newconfigs/metadata.yaml stages/03storage/metadata.yaml
Build and redeploy. If you attempt to deploy after this change, you will see an error message, because you cannot convert a traditional workload to a StatefulSet in Kubernetes. You'll need to remove and redeploy the training application.
$ juju remove-application training
removing application training
View the changes for metadata.yaml
$ diff stages/03storage/metadata.yaml stages/04relation/metadata.yaml
View the changes for src/charm.py
$ diff stages/03storage/src/charm.py stages/04relation/src/charm.py
View the changes for metadata.yaml
$ diff stages/04relation/metadata.yaml stages/05cluster/metadata.yaml
View the changes for src/charm.py
$ diff stages/04relation/src/charm.py stages/05cluster/src/charm.py
View the changes for tests/test_charm.py
$ diff stages/05cluster/tests/test_charm.py stages/06harness/tests/test_charm.py
Create and activate a virtualenv, and install the development requirements, run the testing helper script.
$ cd stages/06harness
$ virtualenv -p python3 venv
$ source venv/bin/activate
$ pip install -r requirements-dev.txt
$ ./run_tests