mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-02 01:16:27 +00:00
Merge pull request #9128 from microsoft/danmihai1/test-genpolicy
tests: k8s: auto-generated policy
This commit is contained in:
@@ -12,14 +12,20 @@ setup() {
|
|||||||
get_pod_config_dir
|
get_pod_config_dir
|
||||||
job_name="jobtest"
|
job_name="jobtest"
|
||||||
names=( "test1" "test2" "test3" )
|
names=( "test1" "test2" "test3" )
|
||||||
|
|
||||||
|
# Create genpolicy settings - common for all of the test jobs
|
||||||
|
policy_settings_dir="$(create_tmp_policy_settings_dir "${pod_config_dir}")"
|
||||||
|
add_requests_to_policy_settings "${policy_settings_dir}" "ReadStreamRequest"
|
||||||
|
|
||||||
|
# Create yaml files
|
||||||
|
for i in "${names[@]}"; do
|
||||||
|
yaml_file="${pod_config_dir}/job-$i.yaml"
|
||||||
|
sed "s/\$ITEM/$i/" ${pod_config_dir}/job-template.yaml > ${yaml_file}
|
||||||
|
auto_generate_policy "${policy_settings_dir}" "${yaml_file}"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Parallel jobs" {
|
@test "Parallel jobs" {
|
||||||
# Create yaml files
|
|
||||||
for i in "${names[@]}"; do
|
|
||||||
sed "s/\$ITEM/$i/" ${pod_config_dir}/job-template.yaml > ${pod_config_dir}/job-$i.yaml
|
|
||||||
done
|
|
||||||
|
|
||||||
# Create the jobs
|
# Create the jobs
|
||||||
for i in "${names[@]}"; do
|
for i in "${names[@]}"; do
|
||||||
kubectl create -f "${pod_config_dir}/job-$i.yaml"
|
kubectl create -f "${pod_config_dir}/job-$i.yaml"
|
||||||
@@ -45,4 +51,6 @@ teardown() {
|
|||||||
for i in "${names[@]}"; do
|
for i in "${names[@]}"; do
|
||||||
rm -f ${pod_config_dir}/job-$i.yaml
|
rm -f ${pod_config_dir}/job-$i.yaml
|
||||||
done
|
done
|
||||||
|
|
||||||
|
delete_tmp_policy_settings_dir "${policy_settings_dir}"
|
||||||
}
|
}
|
||||||
|
@@ -16,9 +16,15 @@ setup() {
|
|||||||
|
|
||||||
@test "Guaranteed QoS" {
|
@test "Guaranteed QoS" {
|
||||||
pod_name="qos-test"
|
pod_name="qos-test"
|
||||||
|
yaml_file="${pod_config_dir}/pod-guaranteed.yaml"
|
||||||
|
|
||||||
|
# Add policy to the yaml file
|
||||||
|
policy_settings_dir="$(create_tmp_policy_settings_dir "${pod_config_dir}")"
|
||||||
|
add_requests_to_policy_settings "${policy_settings_dir}" "ReadStreamRequest"
|
||||||
|
auto_generate_policy "${policy_settings_dir}" "${yaml_file}"
|
||||||
|
|
||||||
# Create pod
|
# Create pod
|
||||||
kubectl create -f "${pod_config_dir}/pod-guaranteed.yaml"
|
kubectl create -f "${yaml_file}"
|
||||||
|
|
||||||
# Check pod creation
|
# Check pod creation
|
||||||
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
||||||
@@ -29,9 +35,15 @@ setup() {
|
|||||||
|
|
||||||
@test "Burstable QoS" {
|
@test "Burstable QoS" {
|
||||||
pod_name="burstable-test"
|
pod_name="burstable-test"
|
||||||
|
yaml_file="${pod_config_dir}/pod-burstable.yaml"
|
||||||
|
|
||||||
|
# Add policy to the yaml file
|
||||||
|
policy_settings_dir="$(create_tmp_policy_settings_dir "${pod_config_dir}")"
|
||||||
|
add_requests_to_policy_settings "${policy_settings_dir}" "ReadStreamRequest"
|
||||||
|
auto_generate_policy "${policy_settings_dir}" "${yaml_file}"
|
||||||
|
|
||||||
# Create pod
|
# Create pod
|
||||||
kubectl create -f "${pod_config_dir}/pod-burstable.yaml"
|
kubectl create -f "${yaml_file}"
|
||||||
|
|
||||||
# Check pod creation
|
# Check pod creation
|
||||||
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
||||||
@@ -42,9 +54,15 @@ setup() {
|
|||||||
|
|
||||||
@test "BestEffort QoS" {
|
@test "BestEffort QoS" {
|
||||||
pod_name="besteffort-test"
|
pod_name="besteffort-test"
|
||||||
|
yaml_file="${pod_config_dir}/pod-besteffort.yaml"
|
||||||
|
|
||||||
|
# Add policy to the yaml file
|
||||||
|
policy_settings_dir="$(create_tmp_policy_settings_dir "${pod_config_dir}")"
|
||||||
|
add_requests_to_policy_settings "${policy_settings_dir}" "ReadStreamRequest"
|
||||||
|
auto_generate_policy "${policy_settings_dir}" "${yaml_file}"
|
||||||
|
|
||||||
# Create pod
|
# Create pod
|
||||||
kubectl create -f "${pod_config_dir}/pod-besteffort.yaml"
|
kubectl create -f "${yaml_file}"
|
||||||
|
|
||||||
# Check pod creation
|
# Check pod creation
|
||||||
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
|
||||||
@@ -55,4 +73,5 @@ setup() {
|
|||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
kubectl delete pod "$pod_name"
|
kubectl delete pod "$pod_name"
|
||||||
|
delete_tmp_policy_settings_dir "${policy_settings_dir}"
|
||||||
}
|
}
|
||||||
|
@@ -13,17 +13,23 @@ setup() {
|
|||||||
nginx_image="nginx:$nginx_version"
|
nginx_image="nginx:$nginx_version"
|
||||||
|
|
||||||
get_pod_config_dir
|
get_pod_config_dir
|
||||||
|
|
||||||
|
# Create yaml
|
||||||
|
test_yaml="${pod_config_dir}/test-replication-controller.yaml"
|
||||||
|
sed -e "s/\${nginx_version}/${nginx_image}/" \
|
||||||
|
"${pod_config_dir}/replication-controller.yaml" > "${test_yaml}"
|
||||||
|
|
||||||
|
# Add policy to the yaml file
|
||||||
|
policy_settings_dir="$(create_tmp_policy_settings_dir "${pod_config_dir}")"
|
||||||
|
add_requests_to_policy_settings "${policy_settings_dir}" "ReadStreamRequest"
|
||||||
|
auto_generate_policy "${policy_settings_dir}" "${test_yaml}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Replication controller" {
|
@test "Replication controller" {
|
||||||
replication_name="replicationtest"
|
replication_name="replicationtest"
|
||||||
|
|
||||||
# Create yaml
|
|
||||||
sed -e "s/\${nginx_version}/${nginx_image}/" \
|
|
||||||
"${pod_config_dir}/replication-controller.yaml" > "${pod_config_dir}/test-replication-controller.yaml"
|
|
||||||
|
|
||||||
# Create replication controller
|
# Create replication controller
|
||||||
kubectl create -f "${pod_config_dir}/test-replication-controller.yaml"
|
kubectl create -f "${test_yaml}"
|
||||||
|
|
||||||
# Check replication controller
|
# Check replication controller
|
||||||
local cmd="kubectl describe replicationcontrollers/$replication_name | grep replication-controller"
|
local cmd="kubectl describe replicationcontrollers/$replication_name | grep replication-controller"
|
||||||
@@ -57,6 +63,7 @@ teardown() {
|
|||||||
# Debugging information
|
# Debugging information
|
||||||
kubectl describe replicationcontrollers/"$replication_name"
|
kubectl describe replicationcontrollers/"$replication_name"
|
||||||
|
|
||||||
rm -f "${pod_config_dir}/test-replication-controller.yaml"
|
rm -f "${test_yaml}"
|
||||||
kubectl delete rc "$replication_name"
|
kubectl delete rc "$replication_name"
|
||||||
|
delete_tmp_policy_settings_dir "${policy_settings_dir}"
|
||||||
}
|
}
|
||||||
|
@@ -14,14 +14,20 @@ setup() {
|
|||||||
replicas="3"
|
replicas="3"
|
||||||
deployment="nginx-deployment"
|
deployment="nginx-deployment"
|
||||||
get_pod_config_dir
|
get_pod_config_dir
|
||||||
|
|
||||||
|
# Create the yaml file
|
||||||
|
test_yaml="${pod_config_dir}/test-${deployment}.yaml"
|
||||||
|
sed -e "s/\${nginx_version}/${nginx_image}/" \
|
||||||
|
"${pod_config_dir}/${deployment}.yaml" > "${test_yaml}"
|
||||||
|
|
||||||
|
# Add policy to the yaml file
|
||||||
|
policy_settings_dir="$(create_tmp_policy_settings_dir "${pod_config_dir}")"
|
||||||
|
add_requests_to_policy_settings "${policy_settings_dir}" "ReadStreamRequest"
|
||||||
|
auto_generate_policy "${policy_settings_dir}" "${test_yaml}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Scale nginx deployment" {
|
@test "Scale nginx deployment" {
|
||||||
|
kubectl create -f "${test_yaml}"
|
||||||
sed -e "s/\${nginx_version}/${nginx_image}/" \
|
|
||||||
"${pod_config_dir}/${deployment}.yaml" > "${pod_config_dir}/test-${deployment}.yaml"
|
|
||||||
|
|
||||||
kubectl create -f "${pod_config_dir}/test-${deployment}.yaml"
|
|
||||||
kubectl wait --for=condition=Available --timeout=$timeout deployment/${deployment}
|
kubectl wait --for=condition=Available --timeout=$timeout deployment/${deployment}
|
||||||
kubectl expose deployment/${deployment}
|
kubectl expose deployment/${deployment}
|
||||||
kubectl scale deployment/${deployment} --replicas=${replicas}
|
kubectl scale deployment/${deployment} --replicas=${replicas}
|
||||||
@@ -30,7 +36,8 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
rm -f "${pod_config_dir}/test-${deployment}.yaml"
|
rm -f "${test_yaml}"
|
||||||
kubectl delete deployment "$deployment"
|
kubectl delete deployment "$deployment"
|
||||||
kubectl delete service "$deployment"
|
kubectl delete service "$deployment"
|
||||||
|
delete_tmp_policy_settings_dir "${policy_settings_dir}"
|
||||||
}
|
}
|
||||||
|
@@ -16,15 +16,25 @@ setup() {
|
|||||||
pod_name="test-shared-volume"
|
pod_name="test-shared-volume"
|
||||||
first_container_name="busybox-first-container"
|
first_container_name="busybox-first-container"
|
||||||
second_container_name="busybox-second-container"
|
second_container_name="busybox-second-container"
|
||||||
|
cmd="cat /tmp/pod-data"
|
||||||
|
yaml_file="${pod_config_dir}/pod-shared-volume.yaml"
|
||||||
|
|
||||||
|
# Add policy to the yaml file
|
||||||
|
policy_settings_dir="$(create_tmp_policy_settings_dir "${pod_config_dir}")"
|
||||||
|
|
||||||
|
exec_command="sh -c ${cmd}"
|
||||||
|
add_exec_to_policy_settings "${policy_settings_dir}" "${exec_command}"
|
||||||
|
|
||||||
|
add_requests_to_policy_settings "${policy_settings_dir}" "ReadStreamRequest"
|
||||||
|
auto_generate_policy "${policy_settings_dir}" "${yaml_file}"
|
||||||
|
|
||||||
# Create pod
|
# Create pod
|
||||||
kubectl create -f "${pod_config_dir}/pod-shared-volume.yaml"
|
kubectl create -f "${yaml_file}"
|
||||||
|
|
||||||
# Check pods
|
# Check pods
|
||||||
kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name
|
kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name
|
||||||
|
|
||||||
# Communicate containers
|
# Communicate containers
|
||||||
cmd="cat /tmp/pod-data"
|
|
||||||
msg="Hello from the $second_container_name"
|
msg="Hello from the $second_container_name"
|
||||||
kubectl exec "$pod_name" -c "$first_container_name" -- sh -c "$cmd" | grep "$msg"
|
kubectl exec "$pod_name" -c "$first_container_name" -- sh -c "$cmd" | grep "$msg"
|
||||||
}
|
}
|
||||||
@@ -32,20 +42,31 @@ setup() {
|
|||||||
@test "initContainer with shared volume" {
|
@test "initContainer with shared volume" {
|
||||||
pod_name="initcontainer-shared-volume"
|
pod_name="initcontainer-shared-volume"
|
||||||
last_container="last"
|
last_container="last"
|
||||||
|
cmd='test $(cat /volume/initContainer) -lt $(cat /volume/container)'
|
||||||
|
yaml_file="${pod_config_dir}/initContainer-shared-volume.yaml"
|
||||||
|
|
||||||
|
# Add policy to the yaml file
|
||||||
|
policy_settings_dir="$(create_tmp_policy_settings_dir "${pod_config_dir}")"
|
||||||
|
|
||||||
|
exec_command="sh -c ${cmd}"
|
||||||
|
add_exec_to_policy_settings "${policy_settings_dir}" "${exec_command}"
|
||||||
|
|
||||||
|
add_requests_to_policy_settings "${policy_settings_dir}" "ReadStreamRequest"
|
||||||
|
auto_generate_policy "${policy_settings_dir}" "${yaml_file}"
|
||||||
|
|
||||||
# Create pod
|
# Create pod
|
||||||
kubectl create -f "${pod_config_dir}/initContainer-shared-volume.yaml"
|
kubectl create -f "${yaml_file}"
|
||||||
|
|
||||||
# Check pods
|
# Check pods
|
||||||
kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name
|
kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name
|
||||||
|
|
||||||
cmd='test $(cat /volume/initContainer) -lt $(cat /volume/container)'
|
|
||||||
kubectl exec "$pod_name" -c "$last_container" -- sh -c "$cmd"
|
kubectl exec "$pod_name" -c "$last_container" -- sh -c "$cmd"
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
# Debugging information
|
# Debugging information
|
||||||
kubectl describe "pod/$pod_name"
|
kubectl describe "pod/$pod_name" || true
|
||||||
|
|
||||||
kubectl delete pod "$pod_name"
|
kubectl delete pod "$pod_name" || true
|
||||||
|
delete_tmp_policy_settings_dir "${policy_settings_dir}"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user