mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-05 19:47:53 +00:00
Merge pull request #10370 from microsoft/danmihai1/k8s-policy-rc
tests: k8s-policy-rc: remove default UID from YAML
This commit is contained in:
commit
9a8341f431
@ -74,6 +74,12 @@ function info() {
|
|||||||
echo -e "[$(basename $0):${BASH_LINENO[0]}] INFO: $msg"
|
echo -e "[$(basename $0):${BASH_LINENO[0]}] INFO: $msg"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bats_unbuffered_info() {
|
||||||
|
local msg="$*"
|
||||||
|
# Ask bats to print this text immediately rather than buffering until the end of a test case.
|
||||||
|
echo -e "[$(basename $0):${BASH_LINENO[0]}] UNBUFFERED: INFO: $msg" >&3
|
||||||
|
}
|
||||||
|
|
||||||
function handle_error() {
|
function handle_error() {
|
||||||
local exit_code="${?}"
|
local exit_code="${?}"
|
||||||
local line_number="${1:-}"
|
local line_number="${1:-}"
|
||||||
|
@ -44,6 +44,7 @@ setup() {
|
|||||||
# Common function for all test cases from this bats script.
|
# Common function for all test cases from this bats script.
|
||||||
test_rc_policy() {
|
test_rc_policy() {
|
||||||
expect_denied_create_container=$1
|
expect_denied_create_container=$1
|
||||||
|
bats_unbuffered_info "test_rc_policy: denied=${expect_denied_create_container}: starting"
|
||||||
|
|
||||||
# Create replication controller
|
# Create replication controller
|
||||||
if [ "${expect_denied_create_container}" = "true" ]; then
|
if [ "${expect_denied_create_container}" = "true" ]; then
|
||||||
@ -54,21 +55,29 @@ test_rc_policy() {
|
|||||||
|
|
||||||
# Check replication controller
|
# Check replication controller
|
||||||
local cmd="kubectl describe rc ${replication_name} | grep replication-controller"
|
local cmd="kubectl describe rc ${replication_name} | grep replication-controller"
|
||||||
info "Waiting for: ${cmd}"
|
bats_unbuffered_info "Waiting for: ${cmd}"
|
||||||
waitForProcess "$wait_time" "$sleep_time" "$cmd"
|
waitForProcess "$wait_time" "$sleep_time" "$cmd"
|
||||||
|
|
||||||
|
bats_unbuffered_info "Getting number of replicas"
|
||||||
number_of_replicas=$(kubectl get rc ${replication_name} \
|
number_of_replicas=$(kubectl get rc ${replication_name} \
|
||||||
--output=jsonpath='{.spec.replicas}')
|
--output=jsonpath='{.spec.replicas}')
|
||||||
|
bats_unbuffered_info "number_of_replicas=${number_of_replicas}"
|
||||||
[ "${number_of_replicas}" -gt 0 ]
|
[ "${number_of_replicas}" -gt 0 ]
|
||||||
|
|
||||||
# Wait for all the expected pods to be created.
|
# Wait for all the expected pods to be created.
|
||||||
|
local pod_creation_sleep="10"
|
||||||
local count=0
|
local count=0
|
||||||
local launched_pods=()
|
local launched_pods=()
|
||||||
while [ $count -lt 6 ] && [ "${#launched_pods[@]}" -ne "${number_of_replicas}" ]; do
|
while [ $count -lt 6 ] && [ "${#launched_pods[@]}" -ne "${number_of_replicas}" ]; do
|
||||||
count=$((count + 1))
|
bats_unbuffered_info "sleep count=${count}, launched ${#launched_pods[@]} pods, sleeping ${pod_creation_sleep}..."
|
||||||
sleep 10
|
sleep "${pod_creation_sleep}"
|
||||||
|
|
||||||
|
bats_unbuffered_info "Getting the list of launched pods"
|
||||||
launched_pods=($(kubectl get pods "--selector=app=${app_name}" \
|
launched_pods=($(kubectl get pods "--selector=app=${app_name}" \
|
||||||
--output=jsonpath={.items..metadata.name}))
|
--output=jsonpath={.items..metadata.name}))
|
||||||
|
bats_unbuffered_info "Launched ${#launched_pods[@]} pods: ${launched_pods}"
|
||||||
|
|
||||||
|
count=$((count + 1))
|
||||||
done
|
done
|
||||||
|
|
||||||
# Check that the number of pods created for the replication controller
|
# Check that the number of pods created for the replication controller
|
||||||
@ -78,13 +87,16 @@ test_rc_policy() {
|
|||||||
# Check pod creation
|
# Check pod creation
|
||||||
for pod_name in ${launched_pods[@]}; do
|
for pod_name in ${launched_pods[@]}; do
|
||||||
if [ "${expect_denied_create_container}" = "true" ]; then
|
if [ "${expect_denied_create_container}" = "true" ]; then
|
||||||
|
bats_unbuffered_info "Waiting for blocked pod: ${pod_name}"
|
||||||
wait_for_blocked_request "CreateContainerRequest" "${pod_name}"
|
wait_for_blocked_request "CreateContainerRequest" "${pod_name}"
|
||||||
else
|
else
|
||||||
cmd="kubectl wait --for=condition=Ready --timeout=${timeout} pod ${pod_name}"
|
cmd="kubectl wait --for=condition=Ready --timeout=0s pod ${pod_name}"
|
||||||
info "Waiting for: ${cmd}"
|
bats_unbuffered_info "Waiting for: ${cmd}"
|
||||||
waitForProcess "${wait_time}" "${sleep_time}" "${cmd}"
|
waitForProcess "${wait_time}" "${sleep_time}" "${cmd}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
bats_unbuffered_info "test_rc_policy: denied=${expect_denied_create_container}: success"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Successful replication controller with auto-generated policy" {
|
@test "Successful replication controller with auto-generated policy" {
|
||||||
|
@ -17,8 +17,6 @@ spec:
|
|||||||
labels:
|
labels:
|
||||||
app: policy-nginx-rc
|
app: policy-nginx-rc
|
||||||
spec:
|
spec:
|
||||||
securityContext:
|
|
||||||
runAsUser: 123
|
|
||||||
terminationGracePeriodSeconds: 0
|
terminationGracePeriodSeconds: 0
|
||||||
runtimeClassName: kata
|
runtimeClassName: kata
|
||||||
containers:
|
containers:
|
||||||
|
Loading…
Reference in New Issue
Block a user