Skip to content

Commit

Permalink
svc mode annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
TrekkieCoder committed May 30, 2023
1 parent dd7b3e0 commit eb5158e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion manifest/kube-loxilb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ spec:
terminationGracePeriodSeconds: 0
containers:
- name: kube-loxilb
image: ghcr.io/loxilb-io/kube-loxilb:latest
image: ghcr.io/loxilb-io/kube-loxilb:debug
imagePullPolicy: Always
command:
- /bin/kube-loxilb
Expand Down
26 changes: 23 additions & 3 deletions pkg/agent/manager/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const (
LoxiMultusServiceAnnotation = "loxilb.io/multus-nets"
numSecIPAnnotation = "loxilb.io/num-secondary-networks"
livenessAnnotation = "loxilb.io/liveness"
lbModeAnnotation = "loxilb.io/lbmode"
)

type Manager struct {
Expand Down Expand Up @@ -242,6 +243,7 @@ func (m *Manager) addLoadBalancer(svc *corev1.Service) error {

numSecondarySvc := 0
livenessCheck := false
lbMode := -1

if strings.Compare(*lbClassName, m.networkConfig.LoxilbLoadBalancerClass) != 0 {
return nil
Expand All @@ -257,6 +259,19 @@ func (m *Manager) addLoadBalancer(svc *corev1.Service) error {
}
}

// Check for loxilb specific annotations - NAT LB Mode
if lbm := svc.Annotations[lbModeAnnotation]; lbm != "" {
if lbm == "fullnat" {
lbMode = 2
} else if lbm == "onearm" {
lbMode = 1
} else if lbm == "default" {
lbMode = 0
} else {
lbMode = -1
}
}

// Check for loxilb specific annotations - Liveness Check
if lchk := svc.Annotations[livenessAnnotation]; lchk != "" {
if lchk == "yes" {
Expand Down Expand Up @@ -361,7 +376,7 @@ func (m *Manager) addLoadBalancer(svc *corev1.Service) error {
var errChList []chan error
var lbModelList []api.LoadBalancerModel
for _, port := range svc.Spec.Ports {
lbModel, err := m.makeLoxiLoadBalancerModel(ingSvcPair.IPString, livenessCheck, m.lbCache[cacheKey].SecIPs, svc, port, endpointIPs, needPodEP)
lbModel, err := m.makeLoxiLoadBalancerModel(ingSvcPair.IPString, livenessCheck, lbMode, m.lbCache[cacheKey].SecIPs, svc, port, endpointIPs, needPodEP)
if err != nil {
return err
}
Expand Down Expand Up @@ -656,9 +671,10 @@ func (m *Manager) getLoadBalancerServiceIngressIPs(service *corev1.Service) []st
return ips
}

func (m *Manager) makeLoxiLoadBalancerModel(externalIP string, livenessCheck bool, secIPs []string, svc *corev1.Service, port corev1.ServicePort, endpointIPs []string, needPodEP bool) (api.LoadBalancerModel, error) {
func (m *Manager) makeLoxiLoadBalancerModel(externalIP string, livenessCheck bool, lbMode int, secIPs []string, svc *corev1.Service, port corev1.ServicePort, endpointIPs []string, needPodEP bool) (api.LoadBalancerModel, error) {
loxiEndpointModelList := []api.LoadBalancerEndpoint{}
loxiSecIPModelList := []api.LoadBalancerSecIp{}
lbModeSvc := api.LbMode(m.networkConfig.SetLBMode)

if len(endpointIPs) > 0 {
endpointWeight := uint8(LoxiMaxWeight / len(endpointIPs))
Expand Down Expand Up @@ -698,13 +714,17 @@ func (m *Manager) makeLoxiLoadBalancerModel(externalIP string, livenessCheck boo
livenessCheck = true
}

if lbMode >= 0 {
lbModeSvc = api.LbMode(lbMode)
}

return api.LoadBalancerModel{
Service: api.LoadBalancerService{
ExternalIP: externalIP,
Port: uint16(port.Port),
Protocol: strings.ToLower(string(port.Protocol)),
BGP: m.networkConfig.SetBGP,
Mode: api.LbMode(m.networkConfig.SetLBMode),
Mode: lbModeSvc,
Monitor: livenessCheck,
},
SecondaryIPs: loxiSecIPModelList,
Expand Down

0 comments on commit eb5158e

Please sign in to comment.