Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR - Support for LB endpoint append #151

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading