From f68345b2f09355a59c99df0ce46ef24dfcadab4b Mon Sep 17 00:00:00 2001 From: MartinForReal Date: Thu, 29 Sep 2022 11:56:03 +0000 Subject: [PATCH] service update event should be triggered when appProtocol in port is changed. Signed-off-by: MartinForReal --- .../controllers/service/controller.go | 4 ++ .../controllers/service/controller_test.go | 69 +++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/staging/src/k8s.io/cloud-provider/controllers/service/controller.go b/staging/src/k8s.io/cloud-provider/controllers/service/controller.go index 273508e75a1..f253a7c8c34 100644 --- a/staging/src/k8s.io/cloud-provider/controllers/service/controller.go +++ b/staging/src/k8s.io/cloud-provider/controllers/service/controller.go @@ -640,6 +640,10 @@ func portEqualForLB(x, y *v1.ServicePort) bool { return false } + if !reflect.DeepEqual(x.AppProtocol, y.AppProtocol) { + return false + } + return true } diff --git a/staging/src/k8s.io/cloud-provider/controllers/service/controller_test.go b/staging/src/k8s.io/cloud-provider/controllers/service/controller_test.go index df0daf1fc0e..e389642addd 100644 --- a/staging/src/k8s.io/cloud-provider/controllers/service/controller_test.go +++ b/staging/src/k8s.io/cloud-provider/controllers/service/controller_test.go @@ -1391,6 +1391,75 @@ func TestNeedsUpdate(t *testing.T) { }, expectedNeedsUpdate: true, }, + { + testName: "If appProtocol is the same", + updateFn: func() { + oldSvc = &v1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: "tcp-service", + Namespace: "default", + }, + Spec: v1.ServiceSpec{ + Ports: []v1.ServicePort{{ + Port: 80, + Protocol: v1.ProtocolTCP, + TargetPort: intstr.Parse("22"), + }}, + Type: v1.ServiceTypeLoadBalancer, + }, + } + newSvc = oldSvc.DeepCopy() + }, + expectedNeedsUpdate: false, + }, + { + testName: "If appProtocol is set when previously unset", + updateFn: func() { + oldSvc = &v1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: "tcp-service", + Namespace: "default", + }, + Spec: v1.ServiceSpec{ + Ports: []v1.ServicePort{{ + Port: 80, + Protocol: v1.ProtocolTCP, + TargetPort: intstr.Parse("22"), + }}, + Type: v1.ServiceTypeLoadBalancer, + }, + } + newSvc = oldSvc.DeepCopy() + protocol := "http" + newSvc.Spec.Ports[0].AppProtocol = &protocol + }, + expectedNeedsUpdate: true, + }, + { + testName: "If appProtocol is set to a different value", + updateFn: func() { + protocol := "http" + oldSvc = &v1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: "tcp-service", + Namespace: "default", + }, + Spec: v1.ServiceSpec{ + Ports: []v1.ServicePort{{ + Port: 80, + Protocol: v1.ProtocolTCP, + TargetPort: intstr.Parse("22"), + AppProtocol: &protocol, + }}, + Type: v1.ServiceTypeLoadBalancer, + }, + } + newSvc = oldSvc.DeepCopy() + newProtocol := "tcp" + newSvc.Spec.Ports[0].AppProtocol = &newProtocol + }, + expectedNeedsUpdate: true, + }, } controller, _, _ := newController()