Skip to content

Commit

Permalink
loxilb-io/loxilb#675 Initial support for proxy protocol v2
Browse files Browse the repository at this point in the history
  • Loading branch information
TrekkieCoder committed Nov 27, 2024
1 parent 06e26d6 commit 31e9582
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/agent/manager/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const (
defaultPoolName = "defaultPool"
loxilbZoneLabelKey = "loxilb.io/zonelabel"
loxilbZoneInstance = "loxilb.io/zoneinstance"
enProxyProtov2Annotation = "loxilb.io/useproxyprotov2"
)

type LoxiInstRole struct {
Expand Down Expand Up @@ -126,6 +127,7 @@ type LbArgs struct {
needMultusEP bool
usePodNetwork bool
inst string
ppv2En bool
}

type LbModelEnt struct {
Expand All @@ -147,6 +149,7 @@ type LbCacheEntry struct {
Timeout int
ActCheck bool
PrefLocal bool
ppv2En bool
Inst string
Addr string
State string
Expand Down Expand Up @@ -408,6 +411,7 @@ func (m *Manager) addLoadBalancer(svc *corev1.Service) error {
usePodNet := false
hasSharedPool := false
overrideZoneInst := ""
enProxyProtov2 := false

if strings.Compare(*lbClassName, m.networkConfig.LoxilbLoadBalancerClass) != 0 && !needMultusEP {
return nil
Expand Down Expand Up @@ -505,6 +509,15 @@ func (m *Manager) addLoadBalancer(svc *corev1.Service) error {
}
}

// Check for loxilb specific annotations - enProxyProtov2Annotation
if ppv2 := svc.Annotations[enProxyProtov2Annotation]; ppv2 != "" {
if ppv2 == "yes" {
enProxyProtov2 = true
} else if ppv2 == "no" {
enProxyProtov2 = false
}
}

// Check for loxilb specific annotations - loxilbZoneInstance
if zni := svc.Annotations[loxilbZoneInstance]; zni != "" {
overrideZoneInst = zni
Expand Down Expand Up @@ -689,6 +702,7 @@ func (m *Manager) addLoadBalancer(svc *corev1.Service) error {
IPPool: ipPool,
SIPPools: sipPools,
Inst: zoneInstName,
ppv2En: enProxyProtov2,
LbServicePairs: make(map[string]*LbServicePairEntry),
}
}()
Expand Down Expand Up @@ -868,6 +882,15 @@ func (m *Manager) addLoadBalancer(svc *corev1.Service) error {
klog.Infof("%s: EpSelect update", cacheKey)
}

if enProxyProtov2 != m.lbCache[cacheKey].ppv2En {
m.lbCache[cacheKey].ppv2En = enProxyProtov2
update = true
if added {
needDelete = true
}
klog.Infof("%s: enProxyProtov2 update", cacheKey)
}

// If the user specifies a secondary IP in the annotation, update the existing secondary IP.
if len(secIPs) > 0 {
if !added {
Expand Down Expand Up @@ -952,6 +975,7 @@ func (m *Manager) addLoadBalancer(svc *corev1.Service) error {
probeRetries: m.lbCache[cacheKey].ProbeRetries,
sel: m.lbCache[cacheKey].EpSelect,
inst: m.lbCache[cacheKey].Inst,
ppv2En: m.lbCache[cacheKey].ppv2En,
needMultusEP: needMultusEP,
usePodNetwork: usePodNet,
}
Expand Down Expand Up @@ -1852,6 +1876,7 @@ func (m *Manager) makeLoxiLoadBalancerModel(lbArgs *LbArgs, svc *corev1.Service,
ProbeResp: lbArgs.probeResp,
ProbeTimeout: lbArgs.probeTimeo,
ProbeRetries: int32(lbArgs.probeRetries),
PpV2: lbArgs.ppv2En,
Sel: lbArgs.sel,
Name: fmt.Sprintf("%s_%s:%s", svc.Namespace, svc.Name, lbArgs.inst),
},
Expand Down
1 change: 1 addition & 0 deletions pkg/api/lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type LoadBalancerService struct {
Name string `json:"name,omitempty"`
Oper LbOP `json:"oper,omitempty"`
Host string `json:"host,omitempty"`
PpV2 bool `json:"proxyprotocolv2,omitempty"`
}

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

0 comments on commit 31e9582

Please sign in to comment.