Skip to content

Commit

Permalink
Merge 4141229 into b937a40
Browse files Browse the repository at this point in the history
  • Loading branch information
cbartz authored Sep 20, 2024
2 parents b937a40 + 4141229 commit af018b6
Show file tree
Hide file tree
Showing 16 changed files with 187 additions and 202 deletions.
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

### 2024-09-18

- Changed code to be able to spawn a runner in reactive mode.
- Removed reactive mode support for LXD as it is not currently in development.

## 2024-09-09

- Added changelog for tracking user-relevant changes.
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ cosl ==0.0.15
# juju 3.1.2.0 depends on pyyaml<=6.0 and >=5.1.2
PyYAML ==6.0.*
pyOpenSSL==24.2.1
kombu==5.4.1
pymongo==4.8.0
github_runner_manager @ git+https://github.com/canonical/github-runner-manager.git@6ee40e296f92f191dd12b1e24a613dfdbdc70f99
github_runner_manager @ git+https://github.com/canonical/github-runner-manager.git@e53ed35048e124e3046b860bc0b8c7d89abd8b18
10 changes: 5 additions & 5 deletions src-docs/charm.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Charm for creating and managing GitHub self-hosted runner instances.

---

<a href="../src/charm.py#L117"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/charm.py#L120"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `catch_charm_errors`

Expand All @@ -47,7 +47,7 @@ Catch common errors in charm.

---

<a href="../src/charm.py#L158"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/charm.py#L161"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `catch_action_errors`

Expand All @@ -73,7 +73,7 @@ Catch common errors in actions.

---

<a href="../src/charm.py#L110"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/charm.py#L113"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `ReconcileRunnersEvent`
Event representing a periodic check to ensure runners are ok.
Expand All @@ -84,7 +84,7 @@ Event representing a periodic check to ensure runners are ok.

---

<a href="../src/charm.py#L196"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/charm.py#L199"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `GithubRunnerCharm`
Charm for managing GitHub self-hosted runners.
Expand All @@ -101,7 +101,7 @@ Charm for managing GitHub self-hosted runners.
- <b>`ram_pool_path`</b>: The path to memdisk storage.
- <b>`kernel_module_path`</b>: The path to kernel modules.

<a href="../src/charm.py#L219"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/charm.py#L222"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `__init__`

Expand Down
22 changes: 11 additions & 11 deletions src-docs/runner_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Runner Manager manages the runners on LXD and GitHub.

---

<a href="../src/runner_manager.py#L64"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/runner_manager.py#L63"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `LXDRunnerManager`
Manage a group of runners according to configuration.
Expand All @@ -25,7 +25,7 @@ Manage a group of runners according to configuration.
- <b>`runner_bin_path`</b>: The github runner app scripts path.
- <b>`cron_path`</b>: The path to runner build image cron job.

<a href="../src/runner_manager.py#L75"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/runner_manager.py#L74"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `__init__`

Expand All @@ -52,7 +52,7 @@ Construct RunnerManager object for creating and managing runners.

---

<a href="../.tox/src-docs/lib/python3.10/site-packages/github_runner_manager/utilities.py#L816"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../.tox/src-docs/lib/python3.10/site-packages/github_runner_manager/utilities.py#L797"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `build_runner_image`

Expand All @@ -72,7 +72,7 @@ Build container image in test mode, else virtual machine image.

---

<a href="../src/runner_manager.py#L117"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/runner_manager.py#L116"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `check_runner_bin`

Expand All @@ -89,7 +89,7 @@ Check if runner binary exists.

---

<a href="../src/runner_manager.py#L627"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/runner_manager.py#L608"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `flush`

Expand Down Expand Up @@ -118,7 +118,7 @@ Remove existing runners.

---

<a href="../src/runner_manager.py#L218"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/runner_manager.py#L217"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `get_github_info`

Expand All @@ -135,7 +135,7 @@ Get information on the runners from GitHub.

---

<a href="../.tox/src-docs/lib/python3.10/site-packages/github_runner_manager/utilities.py#L125"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../.tox/src-docs/lib/python3.10/site-packages/github_runner_manager/utilities.py#L124"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `get_latest_runner_bin_url`

Expand Down Expand Up @@ -166,7 +166,7 @@ The runner binary URL changes when a new version is available.

---

<a href="../src/runner_manager.py#L808"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/runner_manager.py#L789"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `has_runner_image`

Expand All @@ -183,7 +183,7 @@ Check if the runner image exists.

---

<a href="../src/runner_manager.py#L527"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/runner_manager.py#L526"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `reconcile`

Expand All @@ -207,7 +207,7 @@ Bring runners in line with target.

---

<a href="../src/runner_manager.py#L831"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/runner_manager.py#L812"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `schedule_build_runner_image`

Expand All @@ -219,7 +219,7 @@ Install cron job for building runner image.

---

<a href="../.tox/src-docs/lib/python3.10/site-packages/github_runner_manager/utilities.py#L148"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../.tox/src-docs/lib/python3.10/site-packages/github_runner_manager/utilities.py#L147"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `update_runner_bin`

Expand Down
55 changes: 4 additions & 51 deletions src-docs/runner_manager_type.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Types used by RunnerManager class.

---

<a href="../src/runner_manager_type.py#L20"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/runner_manager_type.py#L19"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `LXDFlushMode`
Strategy for flushing runners.
Expand All @@ -32,7 +32,7 @@ During pre-job (repo-check), the runners are marked as idle and if the pre-job f

---

<a href="../src/runner_manager_type.py#L45"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/runner_manager_type.py#L44"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `RunnerManagerClients`
Clients for accessing various services.
Expand Down Expand Up @@ -69,7 +69,7 @@ __init__(

---

<a href="../src/runner_manager_type.py#L62"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/runner_manager_type.py#L61"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `LXDRunnerManagerConfig`
Configuration of runner manager.
Expand Down Expand Up @@ -121,54 +121,7 @@ Whether metrics for the runners should be collected.

---

<a href="../src/runner_manager_type.py#L97"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `OpenstackRunnerManagerConfig`
Configuration of runner manager.



**Attributes:**

- <b>`charm_state`</b>: The state of the charm.
- <b>`path`</b>: GitHub repository path in the format '<owner>/<repo>', or the GitHub organization name.
- <b>`labels`</b>: Additional labels for the runners.
- <b>`token`</b>: GitHub personal access token to register runner to the repository or organization.
- <b>`flavor`</b>: OpenStack flavor for defining the runner resources.
- <b>`image`</b>: Openstack image id to boot the runner with.
- <b>`network`</b>: OpenStack network for runner network access.
- <b>`dockerhub_mirror`</b>: URL of dockerhub mirror to use.
- <b>`reactive_config`</b>: The configuration to spawn runners reactively.

<a href="../<string>"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `__init__`

```python
__init__(
charm_state: CharmState,
path: GitHubOrg | GitHubRepo,
labels: Iterable[str],
token: str,
flavor: str,
image: str,
network: str,
dockerhub_mirror: str | None,
reactive_config: ReactiveConfig | None = None
) → None
```









---

<a href="../src/runner_manager_type.py#L126"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/runner_manager_type.py#L95"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `RunnerInfo`
Information from GitHub of a runner.
Expand Down
61 changes: 47 additions & 14 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
from github_runner_manager.openstack_cloud.openstack_runner_manager import (
OpenStackCloudConfig,
OpenStackRunnerManager,
OpenStackRunnerManagerConfig,
OpenStackServerConfig,
)
from github_runner_manager.reactive.types_ import QueueConfig as ReactiveQueueConfig
from github_runner_manager.reactive.types_ import RunnerConfig as ReactiveRunnerConfig
from github_runner_manager.types_.github import GitHubPath, GitHubRunnerStatus, parse_github_path

from utilities import bytes_with_unit_to_kib, execute_command, remove_residual_venv_dirs, retry
Expand Down Expand Up @@ -1263,6 +1266,46 @@ def _get_runner_scaler(
if path is None:
path = state.charm_config.path

openstack_runner_manager_config = self._create_openstack_runner_manager_config(path, state)
openstack_runner_manager = OpenStackRunnerManager(
config=openstack_runner_manager_config,
)
runner_manager_config = RunnerManagerConfig(
name=self.app.name,
token=token,
path=path,
)
runner_manager = RunnerManager(
cloud_runner_manager=openstack_runner_manager,
config=runner_manager_config,
)
reactive_runner_config = None
if reactive_config := state.reactive_config:
reactive_runner_config = ReactiveRunnerConfig(
queue=ReactiveQueueConfig(
mongodb_uri=reactive_config.mq_uri, queue_name=self.app.name
),
runner_manager=runner_manager_config,
cloud_runner_manager=openstack_runner_manager_config,
github_token=token,
)
return RunnerScaler(
runner_manager=runner_manager, reactive_runner_config=reactive_runner_config
)

def _create_openstack_runner_manager_config(
self, path: GitHubPath, state: CharmState
) -> OpenStackRunnerManagerConfig:
"""Create OpenStackRunnerManagerConfig instance.
Args:
path: GitHub repository path in the format '<org>/<repo>', or the GitHub organization
name.
state: Charm state.
Returns:
An instance of OpenStackRunnerManagerConfig.
"""
clouds = list(state.charm_config.openstack_clouds_yaml["clouds"].keys())
if len(clouds) > 1:
logger.warning(
Expand All @@ -1283,7 +1326,6 @@ def _get_runner_scaler(
)
if image.tags:
image_labels += image.tags

runner_config = GitHubRunnerConfig(
github_path=path, labels=(*state.charm_config.labels, *image_labels)
)
Expand All @@ -1293,25 +1335,16 @@ def _get_runner_scaler(
ssh_debug_connections=state.ssh_debug_connections,
repo_policy_compliance=state.charm_config.repo_policy_compliance,
)
# The prefix is set to f"{application_name}-{unit number}"
openstack_runner_manager = OpenStackRunnerManager(
manager_name=self.app.name,
openstack_runner_manager_config = OpenStackRunnerManagerConfig(
name=self.app.name,
# The prefix is set to f"{application_name}-{unit number}"
prefix=self.unit.name.replace("/", "-"),
cloud_config=cloud_config,
server_config=server_config,
runner_config=runner_config,
service_config=service_config,
)
runner_manager_config = RunnerManagerConfig(
token=token,
path=path,
)
runner_manager = RunnerManager(
manager_name=self.app.name,
cloud_runner_manager=openstack_runner_manager,
config=runner_manager_config,
)
return RunnerScaler(runner_manager=runner_manager, reactive_config=state.reactive_config)
return openstack_runner_manager_config


if __name__ == "__main__":
Expand Down
9 changes: 9 additions & 0 deletions src/charm_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
from firewall import FirewallEntry
from utilities import get_env_var

REACTIVE_MODE_NOT_SUPPORTED_WITH_LXD_ERR_MSG = (
"Reactive mode not supported for local LXD instances. "
"Please remove the mongodb integration."
)

logger = logging.getLogger(__name__)

ARCHITECTURES_ARM64 = {"aarch64", "arm64"}
Expand Down Expand Up @@ -1196,6 +1201,10 @@ def from_charm( # noqa: C901

reactive_config = ReactiveConfig.from_database(database)

if instance_type == InstanceType.LOCAL_LXD and reactive_config:
logger.error(REACTIVE_MODE_NOT_SUPPORTED_WITH_LXD_ERR_MSG)
raise CharmConfigInvalidError(REACTIVE_MODE_NOT_SUPPORTED_WITH_LXD_ERR_MSG)

state = cls(
arch=arch,
is_metrics_logging_available=bool(charm.model.relations[COS_AGENT_INTEGRATION_NAME]),
Expand Down
Loading

0 comments on commit af018b6

Please sign in to comment.