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
3973856a
Commit
3973856a
authored
Jul 15, 2016
by
Ke Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replenish quota for service optimize, add testcase
parent
4fdde68f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
4 deletions
+49
-4
replenishment_controller.go
pkg/controller/resourcequota/replenishment_controller.go
+4
-4
replenishment_controller_test.go
...controller/resourcequota/replenishment_controller_test.go
+34
-0
services.go
pkg/quota/evaluator/core/services.go
+11
-0
No files found.
pkg/controller/resourcequota/replenishment_controller.go
View file @
3973856a
...
...
@@ -59,7 +59,7 @@ func PodReplenishmentUpdateFunc(options *ReplenishmentControllerOptions) func(ol
oldPod
:=
oldObj
.
(
*
api
.
Pod
)
newPod
:=
newObj
.
(
*
api
.
Pod
)
if
core
.
QuotaPod
(
oldPod
)
&&
!
core
.
QuotaPod
(
newPod
)
{
options
.
ReplenishmentFunc
(
options
.
GroupKind
,
newPod
.
Namespace
,
new
Pod
)
options
.
ReplenishmentFunc
(
options
.
GroupKind
,
newPod
.
Namespace
,
old
Pod
)
}
}
}
...
...
@@ -219,13 +219,13 @@ func (r *replenishmentControllerFactory) NewController(options *ReplenishmentCon
return
result
,
nil
}
// ServiceReplenishmentUpdateFunc will replenish if the
old service was quota tracked but the new is not
// ServiceReplenishmentUpdateFunc will replenish if the
service was quota tracked has changed service type
func
ServiceReplenishmentUpdateFunc
(
options
*
ReplenishmentControllerOptions
)
func
(
oldObj
,
newObj
interface
{})
{
return
func
(
oldObj
,
newObj
interface
{})
{
oldService
:=
oldObj
.
(
*
api
.
Service
)
newService
:=
newObj
.
(
*
api
.
Service
)
if
core
.
QuotaServiceType
(
oldService
)
||
core
.
QuotaServiceType
(
newService
)
{
options
.
ReplenishmentFunc
(
options
.
GroupKind
,
newService
.
Namespace
,
n
ewService
)
if
core
.
GetQuotaServiceType
(
oldService
)
!=
core
.
Get
QuotaServiceType
(
newService
)
{
options
.
ReplenishmentFunc
(
options
.
GroupKind
,
newService
.
Namespace
,
n
il
)
}
}
}
pkg/controller/resourcequota/replenishment_controller_test.go
View file @
3973856a
...
...
@@ -118,4 +118,38 @@ func TestServiceReplenishmentUpdateFunc(t *testing.T) {
if
mockReplenish
.
namespace
!=
oldService
.
Namespace
{
t
.
Errorf
(
"Unexpected namespace %v"
,
mockReplenish
.
namespace
)
}
mockReplenish
=
&
testReplenishment
{}
options
=
ReplenishmentControllerOptions
{
GroupKind
:
api
.
Kind
(
"Service"
),
ReplenishmentFunc
:
mockReplenish
.
Replenish
,
ResyncPeriod
:
controller
.
NoResyncPeriodFunc
,
}
oldService
=
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
"test"
,
Name
:
"mysvc"
},
Spec
:
api
.
ServiceSpec
{
Type
:
api
.
ServiceTypeNodePort
,
Ports
:
[]
api
.
ServicePort
{{
Port
:
80
,
TargetPort
:
intstr
.
FromInt
(
80
),
}},
},
}
newService
=
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
"test"
,
Name
:
"mysvc"
},
Spec
:
api
.
ServiceSpec
{
Type
:
api
.
ServiceTypeNodePort
,
Ports
:
[]
api
.
ServicePort
{{
Port
:
81
,
TargetPort
:
intstr
.
FromInt
(
81
),
}}},
}
updateFunc
=
ServiceReplenishmentUpdateFunc
(
&
options
)
updateFunc
(
oldService
,
newService
)
if
mockReplenish
.
groupKind
==
api
.
Kind
(
"Service"
)
{
t
.
Errorf
(
"Unexpected group kind %v"
,
mockReplenish
.
groupKind
)
}
if
mockReplenish
.
namespace
==
oldService
.
Namespace
{
t
.
Errorf
(
"Unexpected namespace %v"
,
mockReplenish
.
namespace
)
}
}
pkg/quota/evaluator/core/services.go
View file @
3973856a
...
...
@@ -73,3 +73,14 @@ func QuotaServiceType(service *api.Service) bool {
}
return
false
}
//GetQuotaServiceType returns ServiceType if the service type is eligible to track against a quota, nor return ""
func
GetQuotaServiceType
(
service
*
api
.
Service
)
api
.
ServiceType
{
switch
service
.
Spec
.
Type
{
case
api
.
ServiceTypeNodePort
:
return
api
.
ServiceTypeNodePort
case
api
.
ServiceTypeLoadBalancer
:
return
api
.
ServiceTypeLoadBalancer
}
return
api
.
ServiceType
(
""
)
}
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