-
Notifications
You must be signed in to change notification settings - Fork 431
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
Add kubectl ko log #2451
Merged
Merged
Add kubectl ko log #2451
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1391bd3
add kubectl-ko log
changluyi db0a4d1
add e2e
changluyi 1116cde
remove -it
changluyi b9b8b6e
exec command not return err
changluyi efa8330
add "all" param for components and tail_lines
changluyi cf71edf
add sysctl and netstat
changluyi a24a59b
iptables nat and filter
changluyi 92198c2
add kubectlko log after e2e failed
changluyi 503bc94
remove merge error
changluyi e2cc4e3
refactor name
changluyi bedbe8a
add matrix param
changluyi 75778b4
remove upload
changluyi File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,15 @@ showHelp(){ | |
echo " env-check check the environment configuration" | ||
echo " tuning {install-fastpath|local-install-fastpath|remove-fastpath|install-stt|local-install-stt|remove-stt} {centos7|centos8}} [kernel-devel-version] deploy kernel optimisation components to the system" | ||
echo " reload restart all kube-ovn components" | ||
echo " log {kube-ovn|ovn|ovs|linux|all} {all|sub_component...} [tail_lines|all] | ||
kube-ovn with sub_components: kube-ovn-controller,kube-ovn-cni,kube-ovn-pinger,kube-ovn-monitor | ||
ovn with sub_components: ovn-controller,ovn-northd,ovsdb-server-nb,ovsdb-server-sb | ||
ovs with sub_components: ovs-vswitchd,ovsdb-server | ||
linux with sub_components: dmesg,iptables,route,link,neigh,memory,top,sysctl,netstat | ||
eg: kubectl ko log all all all -- show all component logs | ||
kubectl ko log all -- show all component logs with default tail_line=100 | ||
kubectl ko log kube-ovn all 1000 -- show kube-ovn all sub_component with tail_line=1000 | ||
" | ||
} | ||
|
||
# usage: ipv4_to_hex 192.168.0.1 | ||
|
@@ -940,6 +949,155 @@ env-check(){ | |
done | ||
} | ||
|
||
log_kube_ovn(){ | ||
sub_component_param=$1 | ||
tail_lines_param=$2 | ||
podNames=`kubectl get pod -n kube-system -l app=$sub_component_param -o 'jsonpath={.items[*].metadata.name}'` | ||
for pod in $podNames; do | ||
echo "************************************************" | ||
echo " component $component sub_component $sub_component_param pod $pod log" | ||
echo "************************************************" | ||
kubectl logs "$pod" -n kube-system $( [ "$tail_lines" == "all" ] || echo "--tail=$tail_lines" ) 2>&1 || : | ||
done | ||
} | ||
|
||
log_ovn_ovs(){ | ||
component_param=$1 | ||
sub_component_param=$2 | ||
tail_lines_param=$3 | ||
podNames=`kubectl get pod -n kube-system -l app=ovs -o 'jsonpath={.items[*].metadata.name}'` | ||
for pod in $podNames; do | ||
echo "************************************************" | ||
echo " component $component_param $sub_component_param.log pod $pod log" | ||
echo "************************************************" | ||
|
||
if [[ "$tail_lines" == "all" ]]; then | ||
kubectl exec $pod -n kube-system -- cat /var/log/$component_param/$sub_component_param.log 2>&1 || : | ||
else | ||
kubectl exec $pod -n kube-system -- tail -n $tail_lines_param /var/log/$component_param/$sub_component_param.log 2>&1 || : | ||
fi | ||
done | ||
} | ||
|
||
log_linux(){ | ||
sub_component_param=$1 | ||
tail_lines_param=$2 | ||
podNames=`kubectl get pod -n kube-system -l app=ovs -o 'jsonpath={.items[*].metadata.name}'` | ||
for pod in $podNames; do | ||
echo "************************************************" | ||
echo " component $component sub_component $sub_component_param pod $pod log" | ||
echo "************************************************" | ||
if [[ "$sub_component_param" == "dmesg" ]]; then | ||
kubectl exec $pod -n kube-system -- dmesg -T $( [ "$tail_lines" == "all" ] || echo "| tail -n $tail_lines_param" ) || : | ||
elif [[ "$sub_component_param" == "iptables" ]]; then | ||
echo "******************legacy filter ************************" | ||
kubectl exec $pod -n kube-system -- iptables -S || : | ||
echo "*********************nft filter ************************" | ||
kubectl exec $pod -n kube-system -- /usr/sbin/iptables-nft -S || : | ||
|
||
echo "****************** legacy nat ************************" | ||
kubectl exec $pod -n kube-system -- iptables -S -t nat || : | ||
echo "********************* nft nat ************************" | ||
kubectl exec $pod -n kube-system -- /usr/sbin/iptables-nft -S -t nat || : | ||
|
||
elif [[ "$sub_component_param" == "route" ]]; then | ||
kubectl exec $pod -n kube-system -- ip route show || : | ||
elif [[ "$sub_component_param" == "link" ]]; then | ||
kubectl exec $pod -n kube-system -- ip -d link show || : | ||
elif [[ "$sub_component_param" == "neigh" ]]; then | ||
kubectl exec $pod -n kube-system -- ip n || : | ||
elif [[ "$sub_component_param" == "memory" ]]; then | ||
kubectl exec $pod -n kube-system -- free -m || : | ||
elif [[ "$sub_component_param" == "top" ]]; then | ||
kubectl exec $pod -n kube-system -- top -b -n 1 | head -n 20 | tail -n 10 || : | ||
elif [[ "$sub_component_param" == "sysctl" ]]; then | ||
kubectl exec $pod -n kube-system -- sysctl -a || : | ||
elif [[ "$sub_component_param" == "netstat" ]]; then | ||
kubectl exec $pod -n kube-system -- netstat -tunlp || : | ||
fi | ||
done | ||
} | ||
|
||
|
||
log(){ | ||
component="$1" | ||
sub_component=${2:-all} | ||
tail_lines=${3:-100} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need a way to collect all lines. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
|
||
components=("kube-ovn" "ovs" "ovn" "linux" "all") | ||
kube_ovn_sub_components=("kube-ovn-controller" "kube-ovn-cni" "kube-ovn-pinger" "kube-ovn-monitor") | ||
ovs_sub_components=("ovs-vswitchd" "ovsdb-server") | ||
ovn_sub_components=("ovn-controller" "ovn-northd" "ovsdb-server-nb" "ovsdb-server-sb") | ||
linux_sub_components=("dmesg" "iptables" "route" "link" "neigh" "memory" "top" "sysctl" "netstat") | ||
|
||
if [[ ! " ${components[@]} " =~ " $component " ]]; then | ||
echo "invalid component $component" | ||
exit 1 | ||
fi | ||
|
||
if [[ ! "$sub_component" == "all" && ! "$components" == "all" ]]; then | ||
case $component in | ||
"kube-ovn") | ||
sub_components=("${kube_ovn_sub_components[@]}") | ||
;; | ||
"ovs") | ||
sub_components=("${ovs_sub_components[@]}") | ||
;; | ||
"ovn") | ||
sub_components=("${ovn_sub_components[@]}") | ||
;; | ||
"linux") | ||
sub_components=("${linux_sub_components[@]}") | ||
;; | ||
esac | ||
|
||
if [[ ! " ${sub_components[@]} " =~ " $sub_component " ]]; then | ||
echo "component $component do not have sub component $sub_component" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
if [[ "$component" == "kube-ovn" || "$component" == "all" ]]; then | ||
if [[ "$sub_component" == "all" ]]; then | ||
for kube_ovn_sub_component in ${kube_ovn_sub_components[@]}; do | ||
log_kube_ovn "$kube_ovn_sub_component" $tail_lines | ||
done | ||
else | ||
log_kube_ovn "$sub_component" $tail_lines | ||
fi | ||
fi | ||
|
||
if [[ "$component" == "ovn" || "$component" == "all" ]]; then | ||
if [[ "$sub_component" == "all" ]]; then | ||
for ovn_sub_component in ${ovn_sub_components[@]}; do | ||
log_ovn_ovs "ovn" "$ovn_sub_component" $tail_lines | ||
done | ||
else | ||
log_ovn_ovs "ovn" "$sub_component" $tail_lines | ||
fi | ||
fi | ||
|
||
if [[ "$component" == "ovs" || "$component" == "all" ]]; then | ||
if [[ "$sub_component" == "all" ]]; then | ||
for ovs_sub_component in ${ovs_sub_components[@]}; do | ||
log_ovn_ovs "openvswitch" "$ovs_sub_component" $tail_lines | ||
done | ||
else | ||
log_ovn_ovs "openvswitch" "$sub_component" $tail_lines | ||
fi | ||
fi | ||
|
||
if [[ "$component" == "linux" || "$component" == "all" ]]; then | ||
if [[ "$sub_component" == "all" ]]; then | ||
for linux_sub_component in ${linux_sub_components[@]}; do | ||
log_linux "$linux_sub_component" $tail_lines | ||
done | ||
else | ||
log_linux "$sub_component" $tail_lines | ||
fi | ||
fi | ||
} | ||
|
||
if [ $# -lt 1 ]; then | ||
showHelp | ||
exit 0 | ||
|
@@ -980,6 +1138,9 @@ case $subcommand in | |
env-check) | ||
env-check | ||
;; | ||
log) | ||
log "$@" | ||
;; | ||
*) | ||
showHelp | ||
exit 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.