generated from canonical/is-charms-template-repo
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare GH workflow actions for new charm (#2)
* Retitle inclusive Naming check action * remove inclusive-name tests as its included with unit-tests * don't require a self-hosted runner * Simplify charm and tests to easily pass * Conform to required linters * Run integration tests on lxd for the time being * simplify charm and testing * disable zap tests * Create k8s and k8s-worker charms * bake in a default .licenserc.yaml * split matrix call into separate workflow calls with unique workflow names * ensure each charm gets a publish and auto-update-libs job * Address review comments
- Loading branch information
Showing
33 changed files
with
915 additions
and
301 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,12 @@ | ||
name: Auto-update K8s-worker charm libraries | ||
|
||
on: | ||
schedule: | ||
- cron: "0 1 * * *" | ||
|
||
jobs: | ||
auto-update-libs: | ||
uses: canonical/operator-workflows/.github/workflows/auto_update_charm_libs.yaml@main | ||
secrets: inherit | ||
with: | ||
working-directory: ./charms/k8s-worker/ |
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 was deleted.
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
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 @@ | ||
name: Publish K8s-worker to edge | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
publish-to-edge: | ||
uses: canonical/operator-workflows/.github/workflows/publish_charm.yaml@main | ||
secrets: inherit | ||
with: | ||
channel: latest/edge | ||
working-directory: ./charms/k8s-worker/ |
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,12 @@ | ||
name: Tests K8s Worker | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
unit-tests: | ||
uses: canonical/operator-workflows/.github/workflows/test.yaml@main | ||
secrets: inherit | ||
with: | ||
self-hosted-runner: false | ||
working-directory: ./charms/k8s-worker/ |
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,47 @@ | ||
header: | ||
- license: | ||
copyright-owner: Canonical Ltd. | ||
content: | | ||
Copyright [year] [owner] | ||
Licensed under the Apache2.0. See LICENSE file in charm source for details. | ||
paths: | ||
- 'lib/**' | ||
comment: on-failure | ||
- license: | ||
spdx-id: Apache-2.0 | ||
copyright-owner: Canonical Ltd. | ||
content: | | ||
Copyright [year] [owner] | ||
See LICENSE file for licensing details. | ||
paths: | ||
- '**' | ||
paths-ignore: | ||
- '.github/**' | ||
- '**/.gitkeep' | ||
- '**/*.cfg' | ||
- '**/*.conf' | ||
- '**/*.ini' | ||
- '**/*.j2' | ||
- '**/*.json' | ||
- '**/*.md' | ||
- '**/*.rule' | ||
- '**/*.tmpl' | ||
- '**/*.txt' | ||
- '**/*.xml' | ||
- '.codespellignore' | ||
- '.dockerignore' | ||
- '.flake8' | ||
- '.jujuignore' | ||
- '.gitignore' | ||
- '.licenserc.yaml' | ||
- '.trivyignore' | ||
- '.woke.yaml' | ||
- '.woke.yml' | ||
- 'CODEOWNERS' | ||
- 'icon.svg' | ||
- 'LICENSE' | ||
- 'pyproject.toml' | ||
- 'trivy.yaml' | ||
- 'zap_rules.tsv' | ||
- 'lib/**' | ||
comment: on-failure |
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 |
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,73 @@ | ||
[tool.bandit] | ||
exclude_dirs = ["/venv/"] | ||
[tool.bandit.assert_used] | ||
skips = ["*/*test.py", "*/test_*.py", "*tests/*.py"] | ||
|
||
# Testing tools configuration | ||
[tool.coverage.run] | ||
branch = true | ||
|
||
# Formatting tools configuration | ||
[tool.black] | ||
line-length = 99 | ||
target-version = ["py38"] | ||
|
||
[tool.coverage.report] | ||
show_missing = true | ||
|
||
# Linting tools configuration | ||
[tool.flake8] | ||
max-line-length = 99 | ||
max-doc-length = 99 | ||
max-complexity = 10 | ||
exclude = [".git", "__pycache__", ".tox", "build", "dist", "*.egg_info", "venv"] | ||
select = ["E", "W", "F", "C", "N", "R", "D", "H"] | ||
# Ignore W503, E501 because using black creates errors with this | ||
# Ignore D107 Missing docstring in __init__ | ||
ignore = ["W503", "E501", "D107"] | ||
# D100, D101, D102, D103: Ignore missing docstrings in tests | ||
per-file-ignores = ["tests/*:D100,D101,D102,D103,D104,D205,D212,D415"] | ||
docstring-convention = "google" | ||
|
||
[tool.isort] | ||
line_length = 99 | ||
profile = "black" | ||
|
||
[tool.mypy] | ||
ignore_missing_imports = true | ||
explicit_package_bases = true | ||
namespace_packages = true | ||
|
||
[tool.pylint] | ||
disable = "wrong-import-order,redefined-outer-name" | ||
|
||
[tool.pytest.ini_options] | ||
minversion = "6.0" | ||
log_cli_level = "INFO" | ||
|
||
# Linting tools configuration | ||
[tool.ruff] | ||
line-length = 99 | ||
select = ["E", "W", "F", "C", "N", "D", "I001"] | ||
extend-ignore = [ | ||
"D203", | ||
"D204", | ||
"D213", | ||
"D215", | ||
"D400", | ||
"D404", | ||
"D406", | ||
"D407", | ||
"D408", | ||
"D409", | ||
"D413", | ||
] | ||
ignore = ["E501", "D107"] | ||
extend-exclude = ["__pycache__", "*.egg_info"] | ||
per-file-ignores = {"tests/*" = ["D100","D101","D102","D103","D104"]} | ||
|
||
[tool.ruff.mccabe] | ||
max-complexity = 10 | ||
|
||
[tool.codespell] | ||
skip = "build,lib,venv,icon.svg,.tox,.git,.mypy_cache,.ruff_cache,.coverage" |
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,49 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright 2023 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
# Learn more at: https://juju.is/docs/sdk | ||
|
||
"""K8s-worker Charm. | ||
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. | ||
""" | ||
|
||
|
||
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,33 @@ | ||
# 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") |
Oops, something went wrong.