Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: add openyurt.io/skip-discard annotation verify for discardcloudservice filter #542

Merged
merged 1 commit into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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