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
cfe7e0c7
Commit
cfe7e0c7
authored
Mar 10, 2021
by
Xiao Deshi
Committed by
Brad Davidson
Mar 31, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove duplicated func GetAddresses
refactor tunnel.go and controller.go, remove duplicated lines. Signed-off-by:
Xiao Deshi
<
xiaods@gmail.com
>
parent
93b18b34
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
47 deletions
+34
-47
tunnel.go
pkg/agent/tunnel/tunnel.go
+4
-24
controller.go
pkg/apiaddresses/controller.go
+2
-23
api.go
pkg/util/api.go
+28
-0
No files found.
pkg/agent/tunnel/tunnel.go
View file @
cfe7e0c7
...
...
@@ -6,13 +6,13 @@ import (
"fmt"
"net"
"reflect"
"strconv"
"sync"
"time"
"github.com/gorilla/websocket"
"github.com/rancher/k3s/pkg/agent/proxy"
"github.com/rancher/k3s/pkg/daemons/config"
"github.com/rancher/k3s/pkg/util"
"github.com/rancher/k3s/pkg/version"
"github.com/rancher/remotedialer"
"github.com/sirupsen/logrus"
...
...
@@ -32,26 +32,6 @@ var (
}
)
func
getAddresses
(
endpoint
*
v1
.
Endpoints
)
[]
string
{
serverAddresses
:=
[]
string
{}
if
endpoint
==
nil
{
return
serverAddresses
}
for
_
,
subset
:=
range
endpoint
.
Subsets
{
var
port
string
if
len
(
subset
.
Ports
)
>
0
{
port
=
strconv
.
Itoa
(
int
(
subset
.
Ports
[
0
]
.
Port
))
}
if
port
==
""
{
port
=
"443"
}
for
_
,
address
:=
range
subset
.
Addresses
{
serverAddresses
=
append
(
serverAddresses
,
net
.
JoinHostPort
(
address
.
IP
,
port
))
}
}
return
serverAddresses
}
func
Setup
(
ctx
context
.
Context
,
config
*
config
.
Node
,
proxy
proxy
.
Proxy
)
error
{
restConfig
,
err
:=
clientcmd
.
BuildConfigFromFlags
(
""
,
config
.
AgentConfig
.
KubeConfigK3sController
)
if
err
!=
nil
{
...
...
@@ -75,9 +55,9 @@ func Setup(ctx context.Context, config *config.Node, proxy proxy.Proxy) error {
endpoint
,
_
:=
client
.
CoreV1
()
.
Endpoints
(
"default"
)
.
Get
(
ctx
,
"kubernetes"
,
metav1
.
GetOptions
{})
if
endpoint
!=
nil
{
addresses
:=
g
etAddresses
(
endpoint
)
addresses
:=
util
.
G
etAddresses
(
endpoint
)
if
len
(
addresses
)
>
0
{
proxy
.
Update
(
g
etAddresses
(
endpoint
))
proxy
.
Update
(
util
.
G
etAddresses
(
endpoint
))
}
}
...
...
@@ -119,7 +99,7 @@ func Setup(ctx context.Context, config *config.Node, proxy proxy.Proxy) error {
continue
watching
}
newAddresses
:=
g
etAddresses
(
endpoint
)
newAddresses
:=
util
.
G
etAddresses
(
endpoint
)
if
reflect
.
DeepEqual
(
newAddresses
,
proxy
.
SupervisorAddresses
())
{
continue
watching
}
...
...
pkg/apiaddresses/controller.go
View file @
cfe7e0c7
...
...
@@ -4,11 +4,10 @@ import (
"bytes"
"context"
"encoding/json"
"net"
"strconv"
"github.com/rancher/k3s/pkg/daemons/config"
"github.com/rancher/k3s/pkg/etcd"
"github.com/rancher/k3s/pkg/util"
"github.com/rancher/k3s/pkg/version"
controllerv1
"github.com/rancher/wrangler-api/pkg/generated/controllers/core/v1"
etcdv3
"go.etcd.io/etcd/clientv3"
...
...
@@ -54,7 +53,7 @@ func (h *handler) sync(key string, endpoint *v1.Endpoints) (*v1.Endpoints, error
}
w
:=
&
bytes
.
Buffer
{}
if
err
:=
json
.
NewEncoder
(
w
)
.
Encode
(
g
etAddresses
(
endpoint
));
err
!=
nil
{
if
err
:=
json
.
NewEncoder
(
w
)
.
Encode
(
util
.
G
etAddresses
(
endpoint
));
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -65,23 +64,3 @@ func (h *handler) sync(key string, endpoint *v1.Endpoints) (*v1.Endpoints, error
return
endpoint
,
nil
}
func
getAddresses
(
endpoint
*
v1
.
Endpoints
)
[]
string
{
serverAddresses
:=
[]
string
{}
if
endpoint
==
nil
{
return
serverAddresses
}
for
_
,
subset
:=
range
endpoint
.
Subsets
{
var
port
string
if
len
(
subset
.
Ports
)
>
0
{
port
=
strconv
.
Itoa
(
int
(
subset
.
Ports
[
0
]
.
Port
))
}
if
port
==
""
{
port
=
"443"
}
for
_
,
address
:=
range
subset
.
Addresses
{
serverAddresses
=
append
(
serverAddresses
,
net
.
JoinHostPort
(
address
.
IP
,
port
))
}
}
return
serverAddresses
}
pkg/util/api.go
0 → 100644
View file @
cfe7e0c7
package
util
import
(
"net"
"strconv"
v1
"k8s.io/api/core/v1"
)
func
GetAddresses
(
endpoint
*
v1
.
Endpoints
)
[]
string
{
serverAddresses
:=
[]
string
{}
if
endpoint
==
nil
{
return
serverAddresses
}
for
_
,
subset
:=
range
endpoint
.
Subsets
{
var
port
string
if
len
(
subset
.
Ports
)
>
0
{
port
=
strconv
.
Itoa
(
int
(
subset
.
Ports
[
0
]
.
Port
))
}
if
port
==
""
{
port
=
"443"
}
for
_
,
address
:=
range
subset
.
Addresses
{
serverAddresses
=
append
(
serverAddresses
,
net
.
JoinHostPort
(
address
.
IP
,
port
))
}
}
return
serverAddresses
}
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