Documentation ¶
Index ¶
- Variables
- func ShuffleStrings(s []string) []string
- type EndpointsHandler
- type Interface
- type LoadBalancer
- type LoadBalancerRR
- func (lb *LoadBalancerRR) CleanupStaleStickySessions(svcPort ServicePortName)
- func (lb *LoadBalancerRR) DeleteService(svcPort ServicePortName)
- func (lb *LoadBalancerRR) NewService(svcPort ServicePortName, affinityClientIP *localv1.ClientIPAffinity, ...) error
- func (lb *LoadBalancerRR) NextEndpoint(svcPort ServicePortName, srcAddr net.Addr, sessionAffinityReset bool) (string, error)
- func (lb *LoadBalancerRR) OnEndpointsAdd(ep *localv1.Endpoint, svc *localv1.Service)
- func (lb *LoadBalancerRR) OnEndpointsDelete(ep *localv1.Endpoint, svc *localv1.Service)
- func (lb *LoadBalancerRR) OnEndpointsSynced()
- type Provider
- type Proxier
- func (proxier *Proxier) OnEndpointsAdd(ep *localv1.Endpoint, svc *localv1.Service)
- func (proxier *Proxier) OnEndpointsDelete(ep *localv1.Endpoint, svc *localv1.Service)
- func (proxier *Proxier) OnEndpointsSynced()
- func (proxier *Proxier) OnEndpointsUpdate(oldEndpoints, endpoints *localv1.Endpoint)
- func (proxier *Proxier) OnServiceAdd(service *localv1.Service)
- func (proxier *Proxier) OnServiceDelete(service *localv1.Service)
- func (proxier *Proxier) OnServiceSynced()
- func (proxier *Proxier) OnServiceUpdate(oldService, service *localv1.Service)
- func (proxier *Proxier) Sync()
- func (proxier *Proxier) SyncLoop()
- type ServicePortName
- type ServicePortPortalName
Constants ¶
This section is empty.
Variables ¶
var ( ErrMissingServiceEntry = errors.New("missing service entry") ErrMissingEndpoints = errors.New("missing endpoints") )
var ( // ErrProxyOnLocalhost is returned by NewProxier if the user requests a proxier on // the loopback address. May be checked for by callers of NewProxier to know whether // the caller provided invalid input. ErrProxyOnLocalhost = fmt.Errorf("cannot proxy on localhost") )
Functions ¶
func ShuffleStrings ¶
ShuffleStrings copies strings from the specified slice into a copy in random order. It returns a new slice.
Types ¶
type EndpointsHandler ¶
type EndpointsHandler interface { // OnEndpointsAdd is called whenever creation of new endpoints object // is observed. OnEndpointsAdd(ep *localv1.Endpoint, svc *localv1.Service) // OnEndpointsDelete is called whenever deletion of an existing endpoints // object is observed. OnEndpointsDelete(ep *localv1.Endpoint, svc *localv1.Service) // OnEndpointsSynced is called once all the initial event handlers were // called and the state is fully propagated to local cache. OnEndpointsSynced() }
EndpointsHandler is an abstract interface of objects which receive notifications about endpoints object changes.
type Interface ¶
type Interface interface { // EnsurePortProxyRule checks if the specified redirect exists, if not creates it EnsurePortProxyRule(args []string) (bool, error) // DeletePortProxyRule deletes the specified portproxy rule. If the rule did not exist, return error. DeletePortProxyRule(args []string) error // EnsureIPAddress checks if the specified IP Address is added to vEthernet (HNSTransparent) interface, if not, add it. If the address existed, return true. EnsureIPAddress(args []string, ip net.IP) (bool, error) // DeleteIPAddress checks if the specified IP address is present and, if so, deletes it. DeleteIPAddress(args []string) error // Restore runs `netsh exec` to restore portproxy or addresses using a file. // TODO Check if this is required, most likely not Restore(args []string) error // GetInterfaceToAddIP returns the interface name where Service IP needs to be added // IP Address needs to be added for netsh portproxy to redirect traffic // Reads Environment variable INTERFACE_TO_ADD_SERVICE_IP, if it is not defined then "vEthernet (HNSTransparent)" is returned GetInterfaceToAddIP() string }
Interface is an injectable interface for running netsh commands. Implementations must be goroutine-safe.
type LoadBalancer ¶
type LoadBalancer interface { // NextEndpoint returns the endpoint to handle a request for the given // service-port and source address. NextEndpoint(service ServicePortName, srcAddr net.Addr, sessionAffinityReset bool) (string, error) NewService(service ServicePortName, affinityClientIP *localv1.ClientIPAffinity, stickyMaxAgeMinutes int) error DeleteService(service ServicePortName) CleanupStaleStickySessions(service ServicePortName) EndpointsHandler }
LoadBalancer is an interface for distributing incoming requests to service endpoints.
type LoadBalancerRR ¶
type LoadBalancerRR struct {
// contains filtered or unexported fields
}
LoadBalancerRR is a round-robin load balancer.
func NewLoadBalancerRR ¶
func NewLoadBalancerRR() *LoadBalancerRR
NewLoadBalancerRR returns a new LoadBalancerRR.
func (*LoadBalancerRR) CleanupStaleStickySessions ¶
func (lb *LoadBalancerRR) CleanupStaleStickySessions(svcPort ServicePortName)
func (*LoadBalancerRR) DeleteService ¶
func (lb *LoadBalancerRR) DeleteService(svcPort ServicePortName)
func (*LoadBalancerRR) NewService ¶
func (lb *LoadBalancerRR) NewService(svcPort ServicePortName, affinityClientIP *localv1.ClientIPAffinity, ttlSeconds int) error
func (*LoadBalancerRR) NextEndpoint ¶
func (lb *LoadBalancerRR) NextEndpoint(svcPort ServicePortName, srcAddr net.Addr, sessionAffinityReset bool) (string, error)
NextEndpoint returns a service endpoint. The service endpoint is chosen using the round-robin algorithm.
func (*LoadBalancerRR) OnEndpointsAdd ¶
func (lb *LoadBalancerRR) OnEndpointsAdd(ep *localv1.Endpoint, svc *localv1.Service)
func (*LoadBalancerRR) OnEndpointsDelete ¶
func (lb *LoadBalancerRR) OnEndpointsDelete(ep *localv1.Endpoint, svc *localv1.Service)
func (*LoadBalancerRR) OnEndpointsSynced ¶
func (lb *LoadBalancerRR) OnEndpointsSynced()
type Provider ¶
type Provider interface { EndpointsHandler // OnServiceAdd is called whenever creation of new service object // is observed. OnServiceAdd(service *localv1.Service) // OnServiceUpdate is called whenever modification of an existing // service object is observed. OnServiceUpdate(oldService, service *localv1.Service) // OnServiceDelete is called whenever deletion of an existing service // object is observed. OnServiceDelete(service *localv1.Service) // OnServiceSynced is called once all the initial event handlers were // called and the state is fully propagated to local cache. OnServiceSynced() // Sync immediately synchronizes the Provider's current state to proxy rules. Sync() // SyncLoop runs periodic work. // This is expected to run as a goroutine or as the main loop of the app. // It does not return. SyncLoop() }
Provider is a proxy interface enforcing services and endpoints methods implementations
type Proxier ¶
type Proxier struct {
// contains filtered or unexported fields
}
Proxier is a simple proxy for TCP connections between a localhost:lport and services that provide the actual implementations.
func NewProxier ¶
func NewProxier(loadBalancer LoadBalancer, listenIP net.IP, netsh Interface, pr utilnet.PortRange, syncPeriod, udpIdleTimeout time.Duration) (*Proxier, error)
NewProxier returns a new Proxier given a LoadBalancer and an address on which to listen. It is assumed that there is only a single Proxier active on a machine. An error will be returned if the proxier cannot be started due to an invalid ListenIP (loopback)
func (*Proxier) OnEndpointsAdd ¶
OnEndpointsAdd is called whenever creation of new endpoints object is observed.
func (*Proxier) OnEndpointsDelete ¶
OnEndpointsDelete is called whenever deletion of an existing endpoints object is observed. Service object
func (*Proxier) OnEndpointsSynced ¶
func (proxier *Proxier) OnEndpointsSynced()
OnEndpointsSynced is called once all the initial event handlers were called and the state is fully propagated to local cache.
func (*Proxier) OnEndpointsUpdate ¶
OnEndpointsUpdate is called whenever modification of an existing endpoints object is observed.
func (*Proxier) OnServiceAdd ¶
OnServiceAdd is called whenever creation of new service object is observed.
func (*Proxier) OnServiceDelete ¶
OnServiceDelete is called whenever deletion of an existing service object is observed.
func (*Proxier) OnServiceSynced ¶
func (proxier *Proxier) OnServiceSynced()
OnServiceSynced is called once all the initial event handlers were called and the state is fully propagated to local cache.
func (*Proxier) OnServiceUpdate ¶
OnServiceUpdate is called whenever modification of an existing service object is observed.
type ServicePortName ¶
type ServicePortName struct { types.NamespacedName Port string Protocol localv1.Protocol }
ServicePortName carries a namespace + name + portname. This is the unique identifier for a load-balanced service.
func (ServicePortName) String ¶
func (spn ServicePortName) String() string
type ServicePortPortalName ¶
type ServicePortPortalName struct { types.NamespacedName Port string PortalIPName string }
ServicePortPortalName carries a namespace + name + portname + portalip. This is the unique identifier for a windows service port portal.
func (ServicePortPortalName) String ¶
func (spn ServicePortPortalName) String() string