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
2b9cfd41
Commit
2b9cfd41
authored
Apr 21, 2016
by
derekwaynecarr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add utility for determining qos of a pod
parent
5555f6e1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
124 additions
and
0 deletions
+124
-0
qos.go
pkg/kubelet/qos/util/qos.go
+20
-0
qos_test.go
pkg/kubelet/qos/util/qos_test.go
+104
-0
No files found.
pkg/kubelet/qos/util/qos.go
View file @
2b9cfd41
...
@@ -18,6 +18,7 @@ package util
...
@@ -18,6 +18,7 @@ package util
import
(
import
(
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/util/sets"
)
)
const
(
const
(
...
@@ -46,6 +47,25 @@ func isResourceBestEffort(container *api.Container, resource api.ResourceName) b
...
@@ -46,6 +47,25 @@ func isResourceBestEffort(container *api.Container, resource api.ResourceName) b
return
!
hasReq
||
req
.
Value
()
==
0
return
!
hasReq
||
req
.
Value
()
==
0
}
}
// GetPodQos returns the QoS class of a pod.
// The QoS class of a pod is the lowest QoS class for each resource in each container.
func
GetPodQos
(
pod
*
api
.
Pod
)
string
{
qosValues
:=
sets
.
NewString
()
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
qosPerResource
:=
GetQoS
(
&
container
)
for
_
,
qosValue
:=
range
qosPerResource
{
qosValues
.
Insert
(
qosValue
)
}
}
if
qosValues
.
Has
(
BestEffort
)
{
return
BestEffort
}
if
qosValues
.
Has
(
Burstable
)
{
return
Burstable
}
return
Guaranteed
}
// GetQos returns a mapping of resource name to QoS class of a container
// GetQos returns a mapping of resource name to QoS class of a container
func
GetQoS
(
container
*
api
.
Container
)
map
[
api
.
ResourceName
]
string
{
func
GetQoS
(
container
*
api
.
Container
)
map
[
api
.
ResourceName
]
string
{
resourceToQoS
:=
map
[
api
.
ResourceName
]
string
{}
resourceToQoS
:=
map
[
api
.
ResourceName
]
string
{}
...
...
pkg/kubelet/qos/util/qos_test.go
0 → 100644
View file @
2b9cfd41
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
util
import
(
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
)
func
getResourceList
(
cpu
,
memory
string
)
api
.
ResourceList
{
res
:=
api
.
ResourceList
{}
if
cpu
!=
""
{
res
[
api
.
ResourceCPU
]
=
resource
.
MustParse
(
cpu
)
}
if
memory
!=
""
{
res
[
api
.
ResourceMemory
]
=
resource
.
MustParse
(
memory
)
}
return
res
}
func
getResourceRequirements
(
requests
,
limits
api
.
ResourceList
)
api
.
ResourceRequirements
{
res
:=
api
.
ResourceRequirements
{}
res
.
Requests
=
requests
res
.
Limits
=
limits
return
res
}
func
newContainer
(
name
string
,
requests
api
.
ResourceList
,
limits
api
.
ResourceList
)
api
.
Container
{
return
api
.
Container
{
Name
:
name
,
Resources
:
getResourceRequirements
(
requests
,
limits
),
}
}
func
newPod
(
name
string
,
containers
[]
api
.
Container
)
*
api
.
Pod
{
return
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
},
Spec
:
api
.
PodSpec
{
Containers
:
containers
,
},
}
}
func
TestGetPodQos
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
pod
*
api
.
Pod
expected
string
}{
{
pod
:
newPod
(
"best-effort"
,
[]
api
.
Container
{
newContainer
(
"best-effort"
,
getResourceList
(
""
,
""
),
getResourceList
(
""
,
""
)),
}),
expected
:
BestEffort
,
},
{
pod
:
newPod
(
"best-effort-guaranteed"
,
[]
api
.
Container
{
newContainer
(
"best-effort"
,
getResourceList
(
""
,
""
),
getResourceList
(
""
,
""
)),
newContainer
(
"guaranteed"
,
getResourceList
(
"10m"
,
"100Mi"
),
getResourceList
(
"10m"
,
"100Mi"
)),
}),
expected
:
BestEffort
,
},
{
pod
:
newPod
(
"best-effort-cpu-guaranteed-memory"
,
[]
api
.
Container
{
newContainer
(
"best-effort"
,
getResourceList
(
""
,
"100Mi"
),
getResourceList
(
""
,
"100Mi"
)),
}),
expected
:
BestEffort
,
},
{
pod
:
newPod
(
"burstable"
,
[]
api
.
Container
{
newContainer
(
"burstable"
,
getResourceList
(
"10m"
,
"100Mi"
),
getResourceList
(
"100m"
,
"200Mi"
)),
}),
expected
:
Burstable
,
},
{
pod
:
newPod
(
"guaranteed"
,
[]
api
.
Container
{
newContainer
(
"guaranteed"
,
getResourceList
(
"100m"
,
"100Mi"
),
getResourceList
(
"100m"
,
"100Mi"
)),
}),
expected
:
Guaranteed
,
},
}
for
_
,
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
)
}
}
}
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