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
1b059e57
Unverified
Commit
1b059e57
authored
Nov 16, 2018
by
k8s-ci-robot
Committed by
GitHub
Nov 16, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #71101 from seans3/qos-resource-fix
kubectl: small internal to external type fix
parents
d0c3cd18
6a57de31
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
24 deletions
+22
-24
BUILD
pkg/kubectl/util/qos/BUILD
+0
-1
qos.go
pkg/kubectl/util/qos/qos.go
+10
-11
resource.go
pkg/kubectl/util/resource/resource.go
+12
-12
No files found.
pkg/kubectl/util/qos/BUILD
View file @
1b059e57
...
@@ -6,7 +6,6 @@ go_library(
...
@@ -6,7 +6,6 @@ go_library(
importpath = "k8s.io/kubernetes/pkg/kubectl/util/qos",
importpath = "k8s.io/kubernetes/pkg/kubectl/util/qos",
visibility = ["//visibility:public"],
visibility = ["//visibility:public"],
deps = [
deps = [
"//pkg/apis/core:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
...
...
pkg/kubectl/util/qos/qos.go
View file @
1b059e57
...
@@ -17,15 +17,14 @@ limitations under the License.
...
@@ -17,15 +17,14 @@ limitations under the License.
package
qos
package
qos
import
(
import
(
"k8s.io/api/core/v1"
corev1
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kubernetes/pkg/apis/core"
)
)
var
supportedQoSComputeResources
=
sets
.
NewString
(
string
(
core
.
ResourceCPU
),
string
(
core
.
ResourceMemory
))
var
supportedQoSComputeResources
=
sets
.
NewString
(
string
(
core
v1
.
ResourceCPU
),
string
(
corev1
.
ResourceMemory
))
func
isSupportedQoSComputeResource
(
name
v1
.
ResourceName
)
bool
{
func
isSupportedQoSComputeResource
(
name
core
v1
.
ResourceName
)
bool
{
return
supportedQoSComputeResources
.
Has
(
string
(
name
))
return
supportedQoSComputeResources
.
Has
(
string
(
name
))
}
}
...
@@ -33,9 +32,9 @@ func isSupportedQoSComputeResource(name v1.ResourceName) bool {
...
@@ -33,9 +32,9 @@ func isSupportedQoSComputeResource(name v1.ResourceName) bool {
// A pod is besteffort if none of its containers have specified any requests or limits.
// A pod is besteffort if none of its containers have specified any requests or limits.
// A pod is guaranteed only when requests and limits are specified for all the containers and they are equal.
// A pod is guaranteed only when requests and limits are specified for all the containers and they are equal.
// A pod is burstable if limits and requests do not match across all containers.
// A pod is burstable if limits and requests do not match across all containers.
func
GetPodQOS
(
pod
*
v1
.
Pod
)
v1
.
PodQOSClass
{
func
GetPodQOS
(
pod
*
corev1
.
Pod
)
core
v1
.
PodQOSClass
{
requests
:=
v1
.
ResourceList
{}
requests
:=
core
v1
.
ResourceList
{}
limits
:=
v1
.
ResourceList
{}
limits
:=
core
v1
.
ResourceList
{}
zeroQuantity
:=
resource
.
MustParse
(
"0"
)
zeroQuantity
:=
resource
.
MustParse
(
"0"
)
isGuaranteed
:=
true
isGuaranteed
:=
true
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
...
@@ -72,12 +71,12 @@ func GetPodQOS(pod *v1.Pod) v1.PodQOSClass {
...
@@ -72,12 +71,12 @@ func GetPodQOS(pod *v1.Pod) v1.PodQOSClass {
}
}
}
}
if
!
qosLimitsFound
.
HasAll
(
string
(
v1
.
ResourceMemory
),
string
(
v1
.
ResourceCPU
))
{
if
!
qosLimitsFound
.
HasAll
(
string
(
corev1
.
ResourceMemory
),
string
(
core
v1
.
ResourceCPU
))
{
isGuaranteed
=
false
isGuaranteed
=
false
}
}
}
}
if
len
(
requests
)
==
0
&&
len
(
limits
)
==
0
{
if
len
(
requests
)
==
0
&&
len
(
limits
)
==
0
{
return
v1
.
PodQOSBestEffort
return
core
v1
.
PodQOSBestEffort
}
}
// Check is requests match limits for all resources.
// Check is requests match limits for all resources.
if
isGuaranteed
{
if
isGuaranteed
{
...
@@ -90,7 +89,7 @@ func GetPodQOS(pod *v1.Pod) v1.PodQOSClass {
...
@@ -90,7 +89,7 @@ func GetPodQOS(pod *v1.Pod) v1.PodQOSClass {
}
}
if
isGuaranteed
&&
if
isGuaranteed
&&
len
(
requests
)
==
len
(
limits
)
{
len
(
requests
)
==
len
(
limits
)
{
return
v1
.
PodQOSGuaranteed
return
core
v1
.
PodQOSGuaranteed
}
}
return
v1
.
PodQOSBurstable
return
core
v1
.
PodQOSBurstable
}
}
pkg/kubectl/util/resource/resource.go
View file @
1b059e57
...
@@ -22,15 +22,15 @@ import (
...
@@ -22,15 +22,15 @@ import (
"strconv"
"strconv"
"strings"
"strings"
"k8s.io/api/core/v1"
corev1
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/sets"
)
)
// PodRequestsAndLimits returns a dictionary of all defined resources summed up for all
// PodRequestsAndLimits returns a dictionary of all defined resources summed up for all
// containers of the pod.
// containers of the pod.
func
PodRequestsAndLimits
(
pod
*
v1
.
Pod
)
(
reqs
,
limits
v1
.
ResourceList
)
{
func
PodRequestsAndLimits
(
pod
*
corev1
.
Pod
)
(
reqs
,
limits
core
v1
.
ResourceList
)
{
reqs
,
limits
=
v1
.
ResourceList
{},
v1
.
ResourceList
{}
reqs
,
limits
=
corev1
.
ResourceList
{},
core
v1
.
ResourceList
{}
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
addResourceList
(
reqs
,
container
.
Resources
.
Requests
)
addResourceList
(
reqs
,
container
.
Resources
.
Requests
)
addResourceList
(
limits
,
container
.
Resources
.
Limits
)
addResourceList
(
limits
,
container
.
Resources
.
Limits
)
...
@@ -44,7 +44,7 @@ func PodRequestsAndLimits(pod *v1.Pod) (reqs, limits v1.ResourceList) {
...
@@ -44,7 +44,7 @@ func PodRequestsAndLimits(pod *v1.Pod) (reqs, limits v1.ResourceList) {
}
}
// addResourceList adds the resources in newList to list
// addResourceList adds the resources in newList to list
func
addResourceList
(
list
,
new
v1
.
ResourceList
)
{
func
addResourceList
(
list
,
new
core
v1
.
ResourceList
)
{
for
name
,
quantity
:=
range
new
{
for
name
,
quantity
:=
range
new
{
if
value
,
ok
:=
list
[
name
];
!
ok
{
if
value
,
ok
:=
list
[
name
];
!
ok
{
list
[
name
]
=
*
quantity
.
Copy
()
list
[
name
]
=
*
quantity
.
Copy
()
...
@@ -57,7 +57,7 @@ func addResourceList(list, new v1.ResourceList) {
...
@@ -57,7 +57,7 @@ func addResourceList(list, new v1.ResourceList) {
// maxResourceList sets list to the greater of list/newList for every resource
// maxResourceList sets list to the greater of list/newList for every resource
// either list
// either list
func
maxResourceList
(
list
,
new
v1
.
ResourceList
)
{
func
maxResourceList
(
list
,
new
core
v1
.
ResourceList
)
{
for
name
,
quantity
:=
range
new
{
for
name
,
quantity
:=
range
new
{
if
value
,
ok
:=
list
[
name
];
!
ok
{
if
value
,
ok
:=
list
[
name
];
!
ok
{
list
[
name
]
=
*
quantity
.
Copy
()
list
[
name
]
=
*
quantity
.
Copy
()
...
@@ -72,7 +72,7 @@ func maxResourceList(list, new v1.ResourceList) {
...
@@ -72,7 +72,7 @@ func maxResourceList(list, new v1.ResourceList) {
// ExtractContainerResourceValue extracts the value of a resource
// ExtractContainerResourceValue extracts the value of a resource
// in an already known container
// in an already known container
func
ExtractContainerResourceValue
(
fs
*
v1
.
ResourceFieldSelector
,
container
*
v1
.
Container
)
(
string
,
error
)
{
func
ExtractContainerResourceValue
(
fs
*
corev1
.
ResourceFieldSelector
,
container
*
core
v1
.
Container
)
(
string
,
error
)
{
divisor
:=
resource
.
Quantity
{}
divisor
:=
resource
.
Quantity
{}
if
divisor
.
Cmp
(
fs
.
Divisor
)
==
0
{
if
divisor
.
Cmp
(
fs
.
Divisor
)
==
0
{
divisor
=
resource
.
MustParse
(
"1"
)
divisor
=
resource
.
MustParse
(
"1"
)
...
@@ -120,19 +120,19 @@ func convertResourceEphemeralStorageToString(ephemeralStorage *resource.Quantity
...
@@ -120,19 +120,19 @@ func convertResourceEphemeralStorageToString(ephemeralStorage *resource.Quantity
}
}
var
standardContainerResources
=
sets
.
NewString
(
var
standardContainerResources
=
sets
.
NewString
(
string
(
v1
.
ResourceCPU
),
string
(
core
v1
.
ResourceCPU
),
string
(
v1
.
ResourceMemory
),
string
(
core
v1
.
ResourceMemory
),
string
(
v1
.
ResourceEphemeralStorage
),
string
(
core
v1
.
ResourceEphemeralStorage
),
)
)
// IsStandardContainerResourceName returns true if the container can make a resource request
// IsStandardContainerResourceName returns true if the container can make a resource request
// for the specified resource
// for the specified resource
func
IsStandardContainerResourceName
(
str
string
)
bool
{
func
IsStandardContainerResourceName
(
str
string
)
bool
{
return
standardContainerResources
.
Has
(
str
)
||
IsHugePageResourceName
(
v1
.
ResourceName
(
str
))
return
standardContainerResources
.
Has
(
str
)
||
IsHugePageResourceName
(
core
v1
.
ResourceName
(
str
))
}
}
// IsHugePageResourceName returns true if the resource name has the huge page
// IsHugePageResourceName returns true if the resource name has the huge page
// resource prefix.
// resource prefix.
func
IsHugePageResourceName
(
name
v1
.
ResourceName
)
bool
{
func
IsHugePageResourceName
(
name
core
v1
.
ResourceName
)
bool
{
return
strings
.
HasPrefix
(
string
(
name
),
v1
.
ResourceHugePagesPrefix
)
return
strings
.
HasPrefix
(
string
(
name
),
core
v1
.
ResourceHugePagesPrefix
)
}
}
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