From db9a7a6dc0567c047a58991ddd272a13a9e77663 Mon Sep 17 00:00:00 2001 From: tina Date: Tue, 3 Dec 2024 09:34:48 +0000 Subject: [PATCH] Test WS2025 GA image Remove {{end}} --- images/capi/packer/azure/scripts/init-sig.sh | 96 ++++++++++++------- .../packer/azure/windows-2025-containerd.json | 7 +- images/capi/packer/goss/goss-package.yaml | 9 +- 3 files changed, 64 insertions(+), 48 deletions(-) diff --git a/images/capi/packer/azure/scripts/init-sig.sh b/images/capi/packer/azure/scripts/init-sig.sh index c2ed66fd36..2c0c7d1a55 100755 --- a/images/capi/packer/azure/scripts/init-sig.sh +++ b/images/capi/packer/azure/scripts/init-sig.sh @@ -58,46 +58,72 @@ SECURITY_TYPE_CVM_SUPPORTED_FEATURE="SecurityType=ConfidentialVmSupported" SIG_TARGET=$1 +# Accept Azure VM image terms if available and required +accept_image_terms() { + # SIG_TARGET is expected to be a global variable + if [[ -z "$SIG_TARGET" ]]; then + echo "Error: SIG_TARGET is not set. Exiting." + exit 1 + fi + # AZURE_LOCATION is expected to be a global variable + if [[ -z "$AZURE_LOCATION" ]]; then + echo "Error: AZURE_LOCATION is not set. Exiting." + exit 1 + fi + + # Resolve the JSON file path and extract necessary fields + target_json="$(realpath "packer/azure/${SIG_TARGET}.json")" + distribution=$(jq -r '.distribution' "$target_json") + distribution_version=$(jq -r '.distribution_version' "$target_json") + + # Return early if not a Windows distribution + if [[ "$distribution" != "windows" ]]; then + return + fi + + # Extract purchase plan details + plan_publisher=$(jq -r '.plan_image_publisher' "$target_json") + plan_offer=$(jq -r '.plan_image_offer' "$target_json") + plan_name=$(jq -r '.plan_image_sku' "$target_json") + plan_version=${PLAN_VERSION:-"latest"} + + # Proceed only if all plan details are valid + if [[ "$plan_publisher" == "null" || "$plan_offer" == "null" || "$plan_name" == "null" ]]; then + echo "Purchase plan details are missing. Skipping terms acceptance." + return + fi -################################################################################# -##### TODO: [SEPTEMBER 2024] Remove purchase plan info when the image is GA ##### -# Creating Azure VMs from a Marketplace Image requires a Purchase Plan -# https://learn.microsoft.com/en-us/azure/virtual-machines/marketplace-images -# HACK: Extract purchase plan info from the target json. We want to avoid changing the Prow jobs YAML files to add these -# values as environment variables. -TARGET_JSON="$(realpath packer/azure/$SIG_TARGET.json)" -DISTRIBUTION=$(jq -r '.distribution' "$TARGET_JSON") -DISTRIBUTION_VERSION=$(jq -r '.distribution_version' "$TARGET_JSON") - -plan_args=() -if [[ "$DISTRIBUTION" == "windows" && "$DISTRIBUTION_VERSION" == "2025" ]]; then - PLAN_PUBLISHER=$(jq -r '.plan_image_publisher' "$TARGET_JSON") - PLAN_OFFER=$(jq -r '.plan_image_offer' "$TARGET_JSON") - PLAN_NAME=$(jq -r '.plan_image_sku' "$TARGET_JSON") - PLAN_VERSION=${PLAN_VERSION:-"latest"} - - plan_args=( - --plan-name ${PLAN_NAME} - --plan-product ${PLAN_OFFER} - --plan-publisher ${PLAN_PUBLISHER} + # Populate the global plan_args variable + PLAN_ARGS=( + --plan-name "${plan_name}" + --plan-product "${plan_offer}" + --plan-publisher "${plan_publisher}" ) - # Proceed only if all plan details are available - # WHY? Build fails with: "You have not accepted the legal terms on this subscription" - if [[ "$PLAN_PUBLISHER" != "null" && "$PLAN_OFFER" != "null" && "$PLAN_NAME" != "null" ]]; then - PLAN_URN="${PLAN_PUBLISHER}:${PLAN_OFFER}:${PLAN_NAME}:$(echo $PLAN_VERSION)" - echo "Plan info: ${PLAN_URN}" + plan_urn="${plan_publisher}:${plan_offer}:${plan_name}:${plan_version}" - # Retrieve the terms and check acceptance status - if [[ "$(az vm image terms show --urn "$PLAN_URN" | jq -r '.accepted')" != "true" ]]; then - echo "Accepting terms for image URN: ${PLAN_URN}" - az vm image terms accept --urn "$PLAN_URN" - fi + # Check if the image has terms to accept + if [[ "$(az vm image show --location "$AZURE_LOCATION" --urn "${plan_urn}" -o json | jq -r '.plan')" == "null" ]]; then + echo "Image '${plan_urn}' has no terms to accept." + return fi -fi -############# END: SECTION TO BE REMOVED AFTER IMAGE IS GA ################### -############################################################################## + echo "Plan info: ${plan_urn}" + + # Check acceptance status and accept terms if not already accepted + if [[ "$(az vm image terms show --urn "$plan_urn" -o json | jq -r '.accepted')" == "true" ]]; then + echo "Terms for image URN: ${plan_urn} are already accepted." + return + fi + + echo "Accepting terms for image URN: ${plan_urn}" + az vm image terms accept --urn "$plan_urn" +} + +PLAN_ARGS=() +accept_image_terms + +# Create a shared image gallery image definition if it does not exist create_image_definition() { if ! az sig image-definition show --gallery-name ${GALLERY_NAME} --gallery-image-definition ${SIG_IMAGE_DEFINITION:-capi-${SIG_SKU:-$1}} --resource-group ${RESOURCE_GROUP_NAME} -o none 2>/dev/null; then az sig image-definition create \ @@ -143,7 +169,7 @@ case ${SIG_TARGET} in create_image_definition ${SIG_TARGET} "win-2022-containerd" "V1" "Windows" ;; windows-2025-containerd) - create_image_definition ${SIG_TARGET} "win-2025-containerd" "V2" "Windows" + create_image_definition ${SIG_TARGET} "win-2025-containerd" "V1" "Windows" ;; windows-annual-containerd) create_image_definition ${SIG_TARGET} "win-annual-containerd" "V1" "Windows" diff --git a/images/capi/packer/azure/windows-2025-containerd.json b/images/capi/packer/azure/windows-2025-containerd.json index 76d36cf2ed..6ec61f61a7 100644 --- a/images/capi/packer/azure/windows-2025-containerd.json +++ b/images/capi/packer/azure/windows-2025-containerd.json @@ -4,14 +4,11 @@ "build_name": "windows-2025-containerd", "distribution": "windows", "distribution_version": "2025", - "image_offer": "microsoftserveroperatingsystems-previews", + "image_offer": "WindowsServer", "image_publisher": "MicrosoftWindowsServer", - "image_sku": "windows-server-2025-azure-edition-hotpatch", + "image_sku": "2025-Datacenter-Core-smalldisk", "image_version": "latest", "load_additional_components": "false", - "plan_image_offer": "microsoftserveroperatingsystems-previews", - "plan_image_publisher": "microsoftwindowsserver", - "plan_image_sku": "windows-server-2025-azure-edition-hotpatch", "runtime": "containerd", "vm_size": "Standard_D4s_v3", "windows_updates_kbs": "" diff --git a/images/capi/packer/goss/goss-package.yaml b/images/capi/packer/goss/goss-package.yaml index 07b37c25dd..3b668c1594 100644 --- a/images/capi/packer/goss/goss-package.yaml +++ b/images/capi/packer/goss/goss-package.yaml @@ -74,13 +74,7 @@ package: {{end}} -################################################################################# -######## TODO: [SEPTEMBER 2024] Revert timeout to 60000ms after image GA ######## -# The WS2025 preview image build is failing due to timeout issues when running -# PowerShell command to Get Windows Features, although the features are enabled. -# Skip this test on WS2025 for now. {{ if eq .Vars.OS "windows"}} # Windows -{{ if ne .Vars.distribution_version "2025" }} # Workaround until windows features are added to goss command: {{range $name, $vers := index .Vars .Vars.OS "common-windows-features"}} @@ -89,8 +83,7 @@ command: exit-status: 0 stdout: {{range $vers.expected}} - {{.}} - timeout: 30000 # Give it enough time to retry if it fails + timeout: 60000 {{end}} {{end}} {{end}} -{{end}}