Skip to content

Commit

Permalink
Add Node and EndpointSlice handlers to metaProxier (#4641)
Browse files Browse the repository at this point in the history
Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
  • Loading branch information
hongliangl committed Feb 22, 2023
1 parent e909b97 commit aafea18
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 1 deletion.
75 changes: 75 additions & 0 deletions third_party/proxy/meta_proxier.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"fmt"

v1 "k8s.io/api/core/v1"
discovery "k8s.io/api/discovery/v1"
"k8s.io/klog/v2"
utilnet "k8s.io/utils/net"
)
Expand Down Expand Up @@ -153,6 +154,80 @@ func (proxier *metaProxier) OnEndpointsSynced() {
proxier.ipv6Proxier.OnEndpointsSynced()
}

// OnEndpointSliceAdd is called whenever creation of a new endpoint slice object
// is observed.
func (proxier *metaProxier) OnEndpointSliceAdd(endpointSlice *discovery.EndpointSlice) {
switch endpointSlice.AddressType {
case discovery.AddressTypeIPv4:
proxier.ipv4Proxier.OnEndpointSliceAdd(endpointSlice)
case discovery.AddressTypeIPv6:
proxier.ipv6Proxier.OnEndpointSliceAdd(endpointSlice)
default:
klog.ErrorS(nil, "EndpointSlice address type not supported", "addressType", endpointSlice.AddressType)
}
}

// OnEndpointSliceUpdate is called whenever modification of an existing endpoint
// slice object is observed.
func (proxier *metaProxier) OnEndpointSliceUpdate(oldEndpointSlice, newEndpointSlice *discovery.EndpointSlice) {
switch newEndpointSlice.AddressType {
case discovery.AddressTypeIPv4:
proxier.ipv4Proxier.OnEndpointSliceUpdate(oldEndpointSlice, newEndpointSlice)
case discovery.AddressTypeIPv6:
proxier.ipv6Proxier.OnEndpointSliceUpdate(oldEndpointSlice, newEndpointSlice)
default:
klog.ErrorS(nil, "EndpointSlice address type not supported", "addressType", newEndpointSlice.AddressType)
}
}

// OnEndpointSliceDelete is called whenever deletion of an existing endpoint slice
// object is observed.
func (proxier *metaProxier) OnEndpointSliceDelete(endpointSlice *discovery.EndpointSlice) {
switch endpointSlice.AddressType {
case discovery.AddressTypeIPv4:
proxier.ipv4Proxier.OnEndpointSliceDelete(endpointSlice)
case discovery.AddressTypeIPv6:
proxier.ipv6Proxier.OnEndpointSliceDelete(endpointSlice)
default:
klog.ErrorS(nil, "EndpointSlice address type not supported", "addressType", endpointSlice.AddressType)
}
}

// OnEndpointSlicesSynced is called once all the initial event handlers were
// called and the state is fully propagated to local cache.
func (proxier *metaProxier) OnEndpointSlicesSynced() {
proxier.ipv4Proxier.OnEndpointSlicesSynced()
proxier.ipv6Proxier.OnEndpointSlicesSynced()
}

// OnNodeAdd is called whenever creation of new node object is observed.
func (proxier *metaProxier) OnNodeAdd(node *v1.Node) {
proxier.ipv4Proxier.OnNodeAdd(node)
proxier.ipv6Proxier.OnNodeAdd(node)
}

// OnNodeUpdate is called whenever modification of an existing
// node object is observed.
func (proxier *metaProxier) OnNodeUpdate(oldNode, node *v1.Node) {
proxier.ipv4Proxier.OnNodeUpdate(oldNode, node)
proxier.ipv6Proxier.OnNodeUpdate(oldNode, node)
}

// OnNodeDelete is called whenever deletion of an existing node
// object is observed.
func (proxier *metaProxier) OnNodeDelete(node *v1.Node) {
proxier.ipv4Proxier.OnNodeDelete(node)
proxier.ipv6Proxier.OnNodeDelete(node)

}

// OnNodeSynced is called once all the initial event handlers were
// called and the state is fully propagated to local cache.
func (proxier *metaProxier) OnNodeSynced() {
proxier.ipv4Proxier.OnNodeSynced()
proxier.ipv6Proxier.OnNodeSynced()
}

func (proxier *metaProxier) Run(stopCh <-chan struct{}) {
go proxier.ipv4Proxier.Run(stopCh)
proxier.ipv6Proxier.Run(stopCh)
Expand Down
99 changes: 98 additions & 1 deletion third_party/proxy/testing/mock_proxy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions third_party/proxy/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ import (
// Provider is the interface provided by proxier implementations.
type Provider interface {
config.EndpointsHandler
config.EndpointSliceHandler
config.NodeHandler
config.ServiceHandler

// SyncLoop runs periodic work.
Expand Down

0 comments on commit aafea18

Please sign in to comment.