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
937d88d8
Commit
937d88d8
authored
Jan 06, 2015
by
Daniel Smith
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3240 from brendandburns/tap
Fix the service proxy to re-poll on watch closure no matter what.
parents
2c25ca22
0f60d7bc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
0 deletions
+77
-0
client.go
pkg/client/client.go
+25
-0
api.go
pkg/proxy/config/api.go
+10
-0
api_test.go
pkg/proxy/config/api_test.go
+42
-0
No files found.
pkg/client/client.go
View file @
937d88d8
...
@@ -19,6 +19,9 @@ package client
...
@@ -19,6 +19,9 @@ package client
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"net"
"net/url"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
...
@@ -107,3 +110,25 @@ func (c *Client) ServerAPIVersions() (*api.APIVersions, error) {
...
@@ -107,3 +110,25 @@ func (c *Client) ServerAPIVersions() (*api.APIVersions, error) {
}
}
return
&
v
,
nil
return
&
v
,
nil
}
}
// IsTimeout tests if this is a timeout error in the underlying transport.
// This is unbelievably ugly.
// See: http://stackoverflow.com/questions/23494950/specifically-check-for-timeout-error for details
func
IsTimeout
(
err
error
)
bool
{
if
err
==
nil
{
return
false
}
switch
err
:=
err
.
(
type
)
{
case
*
url
.
Error
:
if
err
,
ok
:=
err
.
Err
.
(
net
.
Error
);
ok
{
return
err
.
Timeout
()
}
case
net
.
Error
:
return
err
.
Timeout
()
}
if
strings
.
Contains
(
err
.
Error
(),
"use of closed network connection"
)
{
return
true
}
return
false
}
pkg/proxy/config/api.go
View file @
937d88d8
...
@@ -20,6 +20,7 @@ import (
...
@@ -20,6 +20,7 @@ import (
"time"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait"
...
@@ -93,6 +94,10 @@ func (s *SourceAPI) runServices(resourceVersion *string) {
...
@@ -93,6 +94,10 @@ func (s *SourceAPI) runServices(resourceVersion *string) {
watcher
,
err
:=
s
.
servicesWatcher
.
Watch
(
labels
.
Everything
(),
labels
.
Everything
(),
*
resourceVersion
)
watcher
,
err
:=
s
.
servicesWatcher
.
Watch
(
labels
.
Everything
(),
labels
.
Everything
(),
*
resourceVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Unable to watch for services changes: %v"
,
err
)
glog
.
Errorf
(
"Unable to watch for services changes: %v"
,
err
)
if
!
client
.
IsTimeout
(
err
)
{
// Reset so that we do a fresh get request
*
resourceVersion
=
""
}
time
.
Sleep
(
wait
.
Jitter
(
s
.
waitDuration
,
0.0
))
time
.
Sleep
(
wait
.
Jitter
(
s
.
waitDuration
,
0.0
))
return
return
}
}
...
@@ -157,6 +162,11 @@ func (s *SourceAPI) runEndpoints(resourceVersion *string) {
...
@@ -157,6 +162,11 @@ func (s *SourceAPI) runEndpoints(resourceVersion *string) {
watcher
,
err
:=
s
.
endpointsWatcher
.
Watch
(
labels
.
Everything
(),
labels
.
Everything
(),
*
resourceVersion
)
watcher
,
err
:=
s
.
endpointsWatcher
.
Watch
(
labels
.
Everything
(),
labels
.
Everything
(),
*
resourceVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Unable to watch for endpoints changes: %v"
,
err
)
glog
.
Errorf
(
"Unable to watch for endpoints changes: %v"
,
err
)
if
!
client
.
IsTimeout
(
err
)
{
// Reset so that we do a fresh get request
*
resourceVersion
=
""
}
time
.
Sleep
(
wait
.
Jitter
(
s
.
waitDuration
,
0.0
))
time
.
Sleep
(
wait
.
Jitter
(
s
.
waitDuration
,
0.0
))
return
return
}
}
...
...
pkg/proxy/config/api_test.go
View file @
937d88d8
...
@@ -122,6 +122,27 @@ func TestServicesError(t *testing.T) {
...
@@ -122,6 +122,27 @@ func TestServicesError(t *testing.T) {
// should have listed only
// should have listed only
<-
ch
<-
ch
if
resourceVersion
!=
""
{
t
.
Errorf
(
"unexpected resource version, got %#v"
,
resourceVersion
)
}
if
!
reflect
.
DeepEqual
(
fakeClient
.
Actions
,
[]
client
.
FakeAction
{{
"watch-services"
,
"1"
}})
{
t
.
Errorf
(
"unexpected actions, got %#v"
,
fakeClient
)
}
}
func
TestServicesErrorTimeout
(
t
*
testing
.
T
)
{
fakeClient
:=
&
client
.
Fake
{
Err
:
errors
.
New
(
"use of closed network connection"
)}
services
:=
make
(
chan
ServiceUpdate
)
source
:=
SourceAPI
{
servicesWatcher
:
fakeClient
.
Services
(
api
.
NamespaceAll
),
endpointsWatcher
:
fakeClient
.
Endpoints
(
api
.
NamespaceAll
),
services
:
services
}
resourceVersion
:=
"1"
ch
:=
make
(
chan
struct
{})
go
func
()
{
source
.
runServices
(
&
resourceVersion
)
close
(
ch
)
}()
// should have listed only
<-
ch
if
resourceVersion
!=
"1"
{
if
resourceVersion
!=
"1"
{
t
.
Errorf
(
"unexpected resource version, got %#v"
,
resourceVersion
)
t
.
Errorf
(
"unexpected resource version, got %#v"
,
resourceVersion
)
}
}
...
@@ -247,6 +268,27 @@ func TestEndpointsError(t *testing.T) {
...
@@ -247,6 +268,27 @@ func TestEndpointsError(t *testing.T) {
// should have listed only
// should have listed only
<-
ch
<-
ch
if
resourceVersion
!=
""
{
t
.
Errorf
(
"unexpected resource version, got %#v"
,
resourceVersion
)
}
if
!
reflect
.
DeepEqual
(
fakeClient
.
Actions
,
[]
client
.
FakeAction
{{
"watch-endpoints"
,
"1"
}})
{
t
.
Errorf
(
"unexpected actions, got %#v"
,
fakeClient
)
}
}
func
TestEndpointsErrorTimeout
(
t
*
testing
.
T
)
{
fakeClient
:=
&
client
.
Fake
{
Err
:
errors
.
New
(
"use of closed network connection"
)}
endpoints
:=
make
(
chan
EndpointsUpdate
)
source
:=
SourceAPI
{
servicesWatcher
:
fakeClient
.
Services
(
api
.
NamespaceAll
),
endpointsWatcher
:
fakeClient
.
Endpoints
(
api
.
NamespaceAll
),
endpoints
:
endpoints
}
resourceVersion
:=
"1"
ch
:=
make
(
chan
struct
{})
go
func
()
{
source
.
runEndpoints
(
&
resourceVersion
)
close
(
ch
)
}()
// should have listed only
<-
ch
if
resourceVersion
!=
"1"
{
if
resourceVersion
!=
"1"
{
t
.
Errorf
(
"unexpected resource version, got %#v"
,
resourceVersion
)
t
.
Errorf
(
"unexpected resource version, got %#v"
,
resourceVersion
)
}
}
...
...
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