Skip to content

Commit

Permalink
enhancement: add openyurt.io/skip-discard annotation verify for disca…
Browse files Browse the repository at this point in the history
…rdcloudservice filter (openyurtio#542)
  • Loading branch information
rambohe-ch authored Nov 3, 2021
1 parent 8c77692 commit 240ef41
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
11 changes: 8 additions & 3 deletions pkg/yurthub/filter/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 8 additions & 4 deletions pkg/yurthub/filter/discardcloudservice/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions pkg/yurthub/filter/servicetopology/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 240ef41

Please sign in to comment.