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
f006c8bc
Commit
f006c8bc
authored
Feb 16, 2017
by
Minhan Xia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
teach kubenet to use annotation instead of pod object for traffic shaper
parent
947e0e1b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
16 deletions
+19
-16
kubenet_linux.go
pkg/kubelet/network/kubenet/kubenet_linux.go
+16
-16
utils.go
pkg/util/bandwidth/utils.go
+3
-0
No files found.
pkg/kubelet/network/kubenet/kubenet_linux.go
View file @
f006c8bc
...
...
@@ -307,7 +307,7 @@ func (plugin *kubenetNetworkPlugin) Capabilities() utilsets.Int {
// setup sets up networking through CNI using the given ns/name and sandbox ID.
// TODO: Don't pass the pod to this method, it only needs it for bandwidth
// shaping and hostport management.
func
(
plugin
*
kubenetNetworkPlugin
)
setup
(
namespace
string
,
name
string
,
id
kubecontainer
.
ContainerID
,
pod
*
v1
.
Pod
)
error
{
func
(
plugin
*
kubenetNetworkPlugin
)
setup
(
namespace
string
,
name
string
,
id
kubecontainer
.
ContainerID
,
pod
*
v1
.
Pod
,
annotations
map
[
string
]
string
)
error
{
// Bring up container loopback interface
if
_
,
err
:=
plugin
.
addContainerToNetwork
(
plugin
.
loConfig
,
"lo"
,
namespace
,
name
,
id
);
err
!=
nil
{
return
err
...
...
@@ -359,23 +359,22 @@ func (plugin *kubenetNetworkPlugin) setup(namespace string, name string, id kube
plugin
.
podIPs
[
id
]
=
ip4
.
String
()
// The first SetUpPod call creates the bridge; get a shaper for the sake of initialization
// TODO: replace with CNI traffic shaper plugin
shaper
:=
plugin
.
shaper
()
ingress
,
egress
,
err
:=
bandwidth
.
ExtractPodBandwidthResources
(
annotations
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Error reading pod bandwidth annotations: %v"
,
err
)
}
if
egress
!=
nil
||
ingress
!=
nil
{
if
err
:=
shaper
.
ReconcileCIDR
(
fmt
.
Sprintf
(
"%s/32"
,
ip4
.
String
()),
egress
,
ingress
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to add pod to shaper: %v"
,
err
)
}
}
// The host can choose to not support "legacy" features. The remote
// shim doesn't support it (#35457), but the kubelet does.
if
plugin
.
host
.
SupportsLegacyFeatures
()
{
// The first SetUpPod call creates the bridge; get a shaper for the sake of
// initialization
shaper
:=
plugin
.
shaper
()
ingress
,
egress
,
err
:=
bandwidth
.
ExtractPodBandwidthResources
(
pod
.
Annotations
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Error reading pod bandwidth annotations: %v"
,
err
)
}
if
egress
!=
nil
||
ingress
!=
nil
{
if
err
:=
shaper
.
ReconcileCIDR
(
fmt
.
Sprintf
(
"%s/32"
,
ip4
.
String
()),
egress
,
ingress
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to add pod to shaper: %v"
,
err
)
}
}
// Open any hostport the pod's containers want
activePodPortMappings
,
err
:=
plugin
.
getPodPortMappings
()
if
err
!=
nil
{
...
...
@@ -387,6 +386,7 @@ func (plugin *kubenetNetworkPlugin) setup(namespace string, name string, id kube
return
err
}
}
else
{
// TODO: replace with CNI port-forwarding plugin
portMappings
,
err
:=
plugin
.
host
.
GetPodPortMappings
(
id
.
ID
)
if
err
!=
nil
{
return
err
...
...
@@ -425,7 +425,7 @@ func (plugin *kubenetNetworkPlugin) SetUpPod(namespace string, name string, id k
return
fmt
.
Errorf
(
"Kubenet cannot SetUpPod: %v"
,
err
)
}
if
err
:=
plugin
.
setup
(
namespace
,
name
,
id
,
pod
);
err
!=
nil
{
if
err
:=
plugin
.
setup
(
namespace
,
name
,
id
,
pod
,
annotations
);
err
!=
nil
{
// Make sure everything gets cleaned up on errors
podIP
,
_
:=
plugin
.
podIPs
[
id
]
if
err
:=
plugin
.
teardown
(
namespace
,
name
,
id
,
podIP
);
err
!=
nil
{
...
...
pkg/util/bandwidth/utils.go
View file @
f006c8bc
...
...
@@ -36,6 +36,9 @@ func validateBandwidthIsReasonable(rsrc *resource.Quantity) error {
}
func
ExtractPodBandwidthResources
(
podAnnotations
map
[
string
]
string
)
(
ingress
,
egress
*
resource
.
Quantity
,
err
error
)
{
if
podAnnotations
==
nil
{
return
nil
,
nil
,
nil
}
str
,
found
:=
podAnnotations
[
"kubernetes.io/ingress-bandwidth"
]
if
found
{
ingressValue
,
err
:=
resource
.
ParseQuantity
(
str
)
...
...
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