fix: add retry logic to kubectl-ko getOvnCentralPod for leader election#6351
fix: add retry logic to kubectl-ko getOvnCentralPod for leader election#6351
Conversation
getOvnCentralPod() would crash silently during OVN leader election transitions. Under `set -euo pipefail`, when no pod had the leader label (e.g. ovn-nb-leader=true), `grep ovn-central` in the pipeline returned exit code 1, causing the script to exit immediately without any error message. This made kubectl-ko trace and other subcommands fail intermittently in e2e tests. Extract a getLeaderPod() helper that retries up to 10 times with 1s intervals, protecting the pipeline with `set +o pipefail` and suppressing kubectl stderr noise. Also fix NORTHD_POD query to use $KUBE_OVN_NS instead of hardcoded kube-system. Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello @oilbeater, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the robustness of the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a robust retry mechanism for finding OVN leader pods in the kubectl-ko script, addressing intermittent failures during leader elections. The changes include a new getLeaderPod helper function that handles transient states gracefully. The hardcoded kube-system namespace has also been correctly replaced with the $KUBE_OVN_NS variable. My review includes a suggestion to improve the pod selection logic for better robustness.
| local result= | ||
| for i in $(seq 1 10); do | ||
| set +o pipefail | ||
| result=$(kubectl get pod -n $KUBE_OVN_NS -l "$label"=true 2>/dev/null | grep ovn-central | awk '{if($2=="1/1" && $3=="Running") print $1}' | head -n 1) |
There was a problem hiding this comment.
Using grep to filter pods by name can be brittle. It's better to use a more specific label selector with kubectl to ensure you're selecting the correct pods. The ovn-central pods have the app=ovn-central label, which can be used for more precise selection.
| result=$(kubectl get pod -n $KUBE_OVN_NS -l "$label"=true 2>/dev/null | grep ovn-central | awk '{if($2=="1/1" && $3=="Running") print $1}' | head -n 1) | |
| result=$(kubectl get pod -n $KUBE_OVN_NS -l "app=ovn-central,$label=true" 2>/dev/null | awk '{if($2=="1/1" && $3=="Running") print $1}' | head -n 1) |
Summary
getOvnCentralPod()inkubectl-koscript crashed silently during OVN leader election transitions, causingkubectl ko traceand other subcommands to fail intermittently in e2e testsset -euo pipefail, when no pod had the leader label (e.g.ovn-nb-leader=true),grep ovn-centralreturned exit code 1, causing the script to exit immediately — the error handling code (if [ -z "$NB_POD" ]) was unreachable dead codegetLeaderPod()helper with retry logic (up to 10 attempts, 1s interval),set +o pipefailprotection, and stderr suppression$KUBE_OVN_NSinstead of hardcodedkube-systemTest plan
kubectl ko traceworks correctly when leader labels are stablekubectl ko tracerecovers during transient leader election (e.g., afterkubectl delete podof ovn-central leader)🤖 Generated with Claude Code