Skip to content

Commit

Permalink
chore: remove jenkins auto-update (#60)
Browse files Browse the repository at this point in the history
* chore: remove jenkins auto-update

* chore: cleanup code

* fix: unused imports

---------

Co-authored-by: arturo-seijas <[email protected]>
  • Loading branch information
yanksyoon and arturo-seijas authored Nov 16, 2023
1 parent 86fb692 commit f95506c
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 1,117 deletions.
3 changes: 1 addition & 2 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ options:
description: >
Preferred UTC time range in 24 hour format for restarting Jenkins. If empty, restart will
take place whenever Jenkins needs to restart. Jenkins will need to restart on the following
occasions. 1. Patched Jenkins version within the same LTS is available. 2. Plugins that are
not part of `plugins` configuration option are detected.
occasion. Plugins that are not part of `allowed-plugins` configuration option are detected.
For example, 03-05 will allow Jenkins restart to take place from 3AM UTC to 5AM UTC.
Awaits for running job completion for 5 minutes.
default: ""
Expand Down
2 changes: 1 addition & 1 deletion src-docs/charm.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Charm Jenkins.
## <kbd>class</kbd> `JenkinsK8sOperatorCharm`
Charm Jenkins.

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

### <kbd>function</kbd> `__init__`

Expand Down
114 changes: 11 additions & 103 deletions src-docs/jenkins.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Functions to operate Jenkins.

---

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

## <kbd>function</kbd> `wait_ready`

Expand All @@ -53,7 +53,7 @@ Wait until Jenkins service is up.

---

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

## <kbd>function</kbd> `get_admin_credentials`

Expand All @@ -77,7 +77,7 @@ Retrieve admin credentials.

---

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

## <kbd>function</kbd> `calculate_env`

Expand All @@ -95,7 +95,7 @@ Return a dictionary for Jenkins Pebble layer.

---

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

## <kbd>function</kbd> `get_version`

Expand All @@ -119,7 +119,7 @@ Get the Jenkins server version.

---

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

## <kbd>function</kbd> `bootstrap`

Expand All @@ -145,7 +145,7 @@ Initialize and install Jenkins.

---

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

## <kbd>function</kbd> `get_node_secret`

Expand Down Expand Up @@ -176,7 +176,7 @@ Get node secret from jenkins.

---

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

## <kbd>function</kbd> `add_agent_node`

Expand All @@ -202,7 +202,7 @@ Add a Jenkins agent node.

---

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

## <kbd>function</kbd> `remove_agent_node`

Expand All @@ -228,99 +228,7 @@ Remove a Jenkins agent node.

---

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

## <kbd>function</kbd> `get_updatable_version`

```python
get_updatable_version(proxy: ProxyConfig | None = None) → str | None
```

Get version to update to if available.



**Args:**

- <b>`proxy`</b>: Proxy server to route the requests through.



**Raises:**

- <b>`JenkinsUpdateError`</b>: if there was an error trying to determine next Jenkins update version.



**Returns:**
Patched version string if the update is available. None if latest version is applied.


---

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

## <kbd>function</kbd> `has_updates_for_lts`

```python
has_updates_for_lts(proxy: ProxyConfig | None = None) → bool
```

Return whether the Jenkins has a patched LTS update available.



**Args:**

- <b>`proxy`</b>: Proxy server to route the requests through.



**Raises:**

- <b>`JenkinsUpdateError`</b>: If there was an error fetching the Jenkins version information.



**Returns:**
True if an update within the same LTS is available. False otherwise.


---

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

## <kbd>function</kbd> `update_jenkins`

```python
update_jenkins(container: Container, proxy: ProxyConfig | None = None) → str
```

Update Jenkins and return the updated version.



**Args:**

- <b>`container`</b>: The Jenkins workload container.
- <b>`proxy`</b>: The proxy settings to apply.



**Raises:**

- <b>`JenkinsUpdateError`</b>: If there was an error updating Jenkins.
- <b>`JenkinsRestartError`</b>: If there was an error restarting updated Jenkins.



**Returns:**
The updated Jenkins version.


---

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

## <kbd>function</kbd> `safe_restart`

Expand All @@ -345,7 +253,7 @@ Safely restart Jenkins server after all jobs are done executing.

---

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

## <kbd>function</kbd> `get_agent_name`

Expand All @@ -369,7 +277,7 @@ Infer agent name from unit name.

---

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

## <kbd>function</kbd> `remove_unlisted_plugins`

Expand Down
46 changes: 1 addition & 45 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import cos
import ingress
import jenkins
import status
import timerange
from state import CharmConfigInvalidError, CharmRelationDataInvalidError, State

Expand Down Expand Up @@ -169,44 +168,6 @@ def _remove_unlisted_plugins(self, container: ops.Container) -> ops.StatusBase:
return ops.BlockedStatus("Failed to restart Jenkins after removing plugins")
return ops.ActiveStatus()

def _update_jenkins_version(self, container: ops.Container) -> ops.StatusBase:
"""Update Jenkins patch version if available.
The update will only take place if the current time is within the restart-time-range config
value.
Args:
container: The Jenkins workload container.
Returns:
The unit status of the charm after the operation.
"""
original_status = self.unit.status.name
self.unit.status = ops.StatusBase.from_name(original_status, "Checking for updates.")
try:
if not jenkins.has_updates_for_lts():
return ops.StatusBase.from_name(original_status, "")
except jenkins.JenkinsUpdateError as exc:
logger.error("Failed to get Jenkins updates, %s", exc)
return ops.StatusBase.from_name(
original_status, "Failed to get Jenkins patch version."
)

self.unit.status = ops.MaintenanceStatus("Updating Jenkins.")
try:
updated_version = jenkins.update_jenkins(
container=container, proxy=self.state.proxy_config
)
except jenkins.JenkinsUpdateError as exc:
logger.error("Failed to fetch required Jenkins update data, %s", exc)
return ops.StatusBase.from_name(original_status, "Failed to get update data.")
except jenkins.JenkinsRestartError as exc:
logger.error("Failed to safely restart Jenkins. %s", exc)
return ops.BlockedStatus("Update restart failed.")

self.unit.set_workload_version(updated_version)
return ops.ActiveStatus()

def _on_update_status(self, _: ops.UpdateStatusEvent) -> None:
"""Handle update status event.
Expand All @@ -223,12 +184,7 @@ def _on_update_status(self, _: ops.UpdateStatusEvent) -> None:
):
return

self.unit.status = status.get_priority_status(
(
self._update_jenkins_version(container=container),
self._remove_unlisted_plugins(container=container),
)
)
self.unit.status = self._remove_unlisted_plugins(container=container)


if __name__ == "__main__": # pragma: nocover
Expand Down
Loading

0 comments on commit f95506c

Please sign in to comment.