Skip to content

Commit

Permalink
Merge pull request #151 from loxilb-io/ep-append
Browse files Browse the repository at this point in the history
PR - Support for LB endpoint append
  • Loading branch information
TrekkieCoder committed Jun 24, 2024
2 parents b76b657 + 4abf628 commit edee966
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cmd/loxilb-agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func run(o *Options) error {
klog.Infof("ExtBGPPeers: %v", o.config.ExtBGPPeers)
klog.Infof("SetRoles: %s", o.config.SetRoles)
klog.Infof("Zone: %s", o.config.Zone)
klog.Infof("AppendEPs: %v", o.config.AppendEPs)

networkConfig := &config.NetworkConfig{
LoxilbURLs: o.config.LoxiURLs,
Expand All @@ -104,6 +105,7 @@ func run(o *Options) error {
ExtBGPPeers: o.config.ExtBGPPeers,
SetLBMode: o.config.SetLBMode,
Monitor: o.config.Monitor,
AppendEPs: o.config.AppendEPs,
ExternalSecondaryCIDRs: o.config.ExternalSecondaryCIDRs,
ExternalSecondaryCIDRs6: o.config.ExternalSecondaryCIDRs6,
PrivateCIDR: o.config.PrivateCIDR,
Expand Down
2 changes: 2 additions & 0 deletions cmd/loxilb-agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ type AgentConfig struct {
ExclIPAM bool `yaml:"setExclIPAM"`
// Enable monitoring end-points of LB rule
Monitor bool `yaml:"monitor"`
// Enable appending end-points of LB rule
AppendEPs bool `yaml:"appendEPs"`
// Set loxilb node roles
SetRoles string `yaml:"setRoles,omitempty"`
// Set loxilb zone
Expand Down
1 change: 1 addition & 0 deletions cmd/loxilb-agent/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (o *Options) addFlags(fs *pflag.FlagSet) {
fs.StringVar(&o.config.Zone, "zone", o.config.Zone, "The kube-loxilb zone instance")
fs.StringVar(&o.config.PrivateCIDR, "privateCIDR", o.config.PrivateCIDR, "Specify aws secondary IP. Used when configuring HA in AWS and associate with EIP.")
fs.StringVar(&excludeRoleList, "excludeRoleList", excludeRoleList, "List of nodes to exclude in role-selection")
fs.BoolVar(&o.config.AppendEPs, "appendEPs", o.config.AppendEPs, "Attach and detach end-points of LB rule")
}

// complete completes all the required optionst
Expand Down
1 change: 1 addition & 0 deletions pkg/agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type NetworkConfig struct {
ExtBGPPeers []string
SetLBMode uint16
Monitor bool
AppendEPs bool
SetRoles string
Zone string
PrivateCIDR string
Expand Down
13 changes: 12 additions & 1 deletion pkg/agent/manager/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,12 @@ func (m *Manager) deleteLoadBalancer(ns, name string, releaseAll bool) error {

go func(client *api.LoxiClient, ch chan error, lbModel api.LoadBalancerModel) {
klog.Infof("loxilb-lb(%s): delete lb %v", client.Host, lbModel)
ch <- client.LoadBalancer().Delete(context.Background(), &lbModel)
if m.networkConfig.AppendEPs {
lbModel.Service.Oper = api.LBOPDetach
ch <- client.LoadBalancer().Create(context.Background(), &lbModel)
} else {
ch <- client.LoadBalancer().Delete(context.Background(), &lbModel)
}
}(loxiClient, ch, lb)
}
}
Expand Down Expand Up @@ -1515,6 +1520,11 @@ func (m *Manager) makeLoxiLoadBalancerModel(lbArgs *LbArgs, svc *corev1.Service,
loxiEndpointModelList := []api.LoadBalancerEndpoint{}
loxiSecIPModelList := []api.LoadBalancerSecIp{}
lbModeSvc := api.LbMode(m.networkConfig.SetLBMode)
lbOper := api.LBOPAdd

if m.networkConfig.AppendEPs {
lbOper = api.LBOPAttach
}

if len(lbArgs.endpointIPs) > 0 {

Expand Down Expand Up @@ -1564,6 +1574,7 @@ func (m *Manager) makeLoxiLoadBalancerModel(lbArgs *LbArgs, svc *corev1.Service,
Protocol: strings.ToLower(string(port.Protocol)),
BGP: bgpMode,
Mode: lbModeSvc,
Oper: lbOper,
Monitor: lbArgs.livenessCheck,
Timeout: uint32(lbArgs.timeout),
Managed: true,
Expand Down
12 changes: 12 additions & 0 deletions pkg/api/lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ const (
)

type LbMode int32
type LbOP int32

const (
// LBOPAdd - Add te LB rule (replace if existing)
LBOPAdd LbOP = iota
// LBModeOneArm - Attach End-Points
LBOPAttach
// LBOPDetach - Detach End-Points
LBOPDetach
)

type LoadBalancerListModel struct {
Item []LoadBalancerModel `json:"lbAttr"`
}
Expand Down Expand Up @@ -61,6 +72,7 @@ type LoadBalancerService struct {
ProbeRetries int32 `json:"probeRetries,omitempty"`
ProbeTimeout uint32 `json:"probeTimeout,omitempty"`
Name string `json:"name,omitempty"`
Oper LbOP `json:"oper,omitempty"`
}

func (lbService *LoadBalancerService) GetKeyStruct() LoxiModel {
Expand Down

0 comments on commit edee966

Please sign in to comment.