Skip to content

Commit 89236e2

Browse files
authored
Merge pull request #424 from bpradipt/embed-pause
Embed pause image
2 parents 802869b + d84a848 commit 89236e2

8 files changed

+114
-26
lines changed

config/peerpods/podvm/Dockerfile.podvm-builder

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM registry.access.redhat.com/ubi9/ubi:9.3
1+
FROM registry.access.redhat.com/ubi9/ubi:9.4
22

33
# azure-podvm-image-handler.sh script under /scripts/azure-podvm-image-handler.sh
44
# aws-podvm-image-handler.sh script under /scripts/aws-podvm-image-handler.sh
@@ -7,8 +7,8 @@ FROM registry.access.redhat.com/ubi9/ubi:9.3
77
# Binaries like kubectl, packer and yq under /usr/local/bin will be installed by the scripts
88

99

10-
LABEL kata_src=https://github.com/kata-containers/kata-containers/tree/CC-0.8.0
11-
LABEL kata_src_commit=8de1f8e19f858134ba455a7c04edcb21d8bcf6b1
10+
LABEL kata_src=https://github.com/kata-containers/kata-containers
11+
LABEL kata_src_commit=stable-3.6
1212

1313
RUN mkdir -p /scripts
1414

config/peerpods/podvm/aws-podvm-image-handler.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ function verify_vars() {
7777
[[ -z "${CONFIDENTIAL_COMPUTE_ENABLED}" ]] && error_exit "CONFIDENTIAL_COMPUTE_ENABLED is empty"
7878
[[ -z "${DISABLE_CLOUD_CONFIG}" ]] && error_exit "DISABLE_CLOUD_CONFIG is empty"
7979
[[ -z "${ENABLE_NVIDIA_GPU}" ]] && error_exit "ENABLE_NVIDIA_GPU is empty"
80-
8180
}
8281

8382
# function to download and install aws cli
@@ -287,7 +286,6 @@ function delete_ami_id_annotation_from_peer_pods_cm() {
287286
echo "Ami id annotation deleted from peer-pods-cm configmap successfully"
288287
}
289288

290-
291289
# Function to create the ami in AWS
292290

293291
function create_ami() {
@@ -317,6 +315,9 @@ function create_ami() {
317315
# Prepare the source code for building the ami
318316
prepare_source_code
319317

318+
# Prepare the pause image for embedding into the ami
319+
download_and_extract_pause_image "${PAUSE_IMAGE_REPO}" "${PAUSE_IMAGE_VERSION}" "${PAUSE_IMAGE_REPO_AUTH_FILE}"
320+
320321
# Create AWS ami using packer
321322
create_ami_using_packer
322323

config/peerpods/podvm/azure-podvm-image-handler.sh

+3
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,9 @@ function create_image() {
498498
# Prepare the source code for building the image
499499
prepare_source_code
500500

501+
# Prepare the pause image for embedding into the image
502+
download_and_extract_pause_image "${PAUSE_IMAGE_REPO}" "${PAUSE_IMAGE_VERSION}" "${PAUSE_IMAGE_REPO_AUTH_FILE}"
503+
501504
# Create Azure image using packer
502505
create_image_using_packer
503506

config/peerpods/podvm/lib.sh

+72-12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
set -x
55

6+
# Defaults for pause image
7+
# This pause image is multi-arch
8+
PAUSE_IMAGE_REPO_DEFAULT="quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256"
9+
PAUSE_IMAGE_VERSION_DEFAULT="7f3cb6f9d265291b47a7491c2ba4f4dd0752a18b661eee40584f9a5dbcbe13bb"
10+
PAUSE_IMAGE_REPO_AUTH_FILE="/tmp/regauth/auth.json"
11+
612
# function to trap errors and exit
713
function error_exit() {
814
echo "$1" 1>&2
@@ -22,6 +28,7 @@ function install_rpm_packages() {
2228
"git"
2329
"make"
2430
"unzip"
31+
"skopeo"
2532
)
2633

2734
# Create a new array to store rpm packages that are not installed
@@ -58,16 +65,19 @@ function install_rpm_packages() {
5865
# are available in the variable REQUIRED_BINARY_PACKAGES
5966
# the function will download the packages, extract them and install them in /usr/local/bin
6067
# Following are the packages that are installed:
68+
# TBD: add multi-arch support for these binaries
6169
#"packer=https://releases.hashicorp.com/packer/1.9.4/packer_1.9.4_linux_amd64.zip"
6270
#"kubectl=https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/4.14.9/openshift-client-linux.tar.gz"
6371
#"yq=https://github.com/mikefarah/yq/releases/download/v4.35.2/yq_linux_amd64.tar.gz"
72+
#"umoci=https://github.com/opencontainers/umoci/releases/download/v0.4.7/umoci.amd64"
6473

6574
install_binary_packages() {
6675
# Define the required binary packages
6776
REQUIRED_BINARY_PACKAGES=(
6877
"packer=https://releases.hashicorp.com/packer/1.9.4/packer_1.9.4_linux_amd64.zip"
6978
"kubectl=https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/4.14.9/openshift-client-linux.tar.gz"
7079
"yq=https://github.com/mikefarah/yq/releases/download/v4.35.2/yq_linux_amd64.tar.gz"
80+
"umoci=https://github.com/opencontainers/umoci/releases/download/v0.4.7/umoci.amd64"
7181
)
7282

7383
# Specify the installation directory
@@ -94,8 +104,9 @@ install_binary_packages() {
94104
tar -xf "${download_path}" -C "${install_dir}" ||
95105
error_exit "Failed to extract ${package_name}"
96106
else
97-
echo "Unsupported archive format for ${package_name}. Skipping."
98-
continue
107+
echo "Copying ${download_path} to ${install_dir}/${package_name}"
108+
cp "${download_path}" "${install_dir}/${package_name}" ||
109+
error_exit "Failed to move ${package_name} to ${install_dir}"
99110
fi
100111

101112
echo "Marking ${install_dir}/${package_name} executable"
@@ -122,20 +133,23 @@ function download_source_code() {
122133
# Download source code from GitHub
123134
# If any error occurs, exit the script with an error message
124135

125-
# Delete the source code directory if it exists
126-
[[ -d "${CAA_SRC_DIR}" ]] &&
127-
rm -rf "${CAA_SRC_DIR}"
136+
# CAA_SRC_DIR is set to CAA_SRC_DOWNLOAD_DIR/src/cloud-api-adaptor
137+
# The default value of CAA_SRC_DOWNLOAD_DIR is /src/cloud-api-adaptor
138+
139+
# Delete the source code download directory if it exists
140+
[[ -d "${CAA_SRC_DOWNLOAD_DIR}" ]] &&
141+
rm -rf "${CAA_SRC_DOWNLOAD_DIR}"
128142

129143
# Create the root directory for source code
130-
mkdir -p "${CAA_SRC_DIR}"
144+
mkdir -p "${CAA_SRC_DOWNLOAD_DIR}"
131145

132146
# Download the source code from GitHub
133-
git clone "${CAA_SRC}" "${CAA_SRC_DIR}" ||
147+
git clone "${CAA_SRC}" "${CAA_SRC_DOWNLOAD_DIR}" ||
134148
error_exit "Failed to download source code from GitHub"
135149

136150
# Checkout the required commit
137-
cd "${CAA_SRC_DIR}" ||
138-
error_exit "Failed to change directory to ${CAA_SRC_DIR}"
151+
cd "${CAA_SRC_DOWNLOAD_DIR}" ||
152+
error_exit "Failed to change directory to ${CAA_SRC_DOWNLOAD_DIR}"
139153

140154
git checkout "${CAA_REF}" ||
141155
error_exit "Failed to checkout the required commit"
@@ -156,12 +170,12 @@ function prepare_source_code() {
156170

157171
local podvm_dir="${CAA_SRC_DIR}/podvm"
158172

173+
mkdir -p "${podvm_dir}"/files
174+
159175
# Download the podvm binaries and copy it to the podvm/files directory
160176
tar xvf /payload/podvm-binaries.tar.gz -C "${podvm_dir}"/files ||
161177
error_exit "Failed to download podvm binaries"
162178

163-
mkdir -p "${podvm_dir}"/files/pause_bundle # workaround to avoid pause image requirement
164-
165179
# Set the NVIDIA_DRIVER_VERSION if variable is set
166180
if [[ "${NVIDIA_DRIVER_VERSION}" ]]; then
167181
echo "NVIDIA_DRIVER_VERSION is set to ${NVIDIA_DRIVER_VERSION}"
@@ -183,7 +197,53 @@ function prepare_source_code() {
183197
fi
184198
}
185199

200+
# Download and extract pause container image
201+
# Accepts three arguments:
202+
# 1. pause_image_repo_url: The registry URL of the OCP pause image.
203+
# 2. pause_image_tag: The tag of the OCP pause image.
204+
# 2. auth_json_file (optional): Path to the registry secret file to use for downloading the image
205+
function download_and_extract_pause_image() {
206+
207+
# Set default values for the OCP pause image
208+
pause_image_repo_url="${1:-${PAUSE_IMAGE_REPO_DEFAULT}}"
209+
pause_image_tag="${2:-${PAUSE_IMAGE_VERSION_DEFAULT}}"
210+
auth_json_file="${3:-${PAUSE_IMAGE_REPO_AUTH_FILE}}"
211+
212+
# If arguments are not provided, exit the script with an error message
213+
[[ $# -lt 2 ]] &&
214+
error_exit "Usage: download_and_extract_pause_image <pause_image_repo_url> <pause_image_tag> [registry_secret]"
215+
216+
# Ensure CAA_SRC_DIR is set
217+
[[ -z "${CAA_SRC_DIR}" ]] && error_exit "CAA_SRC_DIR is not set"
218+
219+
local podvm_dir="${CAA_SRC_DIR}/podvm"
220+
local pause_src="/tmp/pause"
221+
local pause_bundle="${podvm_dir}/files/pause_bundle"
222+
223+
mkdir -p "${pause_bundle}" ||
224+
error_exit "Failed to create the pause_bundle directory"
225+
226+
# Form the skopeo CLI. Add authfile if provided
227+
if [[ -n "${3}" ]]; then
228+
SKOPEO_CLI="skopeo copy --authfile ${auth_json_file}"
229+
else
230+
SKOPEO_CLI="skopeo copy"
231+
fi
232+
233+
# Download the pause image
234+
$SKOPEO_CLI "docker://${pause_image_repo_url}:${pause_image_tag}" "oci:${pause_src}:${pause_image_tag}" ||
235+
error_exit "Failed to download the pause image"
236+
237+
# Extract the pause image using umoci into pause_bundle directory
238+
umoci unpack --rootless --image "${pause_src}:${pause_image_tag}" "${pause_bundle}" ||
239+
error_exit "Failed to extract the pause image"
240+
241+
}
242+
186243
# Global variables
187244

188245
# Set global variable for the source code directory
189-
export CAA_SRC_DIR="/src/cloud-api-adaptor"
246+
# The project layout has changed for the cloud-api-adaptor project
247+
# https://github.com/confidential-containers/cloud-api-adaptor
248+
export CAA_SRC_DOWNLOAD_DIR="/src/cloud-api-adaptor"
249+
export CAA_SRC_DIR="/src/cloud-api-adaptor/src/cloud-api-adaptor"

config/peerpods/podvm/osc-podvm-create-job.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ spec:
5353
volumeMounts:
5454
- name: payload
5555
mountPath: /payload
56+
- name: regauth
57+
mountPath: /tmp/regauth
5658
volumes:
5759
- name: payload
5860
emptyDir: {}
61+
- name: regauth
62+
secret:
63+
secretName: auth-json-secret
5964
restartPolicy: Never

config/peerpods/podvm/podvm-handling.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ don't want to trigger the pod VM image creation process, then you can set the
1919
respective keys to any dummy value (eg. "****"). Or you can set it to a
2020
pre-created pod VM image.
2121

22+
The image creation process also embeds the `rootfs` of the `pause` container
23+
image into the pod VM image. By default OpenShift's `pause` image is embedded.
24+
If you want to embed a different `pause` container image, then set the following
25+
variables in the job configuration files (eg,`aws-podvm-image-cm` for AWS):
26+
27+
- **PAUSE_IMAGE_REPO**: eg. quay.io/myimage/image
28+
- **PAUSE_IMAGE_VERSION**: eg. latest
29+
- **PAUSE_IMAGE_REPO_AUTH_FILE**: (optional) path to json file with the registry authentication details
30+
2231
Note that the OSC operator controller doesn't watch for changes to the
2332
`peer-pods-cm` configMap. However if the OSC operator reconcile loop is
2433
entered due to the changes in `kataConfig` or node label changes, then the
@@ -42,7 +51,7 @@ The job's pod specification has an init container (**copy**) which uses the
4251
(`/podvm-binaries.tar.gz`) from its own filesystem to a shared volume
4352
(`/payload`). This shared volume is of `emptyDir` type.
4453

45-
The main container (create), uses the `osc-podvm-builder-rhel9:latest` image.
54+
The main container (**create**), uses the `osc-podvm-builder-rhel9:latest` image.
4655
This image contains scripts and sources for handling pod VM image creation and
4756
deletion in Azure and AWS. The container runs as root (`runAsUser: 0`). It also
4857
mounts the shared volume (`/payload`) to access the file copied by the init
@@ -89,7 +98,7 @@ the pod fails, K8s will retry the job once before marking it as failed
8998
The job uses `peer-pods-secret` for cloud-provider credentials, and three
9099
configMaps - `peer-pods-cm`, `azure-podvm-image-cm`, `aws-podvm-image-cm`.
91100

92-
The job's pod specification includes a single container (delete-gallery), which
101+
The job's pod specification includes a single container (**delete-gallery**), which
93102
uses the `osc-podvm-builder-rhel9:latest` image. The container runs as root
94103
(`runAsUser: 0`).
95104

controllers/image_generator.go

+9
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,15 @@ func (r *ImageGenerator) createJobFromFile(jobFileName string) (*batchv1.Job, er
308308
job.Spec.Template.Spec.Containers[0].Image = podvmBuilderImage
309309
}
310310

311+
// If RELATED_PODVM_PAYLOAD_IMAGE environment variable is set, use it
312+
// Otherwise, use the default podvm payload image
313+
// There is only one initContainer in the job, so we don't need to check the container name
314+
podvmPayloadImage := os.Getenv("RELATED_IMAGE_PODVM_PAYLOAD")
315+
if podvmPayloadImage != "" {
316+
igLogger.Info("Using podvm payload image from environment variable", "image", podvmPayloadImage)
317+
job.Spec.Template.Spec.InitContainers[0].Image = podvmPayloadImage
318+
}
319+
311320
return job, nil
312321
}
313322

controllers/openshift_controller.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,14 @@ func (r *KataConfigOpenShiftReconciler) processKataConfigInstallRequest() (ctrl.
12021202

12031203
// create Pod VM image PeerPodConfig CRD and runtimeclass for peerpods
12041204
if r.kataConfig.Spec.EnablePeerPods {
1205+
//Get pull-secret from openshift-config ns and save it as auth-json-secret in our ns
1206+
//This will be used by the podvm image provider to pull the pause image for embedding
1207+
err = r.createAuthJsonSecret()
1208+
if err != nil {
1209+
r.Log.Info("Error in creating auth-json-secret", "err", err)
1210+
return ctrl.Result{Requeue: true, RequeueAfter: 15 * time.Second}, err
1211+
}
1212+
12051213
// Create the podvm image
12061214
// Since we want to declaratively reach the final state, we need to reconcile when there are errors
12071215
// as we want the system to give a chance of fixing the error.
@@ -2237,13 +2245,6 @@ func (r *KataConfigOpenShiftReconciler) enablePeerPodsMiscConfigs() error {
22372245
return err
22382246
}
22392247

2240-
//Get pull-secret from openshift-config ns and save it as auth-json-secret in our ns
2241-
err = r.createAuthJsonSecret()
2242-
if err != nil {
2243-
r.Log.Info("Error in creating auth-json-secret", "err", err)
2244-
return err
2245-
}
2246-
22472248
// Create the mutating webhook deployment
22482249
err = r.createMutatingWebhookDeployment()
22492250
if err != nil {

0 commit comments

Comments
 (0)