Skip to content

Commit

Permalink
Optimise the redundancy code
Browse files Browse the repository at this point in the history
The nodeName env is hanlder in daemon config[1], and initChassisAnno
should use it directly, rather than get it again. this PS to optimise

[1]: https://github.com/kubeovn/kube-ovn/blob/c6da7eaa903889f6cb37523ab2d5ff1ef2a2875e/pkg/daemon/config.go#L88
  • Loading branch information
caoyingjunz committed May 9, 2021
1 parent 47ef2ec commit ddfd06b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
8 changes: 1 addition & 7 deletions cmd/daemon/cniserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"k8s.io/apimachinery/pkg/types"
"net/http"
_ "net/http/pprof" // #nosec
"os"
"strings"
"time"

Expand Down Expand Up @@ -106,18 +105,13 @@ func Retry(attempts int, sleep int, f func(configuration *daemon.Configuration)
}

func initChassisAnno(cfg *daemon.Configuration) error {

chassisID, err := ioutil.ReadFile(util.ChassisLoc)
if err != nil {
klog.Errorf("read chassis file failed, %v", err)
return err
}

hostname := os.Getenv(util.HostnameEnv)
if hostname == "" {
klog.Errorf("env %s does not exist", util.HostnameEnv)
return err
}
hostname := cfg.NodeName
node, err := cfg.KubeClient.CoreV1().Nodes().Get(context.Background(), hostname, v1.GetOptions{})
if err != nil {
klog.Errorf("failed to get node %s %v", hostname, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func ParseFlags() (*Configuration, error) {
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()

nodeName := os.Getenv("KUBE_NODE_NAME")
nodeName := os.Getenv(util.HostnameEnv)
if nodeName == "" {
klog.Errorf("env KUBE_NODE_NAME not exists")
return nil, fmt.Errorf("env KUBE_NODE_NAME not exists")
Expand Down

0 comments on commit ddfd06b

Please sign in to comment.