Skip to content

Commit

Permalink
feat: use windows images from artifactory
Browse files Browse the repository at this point in the history
these images will be periodically updated

Signed-off-by: Karel Simon <[email protected]>
  • Loading branch information
ksimon1 committed Oct 25, 2024
1 parent f1e5d3e commit aa7ac0f
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 110 deletions.
136 changes: 60 additions & 76 deletions automation/test-windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,71 +6,6 @@ namespace="kubevirt"
template_name="windows2k22"
username="Administrator"

dv_name="${TARGET}-datavolume-original"

oc apply -n ${namespace} -f - <<EOF
apiVersion: cdi.kubevirt.io/v1beta1
kind: DataVolume
metadata:
annotations:
cdi.kubevirt.io/storage.bind.immediate.requested: "true"
name: ${dv_name}
spec:
source:
registry:
secretRef: common-templates-container-disk-puller
url: "docker://quay.io/openshift-cnv/ci-common-templates-images:${TARGET}"
storage:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 60Gi
EOF

oc apply -f - <<EOF
---
apiVersion: v1
kind: Pod
metadata:
name: winrmcli
namespace: kubevirt
spec:
securityContext:
runAsNonRoot: true
runAsUser: 1000
containers:
- image: quay.io/kubevirt/winrmcli
command: ["/bin/sh","-c"]
args: [ "sleep 3000"]
imagePullPolicy: Always
name: winrmcli
restartPolicy: Always
---
EOF

timeout=2000
hour_timeout=3600
sample=10
current_time=0

oc wait --for=condition=Ready --timeout=${hour_timeout}s dv/${dv_name} -n $namespace

oc apply -n ${namespace} -f - <<EOF
apiVersion: cdi.kubevirt.io/v1beta1
kind: DataSource
metadata:
name: ${dv_name}
spec:
source:
pvc:
name: ${dv_name}
namespace: ${namespace}
EOF

# Make sure winrmcli pod is ready
oc wait --for=condition=Ready --timeout=${timeout}s pod/winrmcli -n $namespace

sizes=("medium" "large")
workloads=("server" "highperformance")

Expand All @@ -79,16 +14,66 @@ if [[ $TARGET =~ windows10.* ]]; then
workloads=("desktop")
elif [[ $TARGET =~ windows11.* ]]; then
template_name="windows11"
username="Administrator11"
workloads=("desktop")
elif [[ $TARGET =~ windows2016.* ]]; then
template_name="windows2k16"
elif [[ $TARGET =~ windows2019.* ]]; then
template_name="windows2k19"
elif [[ $TARGET =~ windows2022.* ]]; then
template_name="windows2k22"
elif [[ $TARGET =~ windows2025.* ]]; then
template_name="windows2k25"
fi

source_name="${TARGET}-original"
version=$(oc version -o json | jq -r '.openshiftVersion | split("\\."; null)[:2]|join(".")')

oc apply -n ${namespace} -f - <<EOF
apiVersion: image.openshift.io/v1
kind: ImageStream
metadata:
name: ${source_name}
spec:
lookupPolicy:
local: false
tags:
- from:
kind: DockerImage
name: ibmc.artifactory.cnv-qe.rhood.us/docker/kubevirt-common-instancetypes/${template_name}-container-disk:${version}
name: "${version}"
referencePolicy:
type: Source
---
apiVersion: cdi.kubevirt.io/v1beta1
kind: DataImportCron
metadata:
annotations:
"cdi.kubevirt.io/storage.bind.immediate.requested": "true"
name: ${source_name}
spec:
template:
spec:
source:
registry:
imageStream: ${source_name}
pullMethod: node
storage:
resources:
requests:
storage: 25Gi
schedule: "46 10/12 * * *"
garbageCollect: Outdated
importsToKeep: 2
managedDataSource: ${source_name}
EOF

timeout=2000
hour_timeout=3600
sample=10
current_time=0

oc wait --for=condition=UpToDate --timeout="${hour_timeout}s" "dataImportCron/${source_name}" -n "${namespace}"

delete_vm(){
vm_name=$1
set +e
Expand All @@ -111,23 +96,22 @@ run_vm(){
for i in `seq 1 3`; do
error=false

oc process -n $namespace -o json $template_name NAME=$vm_name DATA_SOURCE_NAME=${dv_name} DATA_SOURCE_NAMESPACE=${namespace} | \
oc process -n $namespace -o json $template_name NAME=$vm_name DATA_SOURCE_NAME=${source_name} DATA_SOURCE_NAMESPACE=${namespace} | \
jq '.items[0].metadata.labels["vm.kubevirt.io/template.namespace"]="kubevirt"' | \
oc apply -n $namespace -f -

# start vm
./virtctl start $vm_name -n $namespace

oc wait --for=condition=Ready --timeout=${hour_timeout}s vm/$vm_name -n $namespace

# get ip address of vm
ipAddressVMI=$(oc get vmi $vm_name -o json -n $namespace| jq -r '.status.interfaces[0].ipAddress')
./virtctl start "${vm_name}" -n "${namespace}"

oc wait --for=condition=Ready --timeout="${hour_timeout}s" "vm/${vm_name}" -n "${namespace}"

current_time=0
# run ipconfig /all command on windows vm
while [[ $(oc exec -n $namespace -i winrmcli -- ./usr/bin/winrm-cli -hostname $ipAddressVMI -port 5985 -username $username -password "Heslo123" "ipconfig /all" | grep "IPv4 Address" | wc -l ) -eq 0 ]] ; do
# run command via ssh
while [[ $(sshpass -pAdministrator ssh -o ProxyCommand="./virtctl port-forward \
--stdio=true -n ${namespace} vm/${vm_name} 33333:22" \
-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
"${username}@127.0.0.1" -p 33333 "echo Hello" | grep -c "Hello" ) != 1 ]] ; do
# VM can be stopped during test and recreated. That will change IP, so to be sure, get IP at every iteration
ipAddressVMI=$(oc get vmi $vm_name -o json -n $namespace| jq -r '.status.interfaces[0].ipAddress')
current_time=$((current_time + sample))
if [[ $current_time -gt $timeout ]]; then
error=true
Expand Down
86 changes: 52 additions & 34 deletions automation/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,58 @@ if [ -z "$TARGET" ]; then
exit 1
fi

ocenv="OC"

if [ -z "$CLUSTERENV" ]
then
export CLUSTERENV=$ocenv
fi

key="/tmp/secrets/accessKeyId"
token="/tmp/secrets/secretKey"
caBundle="/tmp/secrets/ca-bundle"
namespace="kubevirt"

if [ "${CLUSTERENV}" == "$ocenv" ]
then
if test -f "$key" && test -f "$token"; then
id=$(cat ${key} | tr -d '\n')
token=$(cat ${token} | tr -d '\n')
idBase64=$(echo -n "${id}" | base64)
token64=$(echo -n "${token}" | base64)

oc apply -n $namespace -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
name: common-templates-container-disk-puller
labels:
app: containerized-data-importer
type: Opaque
data:
accessKeyId: "${idBase64}"
secretKey: "${token64}"
EOF
if test -f "${caBundle}"; then
oc create configmap custom-ca \
--from-file=ca-bundle.crt="${caBundle}" \
-n openshift-config

oc patch proxy/cluster \
--type=merge \
--patch='{"spec":{"trustedCA":{"name":"custom-ca"}}}'

oc get secret/pull-secret -n openshift-config --template='{{index .data ".dockerconfigjson" | base64decode}}' > config.json

oc registry login --registry="ibmc.artifactory.cnv-qe.rhood.us" \
--auth-basic="${id}:${token}" \
--to=config.json

oc set data secret/pull-secret -n openshift-config --from-file=.dockerconfigjson=config.json
fi
fi
fi

# Latest released Kubevirt version
export KUBEVIRT_VERSION=$(latest_version "kubevirt")

Expand Down Expand Up @@ -108,8 +160,6 @@ EOF
oc wait --for=condition=Updated --timeout=900s machineconfigpool worker
fi

namespace="kubevirt"

_curl() {
# this dupes the baseline "curl" command line, but is simpler
# wrt shell quoting/expansion.
Expand All @@ -120,13 +170,6 @@ _curl() {
fi
}

ocenv="OC"

if [ -z "$CLUSTERENV" ]
then
export CLUSTERENV=$ocenv
fi

git submodule update --init

make generate
Expand All @@ -144,38 +187,13 @@ chmod +x virtctl
oc apply -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-operator.yaml
oc apply -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-cr.yaml

sample=10
current_time=0
timeout=600

# Waiting for kubevirt cr to report available
oc wait --for=condition=Available --timeout=${timeout}s kubevirt/kubevirt -n $namespace

oc patch kubevirt kubevirt -n $namespace --type merge -p '{"spec":{"configuration":{"developerConfiguration":{"featureGates": ["DataVolumes", "CPUManager", "NUMA", "DownwardMetrics", "VMPersistentState"]}}}}'

key="/tmp/secrets/accessKeyId"
token="/tmp/secrets/secretKey"

if [ "${CLUSTERENV}" == "$ocenv" ]
then
if test -f "$key" && test -f "$token"; then
id=$(cat $key | tr -d '\n' | base64)
token=$(cat $token | tr -d '\n' | base64 | tr -d ' \n')

oc apply -n $namespace -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
name: common-templates-container-disk-puller
labels:
app: containerized-data-importer
type: Opaque
data:
accessKeyId: "${id}"
secretKey: "${token}"
EOF
fi
fi
echo "Deploying CDI"
oc apply -f https://github.com/kubevirt/containerized-data-importer/releases/download/$CDI_VERSION/cdi-operator.yaml
oc apply -f https://github.com/kubevirt/containerized-data-importer/releases/download/$CDI_VERSION/cdi-cr.yaml
Expand Down

0 comments on commit aa7ac0f

Please sign in to comment.