Skip to content

Commit

Permalink
identifies tetragon pod managing a pod
Browse files Browse the repository at this point in the history
Signed-off-by: sandeshv <sandeshkv92@gmail.com>
  • Loading branch information
SandeshAmin committed Jul 5, 2024
1 parent 85842ad commit 62452ed
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions contrib/k8s-get-tetragon-pod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0
# Copyright Authors of Cilium

set -o errexit
set -o pipefail

# Given a pod name and namespace, get the corresponding tetragon pod name.

K8S_NAMESPACE="${K8S_NAMESPACE:-kube-system}"

if [[ $# -ne 2 ]]
then
echo "Usage: $(basename "$0") <pod> <namespace>" >&2
exit 1
fi
TARGET_POD_NAME="$1"
TARGET_POD_NAMESPACE="$2"

# Get the target pod's node.
target_pod_node="$(kubectl get pod "${TARGET_POD_NAME}" -n "${TARGET_POD_NAMESPACE}" --no-headers -o custom-columns=:.spec.nodeName)"
if [[ -z "${target_pod_node}" ]]
then
echo "pod ${TARGET_POD_NAMESPACE}/${TARGET_POD_NAME} has no node assigned" >&2
exit 1
fi

# Get the Cilium pod running on the target pod's node (using exact node matching).
kubectl get pods -n "${K8S_NAMESPACE}" -l app.kubernetes.io/name=tetragon --no-headers -o custom-columns=:.metadata.name,:.spec.nodeName | awk -v node="${target_pod_node}" '$2==node {print $1}'

0 comments on commit 62452ed

Please sign in to comment.