From 240ef41335d28aa6607e686e4483b5dc6efd7588 Mon Sep 17 00:00:00 2001 From: rambohe Date: Thu, 4 Nov 2021 02:35:42 +0800 Subject: [PATCH] enhancement: add openyurt.io/skip-discard annotation verify for discardcloudservice filter (#542) --- pkg/yurthub/filter/constant.go | 11 ++++++++--- pkg/yurthub/filter/discardcloudservice/handler.go | 12 ++++++++---- pkg/yurthub/filter/servicetopology/handler.go | 6 ------ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/pkg/yurthub/filter/constant.go b/pkg/yurthub/filter/constant.go index 74daf6c0fce..29cb756d1ac 100644 --- a/pkg/yurthub/filter/constant.go +++ b/pkg/yurthub/filter/constant.go @@ -17,17 +17,22 @@ limitations under the License. package filter const ( - // masterservice filter is used to mutate the ClusterIP and https port of default/kubernetes service + // MasterServiceFilterName filter is used to mutate the ClusterIP and https port of default/kubernetes service // in order to pods on edge nodes can access kube-apiserver directly by inClusterConfig. MasterServiceFilterName = "masterservice" - // servicetopology filter is used to reassemble endpointslice in order to make the service traffic + // ServiceTopologyFilterName filter is used to reassemble endpointslice in order to make the service traffic // under the topology that defined by service.Annotation["openyurt.io/topologyKeys"] ServiceTopologyFilterName = "servicetopology" - // discardcloudservice filter is used to discard cloud service(like loadBalancer service) + // DiscardCloudServiceFilterName filter is used to discard cloud service(like loadBalancer service) // on kube-proxy list/watch service request from edge nodes. DiscardCloudServiceFilterName = "discardcloudservice" + + // SkipDiscardServiceAnnotation is annotation used by LB service. + // If end users want to use specified LB service at the edge side, + // End users should add annotation["openyurt.io/skip-discard"]="true" for LB service. + SkipDiscardServiceAnnotation = "openyurt.io/skip-discard" ) // DisabledInCloudMode contains the filters that should be disabled when yurthub is working in cloud mode. diff --git a/pkg/yurthub/filter/discardcloudservice/handler.go b/pkg/yurthub/filter/discardcloudservice/handler.go index f693fcd2508..bde5f025694 100644 --- a/pkg/yurthub/filter/discardcloudservice/handler.go +++ b/pkg/yurthub/filter/discardcloudservice/handler.go @@ -59,8 +59,10 @@ func (fh *discardCloudServiceFilterHandler) ObjectResponseFilter(b []byte) ([]by nsName := fmt.Sprintf("%s/%s", serviceList.Items[i].Namespace, serviceList.Items[i].Name) // remove lb service if serviceList.Items[i].Spec.Type == v1.ServiceTypeLoadBalancer { - klog.V(2).Infof("load balancer service(%s) is discarded in ObjectResponseFilter of discardCloudServiceFilterHandler", nsName) - continue + if serviceList.Items[i].Annotations[filter.SkipDiscardServiceAnnotation] != "true" { + klog.V(2).Infof("load balancer service(%s) is discarded in ObjectResponseFilter of discardCloudServiceFilterHandler", nsName) + continue + } } // remove cloud clusterIP service @@ -101,8 +103,10 @@ func (fh *discardCloudServiceFilterHandler) StreamResponseFilter(rc io.ReadClose nsName := fmt.Sprintf("%s/%s", service.Namespace, service.Name) // remove cloud LoadBalancer service if service.Spec.Type == v1.ServiceTypeLoadBalancer { - klog.V(2).Infof("load balancer service(%s) is discarded in StreamResponseFilter of discardCloudServiceFilterHandler", nsName) - continue + if service.Annotations[filter.SkipDiscardServiceAnnotation] != "true" { + klog.V(2).Infof("load balancer service(%s) is discarded in StreamResponseFilter of discardCloudServiceFilterHandler", nsName) + continue + } } // remove cloud clusterIP service diff --git a/pkg/yurthub/filter/servicetopology/handler.go b/pkg/yurthub/filter/servicetopology/handler.go index 69f9c9dcae5..f50fb9681a2 100644 --- a/pkg/yurthub/filter/servicetopology/handler.go +++ b/pkg/yurthub/filter/servicetopology/handler.go @@ -134,12 +134,6 @@ func (fh *serviceTopologyFilterHandler) reassembleEndpointSlice(endpointSlice *d return endpointSlice } - // discard endpointSlice if service type is LoadBalancer - if svc.Spec.Type == v1.ServiceTypeLoadBalancer { - klog.Infof("endpointSlice(%s/%s) of load balancer service is discarded", endpointSlice.Namespace, endpointSlice.Name) - return nil - } - if serviceTopologyType, ok = svc.Annotations[AnnotationServiceTopologyKey]; !ok { klog.Infof("skip reassemble endpointSlice, service %s/%s has no annotation %s", endpointSlice.Namespace, svcName, AnnotationServiceTopologyKey) return endpointSlice