Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
8e6257c5
Commit
8e6257c5
authored
Sep 23, 2016
by
Manuel de Brito Fontes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lister refactor kubernetes/kubernetes#33269
parent
6e0944eb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
62 deletions
+20
-62
middleware/kubernetes/controller.go
middleware/kubernetes/controller.go
+14
-23
middleware/kubernetes/kubernetes.go
middleware/kubernetes/kubernetes.go
+6
-6
middleware/pkg/strings/slice_test.go
middleware/pkg/strings/slice_test.go
+0
-33
No files found.
middleware/kubernetes/controller.go
View file @
8e6257c5
...
@@ -66,12 +66,15 @@ func newdnsController(kubeClient *client.Client, resyncPeriod time.Duration, lse
...
@@ -66,12 +66,15 @@ func newdnsController(kubeClient *client.Client, resyncPeriod time.Duration, lse
},
},
&
api
.
Endpoints
{},
resyncPeriod
,
cache
.
ResourceEventHandlerFuncs
{})
&
api
.
Endpoints
{},
resyncPeriod
,
cache
.
ResourceEventHandlerFuncs
{})
dns
.
svcLister
.
Store
,
dns
.
svcController
=
cache
.
New
Informer
(
dns
.
svcLister
.
Indexer
,
dns
.
svcController
=
cache
.
NewIndexer
Informer
(
&
cache
.
ListWatch
{
&
cache
.
ListWatch
{
ListFunc
:
serviceListFunc
(
dns
.
client
,
namespace
,
dns
.
selector
),
ListFunc
:
serviceListFunc
(
dns
.
client
,
namespace
,
dns
.
selector
),
WatchFunc
:
serviceWatchFunc
(
dns
.
client
,
namespace
,
dns
.
selector
),
WatchFunc
:
serviceWatchFunc
(
dns
.
client
,
namespace
,
dns
.
selector
),
},
},
&
api
.
Service
{},
resyncPeriod
,
cache
.
ResourceEventHandlerFuncs
{})
&
api
.
Service
{},
resyncPeriod
,
cache
.
ResourceEventHandlerFuncs
{},
cache
.
Indexers
{
cache
.
NamespaceIndex
:
cache
.
MetaNamespaceIndexFunc
})
dns
.
nsLister
.
Store
,
dns
.
nsController
=
cache
.
NewInformer
(
dns
.
nsLister
.
Store
,
dns
.
nsController
=
cache
.
NewInformer
(
&
cache
.
ListWatch
{
&
cache
.
ListWatch
{
...
@@ -174,27 +177,23 @@ func (dns *dnsController) GetNamespaceList() *api.NamespaceList {
...
@@ -174,27 +177,23 @@ func (dns *dnsController) GetNamespaceList() *api.NamespaceList {
return
&
nsList
return
&
nsList
}
}
func
(
dns
*
dnsController
)
GetServiceList
()
*
api
.
ServiceList
{
func
(
dns
*
dnsController
)
GetServiceList
()
[]
*
api
.
Service
{
svc
List
,
err
:=
dns
.
svcLister
.
List
(
)
svc
s
,
err
:=
dns
.
svcLister
.
List
(
labels
.
Everything
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
&
api
.
ServiceList
{}
return
[]
*
api
.
Service
{}
}
}
return
&
svcList
return
svcs
}
}
// GetServicesByNamespace returns a map of
// GetServicesByNamespace returns a map of
// namespacename :: [ kubernetesService ]
// namespacename :: [ kubernetesService ]
func
(
dns
*
dnsController
)
GetServicesByNamespace
()
map
[
string
][]
api
.
Service
{
func
(
dns
*
dnsController
)
GetServicesByNamespace
()
map
[
string
][]
api
.
Service
{
k8sServiceList
:=
dns
.
GetServiceList
()
k8sServiceList
:=
dns
.
GetServiceList
()
if
k8sServiceList
==
nil
{
items
:=
make
(
map
[
string
][]
api
.
Service
,
len
(
k8sServiceList
))
return
nil
for
_
,
i
:=
range
k8sServiceList
{
}
items
:=
make
(
map
[
string
][]
api
.
Service
,
len
(
k8sServiceList
.
Items
))
for
_
,
i
:=
range
k8sServiceList
.
Items
{
namespace
:=
i
.
Namespace
namespace
:=
i
.
Namespace
items
[
namespace
]
=
append
(
items
[
namespace
],
i
)
items
[
namespace
]
=
append
(
items
[
namespace
],
*
i
)
}
}
return
items
return
items
...
@@ -203,18 +202,10 @@ func (dns *dnsController) GetServicesByNamespace() map[string][]api.Service {
...
@@ -203,18 +202,10 @@ func (dns *dnsController) GetServicesByNamespace() map[string][]api.Service {
// GetServiceInNamespace returns the Service that matches
// GetServiceInNamespace returns the Service that matches
// servicename in the namespace
// servicename in the namespace
func
(
dns
*
dnsController
)
GetServiceInNamespace
(
namespace
string
,
servicename
string
)
*
api
.
Service
{
func
(
dns
*
dnsController
)
GetServiceInNamespace
(
namespace
string
,
servicename
string
)
*
api
.
Service
{
svcKey
:=
fmt
.
Sprintf
(
"%v/%v"
,
namespace
,
servicename
)
svcObj
,
err
:=
dns
.
svcLister
.
Services
(
namespace
)
.
Get
(
servicename
)
svcObj
,
svcExists
,
err
:=
dns
.
svcLister
.
Store
.
GetByKey
(
svcKey
)
if
err
!=
nil
{
if
err
!=
nil
{
// TODO(...): should return err here
// TODO(...): should return err here
return
nil
return
nil
}
}
return
svcObj
if
!
svcExists
{
// TODO(...): should return err here
return
nil
}
return
svcObj
.
(
*
api
.
Service
)
}
}
middleware/kubernetes/kubernetes.go
View file @
8e6257c5
...
@@ -159,7 +159,7 @@ func (k *Kubernetes) Records(name string, exact bool) ([]msg.Service, error) {
...
@@ -159,7 +159,7 @@ func (k *Kubernetes) Records(name string, exact bool) ([]msg.Service, error) {
}
}
// TODO: assemble name from parts found in k8s data based on name template rather than reusing query string
// TODO: assemble name from parts found in k8s data based on name template rather than reusing query string
func
(
k
*
Kubernetes
)
getRecordsForServiceItems
(
serviceItems
[]
api
.
Service
,
values
nametemplate
.
NameValues
)
[]
msg
.
Service
{
func
(
k
*
Kubernetes
)
getRecordsForServiceItems
(
serviceItems
[]
*
api
.
Service
,
values
nametemplate
.
NameValues
)
[]
msg
.
Service
{
var
records
[]
msg
.
Service
var
records
[]
msg
.
Service
for
_
,
item
:=
range
serviceItems
{
for
_
,
item
:=
range
serviceItems
{
...
@@ -182,12 +182,12 @@ func (k *Kubernetes) getRecordsForServiceItems(serviceItems []api.Service, value
...
@@ -182,12 +182,12 @@ func (k *Kubernetes) getRecordsForServiceItems(serviceItems []api.Service, value
}
}
// Get performs the call to the Kubernetes http API.
// Get performs the call to the Kubernetes http API.
func
(
k
*
Kubernetes
)
Get
(
namespace
string
,
nsWildcard
bool
,
servicename
string
,
serviceWildcard
bool
)
([]
api
.
Service
,
error
)
{
func
(
k
*
Kubernetes
)
Get
(
namespace
string
,
nsWildcard
bool
,
servicename
string
,
serviceWildcard
bool
)
([]
*
api
.
Service
,
error
)
{
serviceList
:=
k
.
APIConn
.
GetServiceList
()
serviceList
:=
k
.
APIConn
.
GetServiceList
()
var
resultItems
[]
api
.
Service
var
resultItems
[]
*
api
.
Service
for
_
,
item
:=
range
serviceList
.
Items
{
for
_
,
item
:=
range
serviceList
{
if
symbolMatches
(
namespace
,
item
.
Namespace
,
nsWildcard
)
&&
symbolMatches
(
servicename
,
item
.
Name
,
serviceWildcard
)
{
if
symbolMatches
(
namespace
,
item
.
Namespace
,
nsWildcard
)
&&
symbolMatches
(
servicename
,
item
.
Name
,
serviceWildcard
)
{
// If namespace has a wildcard, filter results against Corefile namespace list.
// If namespace has a wildcard, filter results against Corefile namespace list.
// (Namespaces without a wildcard were filtered before the call to this function.)
// (Namespaces without a wildcard were filtered before the call to this function.)
...
@@ -220,11 +220,11 @@ func isKubernetesNameError(err error) bool {
...
@@ -220,11 +220,11 @@ func isKubernetesNameError(err error) bool {
}
}
func
(
k
*
Kubernetes
)
getServiceRecordForIP
(
ip
,
name
string
)
[]
msg
.
Service
{
func
(
k
*
Kubernetes
)
getServiceRecordForIP
(
ip
,
name
string
)
[]
msg
.
Service
{
svcList
,
err
:=
k
.
APIConn
.
svcLister
.
List
()
svcList
,
err
:=
k
.
APIConn
.
svcLister
.
List
(
labels
.
Everything
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
return
nil
}
}
for
_
,
service
:=
range
svcList
.
Items
{
for
_
,
service
:=
range
svcList
{
if
service
.
Spec
.
ClusterIP
==
ip
{
if
service
.
Spec
.
ClusterIP
==
ip
{
return
[]
msg
.
Service
{
msg
.
Service
{
Host
:
ip
}}
return
[]
msg
.
Service
{
msg
.
Service
{
Host
:
ip
}}
}
}
...
...
middleware/pkg/strings/slice_test.go
deleted
100644 → 0
View file @
6e0944eb
package
strings
import
(
"testing"
)
type
InSliceData
struct
{
Slice
[]
string
String
string
InSlice
bool
}
// Test data for TestStringInSlice cases.
var
testdataInSlice
=
[]
struct
{
Slice
[]
string
String
string
ExpectedResult
bool
}{
{[]
string
{
"a"
,
"b"
,
"c"
},
"a"
,
true
},
{[]
string
{
"a"
,
"b"
,
"c"
},
"d"
,
false
},
{[]
string
{
"a"
,
"b"
,
"c"
},
""
,
false
},
{[]
string
{},
"a"
,
false
},
{[]
string
{},
""
,
false
},
}
func
TestStringInSlice
(
t
*
testing
.
T
)
{
for
_
,
example
:=
range
testdataInSlice
{
actualResult
:=
StringInSlice
(
example
.
String
,
example
.
Slice
)
if
actualResult
!=
example
.
ExpectedResult
{
t
.
Errorf
(
"Expected stringInSlice result '%v' for example string='%v', slice='%v'. Instead got result '%v'."
,
example
.
ExpectedResult
,
example
.
String
,
example
.
Slice
,
actualResult
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment