diff --git a/manifest/kube-loxilb.yaml b/manifest/kube-loxilb.yaml index a9284b2..b91f620 100644 --- a/manifest/kube-loxilb.yaml +++ b/manifest/kube-loxilb.yaml @@ -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 diff --git a/pkg/agent/manager/loadbalancer/loadbalancer.go b/pkg/agent/manager/loadbalancer/loadbalancer.go index a953859..e693901 100644 --- a/pkg/agent/manager/loadbalancer/loadbalancer.go +++ b/pkg/agent/manager/loadbalancer/loadbalancer.go @@ -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 { @@ -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 @@ -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" { @@ -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 } @@ -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)) @@ -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,