Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
63ae2603
Unverified
Commit
63ae2603
authored
May 12, 2017
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make endpoints controller update based on semantic equality
parent
bb67819e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
3 deletions
+71
-3
BUILD
pkg/controller/endpoint/BUILD
+1
-0
endpoints_controller.go
pkg/controller/endpoint/endpoints_controller.go
+6
-3
endpoints_controller_test.go
pkg/controller/endpoint/endpoints_controller_test.go
+64
-0
No files found.
pkg/controller/endpoint/BUILD
View file @
63ae2603
...
...
@@ -20,6 +20,7 @@ go_library(
"//pkg/util/metrics:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
...
...
pkg/controller/endpoint/endpoints_controller.go
View file @
63ae2603
...
...
@@ -23,6 +23,7 @@ import (
"time"
"k8s.io/api/core/v1"
apiequality
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
...
...
@@ -434,8 +435,11 @@ func (e *EndpointController) syncService(key string) error {
}
}
if
reflect
.
DeepEqual
(
currentEndpoints
.
Subsets
,
subsets
)
&&
reflect
.
DeepEqual
(
currentEndpoints
.
Labels
,
service
.
Labels
)
{
createEndpoints
:=
len
(
currentEndpoints
.
ResourceVersion
)
==
0
if
!
createEndpoints
&&
apiequality
.
Semantic
.
DeepEqual
(
currentEndpoints
.
Subsets
,
subsets
)
&&
apiequality
.
Semantic
.
DeepEqual
(
currentEndpoints
.
Labels
,
service
.
Labels
)
{
glog
.
V
(
5
)
.
Infof
(
"endpoints are equal for %s/%s, skipping update"
,
service
.
Namespace
,
service
.
Name
)
return
nil
}
...
...
@@ -451,7 +455,6 @@ func (e *EndpointController) syncService(key string) error {
}
glog
.
V
(
4
)
.
Infof
(
"Update endpoints for %v/%v, ready: %d not ready: %d"
,
service
.
Namespace
,
service
.
Name
,
totalReadyEps
,
totalNotReadyEps
)
createEndpoints
:=
len
(
currentEndpoints
.
ResourceVersion
)
==
0
if
createEndpoints
{
// No previous endpoints, create them
_
,
err
=
e
.
client
.
Core
()
.
Endpoints
(
service
.
Namespace
)
.
Create
(
newEndpoints
)
...
...
pkg/controller/endpoint/endpoints_controller_test.go
View file @
63ae2603
...
...
@@ -175,6 +175,70 @@ func TestSyncEndpointsItemsPreserveNoSelector(t *testing.T) {
endpointsHandler
.
ValidateRequestCount
(
t
,
0
)
}
func
TestSyncEndpointsExistingNilSubsets
(
t
*
testing
.
T
)
{
ns
:=
metav1
.
NamespaceDefault
testServer
,
endpointsHandler
:=
makeTestServer
(
t
,
ns
)
defer
testServer
.
Close
()
endpoints
:=
newController
(
testServer
.
URL
)
endpoints
.
endpointsStore
.
Add
(
&
v1
.
Endpoints
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
ns
,
ResourceVersion
:
"1"
,
},
Subsets
:
nil
,
})
endpoints
.
serviceStore
.
Add
(
&
v1
.
Service
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
ns
},
Spec
:
v1
.
ServiceSpec
{
Selector
:
map
[
string
]
string
{
"foo"
:
"bar"
},
Ports
:
[]
v1
.
ServicePort
{{
Port
:
80
}},
},
})
endpoints
.
syncService
(
ns
+
"/foo"
)
endpointsHandler
.
ValidateRequestCount
(
t
,
0
)
}
func
TestSyncEndpointsExistingEmptySubsets
(
t
*
testing
.
T
)
{
ns
:=
metav1
.
NamespaceDefault
testServer
,
endpointsHandler
:=
makeTestServer
(
t
,
ns
)
defer
testServer
.
Close
()
endpoints
:=
newController
(
testServer
.
URL
)
endpoints
.
endpointsStore
.
Add
(
&
v1
.
Endpoints
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
ns
,
ResourceVersion
:
"1"
,
},
Subsets
:
[]
v1
.
EndpointSubset
{},
})
endpoints
.
serviceStore
.
Add
(
&
v1
.
Service
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
ns
},
Spec
:
v1
.
ServiceSpec
{
Selector
:
map
[
string
]
string
{
"foo"
:
"bar"
},
Ports
:
[]
v1
.
ServicePort
{{
Port
:
80
}},
},
})
endpoints
.
syncService
(
ns
+
"/foo"
)
endpointsHandler
.
ValidateRequestCount
(
t
,
0
)
}
func
TestSyncEndpointsNewNoSubsets
(
t
*
testing
.
T
)
{
ns
:=
metav1
.
NamespaceDefault
testServer
,
endpointsHandler
:=
makeTestServer
(
t
,
ns
)
defer
testServer
.
Close
()
endpoints
:=
newController
(
testServer
.
URL
)
endpoints
.
serviceStore
.
Add
(
&
v1
.
Service
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
ns
},
Spec
:
v1
.
ServiceSpec
{
Selector
:
map
[
string
]
string
{
"foo"
:
"bar"
},
Ports
:
[]
v1
.
ServicePort
{{
Port
:
80
}},
},
})
endpoints
.
syncService
(
ns
+
"/foo"
)
endpointsHandler
.
ValidateRequestCount
(
t
,
1
)
}
func
TestCheckLeftoverEndpoints
(
t
*
testing
.
T
)
{
ns
:=
metav1
.
NamespaceDefault
testServer
,
_
:=
makeTestServer
(
t
,
ns
)
...
...
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