Skip to content

Commit

Permalink
feat: proxy config (#18)
Browse files Browse the repository at this point in the history
* feat: proxy config

* feat: use model proxy

* test: proxy integration tests

* debug

* fix: patch environ

* chore: patch charm to integration tests

* feat: add kube config

* fix: run withoht sudo

* fix: pre-runscript

* fix: pre-runscript sudo

* chore: proxy config refactor

* chore: refactor proxy dict

* fix: jenkins client to refresh every function

* fix: github runner proxy

* chore: helper functions

* chore: yield individual lines

* chore: trailing lines

* chore: change env variables

* chore: add jenkins cve

* test: test model proxy settings

* test: confusing proxy variables
  • Loading branch information
yanksyoon committed Jul 28, 2023
1 parent 0357cb5 commit 320633c
Show file tree
Hide file tree
Showing 15 changed files with 783 additions and 59 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/integration_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ jobs:
uses: canonical/operator-workflows/.github/workflows/integration_test.yaml@main
secrets: inherit
with:
pre-run-script: tests/integration/pre_run_script.sh
pre-run-script: |
-c "sudo microk8s config > ${GITHUB_WORKSPACE}/kube-config
chmod +x tests/integration/pre_run_script.sh
./tests/integration/pre_run_script.sh"
extra-arguments: |
--kube-config ${GITHUB_WORKSPACE}/kube-config
1 change: 1 addition & 0 deletions .trivyignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CVE-2023-27900
CVE-2023-27901
CVE-2023-35141
CVE-2023-2976
CVE-2023-39151
# Jenkins plugin manager CVEs
CVE-2022-45688
CVE-2023-20862
Expand Down
44 changes: 30 additions & 14 deletions src-docs/jenkins.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Functions to operate Jenkins.

---

<a href="../src/jenkins.py#L126"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/jenkins.py#L131"><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 @@ -46,7 +46,7 @@ Wait until Jenkins service is up.

---

<a href="../src/jenkins.py#L155"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/jenkins.py#L160"><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 @@ -70,7 +70,7 @@ Retrieve admin credentials.

---

<a href="../src/jenkins.py#L181"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/jenkins.py#L186"><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 @@ -88,7 +88,7 @@ Return a dictionary for Jenkins Pebble layer.

---

<a href="../src/jenkins.py#L192"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/jenkins.py#L197"><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 @@ -112,12 +112,12 @@ Get the Jenkins server version.

---

<a href="../src/jenkins.py#L284"><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`

```python
bootstrap(container: Container) → None
bootstrap(container: Container, proxy_config: ProxyConfig | None = None) → None
```

Initialize and install Jenkins.
Expand All @@ -127,6 +127,7 @@ Initialize and install Jenkins.
**Args:**

- <b>`container`</b>: The Jenkins workload container.
- <b>`proxy_config`</b>: The Jenkins proxy configuration settings.



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

---

<a href="../src/jenkins.py#L320"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/jenkins.py#L409"><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 @@ -173,7 +174,7 @@ Get node secret from jenkins.

---

<a href="../src/jenkins.py#L348"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/jenkins.py#L437"><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 Down Expand Up @@ -204,7 +205,7 @@ Add a Jenkins agent node.

---

<a href="../src/jenkins.py#L378"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/jenkins.py#L467"><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 Down Expand Up @@ -235,18 +236,24 @@ Remove a Jenkins agent node.

---

<a href="../src/jenkins.py#L484"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/jenkins.py#L581"><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() → str | None
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.
Expand All @@ -259,7 +266,7 @@ Get version to update to if available.

---

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

## <kbd>function</kbd> `download_stable_war`

Expand All @@ -285,7 +292,7 @@ Download and replace the war executable.

---

<a href="../src/jenkins.py#L570"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/jenkins.py#L670"><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 @@ -311,7 +318,7 @@ Safely restart Jenkins server after all jobs are done executing.

---

<a href="../src/jenkins.py#L598"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/jenkins.py#L698"><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 Down Expand Up @@ -401,6 +408,15 @@ An error occurred installing Jenkins plugin.



---

## <kbd>class</kbd> `JenkinsProxyError`
An error occurred configuring Jenkins proxy.





---

## <kbd>class</kbd> `JenkinsUpdateError`
Expand Down
47 changes: 41 additions & 6 deletions src-docs/state.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Metadata for registering Jenkins Agent.

---

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

### <kbd>classmethod</kbd> `from_agent_relation`

Expand All @@ -54,7 +54,7 @@ Instantiate AgentMeta from charm relation databag.

---

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

### <kbd>classmethod</kbd> `from_deprecated_agent_relation`

Expand All @@ -79,7 +79,7 @@ Instantiate AgentMeta from charm relation databag.

---

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

### <kbd>classmethod</kbd> `numeric_executors`

Expand Down Expand Up @@ -112,7 +112,7 @@ Exception raised when a charm configuration is found to be invalid.

- <b>`msg`</b>: Explanation of the error.

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

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

Expand Down Expand Up @@ -143,7 +143,7 @@ Represents an error with invalid data in relation data.

- <b>`msg`</b>: Explanation of the error.

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

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

Expand Down Expand Up @@ -172,6 +172,40 @@ Represents an error with charm state.



---

## <kbd>class</kbd> `ProxyConfig`
Configuration for accessing Jenkins through proxy.



**Attributes:**

- <b>`http_proxy`</b>: The http proxy URL.
- <b>`https_proxy`</b>: The https proxy URL.
- <b>`no_proxy`</b>: Comma separated list of hostnames to bypass proxy.




---

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

### <kbd>classmethod</kbd> `from_env`

```python
from_env() → Optional[ForwardRef('ProxyConfig')]
```

Instantiate ProxyConfig from juju charm environment.



**Returns:**
ProxyConfig if proxy configuration is provided, None otherwise.


---

## <kbd>class</kbd> `State`
Expand All @@ -184,14 +218,15 @@ The Jenkins k8s operator charm state.
- <b>`update_time_range`</b>: Time range to allow Jenkins to update version.
- <b>`agent_relation_meta`</b>: Metadata of all agents from units related through agent relation.
- <b>`deprecated_agent_relation_meta`</b>: Metadata of all agents from units related through deprecated agent relation.
- <b>`proxy_config`</b>: Proxy configuration to access Jenkins upstream through.
- <b>`jenkins_service_name`</b>: The Jenkins service name. Note that the container name is the same.




---

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

### <kbd>classmethod</kbd> `from_charm`

Expand Down
4 changes: 2 additions & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _on_jenkins_pebble_ready(self, event: PebbleReadyEvent) -> None:
try:
jenkins.wait_ready()
self.unit.status = MaintenanceStatus("Configuring Jenkins.")
jenkins.bootstrap(container)
jenkins.bootstrap(container, self.state.proxy_config)
# Second Jenkins server start restarts Jenkins to bypass Wizard setup.
container.restart(self.state.jenkins_service_name)
jenkins.wait_ready()
Expand Down Expand Up @@ -162,7 +162,7 @@ def _on_update_status(self, _: UpdateStatusEvent) -> None:

self.unit.status = ActiveStatus("Checking for updates.")
try:
latest_patch_version = jenkins.get_updatable_version()
latest_patch_version = jenkins.get_updatable_version(proxy=self.state.proxy_config)
except jenkins.JenkinsUpdateError as exc:
logger.error("Failed to get Jenkins updates, %s", exc)
self.unit.status = ActiveStatus("Failed to get Jenkins patch version.")
Expand Down
Loading

0 comments on commit 320633c

Please sign in to comment.