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
a094a335
Commit
a094a335
authored
Jul 07, 2016
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add union registry for quota
parent
ec6181d5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
1 deletion
+52
-1
replenishment_controller.go
pkg/controller/resourcequota/replenishment_controller.go
+36
-1
interfaces.go
pkg/quota/interfaces.go
+16
-0
No files found.
pkg/controller/resourcequota/replenishment_controller.go
View file @
a094a335
...
@@ -214,7 +214,7 @@ func (r *replenishmentControllerFactory) NewController(options *ReplenishmentCon
...
@@ -214,7 +214,7 @@ func (r *replenishmentControllerFactory) NewController(options *ReplenishmentCon
},
},
)
)
default
:
default
:
return
nil
,
fmt
.
Errorf
(
"no replenishment controller available for %s"
,
options
.
GroupKind
)
return
nil
,
NewUnhandledGroupKindError
(
options
.
GroupKind
)
}
}
return
result
,
nil
return
result
,
nil
}
}
...
@@ -229,3 +229,38 @@ func ServiceReplenishmentUpdateFunc(options *ReplenishmentControllerOptions) fun
...
@@ -229,3 +229,38 @@ func ServiceReplenishmentUpdateFunc(options *ReplenishmentControllerOptions) fun
}
}
}
}
}
}
type
unhandledKindErr
struct
{
kind
unversioned
.
GroupKind
}
func
(
e
unhandledKindErr
)
Error
()
string
{
return
fmt
.
Sprintf
(
"no replenishment controller available for %s"
,
e
.
kind
)
}
func
NewUnhandledGroupKindError
(
kind
unversioned
.
GroupKind
)
error
{
return
unhandledKindErr
{
kind
:
kind
}
}
func
IsUnhandledGroupKindError
(
err
error
)
bool
{
if
err
==
nil
{
return
false
}
_
,
ok
:=
err
.
(
unhandledKindErr
)
return
ok
}
// UnionReplenishmentControllerFactory iterates through its constituent factories ignoring, UnhandledGroupKindErrors
// returning the first success or failure it hits. If there are no hits either way, it return an UnhandledGroupKind error
type
UnionReplenishmentControllerFactory
[]
ReplenishmentControllerFactory
func
(
f
UnionReplenishmentControllerFactory
)
NewController
(
options
*
ReplenishmentControllerOptions
)
(
framework
.
ControllerInterface
,
error
)
{
for
_
,
factory
:=
range
f
{
controller
,
err
:=
factory
.
NewController
(
options
)
if
!
IsUnhandledGroupKindError
(
err
)
{
return
controller
,
err
}
}
return
nil
,
NewUnhandledGroupKindError
(
options
.
GroupKind
)
}
pkg/quota/interfaces.go
View file @
a094a335
...
@@ -64,3 +64,19 @@ type Registry interface {
...
@@ -64,3 +64,19 @@ type Registry interface {
// Evaluators returns the set Evaluator objects registered to a groupKind
// Evaluators returns the set Evaluator objects registered to a groupKind
Evaluators
()
map
[
unversioned
.
GroupKind
]
Evaluator
Evaluators
()
map
[
unversioned
.
GroupKind
]
Evaluator
}
}
// UnionRegistry combines multiple registries. Order matters because first registry to claim a GroupKind
// is the "winner"
type
UnionRegistry
[]
Registry
func
(
r
UnionRegistry
)
Evaluators
()
map
[
unversioned
.
GroupKind
]
Evaluator
{
ret
:=
map
[
unversioned
.
GroupKind
]
Evaluator
{}
for
i
:=
len
(
r
)
-
1
;
i
>=
0
;
i
--
{
for
k
,
v
:=
range
r
[
i
]
.
Evaluators
()
{
ret
[
k
]
=
v
}
}
return
ret
}
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