forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
unidlerproxy.go
59 lines (49 loc) · 2.25 KB
/
unidlerproxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package unidler
import (
"net"
"time"
"k8s.io/apimachinery/pkg/types"
utilnet "k8s.io/apimachinery/pkg/util/net"
"k8s.io/client-go/pkg/api/v1"
"k8s.io/client-go/tools/record"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/proxy/userspace"
utilexec "k8s.io/kubernetes/pkg/util/exec"
"k8s.io/kubernetes/pkg/util/iptables"
unidlingapi "github.com/openshift/origin/pkg/unidling/api"
)
type NeedPodsSignaler interface {
// NeedPods signals that endpoint addresses are needed in order to
// service a traffic coming to the given service and port
NeedPods(serviceName types.NamespacedName, port string) error
}
type eventSignaler struct {
recorder record.EventRecorder
}
func (sig *eventSignaler) NeedPods(serviceName types.NamespacedName, port string) error {
// TODO: we need to fake this since upstream removed our handle to the ObjectReference
// This *should* be sufficient for the unidling controller
serviceRef := v1.ObjectReference{
Kind: "Service",
Namespace: serviceName.Namespace,
Name: serviceName.Name,
}
// HACK: make the message different to prevent event aggregation
sig.recorder.Eventf(&serviceRef, v1.EventTypeNormal, unidlingapi.NeedPodsReason, "The service-port %s:%s needs pods.", serviceRef.Name, port)
return nil
}
// NewEventSignaler constructs a NeedPodsSignaler which signals by recording
// an event for the service with the "NeedPods" reason.
func NewEventSignaler(eventRecorder record.EventRecorder) NeedPodsSignaler {
return &eventSignaler{
recorder: eventRecorder,
}
}
// NewUnidlerProxier creates a new Proxier for the given LoadBalancer and address which fires off
// unidling signals connections and traffic. It is intended to be used as one half of a HybridProxier.
func NewUnidlerProxier(loadBalancer userspace.LoadBalancer, listenIP net.IP, iptables iptables.Interface, exec utilexec.Interface, pr utilnet.PortRange, syncPeriod, minSyncPeriod, udpIdleTimeout time.Duration, signaler NeedPodsSignaler) (*userspace.Proxier, error) {
newFunc := func(protocol api.Protocol, ip net.IP, port int) (userspace.ProxySocket, error) {
return newUnidlerSocket(protocol, ip, port, signaler)
}
return userspace.NewCustomProxier(loadBalancer, listenIP, iptables, exec, pr, syncPeriod, minSyncPeriod, udpIdleTimeout, newFunc)
}