From 2ee1c80d0f71c9ad73dd2ecdb614f2f178a2bcd3 Mon Sep 17 00:00:00 2001 From: m1093782566 Date: Sun, 10 Dec 2017 15:09:50 +0800 Subject: [PATCH] abstract proxy servicePort and endpoints --- pkg/proxy/types.go | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/pkg/proxy/types.go b/pkg/proxy/types.go index 578baff693..613c570897 100644 --- a/pkg/proxy/types.go +++ b/pkg/proxy/types.go @@ -20,11 +20,12 @@ import ( "fmt" "k8s.io/apimachinery/pkg/types" + api "k8s.io/kubernetes/pkg/apis/core" ) // ProxyProvider is the interface provided by proxier implementations. type ProxyProvider interface { - // Sync immediately synchronizes the ProxyProvider's current state to iptables. + // Sync immediately synchronizes the ProxyProvider'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. @@ -33,7 +34,7 @@ type ProxyProvider interface { } // ServicePortName carries a namespace + name + portname. This is the unique -// identfier for a load-balanced service. +// identifier for a load-balanced service. type ServicePortName struct { types.NamespacedName Port string @@ -42,3 +43,34 @@ type ServicePortName struct { func (spn ServicePortName) String() string { return fmt.Sprintf("%s:%s", spn.NamespacedName.String(), spn.Port) } + +// ServicePort is an interface which abstracts information about a service. +type ServicePort interface { + // String returns service string. An example format can be: `IP:Port/Protocol`. + String() string + // ClusterIP returns service cluster IP. + ClusterIP() string + // Protocol returns service protocol. + Protocol() api.Protocol + // HealthCheckNodePort returns service health check node port if present. If return 0, it means not present. + HealthCheckNodePort() int +} + +// Endpoint in an interface which abstracts information about an endpoint. +type Endpoint interface { + // String returns endpoint string. An example format can be: `IP:Port`. + // We take the returned value as ServiceEndpoint.Endpoint. + String() string + // IsLocal returns true if the endpoint is running in same host as kube-proxy, otherwise returns false. + IsLocal() bool + // IP returns IP part of endpoints. + IP() string + // Equal checks if two endpoints are equal. + Equal(Endpoint) bool +} + +// ServiceEndpoint is used to identify a service and one of its endpoint pair. +type ServiceEndpoint struct { + Endpoint string + ServicePortName ServicePortName +}