Skip to content

Commit

Permalink
CFP: ClusterIP advertisement with BGP Control Plane
Browse files Browse the repository at this point in the history
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
  • Loading branch information
chaunceyjiang committed Feb 26, 2024
1 parent 223a5e0 commit d102537
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ func (r *LBServiceReconciler) svcDesiredRoutes(newc *v2alpha1api.CiliumBGPVirtua
return nil, nil
}

// Ignore non-loadbalancer services.
if svc.Spec.Type != slim_corev1.ServiceTypeLoadBalancer {
// Ignore non-loadbalancer and non-clusterIP services.
if svc.Spec.Type != slim_corev1.ServiceTypeLoadBalancer && svc.Spec.Type != slim_corev1.ServiceTypeClusterIP {
return nil, nil
}

Expand All @@ -298,31 +298,45 @@ func (r *LBServiceReconciler) svcDesiredRoutes(newc *v2alpha1api.CiliumBGPVirtua
if !svcSelector.Matches(serviceLabelSet(svc)) {
return nil, nil
}

// Ignore service managed by an unsupported LB class.
if svc.Spec.LoadBalancerClass != nil && *svc.Spec.LoadBalancerClass != v2alpha1api.BGPLoadBalancerClass {
// The service is managed by a different LB class.
return nil, nil
}

// Ignore externalTrafficPolicy == Local && no local endpoints.
if svc.Spec.ExternalTrafficPolicy == slim_corev1.ServiceExternalTrafficPolicyLocal &&
!hasLocalEndpoints(svc, ls) {
return nil, nil
}

var desiredRoutes []netip.Prefix
for _, ingress := range svc.Status.LoadBalancer.Ingress {
if ingress.IP == "" {
continue
switch svc.Spec.Type {
case slim_corev1.ServiceTypeLoadBalancer:
// Ignore service managed by an unsupported LB class.
if svc.Spec.LoadBalancerClass != nil && *svc.Spec.LoadBalancerClass != v2alpha1api.BGPLoadBalancerClass {
// The service is managed by a different LB class.
return nil, nil
}
for _, ingress := range svc.Status.LoadBalancer.Ingress {
if ingress.IP == "" {
continue
}

addr, err := netip.ParseAddr(ingress.IP)
if err != nil {
continue
}
addr, err := netip.ParseAddr(ingress.IP)
if err != nil {
continue
}

desiredRoutes = append(desiredRoutes, netip.PrefixFrom(addr, addr.BitLen()))
desiredRoutes = append(desiredRoutes, netip.PrefixFrom(addr, addr.BitLen()))
}
case slim_corev1.ServiceTypeClusterIP:
if svc.Spec.ClusterIP == "" || len(svc.Spec.ClusterIPs) == 0 {
return nil, nil
}
for _, clusterIP := range svc.Spec.ClusterIPs {
if clusterIP == "" {
continue
}
addr, err := netip.ParseAddr(clusterIP)
if err != nil {
continue
}
desiredRoutes = append(desiredRoutes, netip.PrefixFrom(addr, addr.BitLen()))
}
}

return desiredRoutes, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,20 @@ spec:
only "value". The requirements are ANDed.
type: object
type: object
serviceAdvertisements:
description: ServiceAdvertisements selects a group of BGP Advertisement(s)
to advertise for the selected services.
items:
description: "BGPServiceAddressType defines type of service
address to be advertised. \n Note list of supported service
addresses is not exhaustive and can be extended in the future.
Consumer of this API should be able to handle unknown values."
enum:
- LoadBalancerIP
- ClusterIP
- ExternalIP
type: string
type: array
serviceSelector:
description: "ServiceSelector selects a group of load balancer
services which this virtual router will announce. The loadBalancerClass
Expand Down
6 changes: 6 additions & 0 deletions pkg/k8s/apis/cilium.io/v2alpha1/bgpp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,12 @@ type CiliumBGPVirtualRouter struct {
//
// +kubebuilder:validation:Optional
ServiceSelector *slimv1.LabelSelector `json:"serviceSelector,omitempty"`
// ServiceAdvertisements selects a group of BGP Advertisement(s) to advertise
// for the selected services.
//
// +kubebuilder:validation:Optional
// +kubebuilder:validation:default={LoadBalancerIP}
ServiceAdvertisements []BGPServiceAddressType `json:"serviceAdvertisements,omitempty"`
// Neighbors is a list of neighboring BGP peers for this virtual router
//
// +kubebuilder:validation:Required
Expand Down
5 changes: 5 additions & 0 deletions pkg/k8s/apis/cilium.io/v2alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions pkg/k8s/apis/cilium.io/v2alpha1/zz_generated.deepequal.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d102537

Please sign in to comment.