mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/kube-vip/kube-vip.git
synced 2026-09-20 08:03:47 +08:00
Improve logging in election.go and set defaultBGPPort constant (#1534)
* improve logging in election.go and set defaultBGPPort constant Signed-off-by: Matthew Carpenter <mattcarp88@gmail.com> * update log messages per code review Signed-off-by: Matthew Carpenter <mattcarp88@gmail.com> --------- Signed-off-by: Matthew Carpenter <mattcarp88@gmail.com>
This commit is contained in:
@@ -6,8 +6,6 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
//nolint
|
|
||||||
|
|
||||||
"github.com/kube-vip/kube-vip/pkg/kubevip"
|
"github.com/kube-vip/kube-vip/pkg/kubevip"
|
||||||
"github.com/kube-vip/kube-vip/pkg/vip"
|
"github.com/kube-vip/kube-vip/pkg/vip"
|
||||||
api "github.com/osrg/gobgp/v3/api"
|
api "github.com/osrg/gobgp/v3/api"
|
||||||
@@ -18,6 +16,8 @@ import (
|
|||||||
"google.golang.org/protobuf/types/known/anypb"
|
"google.golang.org/protobuf/types/known/anypb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const defaultBGPPort uint32 = 179
|
||||||
|
|
||||||
// AddPeer will add peers to the BGP configuration
|
// AddPeer will add peers to the BGP configuration
|
||||||
func (b *Server) AddPeer(ctx context.Context, peer kubevip.BGPPeer) (err error) {
|
func (b *Server) AddPeer(ctx context.Context, peer kubevip.BGPPeer) (err error) {
|
||||||
p := &api.Peer{
|
p := &api.Peer{
|
||||||
@@ -45,7 +45,7 @@ func (b *Server) AddPeer(ctx context.Context, peer kubevip.BGPPeer) (err error)
|
|||||||
Transport: &api.Transport{
|
Transport: &api.Transport{
|
||||||
MtuDiscovery: true,
|
MtuDiscovery: true,
|
||||||
RemoteAddress: peer.Address,
|
RemoteAddress: peer.Address,
|
||||||
RemotePort: uint32(179),
|
RemotePort: defaultBGPPort,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func FindIPAddress(addrName string) (string, string, error) {
|
|||||||
// If we're not searching for a specific adapter return the first one
|
// If we're not searching for a specific adapter return the first one
|
||||||
if addrName == "" {
|
if addrName == "" {
|
||||||
return iface.Name, address, nil
|
return iface.Name, address, nil
|
||||||
} else
|
}
|
||||||
// If this is the correct adapter return the details
|
// If this is the correct adapter return the details
|
||||||
if iface.Name == addrName {
|
if iface.Name == addrName {
|
||||||
return iface.Name, address, nil
|
return iface.Name, address, nil
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ func RunOrDie(ctx context.Context, run *RunConfig, c *kubevip.Config) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
log.Info(fmt.Sprintf("LeaderElectionMode %s not supported, exiting", c.LeaderElectionType))
|
log.Info("LeaderElectionMode not supported, exiting", "mode", c.LeaderElectionType)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -171,7 +171,7 @@ func (em *Manager) NodeWatcher(ctx context.Context, lb *loadbalancer.IPVSLoadBal
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error creating label watcher: %s", err.Error())
|
return fmt.Errorf("error creating label watcher: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Go(func() {
|
wg.Go(func() {
|
||||||
@@ -198,7 +198,7 @@ func (em *Manager) NodeWatcher(ctx context.Context, lb *loadbalancer.IPVSLoadBal
|
|||||||
if checkIfNodeIsReady(node) {
|
if checkIfNodeIsReady(node) {
|
||||||
err = lb.AddBackend(node.Status.Addresses[x].Address, port)
|
err = lb.AddBackend(node.Status.Addresses[x].Address, port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("add IPVS backend", "err", err)
|
log.Error("adding node to load balancer", "node", node.Name, "ip", node.Status.Addresses[x].Address, "err", err)
|
||||||
if errors.Is(err, &utils.PanicError{}) {
|
if errors.Is(err, &utils.PanicError{}) {
|
||||||
return fmt.Errorf("add IPVS backend: %w", err)
|
return fmt.Errorf("add IPVS backend: %w", err)
|
||||||
}
|
}
|
||||||
@@ -206,7 +206,7 @@ func (em *Manager) NodeWatcher(ctx context.Context, lb *loadbalancer.IPVSLoadBal
|
|||||||
} else {
|
} else {
|
||||||
err = lb.RemoveBackend(node.Status.Addresses[x].Address, port)
|
err = lb.RemoveBackend(node.Status.Addresses[x].Address, port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("remove IPVS backend", "err", err)
|
log.Error("removing node from load balancer", "node", node.Name, "ip", node.Status.Addresses[x].Address, "err", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -222,7 +222,7 @@ func (em *Manager) NodeWatcher(ctx context.Context, lb *loadbalancer.IPVSLoadBal
|
|||||||
if node.Status.Addresses[x].Type == v1.NodeInternalIP {
|
if node.Status.Addresses[x].Type == v1.NodeInternalIP {
|
||||||
err = lb.RemoveBackend(node.Status.Addresses[x].Address, port)
|
err = lb.RemoveBackend(node.Status.Addresses[x].Address, port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Del IPVS backend", "err", err)
|
log.Error("removing node from load balancer", "node", node.Name, "ip", node.Status.Addresses[x].Address, "err", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user