-
Notifications
You must be signed in to change notification settings - Fork 16
cilium-dbg exec commands missing -n kube-system namespace flag #54
Copy link
Copy link
Open
Description
cilium-dbg exec commands missing -n kube-system namespace flag
Bug Description
The runCiliumDbgCommandWithContext function in pkg/cilium/cilium.go finds the cilium pod using -n kube-system but then runs kubectl exec without specifying the namespace. This causes all cilium-dbg based tools to fail when the kagent-tools pod runs in a different namespace.
Root Cause
In pkg/cilium/cilium.go, line 604-628:
func getCiliumPodNameWithContext(ctx context.Context, nodeName string) (string, error) {
args := []string{"get", "pods", "-n", "kube-system", "--selector=k8s-app=cilium", ...}
// ✅ correctly uses -n kube-system to find the pod
...
}
func runCiliumDbgCommandWithContext(ctx context.Context, command, nodeName string) (string, error) {
podName, err := getCiliumPodNameWithContext(ctx, nodeName)
...
args := []string{"exec", "-it", podName, "--", "cilium-dbg", command}
// ❌ missing -n kube-system
// ❌ -it flag causes issues in non-interactive/automated contexts
...
}The pod name is resolved correctly from kube-system, but the subsequent kubectl exec defaults to the namespace of the kagent-tools pod (e.g. kagent-tools), so it fails with:
Error from server (NotFound): pods "cilium-rwzxv" not found
Reproduction
- Deploy kagent-tools in a namespace other than
kube-system(e.g.kagent-tools) - Call any cilium debug tool (e.g.
cilium_get_endpoints_list,cilium_get_endpoint_health) with a validnode_name - The tool finds the cilium pod name but
kubectl execfails because it looks in the wrong namespace
Manual verification:
# Fails (no namespace specified, defaults to kagent-tools ns):
kubectl exec cilium-rwzxv -- cilium-dbg endpoint list
# Error from server (NotFound): pods "cilium-rwzxv" not found
# Works (with namespace):
kubectl exec cilium-rwzxv -n kube-system -- cilium-dbg endpoint list
# ENDPOINT POLICY (ingress) ...Affected Tools
All tools that go through runCiliumDbgCommandWithContext:
cilium_get_endpoints_listcilium_get_endpoint_healthcilium_get_endpoint_detailscilium_get_endpoint_logscilium_list_identitiescilium_get_identity_detailscilium_request_debugging_informationcilium_display_encryption_statecilium_get_daemon_statuscilium_show_configuration_optionscilium_list_envoy_configcilium_fqdn_cachecilium_show_dns_namescilium_list_ip_addressescilium_show_ip_cache_informationcilium_list_bpf_map_eventscilium_list_bpf_mapscilium_get_bpf_mapcilium_list_metricscilium_list_cluster_nodescilium_list_node_idscilium_list_servicescilium_get_service_informationcilium_display_policy_node_informationcilium_display_selectorscilium_list_pcap_recorderscilium_get_pcap_recorder- And all write variants
Suggested Fix
func runCiliumDbgCommandWithContext(ctx context.Context, command, nodeName string) (string, error) {
podName, err := getCiliumPodNameWithContext(ctx, nodeName)
if err != nil {
return "", err
}
args := []string{"exec", "-n", "kube-system", podName, "--", "cilium-dbg", command}
kubeconfigPath := utils.GetKubeconfig()
return commands.NewCommandBuilder("kubectl").
WithArgs(args...).
WithKubeconfig(kubeconfigPath).
Execute(ctx)
}Changes:
- Add
-n kube-systemto thekubectl execcommand - Remove
-itflag (not needed for non-interactive execution, can cause TTY errors)
Environment
- kagent-tools chart version: 0.1.2
- kagent-tools deployed in namespace:
kagent-tools - Cilium pods running in:
kube-system
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels