|
| 1 | +# fdp_update_container_images |
| 2 | + |
| 3 | +Ansible role to update specific RPM packages in OpenStack container images by rebuilding them with custom repositories. |
| 4 | + |
| 5 | +This role automates the process of: |
| 6 | +1. Fetching container images from OpenStackVersion CR |
| 7 | +2. Checking if target package exists in each image |
| 8 | +3. Building new images with updated packages from custom repository |
| 9 | +4. Pushing updated images to OpenShift internal registry |
| 10 | +5. Patching OpenStackVersion CR to use the new images |
| 11 | + |
| 12 | +## Privilege escalation |
| 13 | +None - Runs as the user executing Ansible |
| 14 | + |
| 15 | +## Parameters |
| 16 | + |
| 17 | +* `cifmw_fdp_update_container_images_basedir`: (String) Base directory. Defaults to `cifmw_basedir` which defaults to `~/ci-framework-data`. |
| 18 | +* `cifmw_fdp_update_container_images_namespace`: (String) OpenShift namespace where OpenStack is deployed. Defaults to `openstack`. |
| 19 | +* `cifmw_fdp_update_container_images_openstack_cr_name`: (String) Name of the OpenStackVersion CR. Defaults to `controlplane`. |
| 20 | +* `cifmw_fdp_update_container_images_target_package`: (String) Name of the RPM package to update (e.g., `ovn24.03`). **Required**. |
| 21 | +* `cifmw_fdp_update_container_images_repo_name`: (String) Repository name. Defaults to `custom-repo`. |
| 22 | +* `cifmw_fdp_update_container_images_repo_baseurl`: (String) Repository base URL. **Required**. |
| 23 | +* `cifmw_fdp_update_container_images_repo_enabled`: (Integer) Enable repository (0 or 1). Defaults to `1`. |
| 24 | +* `cifmw_fdp_update_container_images_repo_gpgcheck`: (Integer) Enable GPG check (0 or 1). Defaults to `0`. |
| 25 | +* `cifmw_fdp_update_container_images_repo_priority`: (Integer) Repository priority. Defaults to `0`. |
| 26 | +* `cifmw_fdp_update_container_images_repo_sslverify`: (Integer) Enable SSL verification (0 or 1). Defaults to `0`. |
| 27 | +* `cifmw_fdp_update_container_images_image_registry`: (String) External OpenShift image registry URL. Auto-detected from cluster if not specified. Leave empty for auto-detection. |
| 28 | +* `cifmw_fdp_update_container_images_image_registry_internal`: (String) Internal OpenShift image registry URL. Defaults to `image-registry.openshift-image-registry.svc:5000`. |
| 29 | +* `cifmw_fdp_update_container_images_image_name_prefix`: (String) Prefix for new image names. Defaults to `fdp-update`. |
| 30 | +* `cifmw_fdp_update_container_images_update_control_plane_images`: (Boolean) Update control plane container images. Defaults to `true`. |
| 31 | +* `cifmw_fdp_update_container_images_temp_dir`: (String) Temporary directory for build context. Auto-generated if not specified. |
| 32 | +* `cifmw_fdp_update_container_images_update_dnf_args`: (String) Additional arguments for dnf update command. Defaults to `--disablerepo='*' --enablerepo={{ cifmw_fdp_update_container_images_repo_name }}`. |
| 33 | + |
| 34 | +## Examples |
| 35 | + |
| 36 | +### Update OVN package in all containers |
| 37 | +```yaml |
| 38 | +--- |
| 39 | +- hosts: localhost |
| 40 | + vars: |
| 41 | + cifmw_fdp_update_container_images_target_package: "ovn24.03" |
| 42 | + cifmw_fdp_update_container_images_repo_name: "custom-repo" |
| 43 | + cifmw_fdp_update_container_images_repo_baseurl: "http://example.com/custom-repo/" |
| 44 | + cifmw_fdp_update_container_images_namespace: "openstack" |
| 45 | + roles: |
| 46 | + - role: "fdp_update_container_images" |
| 47 | +``` |
| 48 | +
|
| 49 | +### Update with custom registry and image prefix |
| 50 | +```yaml |
| 51 | +--- |
| 52 | +- hosts: localhost |
| 53 | + vars: |
| 54 | + cifmw_fdp_update_container_images_target_package: "ovn24.03" |
| 55 | + cifmw_fdp_update_container_images_repo_baseurl: "http://custom-repo.example.com/repo/" |
| 56 | + cifmw_fdp_update_container_images_image_registry: "registry.example.com" |
| 57 | + cifmw_fdp_update_container_images_image_name_prefix: "ovn-hotfix" |
| 58 | + roles: |
| 59 | + - role: "fdp_update_container_images" |
| 60 | +``` |
| 61 | +
|
| 62 | +### Update with specific DNF arguments |
| 63 | +```yaml |
| 64 | +--- |
| 65 | +- hosts: localhost |
| 66 | + vars: |
| 67 | + cifmw_fdp_update_container_images_target_package: "neutron-ovn-metadata-agent" |
| 68 | + cifmw_fdp_update_container_images_repo_baseurl: "http://custom-repo.example.com/repo/" |
| 69 | + cifmw_fdp_update_container_images_update_dnf_args: "--disablerepo='*' --enablerepo={{ cifmw_fdp_update_container_images_repo_name }} --nobest" |
| 70 | + roles: |
| 71 | + - role: "fdp_update_container_images" |
| 72 | +``` |
| 73 | +
|
| 74 | +## How it works |
| 75 | +
|
| 76 | +1. **Registry Setup**: |
| 77 | + - Enables the default route for OpenShift image registry |
| 78 | + - Auto-detects the registry hostname or uses the configured value |
| 79 | +2. **Authentication**: Obtains a token from OpenShift and authenticates with the internal registry using TLS |
| 80 | +3. **Image Discovery**: Queries the OpenStackVersion CR for all container images |
| 81 | +4. **Package Check**: For each image, creates a temporary container to check if the target package is installed |
| 82 | +5. **Image Build**: If the package exists, builds a new image with the updated package from the custom repository |
| 83 | +6. **Registry Push**: Pushes the new image to the OpenShift internal registry |
| 84 | +7. **CR Update**: Patches the OpenStackVersion CR's `spec.customContainerImages` field with the new image reference |
| 85 | +8. **Summary**: Provides a summary of all updated images |
| 86 | + |
| 87 | +## Requirements |
| 88 | + |
| 89 | +* OpenShift CLI (`oc`) must be available |
| 90 | +* Podman must be installed and accessible |
| 91 | +* User must have permissions to: |
| 92 | + - Create tokens in the target namespace |
| 93 | + - Get and patch OpenStackVersion CRs |
| 94 | + - Push images to the internal registry |
| 95 | + - Patch image registry configuration (`configs.imageregistry.operator.openshift.io/cluster`) |
| 96 | + |
| 97 | +## Notes |
| 98 | + |
| 99 | +* The role uses podman to build and push images with TLS verification |
| 100 | +* Each updated image gets a unique tag with timestamp: `<prefix>-<image-key>-<timestamp>` |
| 101 | +* Only images containing the target package will be updated |
| 102 | +* The role cleans up temporary containers automatically |
| 103 | +* All build contexts are created in a temporary directory that is cleaned up after execution |
| 104 | +* The role automatically configures the OpenShift image registry for external access: |
| 105 | + - Enables the default route if not already enabled |
| 106 | + - Auto-detects the registry hostname from the route |
0 commit comments