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
829fa695
Commit
829fa695
authored
Jan 23, 2015
by
derekwaynecarr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce a ResourceQuota object
parent
c8f61885
Hide whitespace changes
Inline
Side-by-side
Showing
35 changed files
with
1692 additions
and
23 deletions
+1692
-23
helpers.go
pkg/api/helpers.go
+7
-1
register.go
pkg/api/register.go
+6
-0
types.go
pkg/api/types.go
+58
-0
conversion.go
pkg/api/v1beta1/conversion.go
+88
-0
register.go
pkg/api/v1beta1/register.go
+6
-0
types.go
pkg/api/v1beta1/types.go
+55
-0
conversion.go
pkg/api/v1beta2/conversion.go
+88
-0
register.go
pkg/api/v1beta2/register.go
+6
-0
types.go
pkg/api/v1beta2/types.go
+55
-0
register.go
pkg/api/v1beta3/register.go
+6
-0
types.go
pkg/api/v1beta3/types.go
+58
-0
validation.go
pkg/api/validation/validation.go
+25
-0
validation_test.go
pkg/api/validation/validation_test.go
+76
-0
client.go
pkg/client/client.go
+10
-0
fake.go
pkg/client/fake.go
+19
-10
fake_resource_quota_usages.go
pkg/client/fake_resource_quota_usages.go
+33
-0
fake_resource_quotas.go
pkg/client/fake_resource_quotas.go
+54
-0
resource_quota_usages.go
pkg/client/resource_quota_usages.go
+57
-0
resource_quota_usages_test.go
pkg/client/resource_quota_usages_test.go
+93
-0
resource_quotas.go
pkg/client/resource_quotas.go
+94
-0
resource_quotas_test.go
pkg/client/resource_quotas_test.go
+177
-0
describe.go
pkg/kubectl/describe.go
+37
-0
kubectl.go
pkg/kubectl/kubectl.go
+1
-0
resource_printer.go
pkg/kubectl/resource_printer.go
+21
-0
sorted_resource_name_list.go
pkg/kubectl/sorted_resource_name_list.go
+35
-0
master.go
pkg/master/master.go
+18
-12
doc.go
pkg/registry/resourcequota/doc.go
+19
-0
registry.go
pkg/registry/resourcequota/registry.go
+75
-0
registry_test.go
pkg/registry/resourcequota/registry_test.go
+116
-0
rest.go
pkg/registry/resourcequota/rest.go
+162
-0
rest_test.go
pkg/registry/resourcequota/rest_test.go
+17
-0
doc.go
pkg/registry/resourcequotausage/doc.go
+19
-0
registry.go
pkg/registry/resourcequotausage/registry.go
+28
-0
rest.go
pkg/registry/resourcequotausage/rest.go
+56
-0
rest_test.go
pkg/registry/resourcequotausage/rest_test.go
+17
-0
No files found.
pkg/api/helpers.go
View file @
829fa695
...
@@ -62,7 +62,13 @@ var Semantic = conversion.EqualitiesOrDie(
...
@@ -62,7 +62,13 @@ var Semantic = conversion.EqualitiesOrDie(
},
},
)
)
var
standardResources
=
util
.
NewStringSet
(
string
(
ResourceMemory
),
string
(
ResourceCPU
))
var
standardResources
=
util
.
NewStringSet
(
string
(
ResourceMemory
),
string
(
ResourceCPU
),
string
(
ResourcePods
),
string
(
ResourceQuotas
),
string
(
ResourceServices
),
string
(
ResourceReplicationControllers
))
func
IsStandardResourceName
(
str
string
)
bool
{
func
IsStandardResourceName
(
str
string
)
bool
{
return
standardResources
.
Has
(
str
)
return
standardResources
.
Has
(
str
)
...
...
pkg/api/register.go
View file @
829fa695
...
@@ -49,6 +49,9 @@ func init() {
...
@@ -49,6 +49,9 @@ func init() {
&
List
{},
&
List
{},
&
LimitRange
{},
&
LimitRange
{},
&
LimitRangeList
{},
&
LimitRangeList
{},
&
ResourceQuota
{},
&
ResourceQuotaList
{},
&
ResourceQuotaUsage
{},
)
)
// Legacy names are supported
// Legacy names are supported
Scheme
.
AddKnownTypeWithName
(
""
,
"Minion"
,
&
Node
{})
Scheme
.
AddKnownTypeWithName
(
""
,
"Minion"
,
&
Node
{})
...
@@ -81,3 +84,6 @@ func (*BoundPods) IsAnAPIObject() {}
...
@@ -81,3 +84,6 @@ func (*BoundPods) IsAnAPIObject() {}
func
(
*
List
)
IsAnAPIObject
()
{}
func
(
*
List
)
IsAnAPIObject
()
{}
func
(
*
LimitRange
)
IsAnAPIObject
()
{}
func
(
*
LimitRange
)
IsAnAPIObject
()
{}
func
(
*
LimitRangeList
)
IsAnAPIObject
()
{}
func
(
*
LimitRangeList
)
IsAnAPIObject
()
{}
func
(
*
ResourceQuota
)
IsAnAPIObject
()
{}
func
(
*
ResourceQuotaList
)
IsAnAPIObject
()
{}
func
(
*
ResourceQuotaUsage
)
IsAnAPIObject
()
{}
pkg/api/types.go
View file @
829fa695
...
@@ -1133,6 +1133,7 @@ type List struct {
...
@@ -1133,6 +1133,7 @@ type List struct {
Items
[]
runtime
.
Object
`json:"items"`
Items
[]
runtime
.
Object
`json:"items"`
}
}
<<<<<<<
HEAD
// A type of object that is limited
// A type of object that is limited
type
LimitType
string
type
LimitType
string
...
@@ -1176,3 +1177,60 @@ type LimitRangeList struct {
...
@@ -1176,3 +1177,60 @@ type LimitRangeList struct {
// Items is a list of LimitRange objects
// Items is a list of LimitRange objects
Items
[]
LimitRange
`json:"items"`
Items
[]
LimitRange
`json:"items"`
}
}
// The following identify resource constants for Kubernetes object types
const
(
// Pods, number
ResourcePods
ResourceName
=
"pods"
// Services, number
ResourceServices
ResourceName
=
"services"
// ReplicationControllers, number
ResourceReplicationControllers
ResourceName
=
"replicationcontrollers"
// ResourceQuotas, number
ResourceQuotas
ResourceName
=
"resourcequotas"
)
// ResourceQuotaSpec defines the desired hard limits to enforce for Quota
type
ResourceQuotaSpec
struct
{
// Hard is the set of desired hard limits for each named resource
Hard
ResourceList
`json:"hard,omitempty"`
}
// ResourceQuotaStatus defines the enforced hard limits and observed use
type
ResourceQuotaStatus
struct
{
// Hard is the set of enforced hard limits for each named resource
Hard
ResourceList
`json:"hard,omitempty"`
// Used is the current observed total usage of the resource in the namespace
Used
ResourceList
`json:"used,omitempty"`
}
// ResourceQuota sets aggregate quota restrictions enforced per namespace
type
ResourceQuota
struct
{
TypeMeta
`json:",inline"`
ObjectMeta
`json:"metadata,omitempty"`
// Spec defines the desired quota
Spec
ResourceQuotaSpec
`json:"spec,omitempty"`
// Status defines the actual enforced quota and its current usage
Status
ResourceQuotaStatus
`json:"status,omitempty"`
}
// ResourceQuotaUsage captures system observed quota status per namespace
// It is used to enforce atomic updates of a backing ResourceQuota.Status field in storage
type
ResourceQuotaUsage
struct
{
TypeMeta
`json:",inline"`
ObjectMeta
`json:"metadata,omitempty"`
// Status defines the actual enforced quota and its current usage
Status
ResourceQuotaStatus
`json:"status,omitempty"`
}
// ResourceQuotaList is a list of ResourceQuota items
type
ResourceQuotaList
struct
{
TypeMeta
`json:",inline"`
ListMeta
`json:"metadata,omitempty"`
// Items is a list of ResourceQuota objects
Items
[]
ResourceQuota
`json:"items"`
}
pkg/api/v1beta1/conversion.go
View file @
829fa695
...
@@ -634,6 +634,94 @@ func init() {
...
@@ -634,6 +634,94 @@ func init() {
}
}
return
nil
return
nil
},
},
func
(
in
*
newer
.
ResourceQuota
,
out
*
ResourceQuota
,
s
conversion
.
Scope
)
error
{
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
ObjectMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
Spec
,
&
out
.
Spec
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
Status
,
&
out
.
Status
,
0
);
err
!=
nil
{
return
err
}
return
nil
},
func
(
in
*
ResourceQuota
,
out
*
newer
.
ResourceQuota
,
s
conversion
.
Scope
)
error
{
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
ObjectMeta
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
Spec
,
&
out
.
Spec
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
Status
,
&
out
.
Status
,
0
);
err
!=
nil
{
return
err
}
return
nil
},
func
(
in
*
newer
.
ResourceQuotaUsage
,
out
*
ResourceQuotaUsage
,
s
conversion
.
Scope
)
error
{
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
ObjectMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
Status
,
&
out
.
Status
,
0
);
err
!=
nil
{
return
err
}
return
nil
},
func
(
in
*
ResourceQuotaUsage
,
out
*
newer
.
ResourceQuotaUsage
,
s
conversion
.
Scope
)
error
{
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
ObjectMeta
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
Status
,
&
out
.
Status
,
0
);
err
!=
nil
{
return
err
}
return
nil
},
func
(
in
*
newer
.
ResourceQuotaSpec
,
out
*
ResourceQuotaSpec
,
s
conversion
.
Scope
)
error
{
*
out
=
ResourceQuotaSpec
{}
if
err
:=
s
.
Convert
(
&
in
.
Hard
,
&
out
.
Hard
,
0
);
err
!=
nil
{
return
err
}
return
nil
},
func
(
in
*
ResourceQuotaSpec
,
out
*
newer
.
ResourceQuotaSpec
,
s
conversion
.
Scope
)
error
{
*
out
=
newer
.
ResourceQuotaSpec
{}
if
err
:=
s
.
Convert
(
&
in
.
Hard
,
&
out
.
Hard
,
0
);
err
!=
nil
{
return
err
}
return
nil
},
func
(
in
*
newer
.
ResourceQuotaStatus
,
out
*
ResourceQuotaStatus
,
s
conversion
.
Scope
)
error
{
*
out
=
ResourceQuotaStatus
{}
if
err
:=
s
.
Convert
(
&
in
.
Hard
,
&
out
.
Hard
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
Used
,
&
out
.
Used
,
0
);
err
!=
nil
{
return
err
}
return
nil
},
func
(
in
*
ResourceQuotaStatus
,
out
*
newer
.
ResourceQuotaStatus
,
s
conversion
.
Scope
)
error
{
*
out
=
newer
.
ResourceQuotaStatus
{}
if
err
:=
s
.
Convert
(
&
in
.
Hard
,
&
out
.
Hard
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
Used
,
&
out
.
Used
,
0
);
err
!=
nil
{
return
err
}
return
nil
},
// Object ID <-> Name
// Object ID <-> Name
// TODO: amend the conversion package to allow overriding specific fields.
// TODO: amend the conversion package to allow overriding specific fields.
func
(
in
*
ObjectReference
,
out
*
newer
.
ObjectReference
,
s
conversion
.
Scope
)
error
{
func
(
in
*
ObjectReference
,
out
*
newer
.
ObjectReference
,
s
conversion
.
Scope
)
error
{
...
...
pkg/api/v1beta1/register.go
View file @
829fa695
...
@@ -50,6 +50,9 @@ func init() {
...
@@ -50,6 +50,9 @@ func init() {
&
List
{},
&
List
{},
&
LimitRange
{},
&
LimitRange
{},
&
LimitRangeList
{},
&
LimitRangeList
{},
&
ResourceQuota
{},
&
ResourceQuotaList
{},
&
ResourceQuotaUsage
{},
)
)
// Future names are supported
// Future names are supported
api
.
Scheme
.
AddKnownTypeWithName
(
"v1beta1"
,
"Node"
,
&
Minion
{})
api
.
Scheme
.
AddKnownTypeWithName
(
"v1beta1"
,
"Node"
,
&
Minion
{})
...
@@ -82,3 +85,6 @@ func (*BoundPods) IsAnAPIObject() {}
...
@@ -82,3 +85,6 @@ func (*BoundPods) IsAnAPIObject() {}
func
(
*
List
)
IsAnAPIObject
()
{}
func
(
*
List
)
IsAnAPIObject
()
{}
func
(
*
LimitRange
)
IsAnAPIObject
()
{}
func
(
*
LimitRange
)
IsAnAPIObject
()
{}
func
(
*
LimitRangeList
)
IsAnAPIObject
()
{}
func
(
*
LimitRangeList
)
IsAnAPIObject
()
{}
func
(
*
ResourceQuota
)
IsAnAPIObject
()
{}
func
(
*
ResourceQuotaList
)
IsAnAPIObject
()
{}
func
(
*
ResourceQuotaUsage
)
IsAnAPIObject
()
{}
pkg/api/v1beta1/types.go
View file @
829fa695
...
@@ -893,6 +893,7 @@ type List struct {
...
@@ -893,6 +893,7 @@ type List struct {
Items
[]
runtime
.
RawExtension
`json:"items" description:"list of objects"`
Items
[]
runtime
.
RawExtension
`json:"items" description:"list of objects"`
}
}
<<<<<<<
HEAD
// A type of object that is limited
// A type of object that is limited
type
LimitType
string
type
LimitType
string
...
@@ -934,3 +935,57 @@ type LimitRangeList struct {
...
@@ -934,3 +935,57 @@ type LimitRangeList struct {
// Items is a list of LimitRange objects
// Items is a list of LimitRange objects
Items
[]
LimitRange
`json:"items"`
Items
[]
LimitRange
`json:"items"`
}
}
// The following identify resource constants for Kubernetes object types
const
(
// Pods, number
ResourcePods
ResourceName
=
"pods"
// Services, number
ResourceServices
ResourceName
=
"services"
// ReplicationControllers, number
ResourceReplicationControllers
ResourceName
=
"replicationcontrollers"
// ResourceQuotas, number
ResourceQuotas
ResourceName
=
"resourcequotas"
)
// ResourceQuotaSpec defines the desired hard limits to enforce for Quota
type
ResourceQuotaSpec
struct
{
// Hard is the set of desired hard limits for each named resource
Hard
ResourceList
`json:"hard,omitempty"`
}
// ResourceQuotaStatus defines the enforced hard limits and observed use
type
ResourceQuotaStatus
struct
{
// Hard is the set of enforced hard limits for each named resource
Hard
ResourceList
`json:"hard,omitempty"`
// Used is the current observed total usage of the resource in the namespace
Used
ResourceList
`json:"used,omitempty"`
}
// ResourceQuota sets aggregate quota restrictions enforced per namespace
type
ResourceQuota
struct
{
TypeMeta
`json:",inline"`
// Spec defines the desired quota
Spec
ResourceQuotaSpec
`json:"spec,omitempty"`
// Status defines the actual enforced quota and its current usage
Status
ResourceQuotaStatus
`json:"status,omitempty"`
}
// ResourceQuotaUsage captures system observed quota status per namespace
// It is used to enforce atomic updates of a backing ResourceQuota.Status field in storage
type
ResourceQuotaUsage
struct
{
TypeMeta
`json:",inline"`
// Status defines the actual enforced quota and its current usage
Status
ResourceQuotaStatus
`json:"status,omitempty"`
}
// ResourceQuotaList is a list of ResourceQuota items
type
ResourceQuotaList
struct
{
TypeMeta
`json:",inline"`
// Items is a list of ResourceQuota objects
Items
[]
ResourceQuota
`json:"items"`
}
pkg/api/v1beta2/conversion.go
View file @
829fa695
...
@@ -551,6 +551,94 @@ func init() {
...
@@ -551,6 +551,94 @@ func init() {
}
}
return
nil
return
nil
},
},
func
(
in
*
newer
.
ResourceQuota
,
out
*
ResourceQuota
,
s
conversion
.
Scope
)
error
{
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
ObjectMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
Spec
,
&
out
.
Spec
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
Status
,
&
out
.
Status
,
0
);
err
!=
nil
{
return
err
}
return
nil
},
func
(
in
*
ResourceQuota
,
out
*
newer
.
ResourceQuota
,
s
conversion
.
Scope
)
error
{
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
ObjectMeta
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
Spec
,
&
out
.
Spec
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
Status
,
&
out
.
Status
,
0
);
err
!=
nil
{
return
err
}
return
nil
},
func
(
in
*
newer
.
ResourceQuotaUsage
,
out
*
ResourceQuotaUsage
,
s
conversion
.
Scope
)
error
{
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
ObjectMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
Status
,
&
out
.
Status
,
0
);
err
!=
nil
{
return
err
}
return
nil
},
func
(
in
*
ResourceQuotaUsage
,
out
*
newer
.
ResourceQuotaUsage
,
s
conversion
.
Scope
)
error
{
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
TypeMeta
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
TypeMeta
,
&
out
.
ObjectMeta
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
Status
,
&
out
.
Status
,
0
);
err
!=
nil
{
return
err
}
return
nil
},
func
(
in
*
newer
.
ResourceQuotaSpec
,
out
*
ResourceQuotaSpec
,
s
conversion
.
Scope
)
error
{
*
out
=
ResourceQuotaSpec
{}
if
err
:=
s
.
Convert
(
&
in
.
Hard
,
&
out
.
Hard
,
0
);
err
!=
nil
{
return
err
}
return
nil
},
func
(
in
*
ResourceQuotaSpec
,
out
*
newer
.
ResourceQuotaSpec
,
s
conversion
.
Scope
)
error
{
*
out
=
newer
.
ResourceQuotaSpec
{}
if
err
:=
s
.
Convert
(
&
in
.
Hard
,
&
out
.
Hard
,
0
);
err
!=
nil
{
return
err
}
return
nil
},
func
(
in
*
newer
.
ResourceQuotaStatus
,
out
*
ResourceQuotaStatus
,
s
conversion
.
Scope
)
error
{
*
out
=
ResourceQuotaStatus
{}
if
err
:=
s
.
Convert
(
&
in
.
Hard
,
&
out
.
Hard
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
Used
,
&
out
.
Used
,
0
);
err
!=
nil
{
return
err
}
return
nil
},
func
(
in
*
ResourceQuotaStatus
,
out
*
newer
.
ResourceQuotaStatus
,
s
conversion
.
Scope
)
error
{
*
out
=
newer
.
ResourceQuotaStatus
{}
if
err
:=
s
.
Convert
(
&
in
.
Hard
,
&
out
.
Hard
,
0
);
err
!=
nil
{
return
err
}
if
err
:=
s
.
Convert
(
&
in
.
Used
,
&
out
.
Used
,
0
);
err
!=
nil
{
return
err
}
return
nil
},
// Object ID <-> Name
// Object ID <-> Name
// TODO: amend the conversion package to allow overriding specific fields.
// TODO: amend the conversion package to allow overriding specific fields.
func
(
in
*
ObjectReference
,
out
*
newer
.
ObjectReference
,
s
conversion
.
Scope
)
error
{
func
(
in
*
ObjectReference
,
out
*
newer
.
ObjectReference
,
s
conversion
.
Scope
)
error
{
...
...
pkg/api/v1beta2/register.go
View file @
829fa695
...
@@ -50,6 +50,9 @@ func init() {
...
@@ -50,6 +50,9 @@ func init() {
&
List
{},
&
List
{},
&
LimitRange
{},
&
LimitRange
{},
&
LimitRangeList
{},
&
LimitRangeList
{},
&
ResourceQuota
{},
&
ResourceQuotaList
{},
&
ResourceQuotaUsage
{},
)
)
// Future names are supported
// Future names are supported
api
.
Scheme
.
AddKnownTypeWithName
(
"v1beta2"
,
"Node"
,
&
Minion
{})
api
.
Scheme
.
AddKnownTypeWithName
(
"v1beta2"
,
"Node"
,
&
Minion
{})
...
@@ -82,3 +85,6 @@ func (*BoundPods) IsAnAPIObject() {}
...
@@ -82,3 +85,6 @@ func (*BoundPods) IsAnAPIObject() {}
func
(
*
List
)
IsAnAPIObject
()
{}
func
(
*
List
)
IsAnAPIObject
()
{}
func
(
*
LimitRange
)
IsAnAPIObject
()
{}
func
(
*
LimitRange
)
IsAnAPIObject
()
{}
func
(
*
LimitRangeList
)
IsAnAPIObject
()
{}
func
(
*
LimitRangeList
)
IsAnAPIObject
()
{}
func
(
*
ResourceQuota
)
IsAnAPIObject
()
{}
func
(
*
ResourceQuotaList
)
IsAnAPIObject
()
{}
func
(
*
ResourceQuotaUsage
)
IsAnAPIObject
()
{}
pkg/api/v1beta2/types.go
View file @
829fa695
...
@@ -895,6 +895,7 @@ type List struct {
...
@@ -895,6 +895,7 @@ type List struct {
Items
[]
runtime
.
RawExtension
`json:"items" description:"list of objects"`
Items
[]
runtime
.
RawExtension
`json:"items" description:"list of objects"`
}
}
<<<<<<<
HEAD
// A type of object that is limited
// A type of object that is limited
type
LimitType
string
type
LimitType
string
...
@@ -936,3 +937,57 @@ type LimitRangeList struct {
...
@@ -936,3 +937,57 @@ type LimitRangeList struct {
// Items is a list of LimitRange objects
// Items is a list of LimitRange objects
Items
[]
LimitRange
`json:"items"`
Items
[]
LimitRange
`json:"items"`
}
}
// The following identify resource constants for Kubernetes object types
const
(
// Pods, number
ResourcePods
ResourceName
=
"pods"
// Services, number
ResourceServices
ResourceName
=
"services"
// ReplicationControllers, number
ResourceReplicationControllers
ResourceName
=
"replicationcontrollers"
// ResourceQuotas, number
ResourceQuotas
ResourceName
=
"resourcequotas"
)
// ResourceQuotaSpec defines the desired hard limits to enforce for Quota
type
ResourceQuotaSpec
struct
{
// Hard is the set of desired hard limits for each named resource
Hard
ResourceList
`json:"hard,omitempty"`
}
// ResourceQuotaStatus defines the enforced hard limits and observed use
type
ResourceQuotaStatus
struct
{
// Hard is the set of enforced hard limits for each named resource
Hard
ResourceList
`json:"hard,omitempty"`
// Used is the current observed total usage of the resource in the namespace
Used
ResourceList
`json:"used,omitempty"`
}
// ResourceQuota sets aggregate quota restrictions enforced per namespace
type
ResourceQuota
struct
{
TypeMeta
`json:",inline"`
// Spec defines the desired quota
Spec
ResourceQuotaSpec
`json:"spec,omitempty"`
// Status defines the actual enforced quota and its current usage
Status
ResourceQuotaStatus
`json:"status,omitempty"`
}
// ResourceQuotaUsage captures system observed quota status per namespace
// It is used to enforce atomic updates of a backing ResourceQuota.Status field in storage
type
ResourceQuotaUsage
struct
{
TypeMeta
`json:",inline"`
// Status defines the actual enforced quota and its current usage
Status
ResourceQuotaStatus
`json:"status,omitempty"`
}
// ResourceQuotaList is a list of ResourceQuota items
type
ResourceQuotaList
struct
{
TypeMeta
`json:",inline"`
// Items is a list of ResourceQuota objects
Items
[]
ResourceQuota
`json:"items"`
}
pkg/api/v1beta3/register.go
View file @
829fa695
...
@@ -50,6 +50,9 @@ func init() {
...
@@ -50,6 +50,9 @@ func init() {
&
List
{},
&
List
{},
&
LimitRange
{},
&
LimitRange
{},
&
LimitRangeList
{},
&
LimitRangeList
{},
&
ResourceQuota
{},
&
ResourceQuotaList
{},
&
ResourceQuotaUsage
{},
)
)
// Legacy names are supported
// Legacy names are supported
api
.
Scheme
.
AddKnownTypeWithName
(
"v1beta3"
,
"Minion"
,
&
Node
{})
api
.
Scheme
.
AddKnownTypeWithName
(
"v1beta3"
,
"Minion"
,
&
Node
{})
...
@@ -82,3 +85,6 @@ func (*EventList) IsAnAPIObject() {}
...
@@ -82,3 +85,6 @@ func (*EventList) IsAnAPIObject() {}
func
(
*
List
)
IsAnAPIObject
()
{}
func
(
*
List
)
IsAnAPIObject
()
{}
func
(
*
LimitRange
)
IsAnAPIObject
()
{}
func
(
*
LimitRange
)
IsAnAPIObject
()
{}
func
(
*
LimitRangeList
)
IsAnAPIObject
()
{}
func
(
*
LimitRangeList
)
IsAnAPIObject
()
{}
func
(
*
ResourceQuota
)
IsAnAPIObject
()
{}
func
(
*
ResourceQuotaList
)
IsAnAPIObject
()
{}
func
(
*
ResourceQuotaUsage
)
IsAnAPIObject
()
{}
pkg/api/v1beta3/types.go
View file @
829fa695
...
@@ -1055,6 +1055,7 @@ type List struct {
...
@@ -1055,6 +1055,7 @@ type List struct {
Items
[]
runtime
.
RawExtension
`json:"items" description:"list of objects"`
Items
[]
runtime
.
RawExtension
`json:"items" description:"list of objects"`
}
}
<<<<<<<
HEAD
// A type of object that is limited
// A type of object that is limited
type
LimitType
string
type
LimitType
string
...
@@ -1098,3 +1099,60 @@ type LimitRangeList struct {
...
@@ -1098,3 +1099,60 @@ type LimitRangeList struct {
// Items is a list of LimitRange objects
// Items is a list of LimitRange objects
Items
[]
LimitRange
`json:"items"`
Items
[]
LimitRange
`json:"items"`
}
}
// The following identify resource constants for Kubernetes object types
const
(
// Pods, number
ResourcePods
ResourceName
=
"pods"
// Services, number
ResourceServices
ResourceName
=
"services"
// ReplicationControllers, number
ResourceReplicationControllers
ResourceName
=
"replicationcontrollers"
// ResourceQuotas, number
ResourceQuotas
ResourceName
=
"resourcequotas"
)
// ResourceQuotaSpec defines the desired hard limits to enforce for Quota
type
ResourceQuotaSpec
struct
{
// Hard is the set of desired hard limits for each named resource
Hard
ResourceList
`json:"hard,omitempty"`
}
// ResourceQuotaStatus defines the enforced hard limits and observed use
type
ResourceQuotaStatus
struct
{
// Hard is the set of enforced hard limits for each named resource
Hard
ResourceList
`json:"hard,omitempty"`
// Used is the current observed total usage of the resource in the namespace
Used
ResourceList
`json:"used,omitempty"`
}
// ResourceQuota sets aggregate quota restrictions enforced per namespace
type
ResourceQuota
struct
{
TypeMeta
`json:",inline"`
ObjectMeta
`json:"metadata,omitempty"`
// Spec defines the desired quota
Spec
ResourceQuotaSpec
`json:"spec,omitempty"`
// Status defines the actual enforced quota and its current usage
Status
ResourceQuotaStatus
`json:"status,omitempty"`
}
// ResourceQuotaUsage captures system observed quota status per namespace
// It is used to enforce atomic updates of a backing ResourceQuota.Status field in storage
type
ResourceQuotaUsage
struct
{
TypeMeta
`json:",inline"`
ObjectMeta
`json:"metadata,omitempty"`
// Status defines the actual enforced quota and its current usage
Status
ResourceQuotaStatus
`json:"status,omitempty"`
}
// ResourceQuotaList is a list of ResourceQuota items
type
ResourceQuotaList
struct
{
TypeMeta
`json:",inline"`
ListMeta
`json:"metadata,omitempty"`
// Items is a list of ResourceQuota objects
Items
[]
ResourceQuota
`json:"items"`
}
pkg/api/validation/validation.go
View file @
829fa695
...
@@ -666,3 +666,28 @@ func ValidateLimitRange(limitRange *api.LimitRange) errs.ValidationErrorList {
...
@@ -666,3 +666,28 @@ func ValidateLimitRange(limitRange *api.LimitRange) errs.ValidationErrorList {
}
}
return
allErrs
return
allErrs
}
}
// ValidateResourceQuota tests if required fields in the ResourceQuota are set.
func
ValidateResourceQuota
(
resourceQuota
*
api
.
ResourceQuota
)
errs
.
ValidationErrorList
{
allErrs
:=
errs
.
ValidationErrorList
{}
if
len
(
resourceQuota
.
Name
)
==
0
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldRequired
(
"name"
,
resourceQuota
.
Name
))
}
else
if
!
util
.
IsDNSSubdomain
(
resourceQuota
.
Name
)
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"name"
,
resourceQuota
.
Name
,
""
))
}
if
len
(
resourceQuota
.
Namespace
)
==
0
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldRequired
(
"namespace"
,
resourceQuota
.
Namespace
))
}
else
if
!
util
.
IsDNSSubdomain
(
resourceQuota
.
Namespace
)
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"namespace"
,
resourceQuota
.
Namespace
,
""
))
}
for
k
:=
range
resourceQuota
.
Spec
.
Hard
{
allErrs
=
append
(
allErrs
,
ValidateResourceName
(
string
(
k
))
...
)
}
for
k
:=
range
resourceQuota
.
Status
.
Hard
{
allErrs
=
append
(
allErrs
,
ValidateResourceName
(
string
(
k
))
...
)
}
for
k
:=
range
resourceQuota
.
Status
.
Used
{
allErrs
=
append
(
allErrs
,
ValidateResourceName
(
string
(
k
))
...
)
}
return
allErrs
}
pkg/api/validation/validation_test.go
View file @
829fa695
...
@@ -1577,6 +1577,7 @@ func TestValidateLimitRange(t *testing.T) {
...
@@ -1577,6 +1577,7 @@ func TestValidateLimitRange(t *testing.T) {
},
},
},
},
}
}
for
_
,
successCase
:=
range
successCases
{
for
_
,
successCase
:=
range
successCases
{
if
errs
:=
ValidateLimitRange
(
&
successCase
);
len
(
errs
)
!=
0
{
if
errs
:=
ValidateLimitRange
(
&
successCase
);
len
(
errs
)
!=
0
{
t
.
Errorf
(
"expected success: %v"
,
errs
)
t
.
Errorf
(
"expected success: %v"
,
errs
)
...
@@ -1641,3 +1642,78 @@ func TestValidateLimitRange(t *testing.T) {
...
@@ -1641,3 +1642,78 @@ func TestValidateLimitRange(t *testing.T) {
}
}
}
}
}
}
func
TestValidateResourceQuota
(
t
*
testing
.
T
)
{
successCases
:=
[]
api
.
ResourceQuota
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"foo"
,
},
Spec
:
api
.
ResourceQuotaSpec
{
Hard
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourcePods
:
resource
.
MustParse
(
"10"
),
api
.
ResourceServices
:
resource
.
MustParse
(
"10"
),
api
.
ResourceReplicationControllers
:
resource
.
MustParse
(
"10"
),
api
.
ResourceQuotas
:
resource
.
MustParse
(
"10"
),
},
},
},
}
for
_
,
successCase
:=
range
successCases
{
if
errs
:=
ValidateResourceQuota
(
&
successCase
);
len
(
errs
)
!=
0
{
t
.
Errorf
(
"expected success: %v"
,
errs
)
}
}
errorCases
:=
map
[
string
]
api
.
ResourceQuota
{
"zero-length Name"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
""
,
Namespace
:
"foo"
,
},
Spec
:
api
.
ResourceQuotaSpec
{
Hard
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourcePods
:
resource
.
MustParse
(
"10"
),
api
.
ResourceServices
:
resource
.
MustParse
(
"10"
),
api
.
ResourceReplicationControllers
:
resource
.
MustParse
(
"10"
),
api
.
ResourceQuotas
:
resource
.
MustParse
(
"10"
),
},
},
},
"zero-length-namespace"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
""
,
},
Spec
:
api
.
ResourceQuotaSpec
{
Hard
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourcePods
:
resource
.
MustParse
(
"10"
),
api
.
ResourceServices
:
resource
.
MustParse
(
"10"
),
api
.
ResourceReplicationControllers
:
resource
.
MustParse
(
"10"
),
api
.
ResourceQuotas
:
resource
.
MustParse
(
"10"
),
},
},
},
}
for
k
,
v
:=
range
errorCases
{
errs
:=
ValidateResourceQuota
(
&
v
)
if
len
(
errs
)
==
0
{
t
.
Errorf
(
"expected failure for %s"
,
k
)
}
for
i
:=
range
errs
{
field
:=
errs
[
i
]
.
(
*
errors
.
ValidationError
)
.
Field
if
field
!=
"name"
&&
field
!=
"namespace"
{
t
.
Errorf
(
"%s: missing prefix for: %v"
,
k
,
errs
[
i
])
}
}
}
}
pkg/client/client.go
View file @
829fa695
...
@@ -38,6 +38,8 @@ type Interface interface {
...
@@ -38,6 +38,8 @@ type Interface interface {
NodesInterface
NodesInterface
EventNamespacer
EventNamespacer
LimitRangesNamespacer
LimitRangesNamespacer
ResourceQuotasNamespacer
ResourceQuotaUsagesNamespacer
}
}
func
(
c
*
Client
)
ReplicationControllers
(
namespace
string
)
ReplicationControllerInterface
{
func
(
c
*
Client
)
ReplicationControllers
(
namespace
string
)
ReplicationControllerInterface
{
...
@@ -68,6 +70,14 @@ func (c *Client) LimitRanges(namespace string) LimitRangeInterface {
...
@@ -68,6 +70,14 @@ func (c *Client) LimitRanges(namespace string) LimitRangeInterface {
return
newLimitRanges
(
c
,
namespace
)
return
newLimitRanges
(
c
,
namespace
)
}
}
func
(
c
*
Client
)
ResourceQuotas
(
namespace
string
)
ResourceQuotaInterface
{
return
newResourceQuotas
(
c
,
namespace
)
}
func
(
c
*
Client
)
ResourceQuotaUsages
(
namespace
string
)
ResourceQuotaUsageInterface
{
return
newResourceQuotaUsages
(
c
,
namespace
)
}
// VersionInterface has a method to retrieve the server version.
// VersionInterface has a method to retrieve the server version.
type
VersionInterface
interface
{
type
VersionInterface
interface
{
ServerVersion
()
(
*
version
.
Info
,
error
)
ServerVersion
()
(
*
version
.
Info
,
error
)
...
...
pkg/client/fake.go
View file @
829fa695
...
@@ -34,22 +34,31 @@ type FakeAction struct {
...
@@ -34,22 +34,31 @@ type FakeAction struct {
// Fake implements Interface. Meant to be embedded into a struct to get a default
// Fake implements Interface. Meant to be embedded into a struct to get a default
// implementation. This makes faking out just the method you want to test easier.
// implementation. This makes faking out just the method you want to test easier.
type
Fake
struct
{
type
Fake
struct
{
Actions
[]
FakeAction
Actions
[]
FakeAction
PodsList
api
.
PodList
PodsList
api
.
PodList
Ctrl
api
.
ReplicationController
Ctrl
api
.
ReplicationController
ServiceList
api
.
ServiceList
ServiceList
api
.
ServiceList
EndpointsList
api
.
EndpointsList
EndpointsList
api
.
EndpointsList
MinionsList
api
.
NodeList
MinionsList
api
.
NodeList
EventsList
api
.
EventList
EventsList
api
.
EventList
LimitRangesList
api
.
LimitRangeList
LimitRangesList
api
.
LimitRangeList
Err
error
ResourceQuotasList
api
.
ResourceQuotaList
Watch
watch
.
Interface
Err
error
Watch
watch
.
Interface
}
}
func
(
c
*
Fake
)
LimitRanges
(
namespace
string
)
LimitRangeInterface
{
func
(
c
*
Fake
)
LimitRanges
(
namespace
string
)
LimitRangeInterface
{
return
&
FakeLimitRanges
{
Fake
:
c
,
Namespace
:
namespace
}
return
&
FakeLimitRanges
{
Fake
:
c
,
Namespace
:
namespace
}
}
}
func
(
c
*
Fake
)
ResourceQuotas
(
namespace
string
)
ResourceQuotaInterface
{
return
&
FakeResourceQuotas
{
Fake
:
c
,
Namespace
:
namespace
}
}
func
(
c
*
Fake
)
ResourceQuotaUsages
(
namespace
string
)
ResourceQuotaUsageInterface
{
return
&
FakeResourceQuotaUsages
{
Fake
:
c
,
Namespace
:
namespace
}
}
func
(
c
*
Fake
)
ReplicationControllers
(
namespace
string
)
ReplicationControllerInterface
{
func
(
c
*
Fake
)
ReplicationControllers
(
namespace
string
)
ReplicationControllerInterface
{
return
&
FakeReplicationControllers
{
Fake
:
c
,
Namespace
:
namespace
}
return
&
FakeReplicationControllers
{
Fake
:
c
,
Namespace
:
namespace
}
}
}
...
...
pkg/client/fake_resource_quota_usages.go
0 → 100644
View file @
829fa695
/*
Copyright 2014 Google Inc. 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
client
import
(
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)
// FakeResourceQuotaUsages implements ResourceQuotaUsageInterface. Meant to be embedded into a struct to get a default
// implementation. This makes faking out just the methods you want to test easier.
type
FakeResourceQuotaUsages
struct
{
Fake
*
Fake
Namespace
string
}
func
(
c
*
FakeResourceQuotaUsages
)
Create
(
resourceQuotaUsage
*
api
.
ResourceQuotaUsage
)
error
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"create-resourceQuotaUsage"
})
return
nil
}
pkg/client/fake_resource_quotas.go
0 → 100644
View file @
829fa695
/*
Copyright 2014 Google Inc. 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
client
import
(
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
)
// FakeResourceQuotas implements ResourceQuotaInterface. Meant to be embedded into a struct to get a default
// implementation. This makes faking out just the methods you want to test easier.
type
FakeResourceQuotas
struct
{
Fake
*
Fake
Namespace
string
}
func
(
c
*
FakeResourceQuotas
)
List
(
selector
labels
.
Selector
)
(
*
api
.
ResourceQuotaList
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"list-resourceQuotas"
})
return
api
.
Scheme
.
CopyOrDie
(
&
c
.
Fake
.
ResourceQuotasList
)
.
(
*
api
.
ResourceQuotaList
),
nil
}
func
(
c
*
FakeResourceQuotas
)
Get
(
name
string
)
(
*
api
.
ResourceQuota
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"get-resourceQuota"
,
Value
:
name
})
return
&
api
.
ResourceQuota
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
Namespace
:
c
.
Namespace
}},
nil
}
func
(
c
*
FakeResourceQuotas
)
Delete
(
name
string
)
error
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"delete-resourceQuota"
,
Value
:
name
})
return
nil
}
func
(
c
*
FakeResourceQuotas
)
Create
(
resourceQuota
*
api
.
ResourceQuota
)
(
*
api
.
ResourceQuota
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"create-resourceQuota"
})
return
&
api
.
ResourceQuota
{},
nil
}
func
(
c
*
FakeResourceQuotas
)
Update
(
resourceQuota
*
api
.
ResourceQuota
)
(
*
api
.
ResourceQuota
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"update-resourceQuota"
,
Value
:
resourceQuota
.
Name
})
return
&
api
.
ResourceQuota
{},
nil
}
pkg/client/resource_quota_usages.go
0 → 100644
View file @
829fa695
/*
Copyright 2014 Google Inc. 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
client
import
(
"fmt"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)
// ResourceQuotaUsagesNamespacer has methods to work with ResourceQuotaUsage resources in a namespace
type
ResourceQuotaUsagesNamespacer
interface
{
ResourceQuotaUsages
(
namespace
string
)
ResourceQuotaUsageInterface
}
// ResourceQuotaUsageInterface has methods to work with ResourceQuotaUsage resources.
type
ResourceQuotaUsageInterface
interface
{
Create
(
resourceQuotaUsage
*
api
.
ResourceQuotaUsage
)
error
}
// resourceQuotaUsages implements ResourceQuotaUsagesNamespacer interface
type
resourceQuotaUsages
struct
{
r
*
Client
ns
string
}
// newResourceQuotaUsages returns a resourceQuotaUsages
func
newResourceQuotaUsages
(
c
*
Client
,
namespace
string
)
*
resourceQuotaUsages
{
return
&
resourceQuotaUsages
{
r
:
c
,
ns
:
namespace
,
}
}
// Create takes the representation of a resourceQuotaUsage. Returns an error if the usage was not applied
func
(
c
*
resourceQuotaUsages
)
Create
(
resourceQuotaUsage
*
api
.
ResourceQuotaUsage
)
(
err
error
)
{
if
len
(
resourceQuotaUsage
.
ResourceVersion
)
==
0
{
err
=
fmt
.
Errorf
(
"invalid update object, missing resource version: %v"
,
resourceQuotaUsage
)
return
}
err
=
c
.
r
.
Post
()
.
Namespace
(
c
.
ns
)
.
Resource
(
"resourceQuotaUsages"
)
.
Body
(
resourceQuotaUsage
)
.
Do
()
.
Error
()
return
}
pkg/client/resource_quota_usages_test.go
0 → 100644
View file @
829fa695
/*
Copyright 2014 Google Inc. 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
client
import
(
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
)
func
TestResourceQuotaUsageCreate
(
t
*
testing
.
T
)
{
ns
:=
api
.
NamespaceDefault
resourceQuotaUsage
:=
&
api
.
ResourceQuotaUsage
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"foo"
,
ResourceVersion
:
"1"
,
},
Status
:
api
.
ResourceQuotaStatus
{
Hard
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourcePods
:
resource
.
MustParse
(
"10"
),
api
.
ResourceServices
:
resource
.
MustParse
(
"10"
),
api
.
ResourceReplicationControllers
:
resource
.
MustParse
(
"10"
),
api
.
ResourceQuotas
:
resource
.
MustParse
(
"10"
),
},
},
}
c
:=
&
testClient
{
Request
:
testRequest
{
Method
:
"POST"
,
Path
:
buildResourcePath
(
ns
,
"/resourceQuotaUsages"
),
Query
:
buildQueryValues
(
ns
,
nil
),
Body
:
resourceQuotaUsage
,
},
Response
:
Response
{
StatusCode
:
200
,
Body
:
resourceQuotaUsage
},
}
err
:=
c
.
Setup
()
.
ResourceQuotaUsages
(
ns
)
.
Create
(
resourceQuotaUsage
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error %v"
,
err
)
}
}
func
TestInvalidResourceQuotaUsageCreate
(
t
*
testing
.
T
)
{
ns
:=
api
.
NamespaceDefault
resourceQuotaUsage
:=
&
api
.
ResourceQuotaUsage
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"foo"
,
},
Status
:
api
.
ResourceQuotaStatus
{
Hard
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourcePods
:
resource
.
MustParse
(
"10"
),
api
.
ResourceServices
:
resource
.
MustParse
(
"10"
),
api
.
ResourceReplicationControllers
:
resource
.
MustParse
(
"10"
),
api
.
ResourceQuotas
:
resource
.
MustParse
(
"10"
),
},
},
}
c
:=
&
testClient
{
Request
:
testRequest
{
Method
:
"POST"
,
Path
:
buildResourcePath
(
ns
,
"/resourceQuotaUsages"
),
Query
:
buildQueryValues
(
ns
,
nil
),
Body
:
resourceQuotaUsage
,
},
Response
:
Response
{
StatusCode
:
200
,
Body
:
resourceQuotaUsage
},
}
err
:=
c
.
Setup
()
.
ResourceQuotaUsages
(
ns
)
.
Create
(
resourceQuotaUsage
)
if
err
==
nil
{
t
.
Errorf
(
"Expected error due to missing ResourceVersion"
)
}
}
pkg/client/resource_quotas.go
0 → 100644
View file @
829fa695
/*
Copyright 2014 Google Inc. 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
client
import
(
"errors"
"fmt"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
)
// ResourceQuotasNamespacer has methods to work with ResourceQuota resources in a namespace
type
ResourceQuotasNamespacer
interface
{
ResourceQuotas
(
namespace
string
)
ResourceQuotaInterface
}
// ResourceQuotaInterface has methods to work with ResourceQuota resources.
type
ResourceQuotaInterface
interface
{
List
(
selector
labels
.
Selector
)
(
*
api
.
ResourceQuotaList
,
error
)
Get
(
name
string
)
(
*
api
.
ResourceQuota
,
error
)
Delete
(
name
string
)
error
Create
(
resourceQuota
*
api
.
ResourceQuota
)
(
*
api
.
ResourceQuota
,
error
)
Update
(
resourceQuota
*
api
.
ResourceQuota
)
(
*
api
.
ResourceQuota
,
error
)
}
// resourceQuotas implements ResourceQuotasNamespacer interface
type
resourceQuotas
struct
{
r
*
Client
ns
string
}
// newResourceQuotas returns a resourceQuotas
func
newResourceQuotas
(
c
*
Client
,
namespace
string
)
*
resourceQuotas
{
return
&
resourceQuotas
{
r
:
c
,
ns
:
namespace
,
}
}
// List takes a selector, and returns the list of resourceQuotas that match that selector.
func
(
c
*
resourceQuotas
)
List
(
selector
labels
.
Selector
)
(
result
*
api
.
ResourceQuotaList
,
err
error
)
{
result
=
&
api
.
ResourceQuotaList
{}
err
=
c
.
r
.
Get
()
.
Namespace
(
c
.
ns
)
.
Resource
(
"resourceQuotas"
)
.
SelectorParam
(
"labels"
,
selector
)
.
Do
()
.
Into
(
result
)
return
}
// Get takes the name of the resourceQuota, and returns the corresponding ResourceQuota object, and an error if it occurs
func
(
c
*
resourceQuotas
)
Get
(
name
string
)
(
result
*
api
.
ResourceQuota
,
err
error
)
{
if
len
(
name
)
==
0
{
return
nil
,
errors
.
New
(
"name is required parameter to Get"
)
}
result
=
&
api
.
ResourceQuota
{}
err
=
c
.
r
.
Get
()
.
Namespace
(
c
.
ns
)
.
Resource
(
"resourceQuotas"
)
.
Name
(
name
)
.
Do
()
.
Into
(
result
)
return
}
// Delete takes the name of the resourceQuota, and returns an error if one occurs
func
(
c
*
resourceQuotas
)
Delete
(
name
string
)
error
{
return
c
.
r
.
Delete
()
.
Namespace
(
c
.
ns
)
.
Resource
(
"resourceQuotas"
)
.
Name
(
name
)
.
Do
()
.
Error
()
}
// Create takes the representation of a resourceQuota. Returns the server's representation of the resourceQuota, and an error, if it occurs.
func
(
c
*
resourceQuotas
)
Create
(
resourceQuota
*
api
.
ResourceQuota
)
(
result
*
api
.
ResourceQuota
,
err
error
)
{
result
=
&
api
.
ResourceQuota
{}
err
=
c
.
r
.
Post
()
.
Namespace
(
c
.
ns
)
.
Resource
(
"resourceQuotas"
)
.
Body
(
resourceQuota
)
.
Do
()
.
Into
(
result
)
return
}
// Update takes the representation of a resourceQuota to update. Returns the server's representation of the resourceQuota, and an error, if it occurs.
func
(
c
*
resourceQuotas
)
Update
(
resourceQuota
*
api
.
ResourceQuota
)
(
result
*
api
.
ResourceQuota
,
err
error
)
{
result
=
&
api
.
ResourceQuota
{}
if
len
(
resourceQuota
.
ResourceVersion
)
==
0
{
err
=
fmt
.
Errorf
(
"invalid update object, missing resource version: %v"
,
resourceQuota
)
return
}
err
=
c
.
r
.
Put
()
.
Namespace
(
c
.
ns
)
.
Resource
(
"resourceQuotas"
)
.
Name
(
resourceQuota
.
Name
)
.
Body
(
resourceQuota
)
.
Do
()
.
Into
(
result
)
return
}
pkg/client/resource_quotas_test.go
0 → 100644
View file @
829fa695
/*
Copyright 2014 Google Inc. 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
client
import
(
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
)
func
TestResourceQuotaCreate
(
t
*
testing
.
T
)
{
ns
:=
api
.
NamespaceDefault
resourceQuota
:=
&
api
.
ResourceQuota
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"foo"
,
},
Spec
:
api
.
ResourceQuotaSpec
{
Hard
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourcePods
:
resource
.
MustParse
(
"10"
),
api
.
ResourceServices
:
resource
.
MustParse
(
"10"
),
api
.
ResourceReplicationControllers
:
resource
.
MustParse
(
"10"
),
api
.
ResourceQuotas
:
resource
.
MustParse
(
"10"
),
},
},
}
c
:=
&
testClient
{
Request
:
testRequest
{
Method
:
"POST"
,
Path
:
buildResourcePath
(
ns
,
"/resourceQuotas"
),
Query
:
buildQueryValues
(
ns
,
nil
),
Body
:
resourceQuota
,
},
Response
:
Response
{
StatusCode
:
200
,
Body
:
resourceQuota
},
}
response
,
err
:=
c
.
Setup
()
.
ResourceQuotas
(
ns
)
.
Create
(
resourceQuota
)
c
.
Validate
(
t
,
response
,
err
)
}
func
TestResourceQuotaGet
(
t
*
testing
.
T
)
{
ns
:=
api
.
NamespaceDefault
resourceQuota
:=
&
api
.
ResourceQuota
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"foo"
,
},
Spec
:
api
.
ResourceQuotaSpec
{
Hard
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourcePods
:
resource
.
MustParse
(
"10"
),
api
.
ResourceServices
:
resource
.
MustParse
(
"10"
),
api
.
ResourceReplicationControllers
:
resource
.
MustParse
(
"10"
),
api
.
ResourceQuotas
:
resource
.
MustParse
(
"10"
),
},
},
}
c
:=
&
testClient
{
Request
:
testRequest
{
Method
:
"GET"
,
Path
:
buildResourcePath
(
ns
,
"/resourceQuotas/abc"
),
Query
:
buildQueryValues
(
ns
,
nil
),
Body
:
nil
,
},
Response
:
Response
{
StatusCode
:
200
,
Body
:
resourceQuota
},
}
response
,
err
:=
c
.
Setup
()
.
ResourceQuotas
(
ns
)
.
Get
(
"abc"
)
c
.
Validate
(
t
,
response
,
err
)
}
func
TestResourceQuotaList
(
t
*
testing
.
T
)
{
ns
:=
api
.
NamespaceDefault
resourceQuotaList
:=
&
api
.
ResourceQuotaList
{
Items
:
[]
api
.
ResourceQuota
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
},
},
},
}
c
:=
&
testClient
{
Request
:
testRequest
{
Method
:
"GET"
,
Path
:
buildResourcePath
(
ns
,
"/resourceQuotas"
),
Query
:
buildQueryValues
(
ns
,
nil
),
Body
:
nil
,
},
Response
:
Response
{
StatusCode
:
200
,
Body
:
resourceQuotaList
},
}
response
,
err
:=
c
.
Setup
()
.
ResourceQuotas
(
ns
)
.
List
(
labels
.
Everything
())
c
.
Validate
(
t
,
response
,
err
)
}
func
TestResourceQuotaUpdate
(
t
*
testing
.
T
)
{
ns
:=
api
.
NamespaceDefault
resourceQuota
:=
&
api
.
ResourceQuota
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"foo"
,
ResourceVersion
:
"1"
,
},
Spec
:
api
.
ResourceQuotaSpec
{
Hard
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourcePods
:
resource
.
MustParse
(
"10"
),
api
.
ResourceServices
:
resource
.
MustParse
(
"10"
),
api
.
ResourceReplicationControllers
:
resource
.
MustParse
(
"10"
),
api
.
ResourceQuotas
:
resource
.
MustParse
(
"10"
),
},
},
}
c
:=
&
testClient
{
Request
:
testRequest
{
Method
:
"PUT"
,
Path
:
buildResourcePath
(
ns
,
"/resourceQuotas/abc"
),
Query
:
buildQueryValues
(
ns
,
nil
)},
Response
:
Response
{
StatusCode
:
200
,
Body
:
resourceQuota
},
}
response
,
err
:=
c
.
Setup
()
.
ResourceQuotas
(
ns
)
.
Update
(
resourceQuota
)
c
.
Validate
(
t
,
response
,
err
)
}
func
TestInvalidResourceQuotaUpdate
(
t
*
testing
.
T
)
{
ns
:=
api
.
NamespaceDefault
resourceQuota
:=
&
api
.
ResourceQuota
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"foo"
,
},
Spec
:
api
.
ResourceQuotaSpec
{
Hard
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourcePods
:
resource
.
MustParse
(
"10"
),
api
.
ResourceServices
:
resource
.
MustParse
(
"10"
),
api
.
ResourceReplicationControllers
:
resource
.
MustParse
(
"10"
),
api
.
ResourceQuotas
:
resource
.
MustParse
(
"10"
),
},
},
}
c
:=
&
testClient
{
Request
:
testRequest
{
Method
:
"PUT"
,
Path
:
buildResourcePath
(
ns
,
"/resourceQuotas/abc"
),
Query
:
buildQueryValues
(
ns
,
nil
)},
Response
:
Response
{
StatusCode
:
200
,
Body
:
resourceQuota
},
}
_
,
err
:=
c
.
Setup
()
.
ResourceQuotas
(
ns
)
.
Update
(
resourceQuota
)
if
err
==
nil
{
t
.
Errorf
(
"Expected an error due to missing ResourceVersion"
)
}
}
func
TestResourceQuotaDelete
(
t
*
testing
.
T
)
{
ns
:=
api
.
NamespaceDefault
c
:=
&
testClient
{
Request
:
testRequest
{
Method
:
"DELETE"
,
Path
:
buildResourcePath
(
ns
,
"/resourceQuotas/foo"
),
Query
:
buildQueryValues
(
ns
,
nil
)},
Response
:
Response
{
StatusCode
:
200
},
}
err
:=
c
.
Setup
()
.
ResourceQuotas
(
ns
)
.
Delete
(
"foo"
)
c
.
Validate
(
t
,
nil
,
err
)
}
pkg/kubectl/describe.go
View file @
829fa695
...
@@ -49,6 +49,8 @@ func DescriberFor(kind string, c *client.Client) (Describer, bool) {
...
@@ -49,6 +49,8 @@ func DescriberFor(kind string, c *client.Client) (Describer, bool) {
return
&
MinionDescriber
{
c
},
true
return
&
MinionDescriber
{
c
},
true
case
"LimitRange"
:
case
"LimitRange"
:
return
&
LimitRangeDescriber
{
c
},
true
return
&
LimitRangeDescriber
{
c
},
true
case
"ResourceQuota"
:
return
&
ResourceQuotaDescriber
{
c
},
true
}
}
return
nil
,
false
return
nil
,
false
}
}
...
@@ -106,6 +108,41 @@ func (d *LimitRangeDescriber) Describe(namespace, name string) (string, error) {
...
@@ -106,6 +108,41 @@ func (d *LimitRangeDescriber) Describe(namespace, name string) (string, error) {
})
})
}
}
// ResourceQuotaDescriber generates information about a resource quota
type
ResourceQuotaDescriber
struct
{
client
.
Interface
}
func
(
d
*
ResourceQuotaDescriber
)
Describe
(
namespace
,
name
string
)
(
string
,
error
)
{
rq
:=
d
.
ResourceQuotas
(
namespace
)
resourceQuota
,
err
:=
rq
.
Get
(
name
)
if
err
!=
nil
{
return
""
,
err
}
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
resourceQuota
.
Name
)
fmt
.
Fprintf
(
out
,
"Resource
\t
Used
\t
Hard
\n
"
)
fmt
.
Fprintf
(
out
,
"--------
\t
----
\t
----
\n
"
)
resources
:=
[]
api
.
ResourceName
{}
for
resource
:=
range
resourceQuota
.
Status
.
Hard
{
resources
=
append
(
resources
,
resource
)
}
sort
.
Sort
(
SortableResourceNames
(
resources
))
msg
:=
"%v
\t
%v
\t
%v
\n
"
for
i
:=
range
resources
{
resource
:=
resources
[
i
]
hardQuantity
:=
resourceQuota
.
Status
.
Hard
[
resource
]
usedQuantity
:=
resourceQuota
.
Status
.
Used
[
resource
]
fmt
.
Fprintf
(
out
,
msg
,
resource
,
usedQuantity
.
String
(),
hardQuantity
.
String
())
}
return
nil
})
}
// PodDescriber generates information about a pod and the replication controllers that
// PodDescriber generates information about a pod and the replication controllers that
// create it.
// create it.
type
PodDescriber
struct
{
type
PodDescriber
struct
{
...
...
pkg/kubectl/kubectl.go
View file @
829fa695
...
@@ -149,6 +149,7 @@ func expandResourceShortcut(resource string) string {
...
@@ -149,6 +149,7 @@ func expandResourceShortcut(resource string) string {
"mi"
:
"minions"
,
"mi"
:
"minions"
,
"ev"
:
"events"
,
"ev"
:
"events"
,
"limits"
:
"limitRanges"
,
"limits"
:
"limitRanges"
,
"quota"
:
"resourceQuotas"
,
}
}
if
expanded
,
ok
:=
shortForms
[
resource
];
ok
{
if
expanded
,
ok
:=
shortForms
[
resource
];
ok
{
return
expanded
return
expanded
...
...
pkg/kubectl/resource_printer.go
View file @
829fa695
...
@@ -222,6 +222,7 @@ var minionColumns = []string{"NAME", "LABELS", "STATUS"}
...
@@ -222,6 +222,7 @@ var minionColumns = []string{"NAME", "LABELS", "STATUS"}
var
statusColumns
=
[]
string
{
"STATUS"
}
var
statusColumns
=
[]
string
{
"STATUS"
}
var
eventColumns
=
[]
string
{
"TIME"
,
"NAME"
,
"KIND"
,
"SUBOBJECT"
,
"REASON"
,
"SOURCE"
,
"MESSAGE"
}
var
eventColumns
=
[]
string
{
"TIME"
,
"NAME"
,
"KIND"
,
"SUBOBJECT"
,
"REASON"
,
"SOURCE"
,
"MESSAGE"
}
var
limitRangeColumns
=
[]
string
{
"NAME"
}
var
limitRangeColumns
=
[]
string
{
"NAME"
}
var
resourceQuotaColumns
=
[]
string
{
"NAME"
}
// addDefaultHandlers adds print handlers for default Kubernetes types.
// addDefaultHandlers adds print handlers for default Kubernetes types.
func
(
h
*
HumanReadablePrinter
)
addDefaultHandlers
()
{
func
(
h
*
HumanReadablePrinter
)
addDefaultHandlers
()
{
...
@@ -238,6 +239,8 @@ func (h *HumanReadablePrinter) addDefaultHandlers() {
...
@@ -238,6 +239,8 @@ func (h *HumanReadablePrinter) addDefaultHandlers() {
h
.
Handler
(
eventColumns
,
printEventList
)
h
.
Handler
(
eventColumns
,
printEventList
)
h
.
Handler
(
limitRangeColumns
,
printLimitRange
)
h
.
Handler
(
limitRangeColumns
,
printLimitRange
)
h
.
Handler
(
limitRangeColumns
,
printLimitRangeList
)
h
.
Handler
(
limitRangeColumns
,
printLimitRangeList
)
h
.
Handler
(
resourceQuotaColumns
,
printResourceQuota
)
h
.
Handler
(
resourceQuotaColumns
,
printResourceQuotaList
)
}
}
func
(
h
*
HumanReadablePrinter
)
unknown
(
data
[]
byte
,
w
io
.
Writer
)
error
{
func
(
h
*
HumanReadablePrinter
)
unknown
(
data
[]
byte
,
w
io
.
Writer
)
error
{
...
@@ -430,6 +433,24 @@ func printLimitRangeList(list *api.LimitRangeList, w io.Writer) error {
...
@@ -430,6 +433,24 @@ func printLimitRangeList(list *api.LimitRangeList, w io.Writer) error {
return
nil
return
nil
}
}
func
printResourceQuota
(
resourceQuota
*
api
.
ResourceQuota
,
w
io
.
Writer
)
error
{
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s
\n
"
,
resourceQuota
.
Name
,
)
return
err
}
// Prints the ResourceQuotaList in a human-friendly format.
func
printResourceQuotaList
(
list
*
api
.
ResourceQuotaList
,
w
io
.
Writer
)
error
{
for
i
:=
range
list
.
Items
{
if
err
:=
printResourceQuota
(
&
list
.
Items
[
i
],
w
);
err
!=
nil
{
return
err
}
}
return
nil
}
// PrintObj prints the obj in a human-friendly format according to the type of the obj.
// PrintObj prints the obj in a human-friendly format according to the type of the obj.
func
(
h
*
HumanReadablePrinter
)
PrintObj
(
obj
runtime
.
Object
,
output
io
.
Writer
)
error
{
func
(
h
*
HumanReadablePrinter
)
PrintObj
(
obj
runtime
.
Object
,
output
io
.
Writer
)
error
{
w
:=
tabwriter
.
NewWriter
(
output
,
20
,
5
,
3
,
' '
,
0
)
w
:=
tabwriter
.
NewWriter
(
output
,
20
,
5
,
3
,
' '
,
0
)
...
...
pkg/kubectl/sorted_resource_name_list.go
0 → 100644
View file @
829fa695
/*
Copyright 2014 Google Inc. 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
kubectl
import
(
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)
type
SortableResourceNames
[]
api
.
ResourceName
func
(
list
SortableResourceNames
)
Len
()
int
{
return
len
(
list
)
}
func
(
list
SortableResourceNames
)
Swap
(
i
,
j
int
)
{
list
[
i
],
list
[
j
]
=
list
[
j
],
list
[
i
]
}
func
(
list
SortableResourceNames
)
Less
(
i
,
j
int
)
bool
{
return
list
[
i
]
<
list
[
j
]
}
pkg/master/master.go
View file @
829fa695
...
@@ -50,6 +50,8 @@ import (
...
@@ -50,6 +50,8 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/limitrange"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/limitrange"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/minion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/minion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/pod"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/pod"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/resourcequota"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/resourcequotausage"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/service"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/service"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
...
@@ -103,17 +105,18 @@ type Config struct {
...
@@ -103,17 +105,18 @@ type Config struct {
// Master contains state for a Kubernetes cluster master/api server.
// Master contains state for a Kubernetes cluster master/api server.
type
Master
struct
{
type
Master
struct
{
// "Inputs", Copied from Config
// "Inputs", Copied from Config
podRegistry
pod
.
Registry
podRegistry
pod
.
Registry
controllerRegistry
controller
.
Registry
controllerRegistry
controller
.
Registry
serviceRegistry
service
.
Registry
serviceRegistry
service
.
Registry
endpointRegistry
endpoint
.
Registry
endpointRegistry
endpoint
.
Registry
minionRegistry
minion
.
Registry
minionRegistry
minion
.
Registry
bindingRegistry
binding
.
Registry
bindingRegistry
binding
.
Registry
eventRegistry
generic
.
Registry
eventRegistry
generic
.
Registry
limitRangeRegistry
generic
.
Registry
limitRangeRegistry
generic
.
Registry
storage
map
[
string
]
apiserver
.
RESTStorage
resourceQuotaRegistry
resourcequota
.
Registry
client
*
client
.
Client
storage
map
[
string
]
apiserver
.
RESTStorage
portalNet
*
net
.
IPNet
client
*
client
.
Client
portalNet
*
net
.
IPNet
mux
apiserver
.
Mux
mux
apiserver
.
Mux
muxHelper
*
apiserver
.
MuxHelper
muxHelper
*
apiserver
.
MuxHelper
...
@@ -251,6 +254,7 @@ func New(c *Config) *Master {
...
@@ -251,6 +254,7 @@ func New(c *Config) *Master {
eventRegistry
:
event
.
NewEtcdRegistry
(
c
.
EtcdHelper
,
uint64
(
c
.
EventTTL
.
Seconds
())),
eventRegistry
:
event
.
NewEtcdRegistry
(
c
.
EtcdHelper
,
uint64
(
c
.
EventTTL
.
Seconds
())),
minionRegistry
:
minionRegistry
,
minionRegistry
:
minionRegistry
,
limitRangeRegistry
:
limitrange
.
NewEtcdRegistry
(
c
.
EtcdHelper
),
limitRangeRegistry
:
limitrange
.
NewEtcdRegistry
(
c
.
EtcdHelper
),
resourceQuotaRegistry
:
resourcequota
.
NewEtcdRegistry
(
c
.
EtcdHelper
),
client
:
c
.
Client
,
client
:
c
.
Client
,
portalNet
:
c
.
PortalNet
,
portalNet
:
c
.
PortalNet
,
rootWebService
:
new
(
restful
.
WebService
),
rootWebService
:
new
(
restful
.
WebService
),
...
@@ -365,7 +369,9 @@ func (m *Master) init(c *Config) {
...
@@ -365,7 +369,9 @@ func (m *Master) init(c *Config) {
// TODO: should appear only in scheduler API group.
// TODO: should appear only in scheduler API group.
"bindings"
:
binding
.
NewREST
(
m
.
bindingRegistry
),
"bindings"
:
binding
.
NewREST
(
m
.
bindingRegistry
),
"limitRanges"
:
limitrange
.
NewREST
(
m
.
limitRangeRegistry
),
"limitRanges"
:
limitrange
.
NewREST
(
m
.
limitRangeRegistry
),
"resourceQuotas"
:
resourcequota
.
NewREST
(
m
.
resourceQuotaRegistry
),
"resourceQuotaUsages"
:
resourcequotausage
.
NewREST
(
m
.
resourceQuotaRegistry
),
}
}
apiVersions
:=
[]
string
{
"v1beta1"
,
"v1beta2"
}
apiVersions
:=
[]
string
{
"v1beta1"
,
"v1beta2"
}
...
...
pkg/registry/resourcequota/doc.go
0 → 100644
View file @
829fa695
/*
Copyright 2014 Google Inc. 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 resourcequota provides Registry interface and it's REST
// implementation for storing ResourceQuota api objects.
package
resourcequota
pkg/registry/resourcequota/registry.go
0 → 100644
View file @
829fa695
/*
Copyright 2014 Google Inc. 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
resourcequota
import
(
"fmt"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
etcdgeneric
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic/etcd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/resourcequotausage"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
)
// Registry implements operations to modify ResourceQuota objects
type
Registry
interface
{
generic
.
Registry
resourcequotausage
.
Registry
}
// registry implements custom changes to generic.Etcd.
type
registry
struct
{
*
etcdgeneric
.
Etcd
}
// ApplyStatus atomically updates the ResourceQuotaStatus based on the observed ResourceQuotaUsage
func
(
r
*
registry
)
ApplyStatus
(
ctx
api
.
Context
,
usage
*
api
.
ResourceQuotaUsage
)
error
{
obj
,
err
:=
r
.
Get
(
ctx
,
usage
.
Name
)
if
err
!=
nil
{
return
err
}
if
len
(
usage
.
ResourceVersion
)
==
0
{
return
fmt
.
Errorf
(
"A resource observation must have a resourceVersion specified to ensure atomic updates"
)
}
// set the status
resourceQuota
:=
obj
.
(
*
api
.
ResourceQuota
)
resourceQuota
.
ResourceVersion
=
usage
.
ResourceVersion
resourceQuota
.
Status
=
usage
.
Status
return
r
.
Update
(
ctx
,
resourceQuota
.
Name
,
resourceQuota
)
}
// NewEtcdRegistry returns a registry which will store ResourceQuota in the given helper
func
NewEtcdRegistry
(
h
tools
.
EtcdHelper
)
Registry
{
return
&
registry
{
Etcd
:
&
etcdgeneric
.
Etcd
{
NewFunc
:
func
()
runtime
.
Object
{
return
&
api
.
ResourceQuota
{}
},
NewListFunc
:
func
()
runtime
.
Object
{
return
&
api
.
ResourceQuotaList
{}
},
EndpointName
:
"resourcequotas"
,
KeyRootFunc
:
func
(
ctx
api
.
Context
)
string
{
return
etcdgeneric
.
NamespaceKeyRootFunc
(
ctx
,
"/registry/resourcequotas"
)
},
KeyFunc
:
func
(
ctx
api
.
Context
,
id
string
)
(
string
,
error
)
{
return
etcdgeneric
.
NamespaceKeyFunc
(
ctx
,
"/registry/resourcequotas"
,
id
)
},
Helper
:
h
,
},
}
}
pkg/registry/resourcequota/registry_test.go
0 → 100644
View file @
829fa695
/*
Copyright 2014 Google Inc. 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
resourcequota
import
(
"reflect"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
etcdgeneric
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic/etcd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/coreos/go-etcd/etcd"
)
func
NewTestLimitRangeEtcdRegistry
(
t
*
testing
.
T
)
(
*
tools
.
FakeEtcdClient
,
generic
.
Registry
)
{
f
:=
tools
.
NewFakeEtcdClient
(
t
)
f
.
TestIndex
=
true
h
:=
tools
.
EtcdHelper
{
f
,
testapi
.
Codec
(),
tools
.
RuntimeVersionAdapter
{
testapi
.
MetadataAccessor
()}}
return
f
,
NewEtcdRegistry
(
h
)
}
func
TestResourceQuotaCreate
(
t
*
testing
.
T
)
{
resourceQuota
:=
&
api
.
ResourceQuota
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"default"
,
},
Spec
:
api
.
ResourceQuotaSpec
{
Hard
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"100"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"10000"
),
api
.
ResourcePods
:
resource
.
MustParse
(
"10"
),
api
.
ResourceServices
:
resource
.
MustParse
(
"10"
),
api
.
ResourceReplicationControllers
:
resource
.
MustParse
(
"10"
),
api
.
ResourceQuotas
:
resource
.
MustParse
(
"10"
),
},
},
}
nodeWithResourceQuota
:=
tools
.
EtcdResponseWithError
{
R
:
&
etcd
.
Response
{
Node
:
&
etcd
.
Node
{
Value
:
runtime
.
EncodeOrDie
(
testapi
.
Codec
(),
resourceQuota
),
ModifiedIndex
:
1
,
CreatedIndex
:
1
,
},
},
E
:
nil
,
}
emptyNode
:=
tools
.
EtcdResponseWithError
{
R
:
&
etcd
.
Response
{},
E
:
tools
.
EtcdErrorNotFound
,
}
ctx
:=
api
.
NewDefaultContext
()
key
:=
"abc"
path
,
err
:=
etcdgeneric
.
NamespaceKeyFunc
(
ctx
,
"/registry/resourcequotas"
,
key
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
table
:=
map
[
string
]
struct
{
existing
tools
.
EtcdResponseWithError
expect
tools
.
EtcdResponseWithError
toCreate
runtime
.
Object
errOK
func
(
error
)
bool
}{
"normal"
:
{
existing
:
emptyNode
,
expect
:
nodeWithResourceQuota
,
toCreate
:
resourceQuota
,
errOK
:
func
(
err
error
)
bool
{
return
err
==
nil
},
},
"preExisting"
:
{
existing
:
nodeWithResourceQuota
,
expect
:
nodeWithResourceQuota
,
toCreate
:
resourceQuota
,
errOK
:
errors
.
IsAlreadyExists
,
},
}
for
name
,
item
:=
range
table
{
fakeClient
,
registry
:=
NewTestLimitRangeEtcdRegistry
(
t
)
fakeClient
.
Data
[
path
]
=
item
.
existing
err
:=
registry
.
Create
(
ctx
,
key
,
item
.
toCreate
)
if
!
item
.
errOK
(
err
)
{
t
.
Errorf
(
"%v: unexpected error: %v, %v"
,
name
,
err
,
path
)
}
if
e
,
a
:=
item
.
expect
,
fakeClient
.
Data
[
path
];
!
reflect
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"%v:
\n
%s"
,
name
,
util
.
ObjectDiff
(
e
,
a
))
}
}
}
pkg/registry/resourcequota/rest.go
0 → 100644
View file @
829fa695
/*
Copyright 2014 Google Inc. 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
resourcequota
import
(
"fmt"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
// REST provides the RESTStorage access patterns to work with ResourceQuota objects.
type
REST
struct
{
registry
generic
.
Registry
}
// NewREST returns a new REST. You must use a registry created by
// NewEtcdRegistry unless you're testing.
func
NewREST
(
registry
generic
.
Registry
)
*
REST
{
return
&
REST
{
registry
:
registry
,
}
}
// Create a ResourceQuota object
func
(
rs
*
REST
)
Create
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
<-
chan
apiserver
.
RESTResult
,
error
)
{
resourceQuota
,
ok
:=
obj
.
(
*
api
.
ResourceQuota
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"invalid object type"
)
}
if
!
api
.
ValidNamespace
(
ctx
,
&
resourceQuota
.
ObjectMeta
)
{
return
nil
,
errors
.
NewConflict
(
"resourceQuota"
,
resourceQuota
.
Namespace
,
fmt
.
Errorf
(
"ResourceQuota.Namespace does not match the provided context"
))
}
if
len
(
resourceQuota
.
Name
)
==
0
{
resourceQuota
.
Name
=
string
(
util
.
NewUUID
())
}
// callers are not able to set status, instead, it is supplied via a control loop
resourceQuota
.
Status
=
api
.
ResourceQuotaStatus
{}
if
errs
:=
validation
.
ValidateResourceQuota
(
resourceQuota
);
len
(
errs
)
>
0
{
return
nil
,
errors
.
NewInvalid
(
"resourceQuota"
,
resourceQuota
.
Name
,
errs
)
}
api
.
FillObjectMetaSystemFields
(
ctx
,
&
resourceQuota
.
ObjectMeta
)
return
apiserver
.
MakeAsync
(
func
()
(
runtime
.
Object
,
error
)
{
err
:=
rs
.
registry
.
Create
(
ctx
,
resourceQuota
.
Name
,
resourceQuota
)
if
err
!=
nil
{
return
nil
,
err
}
return
rs
.
registry
.
Get
(
ctx
,
resourceQuota
.
Name
)
}),
nil
}
// Update updates a ResourceQuota object.
func
(
rs
*
REST
)
Update
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
<-
chan
apiserver
.
RESTResult
,
error
)
{
resourceQuota
,
ok
:=
obj
.
(
*
api
.
ResourceQuota
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"invalid object type"
)
}
if
!
api
.
ValidNamespace
(
ctx
,
&
resourceQuota
.
ObjectMeta
)
{
return
nil
,
errors
.
NewConflict
(
"resourceQuota"
,
resourceQuota
.
Namespace
,
fmt
.
Errorf
(
"ResourceQuota.Namespace does not match the provided context"
))
}
oldObj
,
err
:=
rs
.
registry
.
Get
(
ctx
,
resourceQuota
.
Name
)
if
err
!=
nil
{
return
nil
,
err
}
editResourceQuota
:=
oldObj
.
(
*
api
.
ResourceQuota
)
// set the editable fields on the existing object
editResourceQuota
.
Labels
=
resourceQuota
.
Labels
editResourceQuota
.
ResourceVersion
=
resourceQuota
.
ResourceVersion
editResourceQuota
.
Annotations
=
resourceQuota
.
Annotations
editResourceQuota
.
Spec
=
resourceQuota
.
Spec
if
errs
:=
validation
.
ValidateResourceQuota
(
editResourceQuota
);
len
(
errs
)
>
0
{
return
nil
,
errors
.
NewInvalid
(
"resourceQuota"
,
editResourceQuota
.
Name
,
errs
)
}
return
apiserver
.
MakeAsync
(
func
()
(
runtime
.
Object
,
error
)
{
err
:=
rs
.
registry
.
Update
(
ctx
,
editResourceQuota
.
Name
,
editResourceQuota
)
if
err
!=
nil
{
return
nil
,
err
}
return
rs
.
registry
.
Get
(
ctx
,
editResourceQuota
.
Name
)
}),
nil
}
// Delete deletes the ResourceQuota with the specified name
func
(
rs
*
REST
)
Delete
(
ctx
api
.
Context
,
name
string
)
(
<-
chan
apiserver
.
RESTResult
,
error
)
{
obj
,
err
:=
rs
.
registry
.
Get
(
ctx
,
name
)
if
err
!=
nil
{
return
nil
,
err
}
_
,
ok
:=
obj
.
(
*
api
.
ResourceQuota
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"invalid object type"
)
}
return
apiserver
.
MakeAsync
(
func
()
(
runtime
.
Object
,
error
)
{
return
&
api
.
Status
{
Status
:
api
.
StatusSuccess
},
rs
.
registry
.
Delete
(
ctx
,
name
)
}),
nil
}
// Get gets a ResourceQuota with the specified name
func
(
rs
*
REST
)
Get
(
ctx
api
.
Context
,
name
string
)
(
runtime
.
Object
,
error
)
{
obj
,
err
:=
rs
.
registry
.
Get
(
ctx
,
name
)
if
err
!=
nil
{
return
nil
,
err
}
resourceQuota
,
ok
:=
obj
.
(
*
api
.
ResourceQuota
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"invalid object type"
)
}
return
resourceQuota
,
err
}
func
(
rs
*
REST
)
getAttrs
(
obj
runtime
.
Object
)
(
objLabels
,
objFields
labels
.
Set
,
err
error
)
{
return
labels
.
Set
{},
labels
.
Set
{},
nil
}
func
(
rs
*
REST
)
List
(
ctx
api
.
Context
,
label
,
field
labels
.
Selector
)
(
runtime
.
Object
,
error
)
{
return
rs
.
registry
.
List
(
ctx
,
&
generic
.
SelectionPredicate
{
label
,
field
,
rs
.
getAttrs
})
}
func
(
rs
*
REST
)
Watch
(
ctx
api
.
Context
,
label
,
field
labels
.
Selector
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
return
rs
.
registry
.
Watch
(
ctx
,
&
generic
.
SelectionPredicate
{
label
,
field
,
rs
.
getAttrs
},
resourceVersion
)
}
// New returns a new api.ResourceQuota
func
(
*
REST
)
New
()
runtime
.
Object
{
return
&
api
.
ResourceQuota
{}
}
func
(
*
REST
)
NewList
()
runtime
.
Object
{
return
&
api
.
ResourceQuotaList
{}
}
pkg/registry/resourcequota/rest_test.go
0 → 100644
View file @
829fa695
/*
Copyright 2014 Google Inc. 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
resourcequota
pkg/registry/resourcequotausage/doc.go
0 → 100644
View file @
829fa695
/*
Copyright 2014 Google Inc. 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 resourcequotausage provides Registry interface and it's REST
// implementation for storing ResourceQuotaUsage api objects.
package
resourcequotausage
pkg/registry/resourcequotausage/registry.go
0 → 100644
View file @
829fa695
/*
Copyright 2014 Google Inc. 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
resourcequotausage
import
(
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)
// Registry contains the functions needed to support a ResourceQuotaUsage
type
Registry
interface
{
// ApplyStatus should update the ResourceQuota.Status with latest observed state.
// This should be atomic, and idempotent based on the ResourceVersion
ApplyStatus
(
ctx
api
.
Context
,
usage
*
api
.
ResourceQuotaUsage
)
error
}
pkg/registry/resourcequotausage/rest.go
0 → 100644
View file @
829fa695
/*
Copyright 2014 Google Inc. 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
resourcequotausage
import
(
"fmt"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
)
// REST implements the RESTStorage interface for ResourceQuotaUsage
type
REST
struct
{
registry
Registry
}
// NewREST creates a new REST backed by the given registry.
func
NewREST
(
registry
Registry
)
*
REST
{
return
&
REST
{
registry
:
registry
,
}
}
// New returns a new resource observation object
func
(
*
REST
)
New
()
runtime
.
Object
{
return
&
api
.
ResourceQuotaUsage
{}
}
// Create takes the incoming ResourceQuotaUsage and applies the latest status atomically to a ResourceQuota
func
(
b
*
REST
)
Create
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
<-
chan
apiserver
.
RESTResult
,
error
)
{
resourceQuotaUsage
,
ok
:=
obj
.
(
*
api
.
ResourceQuotaUsage
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"incorrect type: %#v"
,
obj
)
}
return
apiserver
.
MakeAsync
(
func
()
(
runtime
.
Object
,
error
)
{
if
err
:=
b
.
registry
.
ApplyStatus
(
ctx
,
resourceQuotaUsage
);
err
!=
nil
{
return
nil
,
err
}
return
&
api
.
Status
{
Status
:
api
.
StatusSuccess
},
nil
}),
nil
}
pkg/registry/resourcequotausage/rest_test.go
0 → 100644
View file @
829fa695
/*
Copyright 2014 Google Inc. 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
resourcequotausage
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