Created
September 22, 2023 09:59
-
-
Save bpradipt/838fbe15e8888cdfbcc53394d84031a1 to your computer and use it in GitHub Desktop.
K8s job manifest to create Azure podvm image on local subnet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: batch/v1 | |
kind: Job | |
metadata: | |
name: azure-image-creation-priv | |
namespace: openshift-sandboxed-containers-operator | |
spec: | |
parallelism: 1 | |
completions: 1 | |
backoffLimit: 1 | |
template: | |
metadata: | |
name: azure-image-creation-priv | |
spec: | |
volumes: | |
- name: shared-data | |
emptyDir: {} | |
securityContext: | |
runAsUser: 0 # needed for container mode dnf access | |
initContainers: | |
- name: payload | |
image: registry.redhat.io/openshift-sandboxed-containers/osc-podvm-payload-rhel9:1.4.0 | |
imagePullPolicy: Always | |
volumeMounts: | |
- name: shared-data | |
mountPath: /payload | |
command: ["/bin/sh"] | |
args: ["-c", "cp /podvm-binaries.tar.gz /payload/"] | |
containers: | |
- name: azure-image-creation | |
image: registry.access.redhat.com/ubi9/ubi:9.1 | |
volumeMounts: | |
- name: shared-data | |
mountPath: /payload | |
env: | |
# - name: VM_SIZE | |
# value: "Standard_A2_v2" | |
- name: PODVM_DISTRO | |
value: rhel | |
- name: PUBLISHER | |
value: "RedHat" | |
- name: OFFER | |
value: "rhel-raw" | |
- name: SKU | |
value: "9_2" | |
- name: AZURE_VNET_NAME | |
value: "" #set | |
- name: AZURE_SUBNET_NAME | |
value: "" #set | |
envFrom: | |
- secretRef: | |
name: peer-pods-secret | |
- configMapRef: | |
name: peer-pods-cm | |
optional: true | |
command: | |
- /bin/sh | |
- -c | |
- | | |
yum install -y yum-utils make git | |
yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo | |
yum -y install packer | |
PATH="/usr/bin:${PATH}" | |
git clone https://github.com/bpradipt/cloud-api-adaptor.git -b ocp-azure-priv | |
tar xvf /payload/podvm-binaries.tar.gz -C cloud-api-adaptor/podvm/files | |
mkdir cloud-api-adaptor/podvm/files/pause_bundle # workaround to avoid pause image requirement | |
[[ ! "${AZURE_REGION}" ]] && echo "AZURE_REGION is missing" && exit 1 | |
[[ ! "${AZURE_TENANT_ID}" ]] && echo "AZURE_TENANT_ID is missing" && exit 1 | |
[[ ! "${AZURE_RESOURCE_GROUP}" ]] && echo "AZURE_RESOURCE_GROUP is missing" && exit 1 | |
[[ ! "${AZURE_SUBSCRIPTION_ID}" ]] && echo "AZURE_SUBSCRIPTION_ID is missing" && exit 1 | |
[[ ! "${AZURE_CLIENT_SECRET}" ]] && echo "AZURE_CLIENT_SECRET is missing" && exit 1 | |
[[ ! "${AZURE_CLIENT_ID}" ]] && echo "AZURE_CLIENT_ID is missing" && exit 1 | |
[[ ! "${AZURE_VNET_NAME}" ]] && echo "AZURE_VNET_NAME is missing" && exit 1 | |
[[ ! "${AZURE_SUBNET_NAME}" ]] && echo "AZURE_SUBNET_NAME is missing" && exit 1 | |
export PKR_VAR_client_id=${AZURE_CLIENT_ID} | |
export PKR_VAR_client_secret=${AZURE_CLIENT_SECRET} | |
export PKR_VAR_subscription_id=${AZURE_SUBSCRIPTION_ID} | |
export PKR_VAR_tenant_id=${AZURE_TENANT_ID} | |
export PKR_VAR_resource_group=${AZURE_RESOURCE_GROUP} | |
export PKR_VAR_location=${AZURE_LOCATION} | |
export PKR_VAR_az_image_name=${IMAGE_NAME:-peer-pod-vmimage-private} | |
export PKR_VAR_vm_size=${VM_SIZE:-Standard_A2_v2} | |
export PKR_VAR_ssh_username=${SSH_USERNAME:-peerpod} | |
export PKR_VAR_publisher=${PUBLISHER} | |
export PKR_VAR_offer=${OFFER} | |
export PKR_VAR_sku=${SKU} | |
export PKR_VAR_plan_name=${PLAN_NAME} | |
export PKR_VAR_plan_product=${PLAN_PRODUCT} | |
export PKR_VAR_plan_publisher=${PLAN_PUBLISHER} | |
export PKR_VAR_virtual_network_name=${AZURE_VNET_NAME} | |
export PKR_VAR_virtual_network_subnet_name=${AZURE_SUBNET_NAME} | |
export PKR_VAR_virtual_network_resource_group_name=${AZURE_RESOURCE_GROUP} | |
cd cloud-api-adaptor/azure/image | |
packer init ${PODVM_DISTRO}/ | |
make BINARIES= PAUSE_BUNDLE= image && \ | |
echo "Set the image AZURE_IMAGE_ID^ in your Secret/peer-pods-secret or ConfigMap/peer-pods-cm object" | |
restartPolicy: Never |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment