mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 03:57:41 +00:00
trigger update event when service ipFamilies changes.
Signed-off-by: DingShujie <dingshujie@huawei.com>
This commit is contained in:
parent
3c6e419cc3
commit
8cbe9fe543
@ -582,6 +582,15 @@ func (c *Controller) needsUpdate(oldService *v1.Service, newService *v1.Service)
|
||||
return true
|
||||
}
|
||||
|
||||
// User can upgrade (add another clusterIP or ipFamily) or can downgrade (remove secondary clusterIP or ipFamily),
|
||||
// but CAN NOT change primary/secondary clusterIP || ipFamily UNLESS they are changing from/to/ON ExternalName
|
||||
// so not care about order, only need check the length.
|
||||
if len(oldService.Spec.IPFamilies) != len(newService.Spec.IPFamilies) {
|
||||
c.eventRecorder.Eventf(newService, v1.EventTypeNormal, "IPFamilies", "Count: %v -> %v",
|
||||
len(oldService.Spec.IPFamilies), len(newService.Spec.IPFamilies))
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -1633,6 +1633,80 @@ func TestNeedsUpdate(t *testing.T) {
|
||||
},
|
||||
expectedNeedsUpdate: true,
|
||||
},
|
||||
{
|
||||
testName: "If service IPFamilies from single stack to dual stack",
|
||||
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,
|
||||
}},
|
||||
IPFamilies: []v1.IPFamily{v1.IPv4Protocol},
|
||||
Type: v1.ServiceTypeLoadBalancer,
|
||||
},
|
||||
}
|
||||
newSvc = oldSvc.DeepCopy()
|
||||
newSvc.Spec.IPFamilies = []v1.IPFamily{v1.IPv4Protocol, v1.IPv6Protocol}
|
||||
},
|
||||
expectedNeedsUpdate: true,
|
||||
},
|
||||
{
|
||||
testName: "If service IPFamilies from dual stack to single stack",
|
||||
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,
|
||||
}},
|
||||
IPFamilies: []v1.IPFamily{v1.IPv4Protocol, v1.IPv6Protocol},
|
||||
Type: v1.ServiceTypeLoadBalancer,
|
||||
},
|
||||
}
|
||||
newSvc = oldSvc.DeepCopy()
|
||||
newSvc.Spec.IPFamilies = []v1.IPFamily{v1.IPv4Protocol}
|
||||
},
|
||||
expectedNeedsUpdate: true,
|
||||
},
|
||||
{
|
||||
testName: "If service IPFamilies not change",
|
||||
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,
|
||||
}},
|
||||
IPFamilies: []v1.IPFamily{v1.IPv4Protocol},
|
||||
Type: v1.ServiceTypeLoadBalancer,
|
||||
},
|
||||
}
|
||||
newSvc = oldSvc.DeepCopy()
|
||||
},
|
||||
expectedNeedsUpdate: false,
|
||||
},
|
||||
}
|
||||
|
||||
controller, _, _ := newController()
|
||||
|
Loading…
Reference in New Issue
Block a user