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
10a899f3
Commit
10a899f3
authored
Jan 11, 2018
by
m1093782566
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up code
parent
3574aba7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
41 deletions
+18
-41
proxier.go
pkg/proxy/ipvs/proxier.go
+13
-19
ipset.go
pkg/util/ipset/ipset.go
+5
-22
No files found.
pkg/proxy/ipvs/proxier.go
View file @
10a899f3
...
@@ -970,8 +970,8 @@ func (proxier *Proxier) OnEndpointsSynced() {
...
@@ -970,8 +970,8 @@ func (proxier *Proxier) OnEndpointsSynced() {
proxier
.
syncProxyRules
()
proxier
.
syncProxyRules
()
}
}
// EntryInvalidErr indiates if an ipset entry is invalid or not
// EntryInvalidErr indi
c
ates if an ipset entry is invalid or not
const
EntryInvalidErr
=
"error adding entry %s to ipset %s
since entry is invalid
"
const
EntryInvalidErr
=
"error adding entry %s to ipset %s"
// This is where all of the ipvs calls happen.
// This is where all of the ipvs calls happen.
// assumes proxier.mu is held
// assumes proxier.mu is held
...
@@ -1145,13 +1145,7 @@ func (proxier *Proxier) syncProxyRules() {
...
@@ -1145,13 +1145,7 @@ func (proxier *Proxier) syncProxyRules() {
// add service Cluster IP:Port to kubeServiceAccess ip set for the purpose of solving hairpin.
// add service Cluster IP:Port to kubeServiceAccess ip set for the purpose of solving hairpin.
// proxier.kubeServiceAccessSet.activeEntries.Insert(entry.String())
// proxier.kubeServiceAccessSet.activeEntries.Insert(entry.String())
// Install masquerade rules if 'masqueradeAll' or 'clusterCIDR' is specified.
// Install masquerade rules if 'masqueradeAll' or 'clusterCIDR' is specified.
if
proxier
.
masqueradeAll
{
if
proxier
.
masqueradeAll
||
len
(
proxier
.
clusterCIDR
)
>
0
{
if
valid
:=
proxier
.
clusterIPSet
.
validateEntry
(
entry
);
!
valid
{
glog
.
Errorf
(
"%s"
,
fmt
.
Sprintf
(
EntryInvalidErr
,
entry
,
proxier
.
clusterIPSet
.
Name
))
continue
}
proxier
.
clusterIPSet
.
activeEntries
.
Insert
(
entry
.
String
())
}
else
if
len
(
proxier
.
clusterCIDR
)
>
0
{
if
valid
:=
proxier
.
clusterIPSet
.
validateEntry
(
entry
);
!
valid
{
if
valid
:=
proxier
.
clusterIPSet
.
validateEntry
(
entry
);
!
valid
{
glog
.
Errorf
(
"%s"
,
fmt
.
Sprintf
(
EntryInvalidErr
,
entry
,
proxier
.
clusterIPSet
.
Name
))
glog
.
Errorf
(
"%s"
,
fmt
.
Sprintf
(
EntryInvalidErr
,
entry
,
proxier
.
clusterIPSet
.
Name
))
continue
continue
...
@@ -1380,23 +1374,23 @@ func (proxier *Proxier) syncProxyRules() {
...
@@ -1380,23 +1374,23 @@ func (proxier *Proxier) syncProxyRules() {
Protocol
:
protocol
,
Protocol
:
protocol
,
SetType
:
utilipset
.
BitmapPort
,
SetType
:
utilipset
.
BitmapPort
,
}
}
var
nodePortSet
*
IPSet
switch
protocol
{
switch
protocol
{
case
"tcp"
:
case
"tcp"
:
if
valid
:=
proxier
.
nodePortSetTCP
.
validateEntry
(
entry
);
!
valid
{
nodePortSet
=
proxier
.
nodePortSetTCP
glog
.
Errorf
(
"%s"
,
fmt
.
Sprintf
(
EntryInvalidErr
,
entry
,
proxier
.
nodePortSetTCP
.
Name
))
continue
}
proxier
.
nodePortSetTCP
.
activeEntries
.
Insert
(
entry
.
String
())
case
"udp"
:
case
"udp"
:
if
valid
:=
proxier
.
nodePortSetUDP
.
validateEntry
(
entry
);
!
valid
{
nodePortSet
=
proxier
.
nodePortSetUDP
glog
.
Errorf
(
"%s"
,
fmt
.
Sprintf
(
EntryInvalidErr
,
entry
,
proxier
.
nodePortSetUDP
.
Name
))
continue
}
proxier
.
nodePortSetUDP
.
activeEntries
.
Insert
(
entry
.
String
())
default
:
default
:
// It should never hit
// It should never hit
glog
.
Errorf
(
"Unsupported protocol type: %s"
,
protocol
)
glog
.
Errorf
(
"Unsupported protocol type: %s"
,
protocol
)
}
}
if
nodePortSet
!=
nil
{
if
valid
:=
nodePortSet
.
validateEntry
(
entry
);
!
valid
{
glog
.
Errorf
(
"%s"
,
fmt
.
Sprintf
(
EntryInvalidErr
,
entry
,
nodePortSet
.
Name
))
continue
}
nodePortSet
.
activeEntries
.
Insert
(
entry
.
String
())
}
}
}
// Build ipvs kernel routes for each node ip address
// Build ipvs kernel routes for each node ip address
...
...
pkg/util/ipset/ipset.go
View file @
10a899f3
...
@@ -50,7 +50,6 @@ type Interface interface {
...
@@ -50,7 +50,6 @@ type Interface interface {
ListSets
()
([]
string
,
error
)
ListSets
()
([]
string
,
error
)
// GetVersion returns the "X.Y" version string for ipset.
// GetVersion returns the "X.Y" version string for ipset.
GetVersion
()
(
string
,
error
)
GetVersion
()
(
string
,
error
)
// TODO: add comment message for ipset
}
}
// IPSetCmd represents the ipset util. We use ipset command for ipset execute.
// IPSetCmd represents the ipset util. We use ipset command for ipset execute.
...
@@ -144,6 +143,10 @@ type Entry struct {
...
@@ -144,6 +143,10 @@ type Entry struct {
// Validate checks if a given ipset entry is valid or not. The set parameter is the ipset that entry belongs to.
// Validate checks if a given ipset entry is valid or not. The set parameter is the ipset that entry belongs to.
func
(
e
*
Entry
)
Validate
(
set
*
IPSet
)
bool
{
func
(
e
*
Entry
)
Validate
(
set
*
IPSet
)
bool
{
if
e
.
Port
<
0
{
glog
.
Errorf
(
"Entry %v port number %d should be >=0 for ipset %v"
,
e
,
e
.
Port
,
set
)
return
false
}
switch
e
.
SetType
{
switch
e
.
SetType
{
case
HashIPPort
:
case
HashIPPort
:
// set default protocol to tcp if empty
// set default protocol to tcp if empty
...
@@ -159,11 +162,6 @@ func (e *Entry) Validate(set *IPSet) bool {
...
@@ -159,11 +162,6 @@ func (e *Entry) Validate(set *IPSet) bool {
if
valid
:=
validateProtocol
(
e
.
Protocol
);
!
valid
{
if
valid
:=
validateProtocol
(
e
.
Protocol
);
!
valid
{
return
false
return
false
}
}
if
e
.
Port
<
0
{
glog
.
Errorf
(
"Entry %v port number %d should be >=0 for ipset %v"
,
e
,
e
.
Port
,
set
)
return
false
}
case
HashIPPortIP
:
case
HashIPPortIP
:
// set default protocol to tcp if empty
// set default protocol to tcp if empty
if
len
(
e
.
Protocol
)
==
0
{
if
len
(
e
.
Protocol
)
==
0
{
...
@@ -179,11 +177,6 @@ func (e *Entry) Validate(set *IPSet) bool {
...
@@ -179,11 +177,6 @@ func (e *Entry) Validate(set *IPSet) bool {
return
false
return
false
}
}
if
e
.
Port
<
0
{
glog
.
Errorf
(
"Entry %v port number %d should be >=0 for ipset %v "
,
e
,
e
.
Port
,
set
)
return
false
}
// IP2 can not be empty for `hash:ip,port,ip` type ip set
// IP2 can not be empty for `hash:ip,port,ip` type ip set
if
net
.
ParseIP
(
e
.
IP2
)
==
nil
{
if
net
.
ParseIP
(
e
.
IP2
)
==
nil
{
glog
.
Errorf
(
"Error parsing entry %v second ip address %v for ipset %v"
,
e
,
e
.
IP2
,
set
)
glog
.
Errorf
(
"Error parsing entry %v second ip address %v for ipset %v"
,
e
,
e
.
IP2
,
set
)
...
@@ -204,22 +197,12 @@ func (e *Entry) Validate(set *IPSet) bool {
...
@@ -204,22 +197,12 @@ func (e *Entry) Validate(set *IPSet) bool {
return
false
return
false
}
}
if
e
.
Port
<
0
{
glog
.
Errorf
(
"Entry %v port number %d should be >=0 for ipset %v"
,
e
,
e
.
Port
,
set
)
return
false
}
// Net can not be empty for `hash:ip,port,net` type ip set
// Net can not be empty for `hash:ip,port,net` type ip set
if
_
,
ipNet
,
_
:=
net
.
ParseCIDR
(
e
.
Net
);
ipNet
==
nil
{
if
_
,
ipNet
,
_
:=
net
.
ParseCIDR
(
e
.
Net
);
ipNet
==
nil
{
glog
.
Errorf
(
"Error parsing entry %v ip net %v for ipset %v"
,
e
,
e
.
Net
,
set
)
glog
.
Errorf
(
"Error parsing entry %v ip net %v for ipset %v"
,
e
,
e
.
Net
,
set
)
return
false
return
false
}
}
case
BitmapPort
:
case
BitmapPort
:
if
e
.
Port
<
0
{
glog
.
Errorf
(
"Entry %v port number %d should be >=0 for ipset %v"
,
e
,
e
.
Port
,
set
)
return
false
}
// check if port number satisfies its ipset's requirement of port range
// check if port number satisfies its ipset's requirement of port range
if
set
==
nil
{
if
set
==
nil
{
glog
.
Errorf
(
"Unable to reference ip set where the entry %v exists"
,
e
)
glog
.
Errorf
(
"Unable to reference ip set where the entry %v exists"
,
e
)
...
@@ -297,7 +280,7 @@ func (runner *runner) CreateSet(set *IPSet, ignoreExistErr bool) error {
...
@@ -297,7 +280,7 @@ func (runner *runner) CreateSet(set *IPSet, ignoreExistErr bool) error {
// Validate ipset before creating
// Validate ipset before creating
valid
:=
set
.
Validate
()
valid
:=
set
.
Validate
()
if
!
valid
{
if
!
valid
{
return
fmt
.
Errorf
(
"
E
rror creating ipset since it's invalid"
)
return
fmt
.
Errorf
(
"
e
rror creating ipset since it's invalid"
)
}
}
return
runner
.
createSet
(
set
,
ignoreExistErr
)
return
runner
.
createSet
(
set
,
ignoreExistErr
)
}
}
...
...
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