Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e: upload container logs as artifact #825

Merged
merged 6 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/e2e_kubernetes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,18 @@ jobs:
just coordinator initializer port-forwarder openssl service-mesh-proxy node-installer
- name: E2E Test
run: |
nix run .#scripts.get-logs workspace/e2e.namespace &
nix shell -L .#contrast.e2e --command ${{ matrix.test_name }}.test -test.v \
--image-replacements workspace/just.containerlookup \
--namespace-file workspace/e2e.namespace \
--platform aks-clh-snp \
--skip-undeploy="${{ inputs.skip-undeploy && 'true' || 'false' }}"
- name: Upload logs
if: always()
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
with:
name: e2e_pod_logs-${{ matrix.test_name }}
path: workspace/namespace-logs
- name: Cleanup
if: cancelled() && !inputs.skip-undeploy
run: |
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/e2e_openssl_baremetal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,18 @@ jobs:
just coordinator initializer openssl port-forwarder node-installer K3s-QEMU-${{ matrix.tee }}
- name: E2E Test
run: |
nix run .#scripts.get-logs workspace/e2e.namespace &
nix shell .#contrast.e2e --command openssl.test -test.v \
--image-replacements workspace/just.containerlookup \
--namespace-file workspace/e2e.namespace \
--platform K3s-QEMU-${{ matrix.tee }} \
--skip-undeploy="${{ inputs.skip-undeploy && 'true' || 'false' }}"
- name: Upload logs
if: always()
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
with:
name: e2e_pod_logs
path: workspace/namespace-logs
- name: Cleanup
if: cancelled() && !inputs.skip-undeploy
run: |
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/e2e_regression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,18 @@ jobs:
fi
- name: Run regression test
run: |
nix run .#scripts.get-logs workspace/e2e.namespace &
nix shell -L .#contrast.e2e --command ${{ matrix.case }}.test -test.v \
--image-replacements workspace/just.containerlookup \
--namespace-file workspace/e2e.namespace \
--platform aks-clh-snp \
--skip-undeploy="${{ inputs.skip-undeploy && 'true' || 'false' }}"
- name: Upload logs
if: always()
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
with:
name: e2e_pod_logs-${{ matrix.case }}
path: workspace/namespace-logs
- name: Cleanup
if: cancelled() && !inputs.skip-undeploy
run: |
Expand Down
30 changes: 30 additions & 0 deletions packages/scripts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,34 @@
mv "$mergedConfig" "''${KUBECONFIG_BAK%%:*}"
'';
};

# Usage: get-logs $namespaceFile
get-logs = writeShellApplication {
name = "get-logs";
runtimeInputs = with pkgs; [ kubectl ];
text = ''
set -euo pipefail
# wait until namespace file is populated
while ! [[ -s "$1" ]]; do
sleep 1
done
namespace="$(head -n1 "$1")"
while kubectl get ns "$namespace" 1>/dev/null 2>/dev/null; do
pods="$(kubectl get pods -n "$namespace" | awk '!/^NAME/{print $1}')"
mkdir -p "workspace/namespace-logs"
for pod in $pods; do
logfile="workspace/namespace-logs/$pod.log"
if ! [[ -f "$logfile" ]]; then
{
touch "$logfile" # prevents creation of to much processes
# wait for all containers of the pod to come online, then collect the logs
kubectl wait pod --all --for=condition=Ready --timeout="-1s" -n "$namespace" "$pod" 1>/dev/null 2>/dev/null
kubectl logs -f --all-containers=true -n "$namespace" "$pod" > "$logfile"
} &
fi
done
done
wait
'';
};
}
Loading