Skip to content

Commit

Permalink
tree-wide: Support pending change to use stream metadata for CoreOS
Browse files Browse the repository at this point in the history
This is part of adapting RHCOS to use the same stream metadata JSON format
that FCOS uses:

openshift/os#477

This change specifically will pair with a pending change in:
openshift/installer#4582
to embed CoreOS stream metadata in the installer git instead
of the undocumented ad-hoc JSON format that ships there now.
  • Loading branch information
cgwalters committed Mar 1, 2021
1 parent 9b14d91 commit ad1b2cc
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ export HOME
echo "$(date -u --rfc-3339=seconds) - Locating RHCOS image for release..."

openshift_install_path="/var/lib/openshift-install"
image_json_file="${openshift_install_path}/rhcos.json"
fcos_json_file="${openshift_install_path}/fcos.json"

if [[ -f "$fcos_json_file" ]]; then
image_json_file=$fcos_json_file
if test -f "${openshift_install_path}/coreos-stream.json"; then
ova_url=$(jq -r '.architectures["'"$(arch)"'"].artifacts.vmware.formats.ova.disk.location' < /var/lib/openshift-install/coreos-stream.json)
else
image_json_file="${openshift_install_path}/rhcos.json"
fcos_json_file="${openshift_install_path}/fcos.json"
if [[ -f "$fcos_json_file" ]]; then
image_json_file=$fcos_json_file
fi
ova_url="$(jq -r '.baseURI + .images["vmware"].path' $image_json_file)"
fi

ova_url="$(jq -r '.baseURI + .images["vmware"].path' $image_json_file)"
vm_template="${ova_url##*/}"

# Troubleshooting UPI OVA import issue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ install_config="${SHARED_DIR}/install-config.yaml"
tfvars_path=/var/run/secrets/ci.openshift.io/cluster-profile/vmc.secret.auto.tfvars
vsphere_user=$(grep -oP 'vsphere_user\s*=\s*"\K[^"]+' ${tfvars_path})
vsphere_password=$(grep -oP 'vsphere_password\s*=\s*"\K[^"]+' ${tfvars_path})
ova_url="$(jq -r '.baseURI + .images["vmware"].path' /var/lib/openshift-install/rhcos.json)"
if test -f /var/lib/openshift-install/coreos-stream.json; then
ova_url=$(jq -r '.architectures["'"$(arch)"'"].artifacts.vmware.formats.ova.disk.location' < /var/lib/openshift-install/coreos-stream.json)
else
ova_url="$(jq -r '.baseURI + .images["vmware"].path' /var/lib/openshift-install/rhcos.json)"
fi
vm_template="${ova_url##*/}"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,13 @@ gcloud iam service-accounts keys create service-account-key.json "--iam-account=

## Create the cluster image.
echo "$(date -u --rfc-3339=seconds) - Creating the cluster image..."
IMAGE_SOURCE="$(jq -r .gcp.url /var/lib/openshift-install/rhcos.json)"
gcloud compute images create "${INFRA_ID}-rhcos-image" --source-uri="${IMAGE_SOURCE}"
CLUSTER_IMAGE="$(gcloud compute images describe "${INFRA_ID}-rhcos-image" --format json | jq -r .selfLink)"
if test -f /var/lib/openshift-install/coreos-stream.json; then
CLUSTER_IMAGE=$(jq -r '.architectures["'"$(arch)"'"].images.gcp as $gcp | "projects/" + $gcp.project + "/global/images/" + $gcp.name' < /var/lib/openshift-install/coreos-stream.json)
else
IMAGE_SOURCE="$(jq -r .gcp.url /var/lib/openshift-install/rhcos.json)"
gcloud compute images create "${INFRA_ID}-rhcos-image" --source-uri="${IMAGE_SOURCE}"
CLUSTER_IMAGE="$(gcloud compute images describe "${INFRA_ID}-rhcos-image" --format json | jq -r .selfLink)"
fi

## Upload the bootstrap.ign to a new bucket
echo "$(date -u --rfc-3339=seconds) - Uploading the bootstrap.ign to a new bucket..."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,18 +476,25 @@ objects:
mkdir ${TMP_SHARED}/terraform
cp -r /var/lib/openshift-install/upi/metal/* ${TMP_SHARED}/terraform/
cp /bin/terraform-provider-matchbox ${TMP_SHARED}/terraform/
PXE_INITRD_URL="$(jq -r '.baseURI + (.images["live-initramfs"].path // .images["initramfs"].path)' /var/lib/openshift-install/rhcos.json)"
PXE_KERNEL_URL="$(jq -r '.baseURI + (.images["live-kernel"].path // .images["kernel"].path)' /var/lib/openshift-install/rhcos.json)"
# 4.3 unified 'metal-bios' and 'metal-uefi' into just 'metal'
PXE_OS_IMAGE_URL="$(jq -r '.baseURI + (.images["metal-bios"].path // .images["metal"].path)' /var/lib/openshift-install/rhcos.json)"
PXE_ROOTFS_URL="$(jq -r '.baseURI + (.images["live-rootfs"].path)' /var/lib/openshift-install/rhcos.json)"
if [[ $PXE_KERNEL_URL =~ "live" ]]; then
if test -f /var/lib/openshift-install/coreos-stream.json; then
jq -r '.architectures["'$(arch)'"].artifacts.metal' < /var/lib/openshift-install/coreos-stream.json > metal.json
PXE_INITRD_URL="$(jq -r '.formats.pxe.initramfs.location' < metal.json)"
PXE_KERNEL_URL="$(jq -r '.formats.pxe.kernel.location' < metal.json)"
PXE_OS_IMAGE_URL="$(jq -r '.formats[".raw.gz"].disk.location' < metal.json)"
PXE_ROOTFS_URL="$(jq -r '.formats.pxe.rootfs.location' < metal.json)"
PXE_KERNEL_ARGS="coreos.live.rootfs_url=${PXE_ROOTFS_URL}"
else
PXE_KERNEL_ARGS="coreos.inst.image_url=${PXE_OS_IMAGE_URL}"
PXE_INITRD_URL="$(jq -r '.baseURI + (.images["live-initramfs"].path // .images["initramfs"].path)' /var/lib/openshift-install/rhcos.json)"
PXE_KERNEL_URL="$(jq -r '.baseURI + (.images["live-kernel"].path // .images["kernel"].path)' /var/lib/openshift-install/rhcos.json)"
# 4.3 unified 'metal-bios' and 'metal-uefi' into just 'metal'
PXE_OS_IMAGE_URL="$(jq -r '.baseURI + (.images["metal-bios"].path // .images["metal"].path)' /var/lib/openshift-install/rhcos.json)"
PXE_ROOTFS_URL="$(jq -r '.baseURI + (.images["live-rootfs"].path)' /var/lib/openshift-install/rhcos.json)"
if [[ $PXE_KERNEL_URL =~ "live" ]]; then
PXE_KERNEL_ARGS="coreos.live.rootfs_url=${PXE_ROOTFS_URL}"
else
PXE_KERNEL_ARGS="coreos.inst.image_url=${PXE_OS_IMAGE_URL}"
fi
fi
# 4.3 unified 'metal-bios' and 'metal-uefi' into just 'metal', unused in 4.6
cat > ${TMP_SHARED}/terraform/terraform.tfvars <<-EOF
cluster_id = "${CLUSTER_NAME}"
bootstrap_ign_file = "${TMP_SHARED}/installer/bootstrap.ign"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,25 @@ objects:
function upload_rhcos_image() {
export RHCOS_GLANCE_IMAGE_NAME=${INFRA_ID}-rhcos-${RHCOS_RELEASE}
rm -rf ${TMP_SHARED}/rhcos.json
local IMAGE_SOURCE=https://raw.githubusercontent.com/openshift/installer/${RHCOS_RELEASE}/data/data/rhcos.json
wget -q -O ${TMP_SHARED}/rhcos.json $IMAGE_SOURCE
local GZ_IMAGE_FILENAME=$(grep path ${TMP_SHARED}/rhcos.json | grep openstack |awk '{print $2}' | awk -F\" '{print $2}')
local BASEURI=$(grep base ${TMP_SHARED}/rhcos.json | awk '{print $2}' |awk -F\" '{print $2}')
wget -q -O ${TMP_SHARED}/$GZ_IMAGE_FILENAME $BASEURI$GZ_IMAGE_FILENAME
if test -f "${TMP_SHARED}/coreos-stream.json"; then
jq '.architectures["'$(arch)'"].artifacts.openstack.formats["qcow2.gz"].disk' > openstack.json
local img=$(jq -r '.location' < openstack.json)
local checksum=$(jq -r '.sha256' < openstack.json)
local GZ_IMAGE_FILENAME=$(basename ${img})
curl -L -o ${TMP_SHARED}/${GZ_IMAGE_FILENAME} ${img}
local actual=$(sha256sum ${GZ_IMAGE_FILENAME})
if test "${checksum}" != "${actual}"; then
echo "checksum mismatch expected: ${checksum} actual: ${actual}" 1>&2
exit 1
fi
else
rm -rf ${TMP_SHARED}/rhcos.json
local IMAGE_SOURCE=https://raw.githubusercontent.com/openshift/installer/${RHCOS_RELEASE}/data/data/rhcos.json
wget -q -O ${TMP_SHARED}/rhcos.json $IMAGE_SOURCE
local GZ_IMAGE_FILENAME=$(grep path ${TMP_SHARED}/rhcos.json | grep openstack |awk '{print $2}' | awk -F\" '{print $2}')
local BASEURI=$(grep base ${TMP_SHARED}/rhcos.json | awk '{print $2}' |awk -F\" '{print $2}')
wget -q -O ${TMP_SHARED}/$GZ_IMAGE_FILENAME $BASEURI$GZ_IMAGE_FILENAME
fi
gunzip ${TMP_SHARED}/$GZ_IMAGE_FILENAME
local IMAGE_FILENAME=${GZ_IMAGE_FILENAME%.gz}
IMAGE_ID=$(openstack image create --container-format=bare --disk-format=qcow2 --file ${TMP_SHARED}/$IMAGE_FILENAME $RHCOS_GLANCE_IMAGE_NAME -f value -c id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,11 @@ objects:
# Get user and password from TFVARS_PATH
export VSPHERE_USER=$(grep -oP 'vsphere_user\s*=\s*"\K[^"]+' ${TFVARS_PATH})
export VSPHERE_PASSWORD=$(grep -oP 'vsphere_password\s*=\s*"\K[^"]+' ${TFVARS_PATH})
export OVA_URL="$(jq -r '.baseURI + .images["vmware"].path' /var/lib/openshift-install/rhcos.json)"
if test -f /var/lib/openshift-install/coreos-stream.json; then
export OVA_URL=$(jq -r '.architectures["'$(arch)'"].artifacts.vmware.formats.ova.disk.location' < /var/lib/openshift-install/coreos-stream.json)
else
export OVA_URL="$(jq -r '.baseURI + .images["vmware"].path' /var/lib/openshift-install/rhcos.json)"
fi
export VM_TEMPLATE="${OVA_URL##*/}"
mkdir /tmp/rhcos
Expand Down

0 comments on commit ad1b2cc

Please sign in to comment.