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

feat: improve discardcloudservice filter in yurthub component (#1924) #1926

Merged
merged 1 commit into from
Jan 23, 2024
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
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
Loading