|
31 | 31 | # Set OPENSHELL_E2E_KUBE_EXTRA_VALUES to one or more colon-separated Helm values |
32 | 32 | # files, relative to the repository root or absolute, to layer additional chart |
33 | 33 | # configuration on top of ci/values-skaffold.yaml. |
| 34 | +# Set OPENSHELL_E2E_KUBE_SANDBOX_IMAGE to test a non-default workload image. The |
| 35 | +# local kind/k3d path otherwise derives a strict PolicyDocument fixture from the |
| 36 | +# published community base image, whose baked policy predates that contract. |
34 | 37 | # |
35 | 38 | # Image source: |
36 | 39 | # - Ephemeral k3d mode builds local |
@@ -803,6 +806,33 @@ else |
803 | 806 | fi |
804 | 807 | REGISTRY_VALUE="${REGISTRY_VALUE%/}" |
805 | 808 |
|
| 809 | +prepare_policy_document_community_image() { |
| 810 | + local source_image=$1 |
| 811 | + local source_id source_digest fixture_image |
| 812 | + |
| 813 | + echo "Refreshing latest sandbox image ${source_image}..." >&2 |
| 814 | + docker pull "${source_image}" >&2 |
| 815 | + source_id="$(docker image inspect --format '{{.Id}}' "${source_image}")" |
| 816 | + source_digest="${source_id#sha256:}" |
| 817 | + if ! [[ "${source_digest}" =~ ^[0-9a-f]{64}$ ]]; then |
| 818 | + echo "ERROR: could not resolve a stable image ID for ${source_image}." >&2 |
| 819 | + return 1 |
| 820 | + fi |
| 821 | + |
| 822 | + fixture_image="openshell/e2e-community-base:policy-document-v1-${source_digest:0:12}" |
| 823 | + if ! docker image inspect "${fixture_image}" >/dev/null 2>&1; then |
| 824 | + echo "Preparing PolicyDocument E2E fixture from ${source_image}..." >&2 |
| 825 | + docker build \ |
| 826 | + --pull=false \ |
| 827 | + --build-arg "BASE_IMAGE=${source_image}" \ |
| 828 | + --file "${ROOT}/e2e/docker/Dockerfile.policy-document-community-base" \ |
| 829 | + --tag "${fixture_image}" \ |
| 830 | + "${ROOT}/e2e/docker" >&2 |
| 831 | + fi |
| 832 | + |
| 833 | + printf '%s\n' "${fixture_image}" |
| 834 | +} |
| 835 | + |
806 | 836 | # Resolve a host-gateway IP that sandbox pods can dial to reach test fixtures |
807 | 837 | # running on the developer/CI host (HTTP fixtures bound to 0.0.0.0 plus sibling |
808 | 838 | # Docker containers with published ports). The Helm chart wires this into pod |
@@ -892,6 +922,26 @@ elif [[ "${KUBE_CONTEXT}" == k3d-* ]] && command -v k3d >/dev/null 2>&1; then |
892 | 922 | import_cluster_name="${candidate}" |
893 | 923 | fi |
894 | 924 | fi |
| 925 | + |
| 926 | +DEFAULT_SANDBOX_IMAGE="ghcr.io/nvidia/openshell-community/sandboxes/base:latest" |
| 927 | +KUBE_SANDBOX_IMAGE="${OPENSHELL_E2E_KUBE_SANDBOX_IMAGE:-${DEFAULT_SANDBOX_IMAGE}}" |
| 928 | +KUBE_SANDBOX_IMAGE_PULL_POLICY="${OPENSHELL_E2E_KUBE_SANDBOX_IMAGE_PULL_POLICY:-if_not_present}" |
| 929 | +POLICY_DOCUMENT_FIXTURE_IMAGE="" |
| 930 | +if [ "${KUBE_SANDBOX_IMAGE}" = "${DEFAULT_SANDBOX_IMAGE}" ]; then |
| 931 | + if [ -z "${import_cluster_name}" ] && ! [[ "${KUBE_CONTEXT}" == kind-* ]]; then |
| 932 | + echo "ERROR: the published community base image still contains a legacy policy." >&2 |
| 933 | + echo " Set OPENSHELL_E2E_KUBE_SANDBOX_IMAGE to a PolicyDocument-compatible image for this cluster." >&2 |
| 934 | + exit 2 |
| 935 | + fi |
| 936 | + require_cmd docker |
| 937 | + POLICY_DOCUMENT_FIXTURE_IMAGE="$(prepare_policy_document_community_image "${KUBE_SANDBOX_IMAGE}")" |
| 938 | + export OPENSHELL_COMMUNITY_REGISTRY="openshell/e2e-community-sandboxes" |
| 939 | + KUBE_SANDBOX_IMAGE="${OPENSHELL_COMMUNITY_REGISTRY}/base:latest" |
| 940 | + docker image tag "${POLICY_DOCUMENT_FIXTURE_IMAGE}" "${KUBE_SANDBOX_IMAGE}" |
| 941 | + export OPENSHELL_E2E_COMMUNITY_BASE_IMAGE="${KUBE_SANDBOX_IMAGE}" |
| 942 | + KUBE_SANDBOX_IMAGE_PULL_POLICY=never |
| 943 | +fi |
| 944 | + |
895 | 945 | if [ "${OPENSHELL_E2E_KUBE_BUILD_IMAGES}" = "1" ]; then |
896 | 946 | require_cmd docker |
897 | 947 | echo "Building local Kubernetes e2e images (${REGISTRY_VALUE}/{gateway,sandbox,supervisor}:${IMAGE_TAG_VALUE})..." |
@@ -925,6 +975,8 @@ if [ "${OPENSHELL_E2E_KUBE_BUILD_IMAGES}" = "1" ]; then |
925 | 975 | --build-arg "TARGETARCH=${external_arch}" \ |
926 | 976 | --build-arg "SUPERVISOR_IMAGE=${REGISTRY_VALUE}/supervisor:${IMAGE_TAG_VALUE}" \ |
927 | 977 | --build-arg "SANDBOX_RUNTIME_IMAGE=${REGISTRY_VALUE}/sandbox:${IMAGE_TAG_VALUE}" \ |
| 978 | + --build-arg "SANDBOX_IMAGE=${KUBE_SANDBOX_IMAGE}" \ |
| 979 | + --build-arg "SANDBOX_IMAGE_PULL_POLICY=${KUBE_SANDBOX_IMAGE_PULL_POLICY}" \ |
928 | 980 | --tag "${REGISTRY_VALUE}/gateway:${IMAGE_TAG_VALUE}" \ |
929 | 981 | --file "${ROOT}/e2e/docker/Dockerfile.external-kubernetes-gateway" \ |
930 | 982 | "${ROOT}" |
@@ -983,6 +1035,20 @@ elif [ "${OPENSHELL_E2E_KUBE_BUILD_IMAGES}" = "1" ] \ |
983 | 1035 | kind load docker-image "${image}" --name "${kind_cluster_name}" |
984 | 1036 | done |
985 | 1037 | fi |
| 1038 | +if [ -n "${POLICY_DOCUMENT_FIXTURE_IMAGE}" ]; then |
| 1039 | + if [ -n "${import_cluster_name}" ]; then |
| 1040 | + echo "Importing ${KUBE_SANDBOX_IMAGE} into k3d cluster ${import_cluster_name}..." |
| 1041 | + k3d image import "${KUBE_SANDBOX_IMAGE}" --cluster "${import_cluster_name}" \ |
| 1042 | + --mode direct >/dev/null |
| 1043 | + elif [[ "${KUBE_CONTEXT}" == kind-* ]] && command -v kind >/dev/null 2>&1; then |
| 1044 | + kind_cluster_name="${KUBE_CONTEXT#kind-}" |
| 1045 | + echo "Loading ${KUBE_SANDBOX_IMAGE} into kind cluster ${kind_cluster_name}..." |
| 1046 | + kind load docker-image "${KUBE_SANDBOX_IMAGE}" --name "${kind_cluster_name}" |
| 1047 | + else |
| 1048 | + echo "ERROR: cannot load the PolicyDocument sandbox fixture into ${KUBE_CONTEXT}." >&2 |
| 1049 | + exit 2 |
| 1050 | + fi |
| 1051 | +fi |
986 | 1052 |
|
987 | 1053 | # The Kubernetes compute driver creates and watches Sandbox CRs reconciled |
988 | 1054 | # by the upstream agent-sandbox-controller. Without the CRD + controller, |
|
1009 | 1075 | helm_extra_args=() |
1010 | 1076 | helm_post_renderer_args=() |
1011 | 1077 | helm_extra_args+=(--set "server.telemetryEnabled=${OPENSHELL_TELEMETRY_ENABLED}") |
| 1078 | +helm_extra_args+=(--set "server.sandboxImage=${KUBE_SANDBOX_IMAGE}") |
| 1079 | +helm_extra_args+=(--set "server.sandboxImagePullPolicy=${KUBE_SANDBOX_IMAGE_PULL_POLICY}") |
1012 | 1080 | if [ "${OPENSHELL_E2E_EXTERNAL_COMPUTE_DRIVER:-0}" = "1" ]; then |
1013 | 1081 | if [ "${OPENSHELL_E2E_KUBE_BUILD_IMAGES}" != "1" ]; then |
1014 | 1082 | echo "ERROR: external Kubernetes driver e2e requires OPENSHELL_E2E_KUBE_BUILD_IMAGES=1." >&2 |
|
0 commit comments