Repository: kubernetes/kubernetes
File: test/images/agnhost/fakeregistryserver/prepare_registry.sh (Shell)

Code before:
    local digest="$2"
    local algo="${digest%%:*}"    # e.g., "sha256"
    local hash="${digest#*:}"     # e.g., "abc123..."
    local prefix="${hash:0:2}"    # first 2 chars
    echo "$base_dir/$algo/$prefix/$hash/data"
}

# function to download an image manifest and its blobs to create a fake registry layout.
prepare_image() {
    local image_name="$1"
    local tag="$2"
    local internal_tag="$3"
    local image_dir="$REGISTRY_DIR/$image_name"

    echo "--- Preparing image: ${image_name}:${tag} as ${image_name}:${internal_tag} ---"

    mkdir -p "$image_dir/manifests"
    mkdir -p "$image_dir/blobs"

    echo "Downloading and filtering manifest list for $image_name:$tag..."
    local tmp_manifest_path="$image_dir/manifests/tmp_${internal_tag}"
    # download the manifest and pipe it to jq to filter out windows images
    crane manifest "$REGISTRY_URL/$image_name:$tag" | jq '.manifests |= map(select(.platform.os != "windows"))' > "$tmp_manifest_path"
    echo "Saved manifest list to $tmp_manifest_path"

    local manifest_hash
    manifest_hash="$(sha256sum < "$tmp_manifest_path" | awk '{print $1}')"
    local manifest_digest="sha256:$manifest_hash"
    local manifest_path
    manifest_path="$(digest_to_path "$image_dir/manifests" "$manifest_digest")"
    mkdir -p "$(dirname "$manifest_path")"
    mv "$tmp_manifest_path" "$manifest_path"
    echo "Saved manifest list to $manifest_path"

    # the file named after the tag now contains only the digest, acting as a redirect pointer
    echo "$manifest_digest" > "$image_dir/manifests/${internal_tag}"
    echo "Created tag file ${internal_tag} pointing to digest $manifest_digest"

    echo "Parsing manifest list and downloading individual manifests and blobs..."

    jq -r '.manifests[].digest' < "$manifest_path" | while read -r individual_manifest_digest; do
      echo "  Downloading manifest $individual_manifest_digest..."
      local individual_manifest_path
      individual_manifest_path="$(digest_to_path "$image_dir/manifests" "$individual_manifest_digest")"
      mkdir -p "$(dirname "$individual_manifest_path")"
      crane manifest "$REGISTRY_URL/$image_name@$individual_manifest_digest" > "$individual_manifest_path"
      echo "  Saved manifest to $individual_manifest_path"

      local config_digest
      config_digest=$(jq -r '.config.digest' < "$individual_manifest_path")
      echo "    Downloading config blob $config_digest..."

Review comment (suggestion):
not essential, but you can declare a set of related locals in bulk like this to cut down on the number of lines / noise per var

```suggestion
    local manifest_hash manifest_digest manifest_path
```

this makes less sense when they're not closely related / the further the initial assignment gets from the declaration, but I think it makes sense here.

non-blocking suggestion

Code after:
    local digest="$2"
    local algo="${digest%%:*}"    # e.g., "sha256"
    local hash="${digest#*:}"     # e.g., "abc123..."
    local prefix="${hash:0:2}"    # first 2 chars
    echo "$base_dir/$algo/$prefix/$hash/data"
}

# function to download an image manifest and its blobs to create a fake registry layout.
prepare_image() {
    local image_name="$1"
    local tag="$2"
    local internal_tag="$3"
    local image_dir="$REGISTRY_DIR/$image_name"

    echo "--- Preparing image: ${image_name}:${tag} as ${image_name}:${internal_tag} ---"

    mkdir -p "$image_dir/manifests"
    mkdir -p "$image_dir/blobs"

    echo "Downloading and filtering manifest list for $image_name:$tag..."
    local tmp_manifest_path="$image_dir/manifests/tmp_${internal_tag}"
    # download the manifest and pipe it to jq to filter out windows images
    crane manifest "$REGISTRY_URL/$image_name:$tag" | jq '.manifests |= map(select(.platform.os != "windows"))' > "$tmp_manifest_path"
    echo "Saved manifest list to $tmp_manifest_path"

    local manifest_hash manifest_digest manifest_path
    manifest_hash="$(sha256sum < "$tmp_manifest_path" | awk '{print $1}')"
    manifest_digest="sha256:$manifest_hash"
    manifest_path="$(digest_to_path "$image_dir/manifests" "$manifest_digest")"
    mkdir -p "$(dirname "$manifest_path")"
    mv "$tmp_manifest_path" "$manifest_path"
    echo "Saved manifest list to $manifest_path"

    # the file named after the tag now contains only the digest, acting as a redirect pointer
    echo "$manifest_digest" > "$image_dir/manifests/${internal_tag}"
    echo "Created tag file ${internal_tag} pointing to digest $manifest_digest"

    echo "Parsing manifest list and downloading individual manifests and blobs..."

    jq -r '.manifests[].digest' < "$manifest_path" | while read -r individual_manifest_digest; do
      echo "  Downloading manifest $individual_manifest_digest..."
      local individual_manifest_path
      individual_manifest_path="$(digest_to_path "$image_dir/manifests" "$individual_manifest_digest")"
      mkdir -p "$(dirname "$individual_manifest_path")"
      crane manifest "$REGISTRY_URL/$image_name@$individual_manifest_digest" > "$individual_manifest_path"
      echo "  Saved manifest to $individual_manifest_path"

      local config_digest
      config_digest=$(jq -r '.config.digest' < "$individual_manifest_path")
      echo "    Downloading config blob $config_digest..."
      local config_path