From 8769713dab8edb626288fd63008f5386d84574f3 Mon Sep 17 00:00:00 2001 From: Javier de la Puente Date: Fri, 27 Sep 2024 15:23:57 +0200 Subject: [PATCH 1/7] Try 1 to improve tutorial --- docs/tutorial/getting-started.md | 129 +++++++++++++++++++++++++------ 1 file changed, 104 insertions(+), 25 deletions(-) diff --git a/docs/tutorial/getting-started.md b/docs/tutorial/getting-started.md index 8b81c7e9..fb6d1252 100644 --- a/docs/tutorial/getting-started.md +++ b/docs/tutorial/getting-started.md @@ -1,27 +1,32 @@ -# Getting Started +# Deploy the jenkins-k8s charm for the first time -## What you'll do +## What we do - Deploy the [jenkins-k8s charm](https://charmhub.io/jenkins-k8s) +- Access the UI - Deploy and integrate agents -- Get admin password The jenkins-k8s charm helps deploy a Jenkins automation server application with ease and also helps operate the charm. This -tutorial will walk you through each step of deployment to get a basic Jenkins server deployment. +tutorial will walk through each step of deployment to get a basic Jenkins server deployment. -### Prerequisites +### Requirements -To deploy jenkins-k8s charm, you will need a Juju bootstrapped with any Kubernetes controller. -To see how to bootstrap your Juju installation with MicroK8s, please refer to the documentation -on MicroK8s [installation](https://juju.is/docs/olm/microk8s). +- A machine with amd64 architecture. +- Juju 3 installed. +- Juju MicroK8s controller created and active named microk8s. [MetalLB addon](https://microk8s.io/docs/addon-metallb) should be enabled for traefik-k8s to work. +- LXD controller created and active named lxd (optional). +- All the requirements can be met using the [Multipass charm-dev blueprint](https://juju.is/docs/juju/set-up--tear-down-your-test-environment#heading--set-up---tear-down-automatically). Use the Multipass VM shell to run all commands in this tutorial. + +For more information about how to install Juju, see [Get started with Juju](https://juju.is/docs/olm/get-started-with-juju). ### Set up the tutorial model To easily clean up the resources and to separate your workload from the contents of this tutorial, -set up a new Juju model with the following command. +set up a new Juju model in the microk8s controller with the following command. ``` +juju switch microk8s juju add-model jenkins-tutorial ``` @@ -31,34 +36,59 @@ Start off by deploying the jenkins-k8s charm. By default it will deploy the late of the jenkins-k8s charm. ``` -# Deploy an edge version of the charm until stable version is released. juju deploy jenkins-k8s --channel=latest/edge ``` +Wait for it to be active: +``` +juju wait-for application jenkins-k8s +``` + The Jenkins application can only have a single server unit. Adding more units through `--num-units` parameter will cause the application to misbehave. -### Deploy and integrate agents -By default, jenkins-k8s server application is installed with 0 executors for security purposes. -A functional Jenkins application requires additional Jenkins agents to be integrated. +### Expose jenkins-k8s through ingress -The following commands deploy 3 units of the jenkins-agent-k8s charm and integrate them with the -jenkins-k8s charm. +Deploy traefik-k8s charm and integrate it with the jenkins-k8s charm: +``` +juju deploy traefik-k8s --channel=latest/edge --trust +juju integrate jenkins-k8s:ingress traefik-k8s +``` +You can check the state with: +``` +juju status --relations ``` -juju deploy jenkins-agent-k8s --channel=latest/edge --num-units=3 -# 'agent' relation name is required since jenkins-k8s charm provides multiple compatible -# interfaces with jenkins-agent-k8s charm. -juju relate jenkins-k8s:agent jenkins-agent-k8s:agent + +After a few minutes, you can get the url to connect to. +``` +juju run traefik-k8s/0 show-proxied-endpoints --format=yaml +``` + +The output will be something similar to: ``` +Running operation 1 with 1 task + - task 2 on unit-traefik-k8s-0 -### Get admin credentials +Waiting for task 2... +traefik-k8s/0: + id: "2" + results: + proxied-endpoints: '{"traefik-k8s": {"url": "http://10.12.97.102"}, "jenkins-k8s": + {"url": "http://10.12.97.102/jenkins-tutorial-jenkins-k8s"}}' + return-code: 0 + status: completed + timing: + completed: 2024-09-27 15:09:36 +0200 CEST + enqueued: 2024-09-27 15:09:35 +0200 CEST + started: 2024-09-27 15:09:35 +0200 CEST + unit: traefik-k8s/0 +``` -You can access the Jenkins server application UI by accessing the IP of a jenkins-k8s unit. To -start managing Jenkins server as an administrator, you need to get the password for the admin -account. +In this case, the url to use in your browser will be `http://10.12.97.102/jenkins-tutorial-jenkins-k8s`. In +your case it will probably be a different IP address. By running the `get-admin-password` action on a jenkins-k8s unit, juju will read and fetch the admin credentials setup for you. You can use the following command below. @@ -82,14 +112,63 @@ unit-jenkins-k8s-0: started: ``` -You can now access your Jenkins server UI at `http://:8080` and login using username -"admin" and password from the action above. +You can now access your Jenkins server UI at the previous url, and login using username "admin" and password from the action above. + +### Deploy and integrate k8s agents + +By default, jenkins-k8s server application is installed with 0 executors for security purposes. +A functional Jenkins application requires additional Jenkins agents to be integrated. + +The following commands deploy 3 units of the jenkins-agent-k8s charm and integrate them with the +jenkins-k8s charm. + +``` +juju deploy jenkins-agent-k8s --channel=latest/edge --num-units=3 + +# 'agent' relation name is required since jenkins-k8s charm provides multiple compatible +# interfaces with jenkins-agent-k8s charm. +juju integrate jenkins-k8s:agent jenkins-agent-k8s:agent +``` + +### Deploy and integrate machine agents (optional) + +For this section you need a machine model named `lxd`. + +The first requirement is to create the offer, so the jenkins-k8s agent endpoint is available +for cross-model integrations. + +``` +juju offer jenkins-k8s:agent +``` + +Once the offer is created, we can create the new model, deploy the machine jenkins-agent charm +and integrate it with jenkins-k8s with: +``` +juju add-model --controller=lxd jenkins-tutorial +juju deploy --model lxd:jenkins-tutorial jenkins-agent --channel=latest/edge +juju integrate --model lxd:jenkins-tutorial jenkins-agent:agent microk8s:admin/jenkins-tutorial.jenkins-k8s +``` + +You can check the status of the lxd model with: +``` +juju status --model lxd:jenkins-tutorial --relations +``` + +After a few minutes you should be able to see the jenkins agent machine model as a new build executor +in the Jenkins UI. + ### Cleaning up the environment Congratulations! You have successfully finished the jennkins-k8s tutorial. You can now remove the model environment that you’ve created using the following command. + +``` +juju destroy-model lxd:jenkins-tutorial --destroy-storage +``` + ``` juju destroy-model jenkins-tutorial --destroy-storage ``` + From 7d81fe28991a78882b04f0d01862d6eced2b76ab Mon Sep 17 00:00:00 2001 From: Javier de la Puente Date: Mon, 30 Sep 2024 09:54:33 +0200 Subject: [PATCH 2/7] add extra pylint exception --- tests/unit/test_jenkins.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_jenkins.py b/tests/unit/test_jenkins.py index 357f9adc..39d0d87b 100644 --- a/tests/unit/test_jenkins.py +++ b/tests/unit/test_jenkins.py @@ -1480,7 +1480,7 @@ def test_remove_unlisted_plugins_restart_error( # pylint: disable=too-many-argu ], ) # all arguments below are required -def test_remove_unlisted_plugins( # pylint: disable=too-many-arguments +def test_remove_unlisted_plugins( # pylint: disable=too-many-arguments,too-many-positional-arguments mock_client: MagicMock, container: ops.Container, desired_plugins: tuple[str], From efdb8906404a9d512bc3f8734612dd3c84e52e60 Mon Sep 17 00:00:00 2001 From: Javier de la Puente Date: Mon, 30 Sep 2024 10:36:01 +0200 Subject: [PATCH 3/7] Fixes to the tutorial --- docs/tutorial/getting-started.md | 76 +++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/docs/tutorial/getting-started.md b/docs/tutorial/getting-started.md index fb6d1252..91924179 100644 --- a/docs/tutorial/getting-started.md +++ b/docs/tutorial/getting-started.md @@ -1,6 +1,6 @@ # Deploy the jenkins-k8s charm for the first time -## What we do +## What you'll do - Deploy the [jenkins-k8s charm](https://charmhub.io/jenkins-k8s) - Access the UI @@ -14,8 +14,8 @@ tutorial will walk through each step of deployment to get a basic Jenkins server - A machine with amd64 architecture. - Juju 3 installed. -- Juju MicroK8s controller created and active named microk8s. [MetalLB addon](https://microk8s.io/docs/addon-metallb) should be enabled for traefik-k8s to work. -- LXD controller created and active named lxd (optional). +- Juju MicroK8s controller created and active named `microk8s`. [MetalLB addon](https://microk8s.io/docs/addon-metallb) should be enabled for traefik-k8s to work. +- LXD controller created and active named `lxd` (optional). - All the requirements can be met using the [Multipass charm-dev blueprint](https://juju.is/docs/juju/set-up--tear-down-your-test-environment#heading--set-up---tear-down-automatically). Use the Multipass VM shell to run all commands in this tutorial. For more information about how to install Juju, see [Get started with Juju](https://juju.is/docs/olm/get-started-with-juju). @@ -23,7 +23,7 @@ For more information about how to install Juju, see [Get started with Juju](http ### Set up the tutorial model To easily clean up the resources and to separate your workload from the contents of this tutorial, -set up a new Juju model in the microk8s controller with the following command. +set up a new Juju model in the `microk8s` controller with the following command. ``` juju switch microk8s @@ -39,7 +39,7 @@ of the jenkins-k8s charm. juju deploy jenkins-k8s --channel=latest/edge ``` -Wait for it to be active: +Wait for the charm to be active: ``` juju wait-for application jenkins-k8s ``` @@ -56,13 +56,15 @@ juju deploy traefik-k8s --channel=latest/edge --trust juju integrate jenkins-k8s:ingress traefik-k8s ``` -You can check the state with: +You can check the status with: ``` juju status --relations ``` +After a few minutes, the deployment will be finished and all the units should be in +the active status. -After a few minutes, you can get the url to connect to. +Run the following command to get the URL to connect to Jenkins: ``` juju run traefik-k8s/0 show-proxied-endpoints --format=yaml ``` @@ -87,10 +89,10 @@ traefik-k8s/0: unit: traefik-k8s/0 ``` -In this case, the url to use in your browser will be `http://10.12.97.102/jenkins-tutorial-jenkins-k8s`. In +In this case, the URL to use in your browser will be `http://10.12.97.102/jenkins-tutorial-jenkins-k8s`. In your case it will probably be a different IP address. -By running the `get-admin-password` action on a jenkins-k8s unit, juju will read and fetch the +By running the `get-admin-password` action on the jenkins-k8s unit, Juju will read and fetch the admin credentials setup for you. You can use the following command below. ``` @@ -100,19 +102,16 @@ juju run jenkins-k8s/0 get-admin-password The output should look something similar to the contents below: ``` -unit-jenkins-k8s-0: - UnitId: jenkins-k8s/0 - id: "2" - results: - password: - status: completed - timing: - completed: - enqueued: - started: +Running operation 3 with 1 task + - task 4 on unit-jenkins-k8s-0 + +Waiting for task 4... +password: e67a44447d37423887e278bc8c694f95 ``` -You can now access your Jenkins server UI at the previous url, and login using username "admin" and password from the action above. +You can now access your Jenkins server UI at the previous URL, and login using username "admin" and password from the action above. + +You may need to wait for up to five minutes for the URL to work correctly. ### Deploy and integrate k8s agents @@ -130,9 +129,42 @@ juju deploy jenkins-agent-k8s --channel=latest/edge --num-units=3 juju integrate jenkins-k8s:agent jenkins-agent-k8s:agent ``` +You can check the status with: +``` +juju status --relations +``` + +After the units are active, the output to the previous command should be similar to: +``` +Model Controller Cloud/Region Version SLA Timestamp +jenkins-tutorial microk8s microk8s/localhost 3.5.3 unsupported 10:27:59+02:00 + +App Version Status Scale Charm Channel Rev Address Exposed Message +jenkins-agent-k8s active 3 jenkins-agent-k8s latest/edge 27 10.152.183.108 no +jenkins-k8s 2.462.2 active 1 jenkins-k8s latest/edge 125 10.152.183.178 no +traefik-k8s 2.11.0 active 1 traefik-k8s latest/edge 211 10.152.183.40 no Serving at 10.12.97.102 + +Unit Workload Agent Address Ports Message +jenkins-agent-k8s/0 active idle 10.1.32.148 +jenkins-agent-k8s/1 active idle 10.1.32.153 +jenkins-agent-k8s/2* active idle 10.1.32.152 +jenkins-k8s/0* active idle 10.1.32.132 +traefik-k8s/0* active idle 10.1.32.147 Serving at 10.12.97.102 + +Integration provider Requirer Interface Type Message +jenkins-agent-k8s:agent jenkins-k8s:agent jenkins_agent_v0 regular +traefik-k8s:ingress jenkins-k8s:ingress ingress regular +traefik-k8s:peers traefik-k8s:peers traefik_peers peer +``` + +After a few minutes you should be able to see the jenkins agent K8s model as a new build executor +in the Jenkins UI. + + ### Deploy and integrate machine agents (optional) -For this section you need a machine model named `lxd`. +For this section you need a machine model named `lxd`. If you are using the Multipass, the `charm-dev` blueprint +will automatically set up the machine model for you. The first requirement is to create the offer, so the jenkins-k8s agent endpoint is available for cross-model integrations. @@ -161,7 +193,7 @@ in the Jenkins UI. ### Cleaning up the environment Congratulations! You have successfully finished the jennkins-k8s tutorial. You can now remove the -model environment that you’ve created using the following command. +model environments that you’ve created using the following commands. ``` From 7da31bd149519194092e89110b09c86d889e3da4 Mon Sep 17 00:00:00 2001 From: Javier de la Puente Date: Mon, 30 Sep 2024 17:57:48 +0200 Subject: [PATCH 4/7] Fix integration tests --- CONTRIBUTING.md | 5 ++--- tests/integration/test_plugins.py | 7 ++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e9234d03..5d7adf9e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,14 +5,13 @@ Build the OCI image: ```bash cd jenkins_rock rockcraft pack +cd .. ``` Push the OCI image to microk8s: ```bash -sudo /snap/rockcraft/current/bin/skopeo --insecure-policy copy oci-archive:jenkins_rock/Jenkins_1.0_amd64.rock docker-daemon:jenkins:1.0 -sudo docker tag jenkins:1.0 localhost:32000/jenkins:1.0 -sudo docker push localhost:32000/jenkins:1.0 +rockcraft.skopeo --insecure-policy copy --dest-tls-verify=false oci-archive:jenkins_rock/jenkins_1.0_amd64.rock docker://localhost:32000/jenkins:1.0 ``` Deploy the charm: diff --git a/tests/integration/test_plugins.py b/tests/integration/test_plugins.py index cf1cef8d..fc83c2cb 100644 --- a/tests/integration/test_plugins.py +++ b/tests/integration/test_plugins.py @@ -540,7 +540,12 @@ async def test_openid_connect_plugin( "clientId": keycloak_oidc_meta.client_id, "clientSecret": keycloak_oidc_meta.client_secret, "automanualconfigure": "auto", - "wellKnownOpenIDConfigurationUrl": keycloak_oidc_meta.well_known_endpoint, + "serverConfiguration":{ + "wellKnownOpenIDConfigurationUrl": keycloak_oidc_meta.well_known_endpoint, + "scopesOverride":"", + "stapler-class":"org.jenkinsci.plugins.oic.OicServerWellKnownConfiguration", + "$class":"org.jenkinsci.plugins.oic.OicServerWellKnownConfiguration" + }, "userNameField": "sub", "stapler-class": "org.jenkinsci.plugins.oic.OicSecurityRealm", "$class": "org.jenkinsci.plugins.oic.OicSecurityRealm", From b90efe11c7271eb6ed6acf1fd6ed9aa455062824 Mon Sep 17 00:00:00 2001 From: Javier de la Puente Date: Mon, 30 Sep 2024 18:02:21 +0200 Subject: [PATCH 5/7] fix formatting --- tests/integration/test_plugins.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_plugins.py b/tests/integration/test_plugins.py index fc83c2cb..3dc1d2ec 100644 --- a/tests/integration/test_plugins.py +++ b/tests/integration/test_plugins.py @@ -540,11 +540,11 @@ async def test_openid_connect_plugin( "clientId": keycloak_oidc_meta.client_id, "clientSecret": keycloak_oidc_meta.client_secret, "automanualconfigure": "auto", - "serverConfiguration":{ + "serverConfiguration": { "wellKnownOpenIDConfigurationUrl": keycloak_oidc_meta.well_known_endpoint, - "scopesOverride":"", - "stapler-class":"org.jenkinsci.plugins.oic.OicServerWellKnownConfiguration", - "$class":"org.jenkinsci.plugins.oic.OicServerWellKnownConfiguration" + "scopesOverride": "", + "stapler-class": "org.jenkinsci.plugins.oic.OicServerWellKnownConfiguration", + "$class": "org.jenkinsci.plugins.oic.OicServerWellKnownConfiguration", }, "userNameField": "sub", "stapler-class": "org.jenkinsci.plugins.oic.OicSecurityRealm", From a5ac302258acbc1df7060c4da1a2aeabff176cb5 Mon Sep 17 00:00:00 2001 From: Javier de la Puente Date: Tue, 1 Oct 2024 15:02:50 +0200 Subject: [PATCH 6/7] Combine the juju destroy model commands --- docs/tutorial/getting-started.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/tutorial/getting-started.md b/docs/tutorial/getting-started.md index 91924179..da1064a6 100644 --- a/docs/tutorial/getting-started.md +++ b/docs/tutorial/getting-started.md @@ -196,11 +196,8 @@ Congratulations! You have successfully finished the jennkins-k8s tutorial. You c model environments that you’ve created using the following commands. -``` -juju destroy-model lxd:jenkins-tutorial --destroy-storage -``` - ``` juju destroy-model jenkins-tutorial --destroy-storage +juju destroy-model lxd:jenkins-tutorial --destroy-storage ``` From c5c03a4788c7988156803cd97a491d4e37a25ab3 Mon Sep 17 00:00:00 2001 From: Javier de la Puente Date: Tue, 1 Oct 2024 15:03:35 +0200 Subject: [PATCH 7/7] remove extra space --- docs/tutorial/getting-started.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/tutorial/getting-started.md b/docs/tutorial/getting-started.md index da1064a6..96765940 100644 --- a/docs/tutorial/getting-started.md +++ b/docs/tutorial/getting-started.md @@ -200,4 +200,3 @@ model environments that you’ve created using the following commands. juju destroy-model jenkins-tutorial --destroy-storage juju destroy-model lxd:jenkins-tutorial --destroy-storage ``` -