userspace

package module
v0.0.0-...-edb81cd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

README

Windows Userspace backend

Windows userspace mode standalone out-of-tree backend. Uses netsh tools. The communication is made via gRPC to kpng core.

Flags

The following flags are available in the binary.

  • "bind-address", default: 0.0.0.0" - bind address
  • "port-range", default: "36000-37000" - port address range
  • "sync-period-duration", default: 15 seconds - "sync period duration"
  • "udp-idle-timeout", default: 10 seconds - "UDP idle timeout"

Compilation

Compile with go 1.18 and use the binary as a standalone service.

GOOS=windows go build -o winuserspace.exe ./...

NOTE: Must run with hostProcess if used direclty in the cluster.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingServiceEntry = errors.New("missing service entry")
	ErrMissingEndpoints    = errors.New("missing endpoints")
)
View Source
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

func ShuffleStrings(s []string) []string

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.

func New

func New(exec utilexec.Interface) Interface

New returns a new Interface which will exec netsh.

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

func (proxier *Proxier) OnEndpointsAdd(ep *localv1.Endpoint, svc *localv1.Service)

OnEndpointsAdd is called whenever creation of new endpoints object is observed.

func (*Proxier) OnEndpointsDelete

func (proxier *Proxier) OnEndpointsDelete(ep *localv1.Endpoint, svc *localv1.Service)

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

func (proxier *Proxier) OnEndpointsUpdate(oldEndpoints, endpoints *localv1.Endpoint)

OnEndpointsUpdate is called whenever modification of an existing endpoints object is observed.

func (*Proxier) OnServiceAdd

func (proxier *Proxier) OnServiceAdd(service *localv1.Service)

OnServiceAdd is called whenever creation of new service object is observed.

func (*Proxier) OnServiceDelete

func (proxier *Proxier) OnServiceDelete(service *localv1.Service)

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

func (proxier *Proxier) OnServiceUpdate(oldService, service *localv1.Service)

OnServiceUpdate is called whenever modification of an existing service object is observed.

func (*Proxier) Sync

func (proxier *Proxier) Sync()

Sync is called to immediately synchronize the proxier state

func (*Proxier) SyncLoop

func (proxier *Proxier) SyncLoop()

SyncLoop runs periodic work. This is expected to run as a goroutine or as the main loop of the app. It does not return.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL