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
46123a16
Commit
46123a16
authored
Sep 22, 2016
by
Kubernetes Submit Queue
Committed by
GitHub
Sep 22, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #33112 from vishh/fix-qos
Automatic merge from submit-queue Ignore opaque or counted resources from Pod QoS Fixes #33108
parents
db074337
5d4ee244
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
18 deletions
+46
-18
qos.go
pkg/kubelet/qos/qos.go
+13
-10
qos_test.go
pkg/kubelet/qos/qos_test.go
+33
-8
No files found.
pkg/kubelet/qos/qos.go
View file @
46123a16
...
...
@@ -19,6 +19,7 @@ package qos
import
(
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/util/sets"
)
// isResourceGuaranteed returns true if the container's resource requirements are Guaranteed.
...
...
@@ -53,6 +54,9 @@ func GetPodQOS(pod *api.Pod) QOSClass {
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
// process requests
for
name
,
quantity
:=
range
container
.
Resources
.
Requests
{
if
!
supportedQoSComputeResources
.
Has
(
string
(
name
))
{
continue
}
if
quantity
.
Cmp
(
zeroQuantity
)
==
1
{
delta
:=
quantity
.
Copy
()
if
_
,
exists
:=
requests
[
name
];
!
exists
{
...
...
@@ -65,6 +69,9 @@ func GetPodQOS(pod *api.Pod) QOSClass {
}
// process limits
for
name
,
quantity
:=
range
container
.
Resources
.
Limits
{
if
!
supportedQoSComputeResources
.
Has
(
string
(
name
))
{
continue
}
if
quantity
.
Cmp
(
zeroQuantity
)
==
1
{
delta
:=
quantity
.
Copy
()
if
_
,
exists
:=
limits
[
name
];
!
exists
{
...
...
@@ -75,7 +82,7 @@ func GetPodQOS(pod *api.Pod) QOSClass {
}
}
}
if
len
(
container
.
Resources
.
Limits
)
!=
len
(
supported
ComputeResources
)
{
if
len
(
limits
)
!=
len
(
supportedQoS
ComputeResources
)
{
isGuaranteed
=
false
}
}
...
...
@@ -92,8 +99,7 @@ func GetPodQOS(pod *api.Pod) QOSClass {
}
}
if
isGuaranteed
&&
len
(
requests
)
==
len
(
limits
)
&&
len
(
limits
)
==
len
(
supportedComputeResources
)
{
len
(
requests
)
==
len
(
limits
)
{
return
Guaranteed
}
return
Burstable
...
...
@@ -118,17 +124,14 @@ func GetQOS(container *api.Container) QOSList {
return
resourceToQOS
}
// supportedComputeResources is the list of supported compute resources
var
supportedComputeResources
=
[]
api
.
ResourceName
{
api
.
ResourceCPU
,
api
.
ResourceMemory
,
}
// supportedComputeResources is the list of compute resources for with QoS is supported.
var
supportedQoSComputeResources
=
sets
.
NewString
(
string
(
api
.
ResourceCPU
),
string
(
api
.
ResourceMemory
))
// allResources returns a set of all possible resources whose mapped key value is true if present on the container
func
allResources
(
container
*
api
.
Container
)
map
[
api
.
ResourceName
]
bool
{
resources
:=
map
[
api
.
ResourceName
]
bool
{}
for
_
,
resource
:=
range
supported
ComputeResources
{
resources
[
resource
]
=
false
for
_
,
resource
:=
range
supported
QoSComputeResources
.
List
()
{
resources
[
api
.
ResourceName
(
resource
)
]
=
false
}
for
resource
:=
range
container
.
Resources
.
Requests
{
resources
[
resource
]
=
true
...
...
pkg/kubelet/qos/qos_test.go
View file @
46123a16
...
...
@@ -34,6 +34,11 @@ func getResourceList(cpu, memory string) api.ResourceList {
return
res
}
func
addResource
(
rName
,
value
string
,
rl
api
.
ResourceList
)
api
.
ResourceList
{
rl
[
api
.
ResourceName
(
rName
)]
=
resource
.
MustParse
(
value
)
return
rl
}
func
getResourceRequirements
(
requests
,
limits
api
.
ResourceList
)
api
.
ResourceRequirements
{
res
:=
api
.
ResourceRequirements
{}
res
.
Requests
=
requests
...
...
@@ -71,6 +76,12 @@ func TestGetPodQOS(t *testing.T) {
expected
:
Guaranteed
,
},
{
pod
:
newPod
(
"guaranteed-with-gpu"
,
[]
api
.
Container
{
newContainer
(
"guaranteed"
,
getResourceList
(
"100m"
,
"100Mi"
),
addResource
(
"nvidia-gpu"
,
"2"
,
getResourceList
(
"100m"
,
"100Mi"
))),
}),
expected
:
Guaranteed
,
},
{
pod
:
newPod
(
"guaranteed-guaranteed"
,
[]
api
.
Container
{
newContainer
(
"guaranteed"
,
getResourceList
(
"100m"
,
"100Mi"
),
getResourceList
(
"100m"
,
"100Mi"
)),
newContainer
(
"guaranteed"
,
getResourceList
(
"100m"
,
"100Mi"
),
getResourceList
(
"100m"
,
"100Mi"
)),
...
...
@@ -78,6 +89,13 @@ func TestGetPodQOS(t *testing.T) {
expected
:
Guaranteed
,
},
{
pod
:
newPod
(
"guaranteed-guaranteed-with-gpu"
,
[]
api
.
Container
{
newContainer
(
"guaranteed"
,
getResourceList
(
"100m"
,
"100Mi"
),
addResource
(
"nvidia-gpu"
,
"2"
,
getResourceList
(
"100m"
,
"100Mi"
))),
newContainer
(
"guaranteed"
,
getResourceList
(
"100m"
,
"100Mi"
),
getResourceList
(
"100m"
,
"100Mi"
)),
}),
expected
:
Guaranteed
,
},
{
pod
:
newPod
(
"best-effort-best-effort"
,
[]
api
.
Container
{
newContainer
(
"best-effort"
,
getResourceList
(
""
,
""
),
getResourceList
(
""
,
""
)),
newContainer
(
"best-effort"
,
getResourceList
(
""
,
""
),
getResourceList
(
""
,
""
)),
...
...
@@ -85,21 +103,28 @@ func TestGetPodQOS(t *testing.T) {
expected
:
BestEffort
,
},
{
pod
:
newPod
(
"best-effort"
,
[]
api
.
Container
{
pod
:
newPod
(
"best-effort-best-effort-with-gpu"
,
[]
api
.
Container
{
newContainer
(
"best-effort"
,
getResourceList
(
""
,
""
),
addResource
(
"nvidia-gpu"
,
"2"
,
getResourceList
(
""
,
""
))),
newContainer
(
"best-effort"
,
getResourceList
(
""
,
""
),
getResourceList
(
""
,
""
)),
}),
expected
:
BestEffort
,
},
{
pod
:
newPod
(
"best-effort-with-gpu"
,
[]
api
.
Container
{
newContainer
(
"best-effort"
,
getResourceList
(
""
,
""
),
addResource
(
"nvidia-gpu"
,
"2"
,
getResourceList
(
""
,
""
))),
}),
expected
:
BestEffort
,
},
{
pod
:
newPod
(
"best-effort-burstable"
,
[]
api
.
Container
{
newContainer
(
"best-effort"
,
getResourceList
(
""
,
""
),
getResourceList
(
""
,
""
)),
newContainer
(
"best-effort"
,
getResourceList
(
""
,
""
),
addResource
(
"nvidia-gpu"
,
"2"
,
getResourceList
(
""
,
""
)
)),
newContainer
(
"burstable"
,
getResourceList
(
"1"
,
""
),
getResourceList
(
"2"
,
""
)),
}),
expected
:
Burstable
,
},
{
pod
:
newPod
(
"best-effort-guaranteed"
,
[]
api
.
Container
{
newContainer
(
"best-effort"
,
getResourceList
(
""
,
""
),
getResourceList
(
""
,
""
)),
newContainer
(
"best-effort"
,
getResourceList
(
""
,
""
),
addResource
(
"nvidia-gpu"
,
"2"
,
getResourceList
(
""
,
""
)
)),
newContainer
(
"guaranteed"
,
getResourceList
(
"10m"
,
"100Mi"
),
getResourceList
(
"10m"
,
"100Mi"
)),
}),
expected
:
Burstable
,
...
...
@@ -118,21 +143,21 @@ func TestGetPodQOS(t *testing.T) {
expected
:
Burstable
,
},
{
pod
:
newPod
(
"burstable"
,
[]
api
.
Container
{
pod
:
newPod
(
"burstable
-1
"
,
[]
api
.
Container
{
newContainer
(
"burstable"
,
getResourceList
(
"10m"
,
"100Mi"
),
getResourceList
(
"100m"
,
"200Mi"
)),
}),
expected
:
Burstable
,
},
{
pod
:
newPod
(
"burstable"
,
[]
api
.
Container
{
newContainer
(
"burstable"
,
getResourceList
(
"0"
,
"0"
),
getResourceList
(
"100m"
,
"200Mi"
)),
pod
:
newPod
(
"burstable
-2
"
,
[]
api
.
Container
{
newContainer
(
"burstable"
,
getResourceList
(
"0"
,
"0"
),
addResource
(
"nvidia-gpu"
,
"2"
,
getResourceList
(
"100m"
,
"200Mi"
)
)),
}),
expected
:
Burstable
,
},
}
for
_
,
testCase
:=
range
testCases
{
for
id
,
testCase
:=
range
testCases
{
if
actual
:=
GetPodQOS
(
testCase
.
pod
);
testCase
.
expected
!=
actual
{
t
.
Errorf
(
"
invalid qos pod %s, expected: %s, actual: %s"
,
testCase
.
pod
.
Name
,
testCase
.
expected
,
actual
)
t
.
Errorf
(
"
[%d]: invalid qos pod %s, expected: %s, actual: %s"
,
id
,
testCase
.
pod
.
Name
,
testCase
.
expected
,
actual
)
}
}
}
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