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
2fa1eb06
Commit
2fa1eb06
authored
Apr 10, 2017
by
Kubernetes Submit Queue
Committed by
GitHub
Apr 10, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #44313 from thockin/proxy-healthchecks
Automatic merge from submit-queue Zero-out healthchecks when no endpoints Fixes #44311
parents
859b97b5
0022639a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
healthcheck.go
pkg/proxy/healthcheck/healthcheck.go
+6
-0
healthcheck_test.go
pkg/proxy/healthcheck/healthcheck_test.go
+31
-0
No files found.
pkg/proxy/healthcheck/healthcheck.go
View file @
2fa1eb06
...
@@ -196,6 +196,7 @@ func (h hcHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
...
@@ -196,6 +196,7 @@ func (h hcHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
h
.
hcs
.
lock
.
Lock
()
h
.
hcs
.
lock
.
Lock
()
count
:=
h
.
hcs
.
services
[
h
.
name
]
.
endpoints
count
:=
h
.
hcs
.
services
[
h
.
name
]
.
endpoints
h
.
hcs
.
lock
.
Unlock
()
h
.
hcs
.
lock
.
Unlock
()
resp
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
resp
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
if
count
==
0
{
if
count
==
0
{
resp
.
WriteHeader
(
http
.
StatusServiceUnavailable
)
resp
.
WriteHeader
(
http
.
StatusServiceUnavailable
)
...
@@ -225,5 +226,10 @@ func (hcs *server) SyncEndpoints(newEndpoints map[types.NamespacedName]int) erro
...
@@ -225,5 +226,10 @@ func (hcs *server) SyncEndpoints(newEndpoints map[types.NamespacedName]int) erro
glog
.
V
(
3
)
.
Infof
(
"Reporting %d endpoints for healthcheck %q"
,
count
,
nsn
.
String
())
glog
.
V
(
3
)
.
Infof
(
"Reporting %d endpoints for healthcheck %q"
,
count
,
nsn
.
String
())
hcs
.
services
[
nsn
]
.
endpoints
=
count
hcs
.
services
[
nsn
]
.
endpoints
=
count
}
}
for
nsn
,
hci
:=
range
hcs
.
services
{
if
_
,
found
:=
newEndpoints
[
nsn
];
!
found
{
hci
.
endpoints
=
0
}
}
return
nil
return
nil
}
}
pkg/proxy/healthcheck/healthcheck_test.go
View file @
2fa1eb06
...
@@ -174,6 +174,14 @@ func TestServer(t *testing.T) {
...
@@ -174,6 +174,14 @@ func TestServer(t *testing.T) {
// test the handler
// test the handler
testHandler
(
hcs
,
nsn
,
http
.
StatusServiceUnavailable
,
0
,
t
)
testHandler
(
hcs
,
nsn
,
http
.
StatusServiceUnavailable
,
0
,
t
)
// put the endpoint back
hcs
.
SyncEndpoints
(
map
[
types
.
NamespacedName
]
int
{
nsn
:
11
})
if
len
(
hcs
.
services
)
!=
1
{
t
.
Errorf
(
"expected 1 service, got %d"
,
len
(
hcs
.
services
))
}
if
hcs
.
services
[
nsn
]
.
endpoints
!=
11
{
t
.
Errorf
(
"expected 18 endpoints, got %d"
,
hcs
.
services
[
nsn
]
.
endpoints
)
}
// sync nil endpoints
// sync nil endpoints
hcs
.
SyncEndpoints
(
nil
)
hcs
.
SyncEndpoints
(
nil
)
if
len
(
hcs
.
services
)
!=
1
{
if
len
(
hcs
.
services
)
!=
1
{
...
@@ -227,6 +235,7 @@ func TestServer(t *testing.T) {
...
@@ -227,6 +235,7 @@ func TestServer(t *testing.T) {
// test the handlers
// test the handlers
testHandler
(
hcs
,
nsn1
,
http
.
StatusServiceUnavailable
,
0
,
t
)
testHandler
(
hcs
,
nsn1
,
http
.
StatusServiceUnavailable
,
0
,
t
)
testHandler
(
hcs
,
nsn2
,
http
.
StatusServiceUnavailable
,
0
,
t
)
testHandler
(
hcs
,
nsn2
,
http
.
StatusServiceUnavailable
,
0
,
t
)
testHandler
(
hcs
,
nsn3
,
http
.
StatusServiceUnavailable
,
0
,
t
)
// sync endpoints
// sync endpoints
hcs
.
SyncEndpoints
(
map
[
types
.
NamespacedName
]
int
{
hcs
.
SyncEndpoints
(
map
[
types
.
NamespacedName
]
int
{
...
@@ -298,6 +307,28 @@ func TestServer(t *testing.T) {
...
@@ -298,6 +307,28 @@ func TestServer(t *testing.T) {
testHandler
(
hcs
,
nsn2
,
http
.
StatusOK
,
3
,
t
)
testHandler
(
hcs
,
nsn2
,
http
.
StatusOK
,
3
,
t
)
testHandler
(
hcs
,
nsn3
,
http
.
StatusOK
,
7
,
t
)
testHandler
(
hcs
,
nsn3
,
http
.
StatusOK
,
7
,
t
)
testHandler
(
hcs
,
nsn4
,
http
.
StatusOK
,
6
,
t
)
testHandler
(
hcs
,
nsn4
,
http
.
StatusOK
,
6
,
t
)
// sync endpoints, missing nsn2
hcs
.
SyncEndpoints
(
map
[
types
.
NamespacedName
]
int
{
nsn3
:
7
,
nsn4
:
6
,
})
if
len
(
hcs
.
services
)
!=
3
{
t
.
Errorf
(
"expected 3 services, got %d"
,
len
(
hcs
.
services
))
}
if
hcs
.
services
[
nsn2
]
.
endpoints
!=
0
{
t
.
Errorf
(
"expected 0 endpoints, got %d"
,
hcs
.
services
[
nsn2
]
.
endpoints
)
}
if
hcs
.
services
[
nsn3
]
.
endpoints
!=
7
{
t
.
Errorf
(
"expected 7 endpoints, got %d"
,
hcs
.
services
[
nsn3
]
.
endpoints
)
}
if
hcs
.
services
[
nsn4
]
.
endpoints
!=
6
{
t
.
Errorf
(
"expected 6 endpoints, got %d"
,
hcs
.
services
[
nsn4
]
.
endpoints
)
}
// test the handlers
testHandler
(
hcs
,
nsn2
,
http
.
StatusServiceUnavailable
,
0
,
t
)
testHandler
(
hcs
,
nsn3
,
http
.
StatusOK
,
7
,
t
)
testHandler
(
hcs
,
nsn4
,
http
.
StatusOK
,
6
,
t
)
}
}
func
testHandler
(
hcs
*
server
,
nsn
types
.
NamespacedName
,
status
int
,
endpoints
int
,
t
*
testing
.
T
)
{
func
testHandler
(
hcs
*
server
,
nsn
types
.
NamespacedName
,
status
int
,
endpoints
int
,
t
*
testing
.
T
)
{
...
...
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