Skip to content

Commit 9a454d8

Browse files
committed
HybridProxy: Deal with removed service ObjectRef
Upstream removed our ObjectReference in the ServiceInfo. Now, we have to fake an object reference when we submit events using just the name and namespace from the service info.
1 parent 2cdf44d commit 9a454d8

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

pkg/proxy/unidler/unidlerproxy.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"net"
55
"time"
66

7+
"k8s.io/apimachinery/pkg/types"
78
utilnet "k8s.io/apimachinery/pkg/util/net"
89
"k8s.io/client-go/pkg/api/v1"
910
"k8s.io/client-go/tools/record"
@@ -18,23 +19,20 @@ import (
1819
type NeedPodsSignaler interface {
1920
// NeedPods signals that endpoint addresses are needed in order to
2021
// service a traffic coming to the given service and port
21-
NeedPods(serviceRef api.ObjectReference, port string) error
22+
NeedPods(serviceName types.NamespacedName, port string) error
2223
}
2324

2425
type eventSignaler struct {
2526
recorder record.EventRecorder
2627
}
2728

28-
func (sig *eventSignaler) NeedPods(serviceRefInt api.ObjectReference, port string) error {
29-
// TODO(directxman12): fix upstream so that it passes around v1.ObjectReference instead of api.ObjectReference
30-
// NB: api.ObjectReference doesn't appear to be registered as a type, so we have to do manual conversion...
29+
func (sig *eventSignaler) NeedPods(serviceName types.NamespacedName, port string) error {
30+
// TODO: we need to fake this since upstream removed our handle to the ObjectReference
31+
// This *should* be sufficient for the unidling controller
3132
serviceRef := v1.ObjectReference{
32-
Kind: serviceRefInt.Kind,
33-
Namespace: serviceRefInt.Namespace,
34-
Name: serviceRefInt.Name,
35-
UID: serviceRefInt.UID,
36-
APIVersion: serviceRefInt.APIVersion,
37-
ResourceVersion: serviceRefInt.ResourceVersion,
33+
Kind: "Service",
34+
Namespace: serviceName.Namespace,
35+
Name: serviceName.Name,
3836
}
3937

4038
// HACK: make the message different to prevent event aggregation

pkg/proxy/unidler/unidlersocket.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (tcp *tcpUnidlerSocket) acceptConns(ch chan<- net.Conn, svcInfo *userspace.
199199
// (and thus the hybrid proxy has switched this service over to using the normal proxy). Connections will
200200
// be gradually timed out and dropped off the list of connections on a per-connection basis. The list of current
201201
// connections is returned, in addition to whether or not we should retry this method.
202-
func (tcp *tcpUnidlerSocket) awaitAwakening(service proxy.ServicePortName, serviceRef api.ObjectReference, loadBalancer userspace.LoadBalancer, inConns <-chan net.Conn, endpointsAvail chan<- interface{}) (*connectionList, bool) {
202+
func (tcp *tcpUnidlerSocket) awaitAwakening(service proxy.ServicePortName, loadBalancer userspace.LoadBalancer, inConns <-chan net.Conn, endpointsAvail chan<- interface{}) (*connectionList, bool) {
203203
// collect connections and wait for endpoints to be available
204204
sent_need_pods := false
205205
timeout_started := false
@@ -218,7 +218,7 @@ func (tcp *tcpUnidlerSocket) awaitAwakening(service proxy.ServicePortName, servi
218218

219219
if !sent_need_pods && !loadBalancer.ServiceHasEndpoints(service) {
220220
glog.V(4).Infof("unidling TCP proxy sent unidle event to wake up service %s/%s:%s", service.Namespace, service.Name, service.Port)
221-
tcp.signaler.NeedPods(serviceRef, service.Port)
221+
tcp.signaler.NeedPods(service.NamespacedName, service.Port)
222222

223223
// only send NeedPods once
224224
sent_need_pods = true
@@ -262,7 +262,7 @@ func (tcp *tcpUnidlerSocket) ProxyLoop(service proxy.ServicePortName, svcInfo *u
262262
glog.V(4).Infof("unidling TCP proxy start/reset for service %s/%s:%s", service.Namespace, service.Name, service.Port)
263263

264264
var cont bool
265-
if allConns, cont = tcp.awaitAwakening(service, svcInfo.ServiceRef, loadBalancer, inConns, endpointsAvail); !cont {
265+
if allConns, cont = tcp.awaitAwakening(service, loadBalancer, inConns, endpointsAvail); !cont {
266266
break
267267
}
268268
}
@@ -342,7 +342,7 @@ func (udp *udpUnidlerSocket) readFromSock(buffer []byte, svcInfo *userspace.Serv
342342
func (udp *udpUnidlerSocket) sendWakeup(svcPortName proxy.ServicePortName, svcInfo *userspace.ServiceInfo) *time.Timer {
343343
timeoutTimer := time.NewTimer(needPodsWaitTimeout)
344344
glog.V(4).Infof("unidling proxy sent unidle event to wake up service %s/%s:%s", svcPortName.Namespace, svcPortName.Name, svcPortName.Port)
345-
udp.signaler.NeedPods(svcInfo.ServiceRef, svcPortName.Port)
345+
udp.signaler.NeedPods(svcPortName.NamespacedName, svcPortName.Port)
346346

347347
return timeoutTimer
348348
}

0 commit comments

Comments
 (0)