Merge pull request #9128 from microsoft/danmihai1/test-genpolicy

tests: k8s: auto-generated policy
This commit is contained in:
Dan Mihai
2024-03-07 08:50:47 -08:00
committed by GitHub
5 changed files with 88 additions and 26 deletions

View File

@@ -12,14 +12,20 @@ setup() {
get_pod_config_dir
job_name="jobtest"
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" {
# 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
for i in "${names[@]}"; do
kubectl create -f "${pod_config_dir}/job-$i.yaml"
@@ -45,4 +51,6 @@ teardown() {
for i in "${names[@]}"; do
rm -f ${pod_config_dir}/job-$i.yaml
done
delete_tmp_policy_settings_dir "${policy_settings_dir}"
}

View File

@@ -16,9 +16,15 @@ setup() {
@test "Guaranteed QoS" {
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
kubectl create -f "${pod_config_dir}/pod-guaranteed.yaml"
kubectl create -f "${yaml_file}"
# Check pod creation
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
@@ -29,9 +35,15 @@ setup() {
@test "Burstable QoS" {
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
kubectl create -f "${pod_config_dir}/pod-burstable.yaml"
kubectl create -f "${yaml_file}"
# Check pod creation
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
@@ -42,9 +54,15 @@ setup() {
@test "BestEffort QoS" {
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
kubectl create -f "${pod_config_dir}/pod-besteffort.yaml"
kubectl create -f "${yaml_file}"
# Check pod creation
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
@@ -55,4 +73,5 @@ setup() {
teardown() {
kubectl delete pod "$pod_name"
delete_tmp_policy_settings_dir "${policy_settings_dir}"
}

View File

@@ -13,17 +13,23 @@ setup() {
nginx_image="nginx:$nginx_version"
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" {
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
kubectl create -f "${pod_config_dir}/test-replication-controller.yaml"
kubectl create -f "${test_yaml}"
# Check replication controller
local cmd="kubectl describe replicationcontrollers/$replication_name | grep replication-controller"
@@ -57,6 +63,7 @@ teardown() {
# Debugging information
kubectl describe replicationcontrollers/"$replication_name"
rm -f "${pod_config_dir}/test-replication-controller.yaml"
rm -f "${test_yaml}"
kubectl delete rc "$replication_name"
delete_tmp_policy_settings_dir "${policy_settings_dir}"
}

View File

@@ -14,14 +14,20 @@ setup() {
replicas="3"
deployment="nginx-deployment"
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" {
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 create -f "${test_yaml}"
kubectl wait --for=condition=Available --timeout=$timeout deployment/${deployment}
kubectl expose deployment/${deployment}
kubectl scale deployment/${deployment} --replicas=${replicas}
@@ -30,7 +36,8 @@ setup() {
}
teardown() {
rm -f "${pod_config_dir}/test-${deployment}.yaml"
rm -f "${test_yaml}"
kubectl delete deployment "$deployment"
kubectl delete service "$deployment"
delete_tmp_policy_settings_dir "${policy_settings_dir}"
}

View File

@@ -16,15 +16,25 @@ setup() {
pod_name="test-shared-volume"
first_container_name="busybox-first-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
kubectl create -f "${pod_config_dir}/pod-shared-volume.yaml"
kubectl create -f "${yaml_file}"
# Check pods
kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name
# Communicate containers
cmd="cat /tmp/pod-data"
msg="Hello from the $second_container_name"
kubectl exec "$pod_name" -c "$first_container_name" -- sh -c "$cmd" | grep "$msg"
}
@@ -32,20 +42,31 @@ setup() {
@test "initContainer with shared volume" {
pod_name="initcontainer-shared-volume"
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
kubectl create -f "${pod_config_dir}/initContainer-shared-volume.yaml"
kubectl create -f "${yaml_file}"
# Check pods
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"
}
teardown() {
# 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}"
}