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
5d4ee244
Commit
5d4ee244
authored
Sep 20, 2016
by
Vishnu kannan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ignore non first class QoS resources from computing Pod Qos
Signed-off-by:
Vishnu kannan
<
vishnuk@google.com
>
parent
6184ebdc
Show 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 @
5d4ee244
...
@@ -19,6 +19,7 @@ package qos
...
@@ -19,6 +19,7 @@ package qos
import
(
import
(
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/util/sets"
)
)
// isResourceGuaranteed returns true if the container's resource requirements are Guaranteed.
// isResourceGuaranteed returns true if the container's resource requirements are Guaranteed.
...
@@ -53,6 +54,9 @@ func GetPodQOS(pod *api.Pod) QOSClass {
...
@@ -53,6 +54,9 @@ func GetPodQOS(pod *api.Pod) QOSClass {
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
// process requests
// process requests
for
name
,
quantity
:=
range
container
.
Resources
.
Requests
{
for
name
,
quantity
:=
range
container
.
Resources
.
Requests
{
if
!
supportedQoSComputeResources
.
Has
(
string
(
name
))
{
continue
}
if
quantity
.
Cmp
(
zeroQuantity
)
==
1
{
if
quantity
.
Cmp
(
zeroQuantity
)
==
1
{
delta
:=
quantity
.
Copy
()
delta
:=
quantity
.
Copy
()
if
_
,
exists
:=
requests
[
name
];
!
exists
{
if
_
,
exists
:=
requests
[
name
];
!
exists
{
...
@@ -65,6 +69,9 @@ func GetPodQOS(pod *api.Pod) QOSClass {
...
@@ -65,6 +69,9 @@ func GetPodQOS(pod *api.Pod) QOSClass {
}
}
// process limits
// process limits
for
name
,
quantity
:=
range
container
.
Resources
.
Limits
{
for
name
,
quantity
:=
range
container
.
Resources
.
Limits
{
if
!
supportedQoSComputeResources
.
Has
(
string
(
name
))
{
continue
}
if
quantity
.
Cmp
(
zeroQuantity
)
==
1
{
if
quantity
.
Cmp
(
zeroQuantity
)
==
1
{
delta
:=
quantity
.
Copy
()
delta
:=
quantity
.
Copy
()
if
_
,
exists
:=
limits
[
name
];
!
exists
{
if
_
,
exists
:=
limits
[
name
];
!
exists
{
...
@@ -75,7 +82,7 @@ func GetPodQOS(pod *api.Pod) QOSClass {
...
@@ -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
isGuaranteed
=
false
}
}
}
}
...
@@ -92,8 +99,7 @@ func GetPodQOS(pod *api.Pod) QOSClass {
...
@@ -92,8 +99,7 @@ func GetPodQOS(pod *api.Pod) QOSClass {
}
}
}
}
if
isGuaranteed
&&
if
isGuaranteed
&&
len
(
requests
)
==
len
(
limits
)
&&
len
(
requests
)
==
len
(
limits
)
{
len
(
limits
)
==
len
(
supportedComputeResources
)
{
return
Guaranteed
return
Guaranteed
}
}
return
Burstable
return
Burstable
...
@@ -118,17 +124,14 @@ func GetQOS(container *api.Container) QOSList {
...
@@ -118,17 +124,14 @@ func GetQOS(container *api.Container) QOSList {
return
resourceToQOS
return
resourceToQOS
}
}
// supportedComputeResources is the list of supported compute resources
// supportedComputeResources is the list of compute resources for with QoS is supported.
var
supportedComputeResources
=
[]
api
.
ResourceName
{
var
supportedQoSComputeResources
=
sets
.
NewString
(
string
(
api
.
ResourceCPU
),
string
(
api
.
ResourceMemory
))
api
.
ResourceCPU
,
api
.
ResourceMemory
,
}
// allResources returns a set of all possible resources whose mapped key value is true if present on the container
// 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
{
func
allResources
(
container
*
api
.
Container
)
map
[
api
.
ResourceName
]
bool
{
resources
:=
map
[
api
.
ResourceName
]
bool
{}
resources
:=
map
[
api
.
ResourceName
]
bool
{}
for
_
,
resource
:=
range
supported
ComputeResources
{
for
_
,
resource
:=
range
supported
QoSComputeResources
.
List
()
{
resources
[
resource
]
=
false
resources
[
api
.
ResourceName
(
resource
)
]
=
false
}
}
for
resource
:=
range
container
.
Resources
.
Requests
{
for
resource
:=
range
container
.
Resources
.
Requests
{
resources
[
resource
]
=
true
resources
[
resource
]
=
true
...
...
pkg/kubelet/qos/qos_test.go
View file @
5d4ee244
...
@@ -34,6 +34,11 @@ func getResourceList(cpu, memory string) api.ResourceList {
...
@@ -34,6 +34,11 @@ func getResourceList(cpu, memory string) api.ResourceList {
return
res
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
{
func
getResourceRequirements
(
requests
,
limits
api
.
ResourceList
)
api
.
ResourceRequirements
{
res
:=
api
.
ResourceRequirements
{}
res
:=
api
.
ResourceRequirements
{}
res
.
Requests
=
requests
res
.
Requests
=
requests
...
@@ -71,6 +76,12 @@ func TestGetPodQOS(t *testing.T) {
...
@@ -71,6 +76,12 @@ func TestGetPodQOS(t *testing.T) {
expected
:
Guaranteed
,
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
{
pod
:
newPod
(
"guaranteed-guaranteed"
,
[]
api
.
Container
{
newContainer
(
"guaranteed"
,
getResourceList
(
"100m"
,
"100Mi"
),
getResourceList
(
"100m"
,
"100Mi"
)),
newContainer
(
"guaranteed"
,
getResourceList
(
"100m"
,
"100Mi"
),
getResourceList
(
"100m"
,
"100Mi"
)),
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) {
...
@@ -78,6 +89,13 @@ func TestGetPodQOS(t *testing.T) {
expected
:
Guaranteed
,
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
{
pod
:
newPod
(
"best-effort-best-effort"
,
[]
api
.
Container
{
newContainer
(
"best-effort"
,
getResourceList
(
""
,
""
),
getResourceList
(
""
,
""
)),
newContainer
(
"best-effort"
,
getResourceList
(
""
,
""
),
getResourceList
(
""
,
""
)),
newContainer
(
"best-effort"
,
getResourceList
(
""
,
""
),
getResourceList
(
""
,
""
)),
newContainer
(
"best-effort"
,
getResourceList
(
""
,
""
),
getResourceList
(
""
,
""
)),
...
@@ -85,21 +103,28 @@ func TestGetPodQOS(t *testing.T) {
...
@@ -85,21 +103,28 @@ func TestGetPodQOS(t *testing.T) {
expected
:
BestEffort
,
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
(
""
,
""
)),
newContainer
(
"best-effort"
,
getResourceList
(
""
,
""
),
getResourceList
(
""
,
""
)),
}),
}),
expected
:
BestEffort
,
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
{
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"
,
""
)),
newContainer
(
"burstable"
,
getResourceList
(
"1"
,
""
),
getResourceList
(
"2"
,
""
)),
}),
}),
expected
:
Burstable
,
expected
:
Burstable
,
},
},
{
{
pod
:
newPod
(
"best-effort-guaranteed"
,
[]
api
.
Container
{
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"
)),
newContainer
(
"guaranteed"
,
getResourceList
(
"10m"
,
"100Mi"
),
getResourceList
(
"10m"
,
"100Mi"
)),
}),
}),
expected
:
Burstable
,
expected
:
Burstable
,
...
@@ -118,21 +143,21 @@ func TestGetPodQOS(t *testing.T) {
...
@@ -118,21 +143,21 @@ func TestGetPodQOS(t *testing.T) {
expected
:
Burstable
,
expected
:
Burstable
,
},
},
{
{
pod
:
newPod
(
"burstable"
,
[]
api
.
Container
{
pod
:
newPod
(
"burstable
-1
"
,
[]
api
.
Container
{
newContainer
(
"burstable"
,
getResourceList
(
"10m"
,
"100Mi"
),
getResourceList
(
"100m"
,
"200Mi"
)),
newContainer
(
"burstable"
,
getResourceList
(
"10m"
,
"100Mi"
),
getResourceList
(
"100m"
,
"200Mi"
)),
}),
}),
expected
:
Burstable
,
expected
:
Burstable
,
},
},
{
{
pod
:
newPod
(
"burstable"
,
[]
api
.
Container
{
pod
:
newPod
(
"burstable
-2
"
,
[]
api
.
Container
{
newContainer
(
"burstable"
,
getResourceList
(
"0"
,
"0"
),
getResourceList
(
"100m"
,
"200Mi"
)),
newContainer
(
"burstable"
,
getResourceList
(
"0"
,
"0"
),
addResource
(
"nvidia-gpu"
,
"2"
,
getResourceList
(
"100m"
,
"200Mi"
)
)),
}),
}),
expected
:
Burstable
,
expected
:
Burstable
,
},
},
}
}
for
_
,
testCase
:=
range
testCases
{
for
id
,
testCase
:=
range
testCases
{
if
actual
:=
GetPodQOS
(
testCase
.
pod
);
testCase
.
expected
!=
actual
{
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