|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * hardware_enablement/kmm-kernel-module-management.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | +[id="kmm-building-and-signing-a-kmod-image_{context}"] |
| 7 | += Building and signing a kmod image |
| 8 | + |
| 9 | +Use this procedure if you have source code and must build your image first. |
| 10 | + |
| 11 | +The following YAML file builds a new container image using the source code from the repository. The image produced is saved back in the registry with a temporary name, and this temporary image is then signed using the parameters in the `sign` section. |
| 12 | + |
| 13 | +The temporary image name is based on the final image name and is set to be `<containerImage>:<tag>-<namespace>_<module name>_kmm_unsigned`. |
| 14 | + |
| 15 | +For example, using the following YAML file, Kernel Module Management (KMM) builds an image named `example.org/repository/minimal-driver:final-default_example-module_kmm_unsigned` containing the build with unsigned kmods and pushes it to the registry. Then it creates a second image named `example.org/repository/minimal-driver:final` that contains the signed kmods. It is this second image that is pulled by the worker pods and contains the kmods to be loaded on the cluster nodes. |
| 16 | + |
| 17 | +After it is signed, you can safely delete the temporary image from the registry. It will be rebuilt, if needed. |
| 18 | + |
| 19 | +.Prerequisites |
| 20 | + |
| 21 | +* The `keySecret` and `certSecret` secrets have been created in the same namespace as the rest of the resources. |
| 22 | +
|
| 23 | +.Procedure |
| 24 | + |
| 25 | +* Apply the YAML file: |
| 26 | ++ |
| 27 | +[source,yaml] |
| 28 | +---- |
| 29 | +--- |
| 30 | +apiVersion: v1 |
| 31 | +kind: ConfigMap |
| 32 | +metadata: |
| 33 | + name: example-module-dockerfile |
| 34 | + namespace: <namespace> <1> |
| 35 | +data: |
| 36 | + Dockerfile: | |
| 37 | + ARG DTK_AUTO |
| 38 | + ARG KERNEL_VERSION |
| 39 | + FROM ${DTK_AUTO} as builder |
| 40 | + WORKDIR /build/ |
| 41 | + RUN git clone -b main --single-branch https://github.com/rh-ecosystem-edge/kernel-module-management.git |
| 42 | + WORKDIR kernel-module-management/ci/kmm-kmod/ |
| 43 | + RUN make |
| 44 | + FROM registry.access.redhat.com/ubi9/ubi:latest |
| 45 | + ARG KERNEL_VERSION |
| 46 | + RUN yum -y install kmod && yum clean all |
| 47 | + RUN mkdir -p /opt/lib/modules/${KERNEL_VERSION} |
| 48 | + COPY --from=builder /build/kernel-module-management/ci/kmm-kmod/*.ko /opt/lib/modules/${KERNEL_VERSION}/ |
| 49 | + RUN /usr/sbin/depmod -b /opt |
| 50 | +--- |
| 51 | +apiVersion: kmm.sigs.x-k8s.io/v1beta1 |
| 52 | +kind: Module |
| 53 | +metadata: |
| 54 | + name: example-module |
| 55 | + namespace: <namespace> <1> |
| 56 | +spec: |
| 57 | + moduleLoader: |
| 58 | + serviceAccountName: default <2> |
| 59 | + container: |
| 60 | + modprobe: |
| 61 | + moduleName: simple_kmod |
| 62 | + kernelMappings: |
| 63 | + - regexp: '^.*\.x86_64$' |
| 64 | + containerImage: <final_driver_container_name> |
| 65 | + build: |
| 66 | + dockerfileConfigMap: |
| 67 | + name: example-module-dockerfile |
| 68 | + sign: |
| 69 | + keySecret: |
| 70 | + name: <private_key_secret_name> |
| 71 | + certSecret: |
| 72 | + name: <certificate_secret_name> |
| 73 | + filesToSign: |
| 74 | + - /opt/lib/modules/4.18.0-348.2.1.el8_5.x86_64/kmm_ci_a.ko |
| 75 | + imageRepoSecret: <3> |
| 76 | + name: repo-pull-secret |
| 77 | + selector: # top-level selector |
| 78 | + kubernetes.io/arch: amd64 |
| 79 | +---- |
| 80 | +
|
| 81 | +<1> Replace `default` with a valid namespace. |
| 82 | + |
| 83 | +<2> The default `serviceAccountName` does not have the required permissions to run a module that is privileged. For information on creating a service account, see "Creating service accounts" in the "Additional resources" of this section. |
| 84 | + |
| 85 | +<3> Used as `imagePullSecrets` in the `DaemonSet` object and to pull and push for the build and sign features. |
0 commit comments