====== Downstream CI (RDU3)====== ===== Overview ===== The RDU3 Jenkins deployment is the new Jenkins environment running in the RDU3 OpenShift cluster. Located in RedHat RDU3 lab Jenkins URL: https://jenkins.apps.prod-scale-spoke1-dc-rdu3.itup.redhat.com OpenShift cluster: prod-scale-spoke1-dc-rdu3.itup.redhat.com OpenShift Console: https://console-openshift-console.apps.prod-scale-spoke1-dc-rdu3.itup.redhat.com Production OpenShift project: ceph-downstream-tenant--pipeline ===== Architecture ===== The Jenkins environment consists of: * Jenkins controller running in OpenShift * OpenShift Virtualization (KubeVirt/CNV) VMs used as Jenkins build agents * RHEL 9 builder VMs * On-demand Jenkins agent provisioning * Jenkins agents connect back to the controller using WebSocket Unlike a traditional Kubernetes Jenkins deployment, builds are not executed inside Kubernetes pods. Dedicated KubeVirt VMs are created on demand and used as Jenkins agents. This provides Jenkins jobs with a full RHEL virtual machine while still allowing the builders to be dynamically created and removed as required. ===== Jenkins Configuration Repository ===== The Jenkins configuration is maintained in the following Git repository: git@gitlab.cee.redhat.com:ccit/jenkins-csb-customers/storage-casc-ceph-downstream.git During the RDU3 migration, the new Jenkins instance is using the following branch: rdu3-migration This is a temporary migration branch used for the RDU3 Jenkins configuration while the existing Jenkins environment is still in use. Changes specific to the new RDU3 Jenkins deployment should currently be made against the ''rdu3-migration'' branch. Once the migration to the RDU3 Jenkins instance is complete, the temporary migration branch can be retired and the normal production configuration workflow can be used. ===== Job Definitions ===== Jobs are Jenkins Job Builder YAML in: https://gitlab.cee.redhat.com/ceph/rhcs-jenkins-jobs * Definition: ''/config/definitions/.yaml'' * Build script: ''/build/build'' To change a job: - Branch from ''master'', edit, open an MR. - Merge. The ''jenkins-job-builder'' job runs on every push to ''master'' and updates all jobs. To test a branch before merging: - Run ''jenkins-job-builder'' with ''GITLAB_BRANCH='' and ''JOB_NAME=''. - Only that job is updated. It stays on the branch version until the next ''master'' run. Do not edit jobs in the Jenkins UI. The next ''master'' run overwrites them. ===== Jenkins Access ===== Login is Red Hat SSO. Permissions are roles in ''casc.yaml'' in the [[https://gitlab.cee.redhat.com/ccit/jenkins-csb-customers/storage-casc-ceph-downstream/-/blob/main/casc.yaml#L675|configuration repository]], under ''jenkins.authorizationStrategy''. Roles: ''admin'', ''admin_read'', ''ceph-dev-qe-config'', ''schedule_build'', ''readonly''. To give someone access: - Add ''%%- user: ""%%'' under the role's ''entries''. Use ''%%- group: ""%%'' for an SSO group. - Open an MR to ''main''. Merge. - Restart the Jenkins pod to load it (repository README). Notes: * " is missing the Overall/Read permission" means the user is in no role. * Roles assigned in the Jenkins UI are lost at the next restart. ===== Jenkins Agents ===== The Jenkins build agents are RHEL 9 virtual machines running through OpenShift Virtualization. Builders/OCP VM's subnet is 10.5.225.0/24 Example agent types include: * rhel9medium * rhel9large These builders are not expected to be permanently running Jenkins nodes. They are provisioned on demand when Jenkins needs capacity to execute a job. Each VM is configured as a Jenkins agent and connects back to: https://jenkins.apps.prod-scale-spoke1-dc-rdu3.itup.redhat.com The Jenkins agent uses WebSocket connectivity rather than the traditional JNLP TCP agent port. ===== On-Demand Builder Lifecycle ===== The RDU3 Jenkins builders are dynamically created using OpenShift Virtualization. Instead of maintaining a large pool of permanently running builder VMs, Jenkins creates builders when jobs require them and removes the builders when they are no longer needed. The lifecycle of a builder is: - A Jenkins job is submitted and requests a particular builder type/label. - Jenkins checks whether an appropriate agent is already available. - If no suitable agent is available, Jenkins requests a new builder. - A new KubeVirt VirtualMachine is created in the OpenShift tenant. - OpenShift Virtualization starts the VM and creates the corresponding VirtualMachineInstance (VMI). - The RHEL 9 VM boots. - The VM is provisioned with the required Jenkins agent configuration. - The Jenkins agent connects back to the Jenkins controller using WebSocket. - Jenkins detects the new agent and marks it online. - The queued Jenkins job is assigned to the new builder. - The job runs inside the VM. - After the builder is no longer required, Jenkins removes the agent. - The associated KubeVirt VM is destroyed, releasing the CPU and memory resources back to the OpenShift tenant. This makes the builders effectively disposable. A builder exists only for the period in which Jenkins requires the capacity. A later job can cause a new clean VM to be created instead of depending on the state left behind by an older build. ==== Builder Creation ==== When Jenkins determines that additional capacity is required, it requests a new builder based on the configuration for the requested node type. For example, a job requiring a ''rhel9large'' builder causes Jenkins to request a VM matching the rhel9large configuration. OpenShift Virtualization then creates the VM and allocates the configured resources, including: * CPU * Memory * Storage * Network interfaces The VM boots from the configured RHEL 9 image. As part of provisioning, the VM is configured with the Jenkins agent information required to connect back to the controller. ==== Jenkins Agent Registration ==== Inside the VM, the Jenkins agent is started using ''agent.jar''. An example of the agent command is: java -jar /home/jenkins-build/agent.jar \ -url https://jenkins.apps.prod-scale-spoke1-dc-rdu3.itup.redhat.com \ -secret @/etc/jenkins-agent/secret \ -name \ -webSocket \ -workDir /home/jenkins-build The important part of the RDU3 configuration is: -webSocket The agent establishes an outbound WebSocket connection to the Jenkins controller over HTTPS. Once the connection is established, Jenkins marks the node online and can schedule the waiting job onto it. ==== Running the Build ==== Once the builder is online, Jenkins assigns the queued job to the VM. From the Jenkins job's perspective, the VM behaves like a regular Jenkins node. The build has access to the RHEL environment and any tools installed as part of the builder provisioning process. ==== Builder Destruction ==== The builders are disposable and are not intended to remain running indefinitely after their work has completed. After Jenkins determines that the dynamically created agent is no longer required, the agent is removed and the associated KubeVirt VM is deleted. Deleting the VM also releases the compute resources that were allocated to it. This is particularly important in RDU3 because the OpenShift tenants have resource limits. Dynamically removing unused builders prevents idle Jenkins nodes from continuously consuming the tenant's CPU and memory allocation. ===== Jenkins / KubeVirt Integration ===== The Jenkins integration uses customized logic for managing the KubeVirt builder nodes. The Sorter Jenkins plugin contains Java customizations used as part of the KubeVirt Jenkins agent implementation. The integration allows Jenkins to dynamically request KubeVirt builder VMs when jobs require additional capacity and remove those VMs when they are no longer needed. ==== KubeVirt Builder Flow ==== The following diagram shows the lifecycle of an on-demand Jenkins builder: +-----------------------+ | Jenkins Job | | enters the queue | +-----------+-----------+ | v +-----------------------+ | Jenkins Controller | | | | Builder capacity | | required | +-----------+-----------+ | v +-----------------------+ | Sorter / KubeVirt | | Integration | +-----------+-----------+ | | Create VM v +------------------------------------------------+ | OpenShift RDU3 | | | | ceph-downstream-tenant--pipeline | | | | +-----------------------------+ | | | OpenShift Virtualization | | | | / KubeVirt | | | +-------------+---------------+ | | | | | | Start VM | | v | | +-----------------------------+ | | | RHEL 9 Builder VM | | | | | | | | rhel9medium / rhel9large | | | +-------------+---------------+ | | | | +---------------------|--------------------------+ | | WebSocket / HTTPS v +-----------------------+ | Jenkins Controller | | | | Agent becomes online | +-----------+-----------+ | v +-----------------------+ | Job Runs | | on the Builder VM | +-----------+-----------+ | v +-----------------------+ | Job Completes | +-----------+-----------+ | v +-----------------------+ | Jenkins removes the | | dynamic agent | +-----------+-----------+ | | Delete VM v +-----------------------+ | KubeVirt VM Destroyed | | | | CPU / Memory released | +-----------------------+ The important point is that the builder VM is temporary: Job queued | v VM created | v VM boots | v Agent connects to Jenkins | v Job runs | v Job finishes | v Agent removed | v VM destroyed ===== Networking ===== Outbound traffic from the RDU3 tenant is restricted. When Jenkins or its builder VMs require access to a new external destination, that destination must be allowed by the tenant egress configuration. The tenant uses egress rules to control which external networks and services workloads are allowed to reach. ==== Adding a New Outbound Destination ==== For example, if Jenkins builders need to reach a service at: 192.0.2.50 on TCP port 22, an EgressFirewall rule can be added: apiVersion: network.openshift.io/v1 kind: EgressFirewall metadata: name: default namespace: ceph-downstream-tenant--pipeline spec: egress: - type: Allow to: cidrSelector: 192.0.2.50/32 ports: - protocol: TCP port: 22 For an HTTPS service: - type: Allow to: cidrSelector: 192.0.2.50/32 ports: - protocol: TCP port: 443 The destination should be restricted as much as possible. Prefer allowing the specific destination IP/network and required port instead of opening broad outbound access. Before adding a new external dependency, identify: * Destination hostname/IP * Destination network/CIDR * Protocol * Required port The appropriate egress rule can then be added to the tenant configuration. After the rule is applied, connectivity can be verified from a Jenkins builder VM. ===== OpenShift Access ===== The RDU3 environment provides four tenants for our use. Each tenant has limited CPU, memory, and other resources, so workloads should be placed in the appropriate tenant. The two primary tenants used by Jenkins are: * ''ceph-downstream-tenant--pipeline'' - Production Jenkins workloads. * ''ceph-downstream-tenant--runtime-int'' - Staging and testing environment. The ''ceph-downstream-tenant--pipeline'' tenant hosts the production Jenkins environment and production builder workloads. The ''ceph-downstream-tenant--runtime-int'' tenant should be used for testing changes before they are introduced into production. Examples include: * Testing new Jenkins plugins * Testing plugin upgrades * Testing Jenkins configuration changes * Testing builder changes * Testing Jenkins controller changes * Validating other infrastructure changes Changes should first be validated in ''ceph-downstream-tenant--runtime-int'' before being applied to ''ceph-downstream-tenant--pipeline''. ===== Accessing Running Jenkins Builders (RDU3) ===== Jenkins builders run as KubeVirt Virtual Machines (VMs) in the RDU3 OpenShift cluster. Developers can access running builders via SSH using ''virtctl port-forward''. ==== 1. List running builders ==== Log in to the RDU3 OpenShift cluster and select the Jenkins tenant namespace. oc project ceph-downstream-tenant--pipeline oc get vmi Example output: NAME AGE PHASE IP NODENAME READY rhel8medium-rdu3-c36e1a98 8h Running 172.17.44.37 worker07.itup-003.prod.rdu3.dc.redhat.com True rhel9large-rdu3-8f20a52c 5h38m Running 172.19.12.11 worker26.itup-003.prod.rdu3.dc.redhat.com True Identify the running builder you want to access. ==== 2. Forward the builder's SSH port ==== Open a terminal and run: virtctl port-forward \ vmi/rhel8medium-rdu3-c36e1a98 \ 2222:22 This forwards local TCP port ''2222'' to SSH port ''22'' on the selected VM. **Keep this terminal running** while connected to the builder. ==== 3. Connect to the builder via SSH ==== Open a second terminal and run: ssh -i jenkins-build.id \ -o IdentitiesOnly=yes \ -p 2222 \ jenkins-build@127.0.0.1 Replace ''jenkins-build.id'' with the path to your authorized SSH private key. ==== Notes ==== * You must be logged in to the RDU3 OpenShift cluster and have the required namespace permissions. * VM names are dynamic. Always use ''oc get vmi'' to find the current running builder. * Production builders may be in ''ceph-downstream-tenant--pipeline''. Select the namespace containing your target VM. * SSH access requires an authorized private key for the ''jenkins-build'' user. * Do not modify or interrupt active Jenkins builds. * Stop the port-forward process using ''Ctrl+C'' when finished. ===== Debugging Failed Builds and Builders ===== ==== A build fails ==== - Open the build console. Read the first ''ERROR''. - Bare ''java.lang.NullPointerException'' with no stack trace: open the first failed build after the last green one. It has the trace. - List the recent builds. Note the time the failure started or changed. - Match that time against commits in ''rhcs-jenkins-jobs'' and ''storage-casc-ceph-downstream''. - Open ''/job//config.xml'' and compare it with ''master''. The job may be running a test branch (see Job Definitions). Known signatures: * ''NullPointerException'' in ''SecretBuildWrapper.buildEnvVars'': a credential binding in the job has no ''variable''. * ''Permission denied (publickey)'' from GitHub: the credential is named in the ''[ssh-agent] Using credentials'' line. Check the key is still on the GitHub account at ''https://github.com/.keys''. ==== A build waits for a builder ==== - Manage Jenkins -> Nodes. Open the log of any offline agent. - List the builder VMs and their disks. - Read the namespace events. - DataVolume in ''ErrExceededQuota'': the storage quota is full. No new builder starts until a running one finishes. Check the quota. - Read the controller log. It holds about 30 minutes. oc -n ceph-downstream-tenant--pipeline get vm,vmi,dv,pvc oc -n ceph-downstream-tenant--pipeline get events --sort-by=.lastTimestamp | tail -40 oc -n ceph-downstream-tenant--pipeline get appliedclusterresourcequota -o yaml oc -n ceph-downstream-tenant--pipeline logs deploy/ceph-downstream-jenkins | grep -iE 'kubevirt|Timed out waiting' ===== Managing Jenkins Secrets with git-crypt ===== Jenkins secrets are stored encrypted in the ''storage-casc-ceph-downstream'' repository using ''git-crypt''. Never commit a secret in plaintext. ==== Updating an existing secret ==== Create a new branch from ''main'': git switch main git pull --ff-only git switch -c update-jenkins-secret Verify that git-crypt is unlocked and that the secret is configured for encryption: git-crypt status git check-attr filter diff -- secrets/ceph-jenkins-api-token Update the secret without putting its value in the shell history: read -s SECRET_VALUE echo printf '%s' "$SECRET_VALUE" > secrets/ceph-jenkins-api-token unset SECRET_VALUE Verify the file is still managed by git-crypt: git check-attr filter diff -- secrets/ceph-jenkins-api-token git-crypt status Stage and review the change: git add secrets/ceph-jenkins-api-token git status git diff --cached --stat Commit and push the feature branch: git commit -m "Update Jenkins API token" git push -u origin update-jenkins-secret Create an MR to ''main'' after verifying that no plaintext secret was committed. ==== Adding a new secret ==== Create the new secret under ''secrets/'': read -s SECRET_VALUE echo printf '%s' "$SECRET_VALUE" > secrets/<secret-name> unset SECRET_VALUE Make sure the new file is covered by the git-crypt rules in ''secrets/.gitattributes''. Verify encryption before committing: git check-attr filter diff -- secrets/<secret-name> git-crypt status Then stage ''secrets/.gitattributes'' if it was changed, along with the new secret: git add secrets/.gitattributes secrets/<secret-name> git status git diff --cached --stat Commit and push the feature branch, then create an MR to ''main''. Never paste secret values into Git commit messages, merge requests, Slack, tickets, or command-line arguments. Always verify that git-crypt recognizes a new secret before pushing it. ===== Related Components ===== * OpenShift * OpenShift Virtualization / KubeVirt * RHEL 9 builder VMs * Jenkins Sorter plugin * RDU3 TenantEgress / EgressFirewall * Managing Jenkins Secrets git-crypt