Skip to content

Commit

Permalink
test: migrate tests to HostProcess pods
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-ding committed Oct 24, 2022
1 parent cf83608 commit 67e7a12
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
27 changes: 27 additions & 0 deletions scripts/integration-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: v1
kind: Pod
metadata:
name: integration-test
labels:
app: integration-test
spec:
nodeName: windows_node # to be replaced by sed
securityContext:
windowsOptions:
hostProcess: true
runAsUserName: "NT AUTHORITY\\SYSTEM"
hostNetwork: true
containers:
- name: agnhost
image: mcr.microsoft.com/windows/servercore:ltsc2019
command: ['powershell', '-command', 'Start-Sleep 100000']
volumeMounts:
- mountPath: /integration-test
name: integration-test-volume
nodeSelector:
kubernetes.io/os: windows
volumes:
- name: integration-test-volume
hostPath:
path: /
type: DirectoryOrCreate
19 changes: 12 additions & 7 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if ! [ -z "${GCP_ZONE:-}" ]; then
fi

sync_file_to_vm() {
gcloud compute scp $@ $windows_node:"C:\\Users\\${current_account}"
gcloud compute scp $@ $windows_node:"C:\\"
}

compile_csi_proxy_integration_tests() {
Expand All @@ -25,6 +25,10 @@ compile_csi_proxy_integration_tests() {
}

sync_csi_proxy_integration_tests() {
# delete the pod that is potentially using the old file
# if there is a pod accessing the existing file, this command would hang
kubectl delete -f $pkgdir/scripts/integration-test.yaml --ignore-not-found=true

echo "Sync the integrationtests.exe binary"
local integration_bin_path="$pkgdir/bin/integrationtests.test.exe"
sync_file_to_vm $integration_bin_path
Expand All @@ -33,12 +37,13 @@ sync_csi_proxy_integration_tests() {
run_csi_proxy_integration_tests() {
echo "Run integration tests"
local ps1=$(cat << 'EOF'
"& {
$ErrorActionPreference = \"Stop\";
.\integrationtests.test.exe --test.v
}"
$ErrorActionPreference = "Stop";
.$Env:CONTAINER_SANDBOX_MOUNT_POINT\integration-test\integrationtests.test.exe --test.v
EOF
);

gcloud compute ssh $windows_node --command="powershell -c $(echo $ps1 | tr '\n' ' ')"
kubectl delete -f $pkgdir/scripts/integration-test.yaml --ignore-not-found=true
sed "s/windows_node/$windows_node/g" < <(cat $pkgdir/scripts/integration-test.yaml) | kubectl create -f -
kubectl wait --for=condition=ready pod -l app=integration-test --timeout=600s
kubectl exec pods/integration-test -- powershell -c $(echo $ps1 | tr '\n' ' ')
}

0 comments on commit 67e7a12

Please sign in to comment.