-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 79d68da
Showing
13 changed files
with
821 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[flake8] | ||
max-line-length = 99 | ||
select: E,W,F,C,N | ||
exclude: | ||
venv | ||
.git | ||
build | ||
dist | ||
*.egg_info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.py[cod] | ||
*.charm | ||
*~ | ||
.tox | ||
.coverage | ||
__pycache__ | ||
build | ||
venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/venv | ||
*.py[cod] | ||
*.charm |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# juju-controller | ||
|
||
## Description | ||
|
||
The Juju controller hosts and manages Juju models. | ||
|
||
## Usage | ||
|
||
The controller provides an endpoint to integrate with a dashboard. | ||
|
||
## Developing | ||
|
||
Create and activate a virtualenv with the development requirements: | ||
|
||
virtualenv -p python3 venv | ||
source venv/bin/activate | ||
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`: | ||
|
||
./run_tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2021 Canonical Ltd. | ||
# Licensed under the GPLv3, see LICENSE file for details. | ||
|
||
options: | ||
controller-url: | ||
default: "" | ||
description: The URL used to access the controller API. | ||
type: string | ||
model-url-template: | ||
default: "" | ||
description: The URL template used to access a model API. | ||
type: string | ||
identity-provider-url: | ||
default: "" | ||
description: The URL used to access an external identity provider. | ||
type: string | ||
is-juju: | ||
default: true | ||
description: Whether this is a standalone Juju controller | ||
type: boolean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright 2021 Canonical Ltd. | ||
# Licensed under the GPLv3, see LICENSE file for details. | ||
name: juju-controller | ||
description: | | ||
The Juju controller charm is used to expose various pieces | ||
of functionality of a Juju controller. | ||
summary: | | ||
The Juju controller. | ||
series: | ||
- xenial | ||
- bionic | ||
- focal | ||
provides: | ||
dashboard: | ||
interface: juju-dashboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-r requirements.txt | ||
coverage | ||
flake8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ops |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/sh -e | ||
# Copyright 2021 Canonical Ltd. | ||
# Licensed under the GPLv3, see LICENSE file for details. | ||
|
||
if [ -z "$VIRTUAL_ENV" -a -d venv/ ]; then | ||
. venv/bin/activate | ||
fi | ||
|
||
if [ -z "$PYTHONPATH" ]; then | ||
export PYTHONPATH=src | ||
else | ||
export PYTHONPATH="src:$PYTHONPATH" | ||
fi | ||
|
||
flake8 | ||
coverage run --source=src -m unittest -v "$@" | ||
coverage report -m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2021 Canonical Ltd. | ||
# Licensed under the GPLv3, see LICENSE file for details. | ||
|
||
import logging | ||
|
||
from ops.charm import CharmBase | ||
from ops.main import main | ||
from ops.framework import StoredState | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class JujuControllerCharm(CharmBase): | ||
_stored = StoredState() | ||
|
||
def __init__(self, *args): | ||
super().__init__(*args) | ||
self.framework.observe(self.on.config_changed, self._on_config_changed) | ||
self._stored.set_default(things=[]) | ||
|
||
def _on_config_changed(self, _): | ||
current = self.config["controller-url"] | ||
if current not in self._stored.things: | ||
logger.critical("got a new controller-url: %r", current) | ||
self._stored.things.append(current) | ||
|
||
|
||
if __name__ == "__main__": | ||
main(JujuControllerCharm) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright 2021 Canonical Ltd. | ||
# Licensed under the GPLv3, see LICENSE file for details. | ||
|
||
import unittest | ||
|
||
from ops.testing import Harness | ||
from charm import JujuControllerCharm | ||
|
||
|
||
class TestCharm(unittest.TestCase): | ||
def test_config_changed(self): | ||
harness = Harness(JujuControllerCharm) | ||
self.addCleanup(harness.cleanup) | ||
harness.begin() | ||
self.assertEqual(list(harness.charm._stored.things), []) | ||
harness.update_config({"controller-url": "https://controller"}) | ||
self.assertEqual(list(harness.charm._stored.things), ["https://controller"]) |