Skip to content

Commit

Permalink
kubectl-ko: get ovn db leaders only on necessary (#3158)
Browse files Browse the repository at this point in the history
* kubectl-ko: get ovn db leaders only on necessary
* kubectl-ko: apply yaml from stdin

---------

Signed-off-by: 张祖建 <[email protected]>
  • Loading branch information
zhangzujian committed Aug 23, 2023
1 parent a5c8510 commit 5172b62
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 66 deletions.
61 changes: 16 additions & 45 deletions dist/images/kubectl-ko
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ OVN_NB_POD=
OVN_SB_POD=
OVN_NORTHD_POD=
KUBE_OVN_VERSION=
REGISTRY="kubeovn"
REGISTRY="docker.io/kubeovn"
PERF_TIMES=5
PERF_LABEL="PerfTest"
CONN_CHECK_LABEL="conn-check"
Expand Down Expand Up @@ -36,7 +36,7 @@ showHelp(){
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} save log to ./kubectl-ko-log/"
echo " perf [image] performance test default image is kubeovn/test:v1.12.0"
echo " perf [image] performance test default image is docker.io/kubeovn/test:v1.13.0"
}

# usage: ipv4_to_hex 192.168.0.1
Expand Down Expand Up @@ -509,8 +509,7 @@ applyConnServerDaemonset(){
fi

imageID=$(kubectl get ds -n $KUBE_OVN_NS kube-ovn-pinger -o jsonpath={.spec.template.spec.containers[0].image})
tmpFileName="conn-server.yaml"
cat <<EOF > $tmpFileName
cat <<EOF | kubectl apply -f -
kind: DaemonSet
apiVersion: apps/v1
metadata:
Expand Down Expand Up @@ -544,8 +543,6 @@ spec:
fieldRef:
fieldPath: metadata.name
EOF
kubectl apply -f $tmpFileName
rm $tmpFileName

isfailed=true
for i in {0..59}
Expand All @@ -565,9 +562,7 @@ EOF

applyTestNodePortService() {
local svcName="test-node-port"
tmpFileName="$svcName.yaml"

cat <<EOF > $tmpFileName
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
Expand All @@ -585,12 +580,9 @@ spec:
selector:
app: kube-ovn-pinger
EOF
kubectl apply -f $tmpFileName
rm $tmpFileName
}

getTestNodePortServiceIPPorts() {

targetIPPorts=""
nodeIPs=($(kubectl get node -o wide | grep -v "INTERNAL-IP" | awk '{print $6}'))
nodePort=$(kubectl get svc test-node-port -n $KUBE_OVN_NS -o 'jsonpath={.spec.ports[0].nodePort}')
Expand Down Expand Up @@ -1253,9 +1245,7 @@ applyTestServer() {
podName="test-server"
nodeID=$1
imageID=$2
tmpFileName="$podName.yaml"

cat <<EOF > $tmpFileName
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
Expand All @@ -1277,18 +1267,13 @@ spec:
nodeSelector:
kubernetes.io/hostname: $nodeID
EOF

kubectl apply -f $tmpFileName
rm $tmpFileName
}

applyTestHostServer() {
podName="test-host-server"
nodeID=$1
imageID=$2
tmpFileName="$podName.yaml"

cat <<EOF > $tmpFileName
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
Expand All @@ -1310,19 +1295,13 @@ spec:
nodeSelector:
kubernetes.io/hostname: $nodeID
EOF

kubectl apply -f $tmpFileName
rm $tmpFileName
}


applyTestClient() {
local podName="test-client"
local nodeID=$1
local imageID=$2
tmpFileName="$podName.yaml"

cat <<EOF > $tmpFileName
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
Expand All @@ -1339,17 +1318,13 @@ spec:
nodeSelector:
kubernetes.io/hostname: $nodeID
EOF
kubectl apply -f $tmpFileName
rm $tmpFileName
}

applyTestHostClient() {
local podName="test-host-client"
local nodeID=$1
local imageID=$2
tmpFileName="$podName.yaml"

cat <<EOF > $tmpFileName
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
Expand All @@ -1367,15 +1342,11 @@ spec:
nodeSelector:
kubernetes.io/hostname: $nodeID
EOF
kubectl apply -f $tmpFileName
rm $tmpFileName
}

applyTestServerService() {
local svcName="test-server"
tmpFileName="$svcName.yaml"

cat <<EOF > $tmpFileName
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
Expand Down Expand Up @@ -1404,8 +1375,6 @@ spec:
selector:
env: server
EOF
kubectl apply -f $tmpFileName
rm $tmpFileName
}

addHeaderDecoration() {
Expand Down Expand Up @@ -1456,7 +1425,7 @@ quitPerfTest() {

perf(){
addHeaderDecoration "Prepareing Performance Test Resources"
imageID=${1:-"kubeovn/test:v1.12.0"}
imageID=${1:-"docker.io/kubeovn/test:v1.13.0"}

nodes=($(kubectl get node --no-headers -o custom-columns=NAME:.metadata.name))
if [[ ${#nodes} -eq 1 ]]; then
Expand Down Expand Up @@ -1601,7 +1570,7 @@ genMulticastPerfResult() {
tmpFileName="multicast-$serverName.log"
PERF_GC_COMMAND+=("rm -f $tmpFileName")
LAST_PERF_FAILED_LOG=$tmpFileName

start_server_cmd="iperf -s -B 224.0.0.100 -i 1 -u"
kubectl exec $serverName -n $KUBE_OVN_NS -- $start_server_cmd > $tmpFileName &
sleep 1
Expand All @@ -1627,7 +1596,6 @@ checkLeaderRecover() {
sleep 5
getOvnCentralPod
getPodRecoverTime "northd"

}

getPodRecoverTime(){
Expand Down Expand Up @@ -1663,25 +1631,27 @@ fi

subcommand="$1"; shift

getOvnCentralPod

case $subcommand in
nbctl)
getOvnCentralPod
kubectl exec "$OVN_NB_POD" -n $KUBE_OVN_NS -c ovn-central -- ovn-nbctl "$@"
;;
sbctl)
getOvnCentralPod
kubectl exec "$OVN_SB_POD" -n $KUBE_OVN_NS -c ovn-central -- ovn-sbctl "$@"
;;
vsctl|ofctl|dpctl|appctl)
xxctl "$subcommand" "$@"
;;
nb|sb)
getOvnCentralPod
dbtool "$subcommand" "$@"
;;
tcpdump)
tcpdump "$@"
;;
trace)
getOvnCentralPod
trace "$@"
;;
diagnose)
Expand All @@ -1700,6 +1670,7 @@ case $subcommand in
log "$@"
;;
perf)
getOvnCentralPod
perf "$@"
;;
*)
Expand Down
8 changes: 4 additions & 4 deletions test/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This server mainly focuses on test network break effect during kube-ovn upgrade

## How test server test network break

The test-server will use ping, iperf3 and curl to visit a specified address during upgrade or reload. Then it automatically collect metrics from
The test-server will use ping, iperf3 and curl to visit a specified address during upgrade or reload. Then it automatically collect metrics from
`/proc/net/snmp` and return code to calculate ICMP lost, TCP retransmit packets and TCP connection failure.

```bash
Expand All @@ -13,15 +13,15 @@ make kind-init kind-install

# Build and deploy test-server
make image-test
kind load docker-image --name kube-ovn kubeovn/test:v1.12.0
kind load docker-image --name kube-ovn kubeovn/test:v1.13.0
kubectl apply -f test/server/test-server.yaml
docker run --name kube-ovn-test -d --net=kind kubeovn/test:v1.12.0
docker run --name kube-ovn-test -d --net=kind kubeovn/test:v1.13.0
docker inspect kube-ovn-test -f '{{.NetworkSettings.Networks.kind.IPAddress}}'

# Run test-server analysis tool in one terminal and reload kube-ovn in another terminal
# terminal 1 (replace 172.18.0.5/80 with the address/port you want to test)
kubectl exec -it test-client -- ./test-server --remote-address=172.18.0.5 --remote-port=80 --output=json --duration-seconds=60

# terminal 2
kubectl ko reload

Expand Down
4 changes: 2 additions & 2 deletions test/server/test-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
spec:
containers:
- name: test-server
image: kubeovn/test:v1.12.0
image: kubeovn/test:v1.13.0
imagePullPolicy: IfNotPresent
nodeSelector:
kubernetes.io/hostname: kube-ovn-control-plane
Expand All @@ -23,7 +23,7 @@ metadata:
spec:
containers:
- name: test-client
image: kubeovn/test:v1.12.0
image: kubeovn/test:v1.13.0
imagePullPolicy: IfNotPresent
nodeSelector:
kubernetes.io/hostname: kube-ovn-worker
Expand Down
10 changes: 5 additions & 5 deletions yamls/kube-ovn-dual-stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ spec:
hostNetwork: true
containers:
- name: kube-ovn-controller
image: "kubeovn/kube-ovn:v1.12.0"
image: "kubeovn/kube-ovn:v1.13.0"
imagePullPolicy: IfNotPresent
args:
- /kube-ovn/start-controller.sh
Expand Down Expand Up @@ -169,7 +169,7 @@ spec:
hostPID: true
initContainers:
- name: install-cni
image: "kubeovn/kube-ovn:v1.12.0"
image: "kubeovn/kube-ovn:v1.13.0"
imagePullPolicy: IfNotPresent
command: ["/kube-ovn/install-cni.sh"]
securityContext:
Expand All @@ -182,7 +182,7 @@ spec:
name: local-bin
containers:
- name: cni-server
image: "kubeovn/kube-ovn:v1.12.0"
image: "kubeovn/kube-ovn:v1.13.0"
imagePullPolicy: IfNotPresent
command:
- bash
Expand Down Expand Up @@ -358,7 +358,7 @@ spec:
hostPID: true
containers:
- name: pinger
image: "kubeovn/kube-ovn:v1.12.0"
image: "kubeovn/kube-ovn:v1.13.0"
command:
- /kube-ovn/kube-ovn-pinger
args:
Expand Down Expand Up @@ -489,7 +489,7 @@ spec:
hostNetwork: true
containers:
- name: kube-ovn-monitor
image: "kubeovn/kube-ovn:v1.12.0"
image: "kubeovn/kube-ovn:v1.13.0"
imagePullPolicy: IfNotPresent
command: ["/kube-ovn/start-ovn-monitor.sh"]
args:
Expand Down
10 changes: 5 additions & 5 deletions yamls/kube-ovn-ipv6.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ spec:
hostNetwork: true
containers:
- name: kube-ovn-controller
image: "kubeovn/kube-ovn:v1.12.0"
image: "kubeovn/kube-ovn:v1.13.0"
imagePullPolicy: IfNotPresent
args:
- /kube-ovn/start-controller.sh
Expand Down Expand Up @@ -169,7 +169,7 @@ spec:
hostPID: true
initContainers:
- name: install-cni
image: "kubeovn/kube-ovn:v1.12.0"
image: "kubeovn/kube-ovn:v1.13.0"
imagePullPolicy: IfNotPresent
command: ["/kube-ovn/install-cni.sh"]
securityContext:
Expand All @@ -182,7 +182,7 @@ spec:
name: local-bin
containers:
- name: cni-server
image: "kubeovn/kube-ovn:v1.12.0"
image: "kubeovn/kube-ovn:v1.13.0"
imagePullPolicy: IfNotPresent
command:
- bash
Expand Down Expand Up @@ -358,7 +358,7 @@ spec:
hostPID: true
containers:
- name: pinger
image: "kubeovn/kube-ovn:v1.12.0"
image: "kubeovn/kube-ovn:v1.13.0"
command:
- /kube-ovn/kube-ovn-pinger
args:
Expand Down Expand Up @@ -489,7 +489,7 @@ spec:
hostNetwork: true
containers:
- name: kube-ovn-monitor
image: "kubeovn/kube-ovn:v1.12.0"
image: "kubeovn/kube-ovn:v1.13.0"
imagePullPolicy: IfNotPresent
command: ["/kube-ovn/start-ovn-monitor.sh"]
args:
Expand Down
4 changes: 2 additions & 2 deletions yamls/ovn-ha.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ spec:
hostNetwork: true
containers:
- name: ovn-central
image: "kubeovn/kube-ovn:v1.12.0"
image: "kubeovn/kube-ovn:v1.13.0"
imagePullPolicy: IfNotPresent
command:
- /kube-ovn/start-db.sh
Expand Down Expand Up @@ -243,7 +243,7 @@ spec:
hostPID: true
containers:
- name: openvswitch
image: "kubeovn/kube-ovn:v1.12.0"
image: "kubeovn/kube-ovn:v1.13.0"
imagePullPolicy: IfNotPresent
command:
- /kube-ovn/start-ovs.sh
Expand Down
2 changes: 1 addition & 1 deletion yamls/speaker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
hostNetwork: true
containers:
- name: kube-ovn-speaker
image: "kubeovn/kube-ovn:v1.12.0"
image: "kubeovn/kube-ovn:v1.13.0"
imagePullPolicy: IfNotPresent
command:
- /kube-ovn/kube-ovn-speaker
Expand Down
2 changes: 1 addition & 1 deletion yamls/vpc-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
kubernetes.io/description: |
kube-ovn vpc-nat common config
data:
image: kubeovn/vpc-nat-gateway:v1.12.0
image: kubeovn/vpc-nat-gateway:v1.13.0
---
kind: ConfigMap
apiVersion: v1
Expand Down
Loading

0 comments on commit 5172b62

Please sign in to comment.