Skip to content

Commit

Permalink
Add logs for wait end times and porch package approval times to e2e t…
Browse files Browse the repository at this point in the history
…ests (#267)

* Add logs for wait ends to e2e tests

* Added logging on porchctl approve
  • Loading branch information
liamfallon authored Jun 7, 2024
1 parent 70edb08 commit 73199ca
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 3 deletions.
8 changes: 7 additions & 1 deletion e2e/lib/k8s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function k8s_wait_exists {
while [[ $lapse -gt 0 ]]; do
found=$(kubectl --kubeconfig $kubeconfig -n $resource_namespace get $resource_type $resource_name -o jsonpath='{.metadata.name}' --ignore-not-found)
if [[ $found ]]; then
info "found $resource_type $resource_namespace/$resource_name using $kubeconfig"
[ $((timeout * 2 / 3)) -lt $lapse ] || warn "$resource_namespace/$resource_name $resource_type took $lapse seconds to exist"
return
fi
Expand Down Expand Up @@ -70,6 +71,7 @@ function k8s_wait_ready {
while [[ $lapse -gt 0 ]]; do
ready=$(kubectl --kubeconfig $kubeconfig -n $resource_namespace get $resource_type $resource_name -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}' || echo)
if [[ $ready == "True" ]]; then
info "status ready on $resource_type $resource_namespace/$resource_name using $kubeconfig"
[ $((timeout * 2 / 3)) -lt $lapse ] || warn "$resource_namespace/$resource_name $resource_type took $lapse seconds to be ready"
return
fi
Expand Down Expand Up @@ -104,6 +106,7 @@ function k8s_wait_ready_replicas {
while [[ $lapse -gt 0 ]]; do
ready=$(kubectl --kubeconfig $kubeconfig -n $resource_namespace get $resource_type $resource_name -o jsonpath="{.status.$status_field}" || echo)
if [[ $ready -ge $min_ready ]]; then
info "status ready on $resource_type $resource_namespace/$resource_name using $kubeconfig"
[ $((timeout * 2 / 3)) -lt $lapse ] || warn "$resource_namespace/$resource_name $resource_type took $lapse seconds to have minimum number of replicas"
return
fi
Expand Down Expand Up @@ -136,7 +139,10 @@ function k8s_exec {

info "executing command $command on $resource_name in namespace $resource_namespace using $kubeconfig"
kubectl --kubeconfig $kubeconfig -n $resource_namespace exec $resource_name -- /bin/bash -c "$command"
return $?
result=$?
info "executed command $command on $resource_name in namespace $resource_namespace using $kubeconfig"

return $result
}

function _k8s_absolute_unit {
Expand Down
2 changes: 2 additions & 0 deletions e2e/lib/kpt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function _wait_for_user_repo {
while [[ $lapse -gt 0 ]]; do
found=$(curl_gitea_api "repos/$user/$repo" 'import json; import sys; print("full_name" in json.loads(sys.stdin.read()))')
if [[ $found == "True" ]]; then
info "found $repo repository of $user user"
[ $((timeout * 2 / 3)) -lt $lapse ] || warn "$user user took $lapse seconds to exist in $repo repository"
return
fi
Expand All @@ -57,6 +58,7 @@ function kpt_wait_pkg {
while [[ $lapse -gt 0 ]]; do
found=$(curl_gitea_api "repos/$user/$repo/contents" "import json; import sys; print('$pkg' in [dir['path'] for dir in json.loads(sys.stdin.read()) if dir['type'] == 'dir' ])")
if [[ $found == "True" ]]; then
info "found $pkg kpt package on $user/$repo repository"
[ $((timeout * 2 / 3)) -lt $lapse ] || warn "$pkg kpt package took $lapse seconds to exist"
return
fi
Expand Down
1 change: 1 addition & 0 deletions e2e/lib/porch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function porch_wait_published_packagerev {
fi
done
if [[ $found ]]; then
info "found package published revision on $pkg_name"
[ $((timeout * 2 / 3)) -lt $lapse ] || warn "$pkg_name package took $lapse seconds to be published"
break
fi
Expand Down
4 changes: 4 additions & 0 deletions e2e/tests/free5gc/001.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ assert_commit_msg_in_branch "Intermediate commit" "proposed/regional/v1"
assert_workload_resource_contains "proposed/regional/v1" "nephio.org/site-type: regional" "Workload cluster has not been transformed properly to proposed"

# Approval
info "approving package $regional_pkg_rev"
porchctl rpkg approve -n default "$regional_pkg_rev"
info "approved package $regional_pkg_rev"
kubectl wait --for jsonpath='{.spec.lifecycle}'=Published packagerevisions "$regional_pkg_rev" --timeout="600s"
info "published package $regional_pkg_rev"

assert_workload_resource_contains "main" "nephio.org/site-type: regional" "Workload cluster has not been successfully merged into main branch"

k8s_wait_exists "workloadcluster" "regional"
Expand Down
3 changes: 3 additions & 0 deletions e2e/tests/free5gc/003.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ kubectl wait --for jsonpath='{.spec.lifecycle}'=Proposed packagerevisions "$pkg_
assert_branch_exists "proposed/free5gc-cp/v1" "nephio/regional"
assert_commit_msg_in_branch "Intermediate commit" "proposed/free5gc-cp/v1" "nephio/regional"

info "approving package $pkg_rev"
porchctl rpkg approve -n default "$pkg_rev"
info "approved package $pkg_rev"
kubectl wait --for jsonpath='{.spec.lifecycle}'=Published packagerevisions "$pkg_rev" --timeout="600s"
info "published package $pkg_rev"

kpt_wait_pkg "regional" "free5gc-cp"
k8s_wait_ready_replicas "statefulset" "mongodb" "$(k8s_get_capi_kubeconfig "regional")" "free5gc-cp"
5 changes: 4 additions & 1 deletion e2e/tests/free5gc/008.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ info "Proposing $upf_pkg_rev update"
porchctl rpkg propose -n default "$upf_pkg_rev"
k8s_wait_exists "packagerev" "$upf_pkg_rev"

info "Approving $upf_pkg_rev update"
info "approving package $upf_pkg_rev update"
porchctl rpkg approve -n default "$upf_pkg_rev"
info "approved package $upf_pkg_rev update"
kubectl wait --for jsonpath='{.spec.lifecycle}'=Published packagerevisions "$upf_pkg_rev" --timeout="600s"
info "published package $upf_pkg_rev update"

# Get current UPF pod state after scaling
k8s_wait_ready_replicas "deployment" "upf-edge01" "$cluster_kubeconfig" "free5gc-upf"
Expand Down
6 changes: 5 additions & 1 deletion e2e/tests/free5gc/009.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ while [[ $retries -gt 0 ]]; do
fi

if [[ $modified == false ]]; then
info "Approving update"
info "approving package $smf_pkg_rev update"
output=$(porchctl rpkg approve -n default "$smf_pkg_rev" 2>&1)
info "approved package $smf_pkg_rev update"
kubectl wait --for jsonpath='{.spec.lifecycle}'=Published packagerevisions "$smf_pkg_rev" --timeout="600s"
info "published package $smf_pkg_rev update"

if [[ $output =~ "modified" ]]; then
modified=true
fi
Expand Down
3 changes: 3 additions & 0 deletions e2e/tests/oai/001b-infra-metal-lb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ function _define_ip_address_pool {
assert_commit_msg_in_branch "Intermediate commit" "proposed/$cluster-metallb-sandbox-config/v1" "nephio/mgmt-staging"

# Approval
info "approving package $pkg_rev update"
porchctl rpkg approve -n default "$pkg_rev"
info "approved package $pkg_rev update"
kubectl wait --for jsonpath='{.spec.lifecycle}'=Published packagerevisions "$pkg_rev" --timeout="600s"
info "published package $pkg_rev update"
}

_define_ip_address_pool "core" "172.18.16.0/20"

0 comments on commit 73199ca

Please sign in to comment.