Skip to content

Commit 2706754

Browse files
authored
Merge pull request kubernetes#85246 from robscott/endpointslice-dualstack-proxy
Updating kube-proxy to support new EndpointSlice address types
2 parents 97225e2 + 2a021d0 commit 2706754

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

pkg/proxy/endpoints.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ import (
3535
utilnet "k8s.io/utils/net"
3636
)
3737

38+
var supportedEndpointSliceAddressTypes = sets.NewString(
39+
string(discovery.AddressTypeIP), // IP is a deprecated address type
40+
string(discovery.AddressTypeIPv4),
41+
string(discovery.AddressTypeIPv6),
42+
)
43+
3844
// BaseEndpointInfo contains base information that defines an endpoint.
3945
// This could be used directly by proxier while processing endpoints,
4046
// or can be used for constructing a more specific EndpointInfo struct
@@ -173,6 +179,11 @@ func (ect *EndpointChangeTracker) Update(previous, current *v1.Endpoints) bool {
173179
// It returns true if items changed, otherwise return false. Will add/update/delete items of EndpointsChangeMap.
174180
// If removeSlice is true, slice will be removed, otherwise it will be added or updated.
175181
func (ect *EndpointChangeTracker) EndpointSliceUpdate(endpointSlice *discovery.EndpointSlice, removeSlice bool) bool {
182+
if !supportedEndpointSliceAddressTypes.Has(string(endpointSlice.AddressType)) {
183+
klog.V(4).Infof("EndpointSlice address type not supported by kube-proxy: %s", endpointSlice.AddressType)
184+
return false
185+
}
186+
176187
// This should never happen
177188
if endpointSlice == nil {
178189
klog.Error("Nil endpointSlice passed to EndpointSliceUpdate")

pkg/proxy/endpoints_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,9 @@ func TestLastChangeTriggerTime(t *testing.T) {
14311431
}
14321432

14331433
func TestEndpointSliceUpdate(t *testing.T) {
1434+
fqdnSlice := generateEndpointSlice("svc1", "ns1", 2, 5, 999, []string{"host1"}, []*int32{utilpointer.Int32Ptr(80), utilpointer.Int32Ptr(443)})
1435+
fqdnSlice.AddressType = discovery.AddressTypeFQDN
1436+
14341437
testCases := map[string]struct {
14351438
startingSlices []*discovery.EndpointSlice
14361439
endpointChangeTracker *EndpointChangeTracker
@@ -1473,6 +1476,18 @@ func TestEndpointSliceUpdate(t *testing.T) {
14731476
expectedReturnVal: false,
14741477
expectedCurrentChange: nil,
14751478
},
1479+
// ensure that only valide address types are processed
1480+
"add an FQDN slice (invalid address type)": {
1481+
startingSlices: []*discovery.EndpointSlice{
1482+
generateEndpointSlice("svc1", "ns1", 1, 3, 999, []string{"host1", "host2"}, []*int32{utilpointer.Int32Ptr(80), utilpointer.Int32Ptr(443)}),
1483+
},
1484+
endpointChangeTracker: NewEndpointChangeTracker("host1", nil, nil, nil, true),
1485+
namespacedName: types.NamespacedName{Name: "svc1", Namespace: "ns1"},
1486+
paramEndpointSlice: fqdnSlice,
1487+
paramRemoveSlice: false,
1488+
expectedReturnVal: false,
1489+
expectedCurrentChange: nil,
1490+
},
14761491
// test additions to existing state
14771492
"add a slice that overlaps with existing state": {
14781493
startingSlices: []*discovery.EndpointSlice{

pkg/proxy/ipvs/meta_proxier.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,25 +153,47 @@ func (proxier *metaProxier) OnEndpointsSynced() {
153153
// OnEndpointSliceAdd is called whenever creation of a new endpoint slice object
154154
// is observed.
155155
func (proxier *metaProxier) OnEndpointSliceAdd(endpointSlice *discovery.EndpointSlice) {
156-
// noop
156+
switch endpointSlice.AddressType {
157+
case discovery.AddressTypeIPv4:
158+
proxier.ipv4Proxier.OnEndpointSliceAdd(endpointSlice)
159+
case discovery.AddressTypeIPv6:
160+
proxier.ipv6Proxier.OnEndpointSliceAdd(endpointSlice)
161+
default:
162+
klog.V(4).Infof("EndpointSlice address type not supported by kube-proxy: %s", endpointSlice.AddressType)
163+
}
157164
}
158165

159166
// OnEndpointSliceUpdate is called whenever modification of an existing endpoint
160167
// slice object is observed.
161-
func (proxier *metaProxier) OnEndpointSliceUpdate(_, endpointSlice *discovery.EndpointSlice) {
162-
//noop
168+
func (proxier *metaProxier) OnEndpointSliceUpdate(oldEndpointSlice, newEndpointSlice *discovery.EndpointSlice) {
169+
switch newEndpointSlice.AddressType {
170+
case discovery.AddressTypeIPv4:
171+
proxier.ipv4Proxier.OnEndpointSliceUpdate(oldEndpointSlice, newEndpointSlice)
172+
case discovery.AddressTypeIPv6:
173+
proxier.ipv6Proxier.OnEndpointSliceUpdate(oldEndpointSlice, newEndpointSlice)
174+
default:
175+
klog.V(4).Infof("EndpointSlice address type not supported by kube-proxy: %s", newEndpointSlice.AddressType)
176+
}
163177
}
164178

165179
// OnEndpointSliceDelete is called whenever deletion of an existing endpoint slice
166180
// object is observed.
167181
func (proxier *metaProxier) OnEndpointSliceDelete(endpointSlice *discovery.EndpointSlice) {
168-
//noop
182+
switch endpointSlice.AddressType {
183+
case discovery.AddressTypeIPv4:
184+
proxier.ipv4Proxier.OnEndpointSliceDelete(endpointSlice)
185+
case discovery.AddressTypeIPv6:
186+
proxier.ipv6Proxier.OnEndpointSliceDelete(endpointSlice)
187+
default:
188+
klog.V(4).Infof("EndpointSlice address type not supported by kube-proxy: %s", endpointSlice.AddressType)
189+
}
169190
}
170191

171192
// OnEndpointSlicesSynced is called once all the initial event handlers were
172193
// called and the state is fully propagated to local cache.
173194
func (proxier *metaProxier) OnEndpointSlicesSynced() {
174-
//noop
195+
proxier.ipv4Proxier.OnEndpointSlicesSynced()
196+
proxier.ipv6Proxier.OnEndpointSlicesSynced()
175197
}
176198

177199
// endpointsIPFamily that returns IPFamily of endpoints or error if

0 commit comments

Comments
 (0)