Simplify some code and comments.

Signed-off-by: Yecheng Fu <cofyc.jackson@gmail.com>
pull/4117/head
Yecheng Fu 2018-04-26 00:36:22 +08:00 committed by beorn7
parent 46683dd67d
commit 2be543e65a
7 changed files with 8 additions and 11 deletions

View File

@ -182,7 +182,7 @@ func convertToEndpoints(o interface{}) (*apiv1.Endpoints, error) {
} }
func endpointsSource(ep *apiv1.Endpoints) string { func endpointsSource(ep *apiv1.Endpoints) string {
return "endpoints/" + ep.ObjectMeta.Namespace + "/" + ep.ObjectMeta.Name return endpointsSourceFromNamespaceAndName(ep.Namespace, ep.Name)
} }
func endpointsSourceFromNamespaceAndName(namespace, name string) string { func endpointsSourceFromNamespaceAndName(namespace, name string) string {

View File

@ -122,7 +122,7 @@ func convertToIngress(o interface{}) (*v1beta1.Ingress, error) {
} }
func ingressSource(s *v1beta1.Ingress) string { func ingressSource(s *v1beta1.Ingress) string {
return "ingress/" + s.Namespace + "/" + s.Name return ingressSourceFromNamespaceAndName(s.Namespace, s.Name)
} }
func ingressSourceFromNamespaceAndName(namespace, name string) string { func ingressSourceFromNamespaceAndName(namespace, name string) string {

View File

@ -155,7 +155,6 @@ func init() {
} }
} }
// Copy of discovery.Discoverer to avoid import cycle.
// This is only for internal use. // This is only for internal use.
type discoverer interface { type discoverer interface {
Run(ctx context.Context, up chan<- []*targetgroup.Group) Run(ctx context.Context, up chan<- []*targetgroup.Group)

View File

@ -117,7 +117,7 @@ func (d k8sDiscoveryTest) Run(t *testing.T) {
// Run discoverer and start a goroutine to read results. // Run discoverer and start a goroutine to read results.
go d.discovery.Run(ctx, ch) go d.discovery.Run(ctx, ch)
resChan := make(chan map[string]*targetgroup.Group) resChan := make(chan map[string]*targetgroup.Group)
go readResultWithoutTimeout(t, ch, d.expectedMaxItems, time.Second, resChan) go readResultWithTimeout(t, ch, d.expectedMaxItems, time.Second, resChan)
dd, ok := d.discovery.(hasSynced) dd, ok := d.discovery.(hasSynced)
if !ok { if !ok {
@ -139,9 +139,9 @@ func (d k8sDiscoveryTest) Run(t *testing.T) {
} }
} }
// readResultWithoutTimeout reads all targegroups from channel with timeout. // readResultWithTimeout reads all targegroups from channel with timeout.
// It merges targegroups by source and sends the result to result channel. // It merges targegroups by source and sends the result to result channel.
func readResultWithoutTimeout(t *testing.T, ch <-chan []*targetgroup.Group, max int, timeout time.Duration, resChan chan<- map[string]*targetgroup.Group) { func readResultWithTimeout(t *testing.T, ch <-chan []*targetgroup.Group, max int, timeout time.Duration, resChan chan<- map[string]*targetgroup.Group) {
allTgs := make([][]*targetgroup.Group, 0) allTgs := make([][]*targetgroup.Group, 0)
Loop: Loop:

View File

@ -38,8 +38,6 @@ type Node struct {
queue *workqueue.Type queue *workqueue.Type
} }
var _ discoverer = &Node{}
// NewNode returns a new node discovery. // NewNode returns a new node discovery.
func NewNode(l log.Logger, inf cache.SharedInformer) *Node { func NewNode(l log.Logger, inf cache.SharedInformer) *Node {
if l == nil { if l == nil {
@ -130,7 +128,7 @@ func convertToNode(o interface{}) (*apiv1.Node, error) {
} }
func nodeSource(n *apiv1.Node) string { func nodeSource(n *apiv1.Node) string {
return "node/" + n.Name return nodeSourceFromName(n.Name)
} }
func nodeSourceFromName(name string) string { func nodeSourceFromName(name string) string {

View File

@ -215,7 +215,7 @@ func (p *Pod) buildPod(pod *apiv1.Pod) *targetgroup.Group {
} }
func podSource(pod *apiv1.Pod) string { func podSource(pod *apiv1.Pod) string {
return "pod/" + pod.Namespace + "/" + pod.Name return podSourceFromNamespaceAndName(pod.Namespace, pod.Name)
} }
func podSourceFromNamespaceAndName(namespace, name string) string { func podSourceFromNamespaceAndName(namespace, name string) string {

View File

@ -127,7 +127,7 @@ func convertToService(o interface{}) (*apiv1.Service, error) {
} }
func serviceSource(s *apiv1.Service) string { func serviceSource(s *apiv1.Service) string {
return "svc/" + s.Namespace + "/" + s.Name return serviceSourceFromNamespaceAndName(s.Namespace, s.Name)
} }
func serviceSourceFromNamespaceAndName(namespace, name string) string { func serviceSourceFromNamespaceAndName(namespace, name string) string {