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

service controller trigger update when service ipfamilies changes #116520

Merged
merged 2 commits into from Apr 24, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the order matter in this case? Should we check order in addition to length of ip families?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment #116520 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a comment in the code with this context?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a comment in the code with this context?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, add comment with this context. PTAL

c.eventRecorder.Eventf(newService, v1.EventTypeNormal, "IPFamilies", "Count: %v -> %v",
len(oldService.Spec.IPFamilies), len(newService.Spec.IPFamilies))
return true
}

return false
}

Expand Down
Expand Up @@ -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()
Expand Down