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
339f92c1
Commit
339f92c1
authored
May 08, 2018
by
Lion-Wei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
abstract duplicated code in ipvs proxier
parent
0e42990e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
43 deletions
+40
-43
ipset.go
pkg/proxy/ipvs/ipset.go
+9
-6
proxier.go
pkg/proxy/ipvs/proxier.go
+0
-0
proxier_test.go
pkg/proxy/ipvs/proxier_test.go
+31
-37
No files found.
pkg/proxy/ipvs/ipset.go
View file @
339f92c1
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
utilipset
"k8s.io/kubernetes/pkg/util/ipset"
utilipset
"k8s.io/kubernetes/pkg/util/ipset"
utilversion
"k8s.io/kubernetes/pkg/util/version"
utilversion
"k8s.io/kubernetes/pkg/util/version"
"fmt"
"github.com/golang/glog"
"github.com/golang/glog"
)
)
...
@@ -107,6 +108,10 @@ func (set *IPSet) isEmpty() bool {
...
@@ -107,6 +108,10 @@ func (set *IPSet) isEmpty() bool {
return
len
(
set
.
activeEntries
.
UnsortedList
())
==
0
return
len
(
set
.
activeEntries
.
UnsortedList
())
==
0
}
}
func
(
set
*
IPSet
)
getComment
()
string
{
return
fmt
.
Sprintf
(
"
\"
%s
\"
"
,
set
.
Comment
)
}
func
(
set
*
IPSet
)
resetEntries
()
{
func
(
set
*
IPSet
)
resetEntries
()
{
set
.
activeEntries
=
sets
.
NewString
()
set
.
activeEntries
=
sets
.
NewString
()
}
}
...
@@ -146,12 +151,10 @@ func (set *IPSet) syncIPSetEntries() {
...
@@ -146,12 +151,10 @@ func (set *IPSet) syncIPSetEntries() {
}
}
}
}
func
ensureIPSets
(
ipSets
...*
IPSet
)
error
{
func
ensureIPSet
(
set
*
IPSet
)
error
{
for
_
,
set
:=
range
ipSets
{
if
err
:=
set
.
handle
.
CreateSet
(
&
set
.
IPSet
,
true
);
err
!=
nil
{
if
err
:=
set
.
handle
.
CreateSet
(
&
set
.
IPSet
,
true
);
err
!=
nil
{
glog
.
Errorf
(
"Failed to make sure ip set: %v exist, error: %v"
,
set
,
err
)
glog
.
Errorf
(
"Failed to make sure ip set: %v exist, error: %v"
,
set
,
err
)
return
err
return
err
}
}
}
return
nil
return
nil
}
}
...
...
pkg/proxy/ipvs/proxier.go
View file @
339f92c1
This diff is collapsed.
Click to expand it.
pkg/proxy/ipvs/proxier_test.go
View file @
339f92c1
...
@@ -119,43 +119,37 @@ func NewFakeProxier(ipt utiliptables.Interface, ipvs utilipvs.Interface, ipset u
...
@@ -119,43 +119,37 @@ func NewFakeProxier(ipt utiliptables.Interface, ipvs utilipvs.Interface, ipset u
},
},
LookPathFunc
:
func
(
cmd
string
)
(
string
,
error
)
{
return
cmd
,
nil
},
LookPathFunc
:
func
(
cmd
string
)
(
string
,
error
)
{
return
cmd
,
nil
},
}
}
// initialize ipsetList with all sets we needed
ipsetList
:=
make
(
map
[
string
]
*
IPSet
)
for
_
,
is
:=
range
ipsetInfo
{
ipsetList
[
is
.
name
]
=
NewIPSet
(
ipset
,
is
.
name
,
is
.
setType
,
false
,
is
.
comment
)
}
return
&
Proxier
{
return
&
Proxier
{
exec
:
fexec
,
exec
:
fexec
,
serviceMap
:
make
(
proxy
.
ServiceMap
),
serviceMap
:
make
(
proxy
.
ServiceMap
),
serviceChanges
:
proxy
.
NewServiceChangeTracker
(
newServiceInfo
,
nil
,
nil
),
serviceChanges
:
proxy
.
NewServiceChangeTracker
(
newServiceInfo
,
nil
,
nil
),
endpointsMap
:
make
(
proxy
.
EndpointsMap
),
endpointsMap
:
make
(
proxy
.
EndpointsMap
),
endpointsChanges
:
proxy
.
NewEndpointChangeTracker
(
testHostname
,
nil
,
nil
,
nil
),
endpointsChanges
:
proxy
.
NewEndpointChangeTracker
(
testHostname
,
nil
,
nil
,
nil
),
excludeCIDRs
:
make
([]
string
,
0
),
excludeCIDRs
:
make
([]
string
,
0
),
iptables
:
ipt
,
iptables
:
ipt
,
ipvs
:
ipvs
,
ipvs
:
ipvs
,
ipset
:
ipset
,
ipset
:
ipset
,
clusterCIDR
:
"10.0.0.0/24"
,
clusterCIDR
:
"10.0.0.0/24"
,
hostname
:
testHostname
,
hostname
:
testHostname
,
portsMap
:
make
(
map
[
utilproxy
.
LocalPort
]
utilproxy
.
Closeable
),
portsMap
:
make
(
map
[
utilproxy
.
LocalPort
]
utilproxy
.
Closeable
),
portMapper
:
&
fakePortOpener
{[]
*
utilproxy
.
LocalPort
{}},
portMapper
:
&
fakePortOpener
{[]
*
utilproxy
.
LocalPort
{}},
healthChecker
:
newFakeHealthChecker
(),
healthChecker
:
newFakeHealthChecker
(),
ipvsScheduler
:
DefaultScheduler
,
ipvsScheduler
:
DefaultScheduler
,
ipGetter
:
&
fakeIPGetter
{
nodeIPs
:
nodeIPs
},
ipGetter
:
&
fakeIPGetter
{
nodeIPs
:
nodeIPs
},
iptablesData
:
bytes
.
NewBuffer
(
nil
),
iptablesData
:
bytes
.
NewBuffer
(
nil
),
natChains
:
bytes
.
NewBuffer
(
nil
),
natChains
:
bytes
.
NewBuffer
(
nil
),
natRules
:
bytes
.
NewBuffer
(
nil
),
natRules
:
bytes
.
NewBuffer
(
nil
),
filterChains
:
bytes
.
NewBuffer
(
nil
),
filterChains
:
bytes
.
NewBuffer
(
nil
),
filterRules
:
bytes
.
NewBuffer
(
nil
),
filterRules
:
bytes
.
NewBuffer
(
nil
),
netlinkHandle
:
netlinktest
.
NewFakeNetlinkHandle
(),
netlinkHandle
:
netlinktest
.
NewFakeNetlinkHandle
(),
loopbackSet
:
NewIPSet
(
ipset
,
kubeLoopBackIPSet
,
utilipset
.
HashIPPortIP
,
false
,
kubeLoopBackIPSetComment
),
ipsetList
:
ipsetList
,
clusterIPSet
:
NewIPSet
(
ipset
,
kubeClusterIPSet
,
utilipset
.
HashIPPort
,
false
,
kubeClusterIPSetComment
),
nodePortAddresses
:
make
([]
string
,
0
),
externalIPSet
:
NewIPSet
(
ipset
,
kubeExternalIPSet
,
utilipset
.
HashIPPort
,
false
,
kubeExternalIPSetComment
),
networkInterfacer
:
proxyutiltest
.
NewFakeNetwork
(),
lbSet
:
NewIPSet
(
ipset
,
kubeLoadBalancerSet
,
utilipset
.
HashIPPort
,
false
,
kubeLoadBalancerSetComment
),
lbFWSet
:
NewIPSet
(
ipset
,
kubeLoadbalancerFWSet
,
utilipset
.
HashIPPort
,
false
,
kubeLoadbalancerFWSetComment
),
lbLocalSet
:
NewIPSet
(
ipset
,
kubeLoadBalancerLocalSet
,
utilipset
.
HashIPPort
,
false
,
kubeLoadBalancerLocalSetComment
),
lbWhiteListIPSet
:
NewIPSet
(
ipset
,
kubeLoadBalancerSourceIPSet
,
utilipset
.
HashIPPortIP
,
false
,
kubeLoadBalancerSourceIPSetComment
),
lbWhiteListCIDRSet
:
NewIPSet
(
ipset
,
kubeLoadBalancerSourceCIDRSet
,
utilipset
.
HashIPPortNet
,
false
,
kubeLoadBalancerSourceCIDRSetComment
),
nodePortSetTCP
:
NewIPSet
(
ipset
,
kubeNodePortSetTCP
,
utilipset
.
BitmapPort
,
false
,
kubeNodePortSetTCPComment
),
nodePortLocalSetTCP
:
NewIPSet
(
ipset
,
kubeNodePortLocalSetTCP
,
utilipset
.
BitmapPort
,
false
,
kubeNodePortSetTCPComment
),
nodePortLocalSetUDP
:
NewIPSet
(
ipset
,
kubeNodePortLocalSetUDP
,
utilipset
.
BitmapPort
,
false
,
kubeNodePortLocalSetUDPComment
),
nodePortSetUDP
:
NewIPSet
(
ipset
,
kubeNodePortSetUDP
,
utilipset
.
BitmapPort
,
false
,
kubeNodePortSetUDPComment
),
nodePortAddresses
:
make
([]
string
,
0
),
networkInterfacer
:
proxyutiltest
.
NewFakeNetwork
(),
}
}
}
}
...
@@ -887,7 +881,7 @@ func TestOnlyLocalNodePorts(t *testing.T) {
...
@@ -887,7 +881,7 @@ func TestOnlyLocalNodePorts(t *testing.T) {
JumpChain
:
string
(
KubeNodePortChain
),
MatchSet
:
kubeNodePortSetTCP
,
JumpChain
:
string
(
KubeNodePortChain
),
MatchSet
:
kubeNodePortSetTCP
,
}},
}},
string
(
KubeNodePortChain
)
:
{{
string
(
KubeNodePortChain
)
:
{{
JumpChain
:
"
ACCEPT
"
,
MatchSet
:
kubeNodePortLocalSetTCP
,
JumpChain
:
"
RETURN
"
,
MatchSet
:
kubeNodePortLocalSetTCP
,
},
{
},
{
JumpChain
:
string
(
KubeMarkMasqChain
),
MatchSet
:
""
,
JumpChain
:
string
(
KubeMarkMasqChain
),
MatchSet
:
""
,
}},
}},
...
...
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