Skip to content

Commit

Permalink
simplify file reading (#4010)
Browse files Browse the repository at this point in the history
Signed-off-by: zhangzujian <zhangzujian.7@gmail.com>
  • Loading branch information
zhangzujian committed May 13, 2024
1 parent d8c8f8a commit fcfc099
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions pkg/ovn_leader_checker/ovn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"flag"
"fmt"
"io"
"net"
"os"
"os/exec"
Expand Down Expand Up @@ -183,22 +182,15 @@ func isDBLeader(dbName string, port int) bool {
}

func checkNorthdActive() bool {
var command []string
file, err := os.OpenFile(OvnNorthdPid, os.O_RDWR, 0o600)
pid, err := os.ReadFile(OvnNorthdPid)
if err != nil {
klog.Errorf("failed to open %s err = %v", OvnNorthdPid, err)
return false
}
defer file.Close()
fileByte, err := io.ReadAll(file)
if err != nil {
klog.Errorf("failed to read %s err = %v", OvnNorthdPid, err)
return false
}

command = []string{
command := []string{
"-t",
fmt.Sprintf("/var/run/ovn/ovn-northd.%s.ctl", strings.TrimSpace(string(fileByte))),
fmt.Sprintf("/var/run/ovn/ovn-northd.%s.ctl", strings.TrimSpace(string(pid))),
"status",
}
output, err := exec.Command("ovs-appctl", command...).CombinedOutput()
Expand Down

0 comments on commit fcfc099

Please sign in to comment.