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
74f368f5
Commit
74f368f5
authored
Jan 22, 2015
by
derekwaynecarr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modified LimitRangeItem.Kind to LimitRangeItem.Type, added example files
parent
31a1145a
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
107 additions
and
39 deletions
+107
-39
plugins.go
cmd/kube-apiserver/plugins.go
+1
-0
invalid-pod.json
examples/limitrange/invalid-pod.json
+19
-0
limit-range.json
examples/limitrange/limit-range.json
+2
-2
valid-pod.json
examples/limitrange/valid-pod.json
+21
-0
types.go
pkg/api/types.go
+9
-2
conversion.go
pkg/api/v1beta1/conversion.go
+2
-2
types.go
pkg/api/v1beta1/types.go
+9
-2
conversion.go
pkg/api/v1beta2/conversion.go
+2
-2
types.go
pkg/api/v1beta2/types.go
+9
-2
types.go
pkg/api/v1beta3/types.go
+9
-2
validation_test.go
pkg/api/validation/validation_test.go
+3
-3
limit_ranges_test.go
pkg/client/limit_ranges_test.go
+4
-4
describe.go
pkg/kubectl/describe.go
+2
-3
registry_test.go
pkg/registry/limitrange/registry_test.go
+1
-1
admission.go
plugin/pkg/admission/limitranger/admission.go
+12
-12
admission_test.go
plugin/pkg/admission/limitranger/admission_test.go
+2
-2
No files found.
cmd/kube-apiserver/plugins.go
View file @
74f368f5
...
@@ -28,5 +28,6 @@ import (
...
@@ -28,5 +28,6 @@ import (
_
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/admission/admit"
_
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/admission/admit"
_
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/admission/deny"
_
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/admission/deny"
_
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/admission/limitranger"
_
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/admission/resourcedefaults"
_
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/admission/resourcedefaults"
)
)
examples/limitrange/invalid-pod.json
0 → 100644
View file @
74f368f5
{
"id"
:
"invalid-pod"
,
"kind"
:
"Pod"
,
"apiVersion"
:
"v1beta2"
,
"labels"
:
{
"name"
:
"invalid-pod"
},
"desiredState"
:
{
"manifest"
:
{
"version"
:
"v1beta1"
,
"id"
:
"invalid-pod"
,
"containers"
:
[{
"name"
:
"kubernetes-serve-hostname"
,
"image"
:
"kubernetes/serve_hostname"
,
}]
}
},
}
\ No newline at end of file
examples/limitrange/limitrange.json
→
examples/limitrange/limit
-
range.json
View file @
74f368f5
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
"spec"
:
{
"spec"
:
{
"limits"
:
[
"limits"
:
[
{
{
"
kind"
:
"pods
"
,
"
type"
:
"Pod
"
,
"max"
:
{
"max"
:
{
"memory"
:
"1073741824"
,
"memory"
:
"1073741824"
,
"cpu"
:
"2"
,
"cpu"
:
"2"
,
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
}
}
},
},
{
{
"
kind"
:
"containers
"
,
"
type"
:
"Container
"
,
"max"
:
{
"max"
:
{
"memory"
:
"1073741824"
,
"memory"
:
"1073741824"
,
"cpu"
:
"2"
,
"cpu"
:
"2"
,
...
...
examples/limitrange/valid-pod.json
0 → 100644
View file @
74f368f5
{
"id"
:
"valid-pod"
,
"kind"
:
"Pod"
,
"apiVersion"
:
"v1beta2"
,
"labels"
:
{
"name"
:
"valid-pod"
},
"desiredState"
:
{
"manifest"
:
{
"version"
:
"v1beta1"
,
"id"
:
"invalid-pod"
,
"containers"
:
[{
"name"
:
"kubernetes-serve-hostname"
,
"image"
:
"kubernetes/serve_hostname"
,
"cpu"
:
1000
,
"memory"
:
1048576
,
}]
}
},
}
\ No newline at end of file
pkg/api/types.go
View file @
74f368f5
...
@@ -1139,10 +1139,17 @@ type List struct {
...
@@ -1139,10 +1139,17 @@ type List struct {
Items
[]
runtime
.
Object
`json:"items"`
Items
[]
runtime
.
Object
`json:"items"`
}
}
const
(
// Limit that applies to all pods in a namespace
LimitTypePod
string
=
"Pod"
// Limit that applies to all containers in a namespace
LimitTypeContainer
string
=
"Container"
)
// LimitRangeItem defines a min/max usage limit for any resource that matches on kind
// LimitRangeItem defines a min/max usage limit for any resource that matches on kind
type
LimitRangeItem
struct
{
type
LimitRangeItem
struct
{
//
Kind is the resource kind that this limit range is applied (i.e. pods, etc.)
//
Type of resource that this limit applies to
Kind
string
Type
string
`json:"type,omitempty"`
// Max usage constraints on this kind by resource name
// Max usage constraints on this kind by resource name
Max
ResourceList
`json:"max,omitempty"`
Max
ResourceList
`json:"max,omitempty"`
// Min usage constraints on this kind by resource name
// Min usage constraints on this kind by resource name
...
...
pkg/api/v1beta1/conversion.go
View file @
74f368f5
...
@@ -614,7 +614,7 @@ func init() {
...
@@ -614,7 +614,7 @@ func init() {
},
},
func
(
in
*
newer
.
LimitRangeItem
,
out
*
LimitRangeItem
,
s
conversion
.
Scope
)
error
{
func
(
in
*
newer
.
LimitRangeItem
,
out
*
LimitRangeItem
,
s
conversion
.
Scope
)
error
{
*
out
=
LimitRangeItem
{}
*
out
=
LimitRangeItem
{}
out
.
Kind
=
in
.
Kind
out
.
Type
=
in
.
Type
if
err
:=
s
.
Convert
(
&
in
.
Max
,
&
out
.
Max
,
0
);
err
!=
nil
{
if
err
:=
s
.
Convert
(
&
in
.
Max
,
&
out
.
Max
,
0
);
err
!=
nil
{
return
err
return
err
}
}
...
@@ -625,7 +625,7 @@ func init() {
...
@@ -625,7 +625,7 @@ func init() {
},
},
func
(
in
*
LimitRangeItem
,
out
*
newer
.
LimitRangeItem
,
s
conversion
.
Scope
)
error
{
func
(
in
*
LimitRangeItem
,
out
*
newer
.
LimitRangeItem
,
s
conversion
.
Scope
)
error
{
*
out
=
newer
.
LimitRangeItem
{}
*
out
=
newer
.
LimitRangeItem
{}
out
.
Kind
=
in
.
Kind
out
.
Type
=
in
.
Type
if
err
:=
s
.
Convert
(
&
in
.
Max
,
&
out
.
Max
,
0
);
err
!=
nil
{
if
err
:=
s
.
Convert
(
&
in
.
Max
,
&
out
.
Max
,
0
);
err
!=
nil
{
return
err
return
err
}
}
...
...
pkg/api/v1beta1/types.go
View file @
74f368f5
...
@@ -905,10 +905,17 @@ type List struct {
...
@@ -905,10 +905,17 @@ type List struct {
Items
[]
runtime
.
RawExtension
`json:"items" description:"list of objects"`
Items
[]
runtime
.
RawExtension
`json:"items" description:"list of objects"`
}
}
const
(
// Limit that applies to all pods in a namespace
LimitTypePod
string
=
"Pod"
// Limit that applies to all containers in a namespace
LimitTypeContainer
string
=
"Container"
)
// LimitRangeItem defines a min/max usage limit for any resource that matches on kind
// LimitRangeItem defines a min/max usage limit for any resource that matches on kind
type
LimitRangeItem
struct
{
type
LimitRangeItem
struct
{
//
Kind is the resource kind that this limit range is applied (i.e. pods, etc.)
//
Type of resource that this limit applies to
Kind
string
Type
string
`json:"type,omitempty"`
// Max usage constraints on this kind by resource name
// Max usage constraints on this kind by resource name
Max
ResourceList
`json:"max,omitempty"`
Max
ResourceList
`json:"max,omitempty"`
// Min usage constraints on this kind by resource name
// Min usage constraints on this kind by resource name
...
...
pkg/api/v1beta2/conversion.go
View file @
74f368f5
...
@@ -531,7 +531,7 @@ func init() {
...
@@ -531,7 +531,7 @@ func init() {
},
},
func
(
in
*
newer
.
LimitRangeItem
,
out
*
LimitRangeItem
,
s
conversion
.
Scope
)
error
{
func
(
in
*
newer
.
LimitRangeItem
,
out
*
LimitRangeItem
,
s
conversion
.
Scope
)
error
{
*
out
=
LimitRangeItem
{}
*
out
=
LimitRangeItem
{}
out
.
Kind
=
in
.
Kind
out
.
Type
=
in
.
Type
if
err
:=
s
.
Convert
(
&
in
.
Max
,
&
out
.
Max
,
0
);
err
!=
nil
{
if
err
:=
s
.
Convert
(
&
in
.
Max
,
&
out
.
Max
,
0
);
err
!=
nil
{
return
err
return
err
}
}
...
@@ -542,7 +542,7 @@ func init() {
...
@@ -542,7 +542,7 @@ func init() {
},
},
func
(
in
*
LimitRangeItem
,
out
*
newer
.
LimitRangeItem
,
s
conversion
.
Scope
)
error
{
func
(
in
*
LimitRangeItem
,
out
*
newer
.
LimitRangeItem
,
s
conversion
.
Scope
)
error
{
*
out
=
newer
.
LimitRangeItem
{}
*
out
=
newer
.
LimitRangeItem
{}
out
.
Kind
=
in
.
Kind
out
.
Type
=
in
.
Type
if
err
:=
s
.
Convert
(
&
in
.
Max
,
&
out
.
Max
,
0
);
err
!=
nil
{
if
err
:=
s
.
Convert
(
&
in
.
Max
,
&
out
.
Max
,
0
);
err
!=
nil
{
return
err
return
err
}
}
...
...
pkg/api/v1beta2/types.go
View file @
74f368f5
...
@@ -907,10 +907,17 @@ type List struct {
...
@@ -907,10 +907,17 @@ type List struct {
Items
[]
runtime
.
RawExtension
`json:"items" description:"list of objects"`
Items
[]
runtime
.
RawExtension
`json:"items" description:"list of objects"`
}
}
const
(
// Limit that applies to all pods in a namespace
LimitTypePod
string
=
"Pod"
// Limit that applies to all containers in a namespace
LimitTypeContainer
string
=
"Container"
)
// LimitRangeItem defines a min/max usage limit for any resource that matches on kind
// LimitRangeItem defines a min/max usage limit for any resource that matches on kind
type
LimitRangeItem
struct
{
type
LimitRangeItem
struct
{
//
Kind is the resource kind that this limit range is applied (i.e. pods, etc.)
//
Type of resource that this limit applies to
Kind
string
Type
string
`json:"type,omitempty"`
// Max usage constraints on this kind by resource name
// Max usage constraints on this kind by resource name
Max
ResourceList
`json:"max,omitempty"`
Max
ResourceList
`json:"max,omitempty"`
// Min usage constraints on this kind by resource name
// Min usage constraints on this kind by resource name
...
...
pkg/api/v1beta3/types.go
View file @
74f368f5
...
@@ -1067,10 +1067,17 @@ type List struct {
...
@@ -1067,10 +1067,17 @@ type List struct {
Items
[]
runtime
.
RawExtension
`json:"items" description:"list of objects"`
Items
[]
runtime
.
RawExtension
`json:"items" description:"list of objects"`
}
}
const
(
// Limit that applies to all pods in a namespace
LimitTypePod
string
=
"Pod"
// Limit that applies to all containers in a namespace
LimitTypeContainer
string
=
"Container"
)
// LimitRangeItem defines a min/max usage limit for any resource that matches on kind
// LimitRangeItem defines a min/max usage limit for any resource that matches on kind
type
LimitRangeItem
struct
{
type
LimitRangeItem
struct
{
//
Kind is the resource kind that this limit range is applied (i.e. pods, etc.)
//
Type of resource that this limit applies to
Kind
string
Type
string
`json:"type,omitempty"`
// Max usage constraints on this kind by resource name
// Max usage constraints on this kind by resource name
Max
ResourceList
`json:"max,omitempty"`
Max
ResourceList
`json:"max,omitempty"`
// Min usage constraints on this kind by resource name
// Min usage constraints on this kind by resource name
...
...
pkg/api/validation/validation_test.go
View file @
74f368f5
...
@@ -1563,7 +1563,7 @@ func TestValidateLimitRange(t *testing.T) {
...
@@ -1563,7 +1563,7 @@ func TestValidateLimitRange(t *testing.T) {
Spec
:
api
.
LimitRangeSpec
{
Spec
:
api
.
LimitRangeSpec
{
Limits
:
[]
api
.
LimitRangeItem
{
Limits
:
[]
api
.
LimitRangeItem
{
{
{
Kind
:
"pods"
,
Type
:
api
.
LimitTypePod
,
Max
:
api
.
ResourceList
{
Max
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
...
@@ -1592,7 +1592,7 @@ func TestValidateLimitRange(t *testing.T) {
...
@@ -1592,7 +1592,7 @@ func TestValidateLimitRange(t *testing.T) {
Spec
:
api
.
LimitRangeSpec
{
Spec
:
api
.
LimitRangeSpec
{
Limits
:
[]
api
.
LimitRangeItem
{
Limits
:
[]
api
.
LimitRangeItem
{
{
{
Kind
:
"pods"
,
Type
:
api
.
LimitTypePod
,
Max
:
api
.
ResourceList
{
Max
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
...
@@ -1613,7 +1613,7 @@ func TestValidateLimitRange(t *testing.T) {
...
@@ -1613,7 +1613,7 @@ func TestValidateLimitRange(t *testing.T) {
Spec
:
api
.
LimitRangeSpec
{
Spec
:
api
.
LimitRangeSpec
{
Limits
:
[]
api
.
LimitRangeItem
{
Limits
:
[]
api
.
LimitRangeItem
{
{
{
Kind
:
"pods"
,
Type
:
api
.
LimitTypePod
,
Max
:
api
.
ResourceList
{
Max
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
...
...
pkg/client/limit_ranges_test.go
View file @
74f368f5
...
@@ -34,7 +34,7 @@ func TestLimitRangeCreate(t *testing.T) {
...
@@ -34,7 +34,7 @@ func TestLimitRangeCreate(t *testing.T) {
Spec
:
api
.
LimitRangeSpec
{
Spec
:
api
.
LimitRangeSpec
{
Limits
:
[]
api
.
LimitRangeItem
{
Limits
:
[]
api
.
LimitRangeItem
{
{
{
Kind
:
"pods"
,
Type
:
api
.
LimitTypePod
,
Max
:
api
.
ResourceList
{
Max
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
...
@@ -70,7 +70,7 @@ func TestLimitRangeGet(t *testing.T) {
...
@@ -70,7 +70,7 @@ func TestLimitRangeGet(t *testing.T) {
Spec
:
api
.
LimitRangeSpec
{
Spec
:
api
.
LimitRangeSpec
{
Limits
:
[]
api
.
LimitRangeItem
{
Limits
:
[]
api
.
LimitRangeItem
{
{
{
Kind
:
"pods"
,
Type
:
api
.
LimitTypePod
,
Max
:
api
.
ResourceList
{
Max
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
...
@@ -130,7 +130,7 @@ func TestLimitRangeUpdate(t *testing.T) {
...
@@ -130,7 +130,7 @@ func TestLimitRangeUpdate(t *testing.T) {
Spec
:
api
.
LimitRangeSpec
{
Spec
:
api
.
LimitRangeSpec
{
Limits
:
[]
api
.
LimitRangeItem
{
Limits
:
[]
api
.
LimitRangeItem
{
{
{
Kind
:
"pods"
,
Type
:
api
.
LimitTypePod
,
Max
:
api
.
ResourceList
{
Max
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
...
@@ -160,7 +160,7 @@ func TestInvalidLimitRangeUpdate(t *testing.T) {
...
@@ -160,7 +160,7 @@ func TestInvalidLimitRangeUpdate(t *testing.T) {
Spec
:
api
.
LimitRangeSpec
{
Spec
:
api
.
LimitRangeSpec
{
Limits
:
[]
api
.
LimitRangeItem
{
Limits
:
[]
api
.
LimitRangeItem
{
{
{
Kind
:
"pods"
,
Type
:
api
.
LimitTypePod
,
Max
:
api
.
ResourceList
{
Max
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
...
...
pkg/kubectl/describe.go
View file @
74f368f5
...
@@ -68,11 +68,10 @@ func (d *LimitRangeDescriber) Describe(namespace, name string) (string, error) {
...
@@ -68,11 +68,10 @@ func (d *LimitRangeDescriber) Describe(namespace, name string) (string, error) {
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
limitRange
.
Name
)
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
limitRange
.
Name
)
fmt
.
Fprintf
(
out
,
"
Kind
\t
Resource
\t
Min
\t
Max
\n
"
)
fmt
.
Fprintf
(
out
,
"
Type
\t
Resource
\t
Min
\t
Max
\n
"
)
fmt
.
Fprintf
(
out
,
"----
\t
--------
\t
---
\t
---
\n
"
)
fmt
.
Fprintf
(
out
,
"----
\t
--------
\t
---
\t
---
\n
"
)
for
i
,
_
:=
range
limitRange
.
Spec
.
Limits
{
for
i
,
_
:=
range
limitRange
.
Spec
.
Limits
{
item
:=
limitRange
.
Spec
.
Limits
[
i
]
item
:=
limitRange
.
Spec
.
Limits
[
i
]
kind
:=
item
.
Kind
maxResources
:=
item
.
Max
maxResources
:=
item
.
Max
minResources
:=
item
.
Min
minResources
:=
item
.
Min
...
@@ -100,7 +99,7 @@ func (d *LimitRangeDescriber) Describe(namespace, name string) (string, error) {
...
@@ -100,7 +99,7 @@ func (d *LimitRangeDescriber) Describe(namespace, name string) (string, error) {
}
}
msg
:=
"%v
\t
%v
\t
%v
\t
%v
\n
"
msg
:=
"%v
\t
%v
\t
%v
\t
%v
\n
"
fmt
.
Fprintf
(
out
,
msg
,
kind
,
k
,
minValue
,
maxValue
)
fmt
.
Fprintf
(
out
,
msg
,
item
.
Type
,
k
,
minValue
,
maxValue
)
}
}
}
}
return
nil
return
nil
...
...
pkg/registry/limitrange/registry_test.go
View file @
74f368f5
...
@@ -49,7 +49,7 @@ func TestLimitRangeCreate(t *testing.T) {
...
@@ -49,7 +49,7 @@ func TestLimitRangeCreate(t *testing.T) {
Spec
:
api
.
LimitRangeSpec
{
Spec
:
api
.
LimitRangeSpec
{
Limits
:
[]
api
.
LimitRangeItem
{
Limits
:
[]
api
.
LimitRangeItem
{
{
{
Kind
:
"pods"
,
Type
:
api
.
LimitTypePod
,
Max
:
api
.
ResourceList
{
Max
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
...
...
plugin/pkg/admission/limitranger/admission.go
View file @
74f368f5
...
@@ -131,21 +131,21 @@ func PodLimitFunc(limitRange *api.LimitRange, kind string, obj runtime.Object) e
...
@@ -131,21 +131,21 @@ func PodLimitFunc(limitRange *api.LimitRange, kind string, obj runtime.Object) e
switch
k
{
switch
k
{
case
api
.
ResourceMemory
:
case
api
.
ResourceMemory
:
enforced
=
v
.
Value
()
enforced
=
v
.
Value
()
switch
limit
.
Kind
{
switch
limit
.
Type
{
case
"pods"
:
case
api
.
LimitTypePod
:
observed
=
podMem
observed
=
podMem
err
=
fmt
.
Errorf
(
"Maximum memory usage per pod is %s"
,
v
.
String
())
err
=
fmt
.
Errorf
(
"Maximum memory usage per pod is %s"
,
v
.
String
())
case
"containers"
:
case
api
.
LimitTypeContainer
:
observed
=
maxContainerMem
observed
=
maxContainerMem
err
=
fmt
.
Errorf
(
"Maximum memory usage per container is %s"
,
v
.
String
())
err
=
fmt
.
Errorf
(
"Maximum memory usage per container is %s"
,
v
.
String
())
}
}
case
api
.
ResourceCPU
:
case
api
.
ResourceCPU
:
enforced
=
v
.
MilliValue
()
enforced
=
v
.
MilliValue
()
switch
limit
.
Kind
{
switch
limit
.
Type
{
case
"pods"
:
case
api
.
LimitTypePod
:
observed
=
podCPU
observed
=
podCPU
err
=
fmt
.
Errorf
(
"Maximum CPU usage per pod is %s, but requested %s"
,
v
.
String
(),
resource
.
NewMilliQuantity
(
observed
,
resource
.
DecimalSI
))
err
=
fmt
.
Errorf
(
"Maximum CPU usage per pod is %s, but requested %s"
,
v
.
String
(),
resource
.
NewMilliQuantity
(
observed
,
resource
.
DecimalSI
))
case
"containers"
:
case
api
.
LimitTypeContainer
:
observed
=
maxContainerCPU
observed
=
maxContainerCPU
err
=
fmt
.
Errorf
(
"Maximum CPU usage per container is %s"
,
v
.
String
())
err
=
fmt
.
Errorf
(
"Maximum CPU usage per container is %s"
,
v
.
String
())
}
}
...
@@ -161,21 +161,21 @@ func PodLimitFunc(limitRange *api.LimitRange, kind string, obj runtime.Object) e
...
@@ -161,21 +161,21 @@ func PodLimitFunc(limitRange *api.LimitRange, kind string, obj runtime.Object) e
switch
k
{
switch
k
{
case
api
.
ResourceMemory
:
case
api
.
ResourceMemory
:
enforced
=
v
.
Value
()
enforced
=
v
.
Value
()
switch
limit
.
Kind
{
switch
limit
.
Type
{
case
"pods"
:
case
api
.
LimitTypePod
:
observed
=
podMem
observed
=
podMem
err
=
fmt
.
Errorf
(
"Minimum memory usage per pod is %s"
,
v
.
String
())
err
=
fmt
.
Errorf
(
"Minimum memory usage per pod is %s"
,
v
.
String
())
case
"containers"
:
case
api
.
LimitTypeContainer
:
observed
=
maxContainerMem
observed
=
maxContainerMem
err
=
fmt
.
Errorf
(
"Minimum memory usage per container is %s"
,
v
.
String
())
err
=
fmt
.
Errorf
(
"Minimum memory usage per container is %s"
,
v
.
String
())
}
}
case
api
.
ResourceCPU
:
case
api
.
ResourceCPU
:
enforced
=
v
.
MilliValue
()
enforced
=
v
.
MilliValue
()
switch
limit
.
Kind
{
switch
limit
.
Type
{
case
"pods"
:
case
api
.
LimitTypePod
:
observed
=
podCPU
observed
=
podCPU
err
=
fmt
.
Errorf
(
"Minimum CPU usage per pod is %s"
,
v
.
String
())
err
=
fmt
.
Errorf
(
"Minimum CPU usage per pod is %s"
,
v
.
String
())
case
"containers"
:
case
api
.
LimitTypeContainer
:
observed
=
maxContainerCPU
observed
=
maxContainerCPU
err
=
fmt
.
Errorf
(
"Minimum CPU usage per container is %s"
,
v
.
String
())
err
=
fmt
.
Errorf
(
"Minimum CPU usage per container is %s"
,
v
.
String
())
}
}
...
...
plugin/pkg/admission/limitranger/admission_test.go
View file @
74f368f5
...
@@ -31,7 +31,7 @@ func TestPodLimitFunc(t *testing.T) {
...
@@ -31,7 +31,7 @@ func TestPodLimitFunc(t *testing.T) {
Spec
:
api
.
LimitRangeSpec
{
Spec
:
api
.
LimitRangeSpec
{
Limits
:
[]
api
.
LimitRangeItem
{
Limits
:
[]
api
.
LimitRangeItem
{
{
{
Kind
:
"pods"
,
Type
:
api
.
LimitTypePod
,
Max
:
api
.
ResourceList
{
Max
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"200m"
),
api
.
ResourceCPU
:
resource
.
MustParse
(
"200m"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"4Gi"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"4Gi"
),
...
@@ -42,7 +42,7 @@ func TestPodLimitFunc(t *testing.T) {
...
@@ -42,7 +42,7 @@ func TestPodLimitFunc(t *testing.T) {
},
},
},
},
{
{
Kind
:
"containers"
,
Type
:
api
.
LimitTypeContainer
,
Max
:
api
.
ResourceList
{
Max
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100m"
),
api
.
ResourceCPU
:
resource
.
MustParse
(
"100m"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"2Gi"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"2Gi"
),
...
...
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