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
932cf077
Commit
932cf077
authored
Nov 06, 2017
by
Chun Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix hostport duplicate chain names
closes #55771
parent
86480fc0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
2 deletions
+30
-2
hostport_manager.go
pkg/kubelet/network/hostport/hostport_manager.go
+2
-1
hostport_manager_test.go
pkg/kubelet/network/hostport/hostport_manager_test.go
+13
-0
hostport_syncer.go
pkg/kubelet/network/hostport/hostport_syncer.go
+2
-1
hostport_syncer_test.go
pkg/kubelet/network/hostport/hostport_syncer_test.go
+13
-0
No files found.
pkg/kubelet/network/hostport/hostport_manager.go
View file @
932cf077
...
...
@@ -21,6 +21,7 @@ import (
"crypto/sha256"
"encoding/base32"
"fmt"
"strconv"
"strings"
"sync"
...
...
@@ -247,7 +248,7 @@ func (hm *hostportManager) closeHostports(hostportMappings []*PortMapping) error
// WARNING: Please do not change this function. Otherwise, HostportManager may not be able to
// identify existing iptables chains.
func
getHostportChain
(
id
string
,
pm
*
PortMapping
)
utiliptables
.
Chain
{
hash
:=
sha256
.
Sum256
([]
byte
(
id
+
str
ing
(
pm
.
HostPort
)
+
string
(
pm
.
Protocol
)))
hash
:=
sha256
.
Sum256
([]
byte
(
id
+
str
conv
.
Itoa
(
int
(
pm
.
HostPort
)
)
+
string
(
pm
.
Protocol
)))
encoded
:=
base32
.
StdEncoding
.
EncodeToString
(
hash
[
:
])
return
utiliptables
.
Chain
(
kubeHostportChainPrefix
+
encoded
[
:
16
])
}
...
...
pkg/kubelet/network/hostport/hostport_manager_test.go
View file @
932cf077
...
...
@@ -198,3 +198,16 @@ func TestHostportManager(t *testing.T) {
assert
.
EqualValues
(
t
,
true
,
port
.
closed
)
}
}
func
TestGetHostportChain
(
t
*
testing
.
T
)
{
m
:=
make
(
map
[
string
]
int
)
chain
:=
getHostportChain
(
"testrdma-2"
,
&
PortMapping
{
HostPort
:
57119
,
Protocol
:
"TCP"
,
ContainerPort
:
57119
})
m
[
string
(
chain
)]
=
1
chain
=
getHostportChain
(
"testrdma-2"
,
&
PortMapping
{
HostPort
:
55429
,
Protocol
:
"TCP"
,
ContainerPort
:
55429
})
m
[
string
(
chain
)]
=
1
chain
=
getHostportChain
(
"testrdma-2"
,
&
PortMapping
{
HostPort
:
56833
,
Protocol
:
"TCP"
,
ContainerPort
:
56833
})
m
[
string
(
chain
)]
=
1
if
len
(
m
)
!=
3
{
t
.
Fatal
(
m
)
}
}
pkg/kubelet/network/hostport/hostport_syncer.go
View file @
932cf077
...
...
@@ -21,6 +21,7 @@ import (
"crypto/sha256"
"encoding/base32"
"fmt"
"strconv"
"strings"
"time"
...
...
@@ -142,7 +143,7 @@ func writeLine(buf *bytes.Buffer, words ...string) {
// this because IPTables Chain Names must be <= 28 chars long, and the longer
// they are the harder they are to read.
func
hostportChainName
(
pm
*
PortMapping
,
podFullName
string
)
utiliptables
.
Chain
{
hash
:=
sha256
.
Sum256
([]
byte
(
str
ing
(
pm
.
HostPort
)
+
string
(
pm
.
Protocol
)
+
podFullName
))
hash
:=
sha256
.
Sum256
([]
byte
(
str
conv
.
Itoa
(
int
(
pm
.
HostPort
)
)
+
string
(
pm
.
Protocol
)
+
podFullName
))
encoded
:=
base32
.
StdEncoding
.
EncodeToString
(
hash
[
:
])
return
utiliptables
.
Chain
(
kubeHostportChainPrefix
+
encoded
[
:
16
])
}
...
...
pkg/kubelet/network/hostport/hostport_syncer_test.go
View file @
932cf077
...
...
@@ -223,3 +223,16 @@ func matchRule(chain *fakeChain, match string) bool {
}
return
false
}
func
TestHostportChainName
(
t
*
testing
.
T
)
{
m
:=
make
(
map
[
string
]
int
)
chain
:=
hostportChainName
(
&
PortMapping
{
HostPort
:
57119
,
Protocol
:
"TCP"
,
ContainerPort
:
57119
},
"testrdma-2"
)
m
[
string
(
chain
)]
=
1
chain
=
hostportChainName
(
&
PortMapping
{
HostPort
:
55429
,
Protocol
:
"TCP"
,
ContainerPort
:
55429
},
"testrdma-2"
)
m
[
string
(
chain
)]
=
1
chain
=
hostportChainName
(
&
PortMapping
{
HostPort
:
56833
,
Protocol
:
"TCP"
,
ContainerPort
:
56833
},
"testrdma-2"
)
m
[
string
(
chain
)]
=
1
if
len
(
m
)
!=
3
{
t
.
Fatal
(
m
)
}
}
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