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
d11ee913
Commit
d11ee913
authored
Aug 27, 2018
by
yue9944882
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prune flipping int/ext conversion for quota controller
parent
b8f4aa35
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
42 deletions
+24
-42
BUILD
pkg/controller/resourcequota/BUILD
+6
-8
resource_quota_controller.go
pkg/controller/resourcequota/resource_quota_controller.go
+12
-28
resource_quota_controller_test.go
...ontroller/resourcequota/resource_quota_controller_test.go
+3
-3
resource_quota_monitor.go
pkg/controller/resourcequota/resource_quota_monitor.go
+3
-3
No files found.
pkg/controller/resourcequota/BUILD
View file @
d11ee913
...
@@ -15,12 +15,10 @@ go_library(
...
@@ -15,12 +15,10 @@ go_library(
],
],
importpath = "k8s.io/kubernetes/pkg/controller/resourcequota",
importpath = "k8s.io/kubernetes/pkg/controller/resourcequota",
deps = [
deps = [
"//pkg/apis/core:go_default_library",
"//pkg/apis/core/v1:go_default_library",
"//pkg/controller:go_default_library",
"//pkg/controller:go_default_library",
"//pkg/quota:go_default_library",
"//pkg/quota
/v1
:go_default_library",
"//pkg/quota/evaluator/core:go_default_library",
"//pkg/quota/
v1/
evaluator/core:go_default_library",
"//pkg/quota/generic:go_default_library",
"//pkg/quota/
v1/
generic:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
...
@@ -49,9 +47,9 @@ go_test(
...
@@ -49,9 +47,9 @@ go_test(
embed = [":go_default_library"],
embed = [":go_default_library"],
deps = [
deps = [
"//pkg/controller:go_default_library",
"//pkg/controller:go_default_library",
"//pkg/quota:go_default_library",
"//pkg/quota
/v1
:go_default_library",
"//pkg/quota/generic:go_default_library",
"//pkg/quota/
v1/
generic:go_default_library",
"//pkg/quota/install:go_default_library",
"//pkg/quota/
v1/
install:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
...
...
pkg/controller/resourcequota/resource_quota_controller.go
View file @
d11ee913
...
@@ -39,10 +39,8 @@ import (
...
@@ -39,10 +39,8 @@ import (
corelisters
"k8s.io/client-go/listers/core/v1"
corelisters
"k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue"
"k8s.io/client-go/util/workqueue"
api
"k8s.io/kubernetes/pkg/apis/core"
k8s_api_v1
"k8s.io/kubernetes/pkg/apis/core/v1"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/quota
"
quota
"k8s.io/kubernetes/pkg/quota/v1
"
)
)
// NamespacedResourcesFunc knows how to discover namespaced resources.
// NamespacedResourcesFunc knows how to discover namespaced resources.
...
@@ -226,7 +224,7 @@ func (rq *ResourceQuotaController) addQuota(obj interface{}) {
...
@@ -226,7 +224,7 @@ func (rq *ResourceQuotaController) addQuota(obj interface{}) {
// if we declared a constraint that has no usage (which this controller can calculate, prioritize it)
// if we declared a constraint that has no usage (which this controller can calculate, prioritize it)
for
constraint
:=
range
resourceQuota
.
Status
.
Hard
{
for
constraint
:=
range
resourceQuota
.
Status
.
Hard
{
if
_
,
usageFound
:=
resourceQuota
.
Status
.
Used
[
constraint
];
!
usageFound
{
if
_
,
usageFound
:=
resourceQuota
.
Status
.
Used
[
constraint
];
!
usageFound
{
matchedResources
:=
[]
api
.
ResourceName
{
api
.
ResourceName
(
constraint
)}
matchedResources
:=
[]
v1
.
ResourceName
{
v1
.
ResourceName
(
constraint
)}
for
_
,
evaluator
:=
range
rq
.
registry
.
List
()
{
for
_
,
evaluator
:=
range
rq
.
registry
.
List
()
{
if
intersection
:=
evaluator
.
MatchingResources
(
matchedResources
);
len
(
intersection
)
>
0
{
if
intersection
:=
evaluator
.
MatchingResources
(
matchedResources
);
len
(
intersection
)
>
0
{
rq
.
missingUsageQueue
.
Add
(
key
)
rq
.
missingUsageQueue
.
Add
(
key
)
...
@@ -320,25 +318,20 @@ func (rq *ResourceQuotaController) syncResourceQuotaFromKey(key string) (err err
...
@@ -320,25 +318,20 @@ func (rq *ResourceQuotaController) syncResourceQuotaFromKey(key string) (err err
}
}
// syncResourceQuota runs a complete sync of resource quota status across all known kinds
// syncResourceQuota runs a complete sync of resource quota status across all known kinds
func
(
rq
*
ResourceQuotaController
)
syncResourceQuota
(
v1R
esourceQuota
*
v1
.
ResourceQuota
)
(
err
error
)
{
func
(
rq
*
ResourceQuotaController
)
syncResourceQuota
(
r
esourceQuota
*
v1
.
ResourceQuota
)
(
err
error
)
{
// quota is dirty if any part of spec hard limits differs from the status hard limits
// quota is dirty if any part of spec hard limits differs from the status hard limits
dirty
:=
!
apiequality
.
Semantic
.
DeepEqual
(
v1ResourceQuota
.
Spec
.
Hard
,
v1ResourceQuota
.
Status
.
Hard
)
dirty
:=
!
apiequality
.
Semantic
.
DeepEqual
(
resourceQuota
.
Spec
.
Hard
,
resourceQuota
.
Status
.
Hard
)
resourceQuota
:=
api
.
ResourceQuota
{}
if
err
:=
k8s_api_v1
.
Convert_v1_ResourceQuota_To_core_ResourceQuota
(
v1ResourceQuota
,
&
resourceQuota
,
nil
);
err
!=
nil
{
return
err
}
// dirty tracks if the usage status differs from the previous sync,
// dirty tracks if the usage status differs from the previous sync,
// if so, we send a new usage with latest status
// if so, we send a new usage with latest status
// if this is our first sync, it will be dirty by default, since we need track usage
// if this is our first sync, it will be dirty by default, since we need track usage
dirty
=
dirty
||
(
resourceQuota
.
Status
.
Hard
==
nil
||
resourceQuota
.
Status
.
Used
==
nil
)
dirty
=
dirty
||
resourceQuota
.
Status
.
Hard
==
nil
||
resourceQuota
.
Status
.
Used
==
nil
used
:=
api
.
ResourceList
{}
used
:=
v1
.
ResourceList
{}
if
resourceQuota
.
Status
.
Used
!=
nil
{
if
resourceQuota
.
Status
.
Used
!=
nil
{
used
=
quota
.
Add
(
api
.
ResourceList
{},
resourceQuota
.
Status
.
Used
)
used
=
quota
.
Add
(
v1
.
ResourceList
{},
resourceQuota
.
Status
.
Used
)
}
}
hardLimits
:=
quota
.
Add
(
api
.
ResourceList
{},
resourceQuota
.
Spec
.
Hard
)
hardLimits
:=
quota
.
Add
(
v1
.
ResourceList
{},
resourceQuota
.
Spec
.
Hard
)
newUsage
,
err
:=
quota
.
CalculateUsage
(
resourceQuota
.
Namespace
,
resourceQuota
.
Spec
.
Scopes
,
hardLimits
,
rq
.
registry
,
resourceQuota
.
Spec
.
ScopeSelector
)
newUsage
,
err
:=
quota
.
CalculateUsage
(
resourceQuota
.
Namespace
,
resourceQuota
.
Spec
.
Scopes
,
hardLimits
,
rq
.
registry
,
resourceQuota
.
Spec
.
ScopeSelector
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -354,14 +347,14 @@ func (rq *ResourceQuotaController) syncResourceQuota(v1ResourceQuota *v1.Resourc
...
@@ -354,14 +347,14 @@ func (rq *ResourceQuotaController) syncResourceQuota(v1ResourceQuota *v1.Resourc
// Create a usage object that is based on the quota resource version that will handle updates
// Create a usage object that is based on the quota resource version that will handle updates
// by default, we preserve the past usage observation, and set hard to the current spec
// by default, we preserve the past usage observation, and set hard to the current spec
usage
:=
api
.
ResourceQuota
{
usage
:=
v1
.
ResourceQuota
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
resourceQuota
.
Name
,
Name
:
resourceQuota
.
Name
,
Namespace
:
resourceQuota
.
Namespace
,
Namespace
:
resourceQuota
.
Namespace
,
ResourceVersion
:
resourceQuota
.
ResourceVersion
,
ResourceVersion
:
resourceQuota
.
ResourceVersion
,
Labels
:
resourceQuota
.
Labels
,
Labels
:
resourceQuota
.
Labels
,
Annotations
:
resourceQuota
.
Annotations
},
Annotations
:
resourceQuota
.
Annotations
},
Status
:
api
.
ResourceQuotaStatus
{
Status
:
v1
.
ResourceQuotaStatus
{
Hard
:
hardLimits
,
Hard
:
hardLimits
,
Used
:
used
,
Used
:
used
,
},
},
...
@@ -371,11 +364,7 @@ func (rq *ResourceQuotaController) syncResourceQuota(v1ResourceQuota *v1.Resourc
...
@@ -371,11 +364,7 @@ func (rq *ResourceQuotaController) syncResourceQuota(v1ResourceQuota *v1.Resourc
// there was a change observed by this controller that requires we update quota
// there was a change observed by this controller that requires we update quota
if
dirty
{
if
dirty
{
v1Usage
:=
&
v1
.
ResourceQuota
{}
_
,
err
=
rq
.
rqClient
.
ResourceQuotas
(
usage
.
Namespace
)
.
UpdateStatus
(
&
usage
)
if
err
:=
k8s_api_v1
.
Convert_core_ResourceQuota_To_v1_ResourceQuota
(
&
usage
,
v1Usage
,
nil
);
err
!=
nil
{
return
err
}
_
,
err
=
rq
.
rqClient
.
ResourceQuotas
(
usage
.
Namespace
)
.
UpdateStatus
(
v1Usage
)
return
err
return
err
}
}
return
nil
return
nil
...
@@ -406,12 +395,7 @@ func (rq *ResourceQuotaController) replenishQuota(groupResource schema.GroupReso
...
@@ -406,12 +395,7 @@ func (rq *ResourceQuotaController) replenishQuota(groupResource schema.GroupReso
// only queue those quotas that are tracking a resource associated with this kind.
// only queue those quotas that are tracking a resource associated with this kind.
for
i
:=
range
resourceQuotas
{
for
i
:=
range
resourceQuotas
{
resourceQuota
:=
resourceQuotas
[
i
]
resourceQuota
:=
resourceQuotas
[
i
]
internalResourceQuota
:=
&
api
.
ResourceQuota
{}
resourceQuotaResources
:=
quota
.
ResourceNames
(
resourceQuota
.
Status
.
Hard
)
if
err
:=
k8s_api_v1
.
Convert_v1_ResourceQuota_To_core_ResourceQuota
(
resourceQuota
,
internalResourceQuota
,
nil
);
err
!=
nil
{
glog
.
Error
(
err
)
continue
}
resourceQuotaResources
:=
quota
.
ResourceNames
(
internalResourceQuota
.
Status
.
Hard
)
if
intersection
:=
evaluator
.
MatchingResources
(
resourceQuotaResources
);
len
(
intersection
)
>
0
{
if
intersection
:=
evaluator
.
MatchingResources
(
resourceQuotaResources
);
len
(
intersection
)
>
0
{
// TODO: make this support targeted replenishment to a specific kind, right now it does a full recalc on that quota.
// TODO: make this support targeted replenishment to a specific kind, right now it does a full recalc on that quota.
rq
.
enqueueResourceQuota
(
resourceQuota
)
rq
.
enqueueResourceQuota
(
resourceQuota
)
...
...
pkg/controller/resourcequota/resource_quota_controller_test.go
View file @
d11ee913
...
@@ -33,9 +33,9 @@ import (
...
@@ -33,9 +33,9 @@ import (
core
"k8s.io/client-go/testing"
core
"k8s.io/client-go/testing"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/cache"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/quota
"
quota
"k8s.io/kubernetes/pkg/quota/v1
"
"k8s.io/kubernetes/pkg/quota/generic"
"k8s.io/kubernetes/pkg/quota/
v1/
generic"
"k8s.io/kubernetes/pkg/quota/install"
"k8s.io/kubernetes/pkg/quota/
v1/
install"
)
)
func
getResourceList
(
cpu
,
memory
string
)
v1
.
ResourceList
{
func
getResourceList
(
cpu
,
memory
string
)
v1
.
ResourceList
{
...
...
pkg/controller/resourcequota/resource_quota_monitor.go
View file @
d11ee913
...
@@ -33,9 +33,9 @@ import (
...
@@ -33,9 +33,9 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue"
"k8s.io/client-go/util/workqueue"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/quota
"
quota
"k8s.io/kubernetes/pkg/quota/v1
"
"k8s.io/kubernetes/pkg/quota/evaluator/core"
"k8s.io/kubernetes/pkg/quota/
v1/
evaluator/core"
"k8s.io/kubernetes/pkg/quota/generic"
"k8s.io/kubernetes/pkg/quota/
v1/
generic"
)
)
type
eventType
int
type
eventType
int
...
...
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