Skip to content

Commit ad32bf0

Browse files
committed
ci: use external github action for the namespace report
1 parent 60b5c5f commit ad32bf0

File tree

2 files changed

+7
-133
lines changed

2 files changed

+7
-133
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ jobs:
147147
export BINDER_URL=http://localhost:30901
148148
pytest -m "remote" -v --maxfail=10 --cov binderhub --durations=10 --color=yes
149149
150+
# GitHub Action reference: https://github.com/jupyterhub/action-k8s-namespace-report
150151
- name: Kubernetes namespace report
151-
if: ${{ always() }}
152-
run: |
153-
# Display debugging information and always provide the logs from
154-
# certain important k8s deployments.
155-
. ci/common
156-
full_namespace_report deploy/binder deploy/hub deploy/proxy
152+
uses: jupyterhub/action-k8s-namespace-report@v1
153+
if: always()
154+
with:
155+
important-workloads: deploy/binder deploy/hub deploy/proxy
157156

157+
# GitHub action reference: https://github.com/codecov/codecov-action
158158
- name: Upload coverage stats
159159
uses: codecov/codecov-action@v1
160160
if: ${{ always() }}

ci/common

Lines changed: 1 addition & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ await_jupyterhub() {
1212
&& kubectl rollout status --watch --timeout 300s deployment/hub \
1313
&& (
1414
if kubectl get deploy/autohttps > /dev/null 2>&1; then
15-
kubectl rollout status --watch --timeout 300s deployment/autohttps || exit 1
15+
kubectl rollout status --watch --timeout 300s deployment/autohttps
1616
fi
1717
)
1818
}
@@ -21,129 +21,3 @@ await_binderhub() {
2121
await_jupyterhub
2222
kubectl rollout status --watch --timeout 300s deployment/binder
2323
}
24-
25-
full_namespace_report () {
26-
# This was copied from z2jh 2021-01-06. Work to make it a dedicated GitHub
27-
# action and avoid a duplicated code base is planned. / @consideRatio
28-
# ------------------------------------------------------------------------
29-
#
30-
# Purpose:
31-
# - To chart agnostically print relevant information of the resources in a
32-
# namespace.
33-
#
34-
# Arguments:
35-
# - Accepts a sequence of arguments such as "deploy/hub" "deploy/proxy". It
36-
# will do `kubectl logs --all-containers <arg>` on them.
37-
#
38-
# Relevant references:
39-
# - ContainerStatus ref: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#containerstatus-v1-core
40-
41-
# printf formatting: a bold bold colored topic with a divider.
42-
yellow=33
43-
red=31
44-
divider='--------------------------------------------------------------------------------'
45-
# GitHub Workflows resets formatting after \n, so its reapplied.
46-
export format="\n\033[${yellow};1m%s\n\033[${yellow};1m${divider}\033[0m\n"
47-
export format_error="\n\033[${red};1m%s\n\033[${red};1m${divider}\033[0m\n"
48-
49-
printf "$format" "# Full namespace report"
50-
printf "$format" "## Resource overview"
51-
# list workloads (deployment,statefulset,daemonset,pod)
52-
printf "$format" "### \$ kubectl get deploy,sts,ds,pod"
53-
kubectl get deploy,sts,ds,pod
54-
# list config (secret,configmap)
55-
printf "$format" "### \$ kubectl get secret,cm"
56-
kubectl get secret,cm
57-
# list networking (service,ingress,networkpolicy)
58-
printf "$format" "### \$ kubectl get svc,ing,netpol"
59-
kubectl get svc,ing,netpol
60-
# list rbac (serviceaccount,role,rolebinding)
61-
printf "$format" "### \$ kubectl get sa,role,rolebinding"
62-
kubectl get sa,role,rolebinding
63-
64-
# Check if any container of any pod has a non ready status
65-
PODS_WITH_NON_READY_CONTAINER=$(
66-
kubectl get pods -o json \
67-
| jq -r '
68-
.items[]
69-
| select(
70-
any(.status.initContainerStatuses[]?; .ready == false)
71-
or
72-
any(.status.containerStatuses[]?; .ready == false)
73-
)
74-
| .metadata.name
75-
'
76-
)
77-
if [ -n "$PODS_WITH_NON_READY_CONTAINER" ]; then
78-
printf "$format_error" "## Pods with non-ready container(s) detected!"
79-
echo "$PODS_WITH_NON_READY_CONTAINER" | xargs --max-args=1 echo -
80-
81-
for var in $PODS_WITH_NON_READY_CONTAINER; do
82-
printf "$format_error" "### \$ kubectl describe pod/$var"
83-
kubectl describe pod/$var
84-
printf "$format_error" "### \$ kubectl logs --all-containers pod/$var"
85-
kubectl logs --all-containers pod/$var || echo # a newline on failure for consistency with non-failure
86-
done
87-
88-
fi
89-
90-
# Check if any container of any pod has a restartCount > 0. Then, we inspect
91-
# their logs with --previous. We also add --follow and --ignore-errors in
92-
# order to ensure we get the information from all containers, and combined
93-
# with --previous it will exit and not get stuck.
94-
#
95-
# ref: https://github.com/kubernetes/kubernetes/issues/97530
96-
PODS_WITH_RESTARTED_CONTAINERS=$(
97-
kubectl get pods -o json \
98-
| jq -r '
99-
.items[]
100-
| select(
101-
any(.status.initContainerStatuses[]?; .restartCount > 0)
102-
or
103-
any(.status.containerStatuses[]?; .restartCount > 0)
104-
)
105-
| .metadata.name
106-
'
107-
)
108-
if [ -n "$PODS_WITH_RESTARTED_CONTAINERS" ]; then
109-
printf "$format_error" "## Pods with restarted containers detected!"
110-
echo "$PODS_WITH_RESTARTED_CONTAINERS" | xargs --max-args=1 echo -
111-
112-
for var in $PODS_WITH_RESTARTED_CONTAINERS; do
113-
printf "$format_error" "### \$ kubectl describe pod/$var"
114-
kubectl describe pod/$var
115-
printf "$format_error" "### \$ kubectl logs --previous --all-containers --follow --ignore-errors pod/$var"
116-
kubectl logs --previous --all-containers --follow --ignore-errors pod/$var
117-
done
118-
fi
119-
120-
# if any pods that should be scheduled by the user-scheduler are pending ->
121-
# show user-scheduler's logs
122-
PENDING_USER_PODS=$(
123-
kubectl get pods -l "component in (user-placeholder,singleuser-server)" -o json \
124-
| jq -r '
125-
.items[]
126-
| select(.status.phase == "Pending")
127-
| .metadata.name
128-
'
129-
)
130-
if [ -n "$PENDING_USER_PODS" ]; then
131-
printf "$format_error" "## Pending pods detected!"
132-
echo "$PENDING_USER_PODS" | xargs --max-args=1 echo -
133-
134-
printf "$format_error" "### \$ kubectl logs --all-containers deploy/user-scheduler"
135-
kubectl logs --all-containers deploy/user-scheduler || echo # a newline on failure for consistency with non-failure
136-
fi
137-
138-
# show container logs of all important workloads passed to the function,
139-
# "deploy/hub" and "deploy/proxy" for example.
140-
if [ "$#" -gt 0 ]; then
141-
printf "$format" "## Important workload's logs"
142-
echo "$@" | xargs --max-args=1 echo -
143-
144-
for var in "$@"; do
145-
printf "$format" "### \$ kubectl logs --all-containers $var"
146-
kubectl logs --all-containers $var || echo # a newline on failure for consistency with non-failure
147-
done
148-
fi
149-
}

0 commit comments

Comments
 (0)