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
72dac14b
Commit
72dac14b
authored
Feb 05, 2020
by
Miek Gieben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correctly re-establish the stream
Signed-off-by:
Miek Gieben
<
miek@miek.nl
>
parent
a47aea02
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
21 deletions
+35
-21
plugin/traffic/setup.go
plugin/traffic/setup.go
+25
-13
plugin/traffic/traffic.go
plugin/traffic/traffic.go
+6
-1
plugin/traffic/xds/client.go
plugin/traffic/xds/client.go
+4
-7
No files found.
plugin/traffic/setup.go
View file @
72dac14b
...
...
@@ -38,7 +38,26 @@ func setup(c *caddy.Controller) error {
})
c
.
OnStartup
(
func
()
error
{
go
t
.
c
.
Run
()
go
func
()
{
for
{
opts
:=
[]
grpc
.
DialOption
{
grpc
.
WithInsecure
()}
if
t
.
tlsConfig
!=
nil
{
opts
=
[]
grpc
.
DialOption
{
grpc
.
WithTransportCredentials
(
credentials
.
NewTLS
(
t
.
tlsConfig
))}
}
redo
:
t
.
c
,
err
=
xds
.
New
(
t
.
hosts
[
0
],
t
.
node
,
opts
...
)
err
:=
t
.
c
.
Run
()
if
err
!=
nil
{
log
.
Warning
(
err
)
time
.
Sleep
(
2
*
time
.
Second
)
// back off foo
goto
redo
}
// err == nil
break
}
}()
metrics
.
MustRegister
(
c
,
xds
.
ClusterGauge
)
return
nil
})
...
...
@@ -47,9 +66,8 @@ func setup(c *caddy.Controller) error {
}
func
parseTraffic
(
c
*
caddy
.
Controller
)
(
*
Traffic
,
error
)
{
node
:=
"coredns"
toHosts
:=
[]
string
{}
t
:=
&
Traffic
{}
t
:=
&
Traffic
{
node
:
"coredns"
}
var
(
err
error
tlsConfig
*
tls
.
Config
...
...
@@ -85,7 +103,7 @@ func parseTraffic(c *caddy.Controller) (*Traffic, error) {
if
len
(
args
)
!=
1
{
return
nil
,
c
.
ArgErr
()
}
node
=
args
[
0
]
t
.
node
=
args
[
0
]
case
"tls"
:
args
:=
c
.
RemainingArgs
()
if
len
(
args
)
>
3
{
...
...
@@ -109,19 +127,13 @@ func parseTraffic(c *caddy.Controller) (*Traffic, error) {
}
}
opts
:=
[]
grpc
.
DialOption
{
grpc
.
WithInsecure
()}
if
tlsConfig
!=
nil
{
t
.
tlsConfig
=
tlsConfig
if
tlsServerName
!=
""
{
tlsConfig
.
ServerName
=
tlsServerName
t
.
t
lsConfig
.
ServerName
=
tlsServerName
}
opts
=
[]
grpc
.
DialOption
{
grpc
.
WithTransportCredentials
(
credentials
.
NewTLS
(
tlsConfig
))}
}
// TODO: only the first host is used, need to figure out how to reconcile multiple upstream providers.
if
t
.
c
,
err
=
xds
.
New
(
toHosts
[
0
],
node
,
opts
...
);
err
!=
nil
{
return
nil
,
err
}
t
.
hosts
=
toHosts
return
t
,
nil
}
...
...
plugin/traffic/traffic.go
View file @
72dac14b
...
...
@@ -2,6 +2,7 @@ package traffic
import
(
"context"
"crypto/tls"
"fmt"
"strconv"
"strings"
...
...
@@ -17,7 +18,11 @@ import (
// Traffic is a plugin that load balances according to assignments.
type
Traffic
struct
{
c
*
xds
.
Client
c
*
xds
.
Client
node
string
tlsConfig
*
tls
.
Config
hosts
[]
string
id
string
health
bool
origins
[]
string
...
...
plugin/traffic/xds/client.go
View file @
72dac14b
...
...
@@ -24,7 +24,6 @@ import (
"context"
"fmt"
"sync"
"time"
"github.com/coredns/coredns/coremain"
clog
"github.com/coredns/coredns/plugin/pkg/log"
...
...
@@ -79,21 +78,19 @@ func New(addr, node string, opts ...grpc.DialOption) (*Client, error) {
func
(
c
*
Client
)
Stop
()
error
{
c
.
cancel
();
return
c
.
cc
.
Close
()
}
// Run starts all goroutines and gathers the clusters and endpoint information from the upstream manager.
func
(
c
*
Client
)
Run
()
{
func
(
c
*
Client
)
Run
()
error
{
first
:=
true
for
{
select
{
case
<-
c
.
ctx
.
Done
()
:
return
return
nil
default
:
}
cli
:=
xdspb
.
NewAggregatedDiscoveryServiceClient
(
c
.
cc
)
stream
,
err
:=
cli
.
StreamAggregatedResources
(
c
.
ctx
)
if
err
!=
nil
{
log
.
Debug
(
err
)
time
.
Sleep
(
2
*
time
.
Second
)
// grpc's client.go does more spiffy exp. backoff, do we really need that?
continue
return
err
}
if
first
{
...
...
@@ -107,7 +104,7 @@ func (c *Client) Run() {
}
if
err
:=
c
.
receive
(
stream
);
err
!=
nil
{
log
.
Warning
(
err
)
return
err
}
}
}
...
...
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