generated from canonical/is-charms-template-repo
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
19 changed files
with
517 additions
and
74 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
File renamed without changes.
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,27 @@ | ||
# Copyright 2023 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
# This file populates the Overview on Charmhub. | ||
# See https://juju.is/docs/sdk/metadata-reference for a checklist and guidance. | ||
|
||
name: k8s-worker | ||
display-name: Kubernetes Worker | ||
summary: A machine charm for a K8s Worker | ||
docs: https://discourse.charmhub.io | ||
issues: https://github.com/canonical/k8s-operator/issues | ||
maintainers: | ||
- https://launchpad.net/~containers | ||
source: https://github.com/canonical/k8s-operator | ||
|
||
assumes: | ||
- juju >= 3.1 | ||
|
||
description: | | ||
A machine charm which operates a Kubernetes worker. | ||
This charm installs and operates a Kubernetes worker via the k8s snap. It exposes | ||
relations to co-operate with other kubernetes components | ||
This charm provides the following running components: | ||
* kube-proxy | ||
* kubelet | ||
* containerd |
File renamed without changes.
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,48 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright 2023 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
# Learn more at: https://juju.is/docs/sdk | ||
|
||
"""Charm the service. | ||
Refer to the following post for a quick-start guide that will help you | ||
develop a new k8s charm using the Operator Framework: | ||
https://discourse.charmhub.io/t/4208 | ||
""" | ||
|
||
import logging | ||
|
||
import ops | ||
|
||
# Log messages can be retrieved using juju debug-log | ||
logger = logging.getLogger(__name__) | ||
|
||
VALID_LOG_LEVELS = ["info", "debug", "warning", "error", "critical"] | ||
|
||
|
||
class K8sWorkerCharm(ops.CharmBase): | ||
"""Charm the service.""" | ||
|
||
def __init__(self, *args): | ||
"""Construct. | ||
Args: | ||
args: Arguments passed to the CharmBase parent constructor. | ||
""" | ||
super().__init__(*args) | ||
self.framework.observe(self.on.update_status, self._on_update_status) | ||
|
||
def _on_update_status(self, _event: ops.UpdateStatusEvent): | ||
"""Handle update-status event. | ||
Args: | ||
_event: event triggering the handler. | ||
""" | ||
self.unit.status = ops.ActiveStatus("Ready") | ||
|
||
|
||
if __name__ == "__main__": # pragma: nocover | ||
ops.main.main(K8sWorkerCharm) |
File renamed without changes.
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,32 @@ | ||
# Copyright 2023 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
# Learn more about testing at: https://juju.is/docs/sdk/testing | ||
|
||
# pylint: disable=duplicate-code,missing-function-docstring | ||
"""Unit tests.""" | ||
|
||
|
||
import ops | ||
import ops.testing | ||
import pytest | ||
from charm import K8sWorkerCharm | ||
|
||
|
||
@pytest.fixture() | ||
def harness(): | ||
harness = ops.testing.Harness(K8sWorkerCharm) | ||
harness.begin() | ||
yield harness | ||
harness.cleanup() | ||
|
||
|
||
def test_config_changed_invalid(harness): | ||
# Trigger a config-changed event with an unknown-config option | ||
with pytest.raises(ValueError): | ||
harness.update_config({"unknown-config": "foobar"}) | ||
|
||
|
||
def test_update_status(harness): | ||
harness.charm.on.update_status.emit() | ||
assert harness.model.unit.status == ops.ActiveStatus("Ready") |
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,120 @@ | ||
# Copyright 2023 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
[tox] | ||
skipsdist=True | ||
skip_missing_interpreters = True | ||
envlist = lint, unit, static, coverage-report | ||
|
||
[vars] | ||
src_path = {toxinidir}/src/ | ||
tst_path = {toxinidir}/tests/ | ||
;lib_path = {toxinidir}/lib/charms/operator_name_with_underscores | ||
all_path = {[vars]src_path} {[vars]tst_path} | ||
|
||
[testenv] | ||
setenv = | ||
PYTHONPATH = {toxinidir}:{toxinidir}/lib:{[vars]src_path} | ||
PYTHONBREAKPOINT=ipdb.set_trace | ||
PY_COLORS=1 | ||
passenv = | ||
PYTHONPATH | ||
CHARM_BUILD_DIR | ||
MODEL_SETTINGS | ||
|
||
[testenv:format] | ||
description = Apply coding style standards to code | ||
deps = | ||
black | ||
isort | ||
commands = | ||
isort {[vars]all_path} | ||
black {[vars]all_path} | ||
|
||
[testenv:lint] | ||
description = Check code against coding style standards | ||
deps = | ||
black | ||
codespell | ||
flake8<6.0.0 | ||
flake8-builtins | ||
flake8-copyright<6.0.0 | ||
flake8-docstrings>=1.6.0 | ||
flake8-docstrings-complete>=1.0.3 | ||
flake8-test-docs>=1.0 | ||
mypy | ||
pep8-naming | ||
pydocstyle>=2.10 | ||
pylint | ||
pyproject-flake8<6.0.0 | ||
pytest | ||
pytest-asyncio | ||
pytest-operator | ||
requests | ||
types-PyYAML | ||
types-requests | ||
-r{toxinidir}/requirements.txt | ||
commands = | ||
pydocstyle {[vars]src_path} | ||
# uncomment the following line if this charm owns a lib | ||
# codespell {[vars]lib_path} | ||
codespell {toxinidir} --skip {toxinidir}/.git --skip {toxinidir}/.tox \ | ||
--skip {toxinidir}/build --skip {toxinidir}/lib --skip {toxinidir}/venv \ | ||
--skip {toxinidir}/.mypy_cache --skip {toxinidir}/icon.svg | ||
# pflake8 wrapper supports config from pyproject.toml | ||
pflake8 {[vars]all_path} --ignore=W503 | ||
isort --check-only --diff {[vars]all_path} | ||
black --check --diff {[vars]all_path} | ||
mypy {[vars]all_path} | ||
pylint {[vars]all_path} | ||
|
||
[testenv:unit] | ||
description = Run unit tests | ||
deps = | ||
coverage[toml] | ||
pytest | ||
-r{toxinidir}/requirements.txt | ||
commands = | ||
coverage run --source={[vars]src_path} \ | ||
-m pytest --ignore={[vars]tst_path}integration -v --tb native -s {posargs} | ||
coverage report | ||
|
||
[testenv:coverage-report] | ||
description = Create test coverage report | ||
deps = | ||
coverage[toml] | ||
pytest | ||
-r{toxinidir}/requirements.txt | ||
commands = | ||
coverage report | ||
|
||
[testenv:static] | ||
description = Run static analysis tests | ||
deps = | ||
bandit[toml] | ||
-r{toxinidir}/requirements.txt | ||
commands = | ||
bandit -c {toxinidir}/pyproject.toml -r {[vars]src_path} {[vars]tst_path} | ||
|
||
[testenv:integration] | ||
description = Run integration tests | ||
deps = | ||
juju | ||
pytest | ||
pytest-asyncio | ||
pytest-operator | ||
-r{toxinidir}/requirements.txt | ||
commands = | ||
pytest -v --tb native --ignore={[vars]tst_path}unit --log-cli-level=INFO -s {posargs} | ||
|
||
[testenv:src-docs] | ||
allowlist_externals=sh | ||
setenv = | ||
PYTHONPATH = {toxinidir}:{toxinidir}/lib:{[vars]src_path} | ||
description = Generate documentation for src | ||
deps = | ||
lazydocs | ||
-r{toxinidir}/requirements.txt | ||
commands = | ||
; can't run lazydocs directly due to needing to run it on src/* which produces an invocation error in tox | ||
sh generate-src-docs.sh |
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,13 @@ | ||
# Copyright 2023 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
# This file configures Charmcraft. | ||
# See https://juju.is/docs/sdk/charmcraft-config for guidance. | ||
|
||
type: charm | ||
bases: | ||
- build-on: | ||
- name: ubuntu | ||
channel: "22.04" | ||
run-on: | ||
- name: ubuntu | ||
channel: "22.04" |
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
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 >= 2.2.0 |
File renamed without changes.
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,2 @@ | ||
# Copyright 2023 Canonical Ltd. | ||
# See LICENSE file for licensing details. |
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 |
---|---|---|
|
@@ -10,7 +10,6 @@ | |
import ops | ||
import ops.testing | ||
import pytest | ||
|
||
from charm import K8sCharm | ||
|
||
|
||
|
Oops, something went wrong.