@@ -27,6 +27,7 @@ import (
2727
2828 "github.com/golang/glog"
2929 "k8s.io/kubernetes/pkg/api"
30+ kubeclient "k8s.io/kubernetes/pkg/client/unversioned"
3031 "k8s.io/kubernetes/pkg/proxy"
3132 "k8s.io/kubernetes/pkg/types"
3233 utilnet "k8s.io/kubernetes/pkg/util/net"
@@ -95,6 +96,8 @@ type Proxier struct {
9596 iptables iptables.Interface
9697 hostIP net.IP
9798 proxyPorts PortAllocator
99+ kubeClient * kubeclient.Client
100+ withHaproxier bool
98101}
99102
100103// assert Proxier is a ProxyProvider
@@ -139,7 +142,7 @@ func IsProxyLocked(err error) bool {
139142// if iptables fails to update or acquire the initial lock. Once a proxier is
140143// created, it will keep iptables up to date in the background and will not
141144// terminate if a particular iptables call fails.
142- func NewProxier (loadBalancer LoadBalancer , listenIP net.IP , iptables iptables.Interface , pr utilnet.PortRange , syncPeriod , udpIdleTimeout time.Duration ) (* Proxier , error ) {
145+ func NewProxier (loadBalancer LoadBalancer , listenIP net.IP , iptables iptables.Interface , pr utilnet.PortRange , syncPeriod , udpIdleTimeout time.Duration , kubeClient * kubeclient. Client , withHaproxier bool ) (* Proxier , error ) {
143146 if listenIP .Equal (localhostIPv4 ) || listenIP .Equal (localhostIPv6 ) {
144147 return nil , ErrProxyOnLocalhost
145148 }
@@ -157,10 +160,14 @@ func NewProxier(loadBalancer LoadBalancer, listenIP net.IP, iptables iptables.In
157160 proxyPorts := newPortAllocator (pr )
158161
159162 glog .V (2 ).Infof ("Setting proxy IP to %v and initializing iptables" , hostIP )
160- return createProxier (loadBalancer , listenIP , iptables , hostIP , proxyPorts , syncPeriod , udpIdleTimeout )
163+ return createProxier (loadBalancer , listenIP , iptables , hostIP , proxyPorts , syncPeriod , udpIdleTimeout , kubeClient , withHaproxier )
161164}
162165
163- func createProxier (loadBalancer LoadBalancer , listenIP net.IP , iptables iptables.Interface , hostIP net.IP , proxyPorts PortAllocator , syncPeriod , udpIdleTimeout time.Duration ) (* Proxier , error ) {
166+ func setRLimit (limit uint64 ) error {
167+ return syscall .Setrlimit (syscall .RLIMIT_NOFILE , & syscall.Rlimit {Max : limit , Cur : limit })
168+ }
169+
170+ func createProxier (loadBalancer LoadBalancer , listenIP net.IP , iptables iptables.Interface , hostIP net.IP , proxyPorts PortAllocator , syncPeriod , udpIdleTimeout time.Duration , kubeClient * kubeclient.Client , withHaproxier bool ) (* Proxier , error ) {
164171 // convenient to pass nil for tests..
165172 if proxyPorts == nil {
166173 proxyPorts = newPortAllocator (utilnet.PortRange {})
@@ -184,6 +191,8 @@ func createProxier(loadBalancer LoadBalancer, listenIP net.IP, iptables iptables
184191 iptables : iptables ,
185192 hostIP : hostIP ,
186193 proxyPorts : proxyPorts ,
194+ kubeClient : kubeClient ,
195+ withHaproxier : withHaproxier ,
187196 }, nil
188197}
189198
@@ -377,6 +386,20 @@ func (proxier *Proxier) OnServiceUpdate(services []api.Service) {
377386 for i := range services {
378387 service := & services [i ]
379388
389+ // Check if namespace is configured with network
390+ if proxier .withHaproxier {
391+ namespace , err := proxier .kubeClient .Namespaces ().Get (service .Namespace )
392+ if err != nil {
393+ glog .Warningf ("Get namespace error: %v" , err )
394+ continue
395+ }
396+ if namespace .Spec .Network != "" {
397+ // Only process namespaces without network
398+ // Namespaces with network will be processed by haproxy proxier
399+ continue
400+ }
401+ }
402+
380403 // if ClusterIP is "None" or empty, skip proxying
381404 if ! api .IsServiceIPSet (service ) {
382405 glog .V (3 ).Infof ("Skipping service %s due to clusterIP = %q" , types.NamespacedName {Namespace : service .Namespace , Name : service .Name }, service .Spec .ClusterIP )
0 commit comments