Skip to content

Commit

Permalink
feat: improve discardcloudservice filter in yurthub component (#1924)
Browse files Browse the repository at this point in the history
Signed-off-by: Chenzhao Huang <[email protected]>
  • Loading branch information
huangchenzhao committed Jan 19, 2024
1 parent 81d21b7 commit e651e7d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 5 additions & 0 deletions pkg/yurthub/filter/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ const (
// 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"

// DiscardServiceAnnotation is annotation used by LB service.
// If end users want to discard specified LB service at the edge side,
// End users should add annotation["svc.openyurt.io/discard"]="true" for LB service.
DiscardServiceAnnotation = "svc.openyurt.io/discard"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion pkg/yurthub/filter/discardcloudservice/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func discardCloudService(svc *v1.Service) *v1.Service {
nsName := fmt.Sprintf("%s/%s", svc.Namespace, svc.Name)
// remove cloud LoadBalancer service
if svc.Spec.Type == v1.ServiceTypeLoadBalancer {
if svc.Annotations[filter.SkipDiscardServiceAnnotation] != "true" {
if svc.Annotations[filter.DiscardServiceAnnotation] == "true" {
klog.V(2).Infof("load balancer service(%s) is discarded in StreamResponseFilter of discardCloudServiceFilterHandler", nsName)
return nil
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/yurthub/filter/discardcloudservice/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestFilter(t *testing.T) {
Name: "svc1",
Namespace: "default",
Annotations: map[string]string{
filter.SkipDiscardServiceAnnotation: "false",
filter.DiscardServiceAnnotation: "true",
},
},
Spec: corev1.ServiceSpec{
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestFilter(t *testing.T) {
Name: "svc1",
Namespace: "default",
Annotations: map[string]string{
filter.SkipDiscardServiceAnnotation: "true",
filter.DiscardServiceAnnotation: "false",
},
},
Spec: corev1.ServiceSpec{
Expand All @@ -177,7 +177,7 @@ func TestFilter(t *testing.T) {
Name: "svc1",
Namespace: "default",
Annotations: map[string]string{
filter.SkipDiscardServiceAnnotation: "true",
filter.DiscardServiceAnnotation: "false",
},
},
Spec: corev1.ServiceSpec{
Expand Down Expand Up @@ -205,6 +205,9 @@ func TestFilter(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "svc1",
Namespace: "default",
Annotations: map[string]string{
filter.DiscardServiceAnnotation: "true",
},
},
Spec: corev1.ServiceSpec{
ClusterIP: "10.96.105.187",
Expand All @@ -230,6 +233,9 @@ func TestFilter(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "svc1",
Namespace: "default",
Annotations: map[string]string{
filter.DiscardServiceAnnotation: "true",
},
},
Spec: corev1.ServiceSpec{
ClusterIP: "10.96.105.187",
Expand All @@ -256,9 +262,6 @@ func TestFilter(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "svc1",
Namespace: "default",
Annotations: map[string]string{
filter.SkipDiscardServiceAnnotation: "true",
},
},
Spec: corev1.ServiceSpec{
ClusterIP: "10.96.105.187",
Expand All @@ -269,9 +272,6 @@ func TestFilter(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "svc1",
Namespace: "default",
Annotations: map[string]string{
filter.SkipDiscardServiceAnnotation: "true",
},
},
Spec: corev1.ServiceSpec{
ClusterIP: "10.96.105.187",
Expand Down

0 comments on commit e651e7d

Please sign in to comment.