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
041c0a6f
Commit
041c0a6f
authored
Feb 19, 2015
by
Xiang Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
admission: cleanup admission
parent
984fb2e6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
10 deletions
+14
-10
chain.go
pkg/admission/chain.go
+3
-2
plugins.go
pkg/admission/plugins.go
+11
-8
No files found.
pkg/admission/chain.go
View file @
041c0a6f
...
@@ -23,7 +23,8 @@ import (
...
@@ -23,7 +23,8 @@ import (
// chainAdmissionHandler is an instance of admission.Interface that performs admission control using a chain of admission handlers
// chainAdmissionHandler is an instance of admission.Interface that performs admission control using a chain of admission handlers
type
chainAdmissionHandler
[]
Interface
type
chainAdmissionHandler
[]
Interface
// New returns an admission.Interface that will enforce admission control decisions
// NewFromPlugins returns an admission.Interface that will enforce admission control decisions of all
// the given plugins.
func
NewFromPlugins
(
client
client
.
Interface
,
pluginNames
[]
string
,
configFilePath
string
)
Interface
{
func
NewFromPlugins
(
client
client
.
Interface
,
pluginNames
[]
string
,
configFilePath
string
)
Interface
{
plugins
:=
[]
Interface
{}
plugins
:=
[]
Interface
{}
for
_
,
pluginName
:=
range
pluginNames
{
for
_
,
pluginName
:=
range
pluginNames
{
...
@@ -36,7 +37,7 @@ func NewFromPlugins(client client.Interface, pluginNames []string, configFilePat
...
@@ -36,7 +37,7 @@ func NewFromPlugins(client client.Interface, pluginNames []string, configFilePat
}
}
// Admit performs an admission control check using a chain of handlers, and returns immediately on first error
// Admit performs an admission control check using a chain of handlers, and returns immediately on first error
func
(
admissionHandler
chainAdmissionHandler
)
Admit
(
a
Attributes
)
(
err
error
)
{
func
(
admissionHandler
chainAdmissionHandler
)
Admit
(
a
Attributes
)
error
{
for
_
,
handler
:=
range
admissionHandler
{
for
_
,
handler
:=
range
admissionHandler
{
err
:=
handler
.
Admit
(
a
)
err
:=
handler
.
Admit
(
a
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/admission/plugins.go
View file @
041c0a6f
...
@@ -25,15 +25,17 @@ import (
...
@@ -25,15 +25,17 @@ import (
"github.com/golang/glog"
"github.com/golang/glog"
)
)
// Factory is a function that returns a Interface for admission decisions.
// Factory is a function that returns a
n
Interface for admission decisions.
// The config parameter provides an io.Reader handler to the factory in
// The config parameter provides an io.Reader handler to the factory in
// order to load specific configurations. If no configuration is provided
// order to load specific configurations. If no configuration is provided
// the parameter is nil.
// the parameter is nil.
type
Factory
func
(
client
client
.
Interface
,
config
io
.
Reader
)
(
Interface
,
error
)
type
Factory
func
(
client
client
.
Interface
,
config
io
.
Reader
)
(
Interface
,
error
)
// All registered admission options.
// All registered admission options.
var
pluginsMutex
sync
.
Mutex
var
(
var
plugins
=
make
(
map
[
string
]
Factory
)
pluginsMutex
sync
.
Mutex
plugins
=
make
(
map
[
string
]
Factory
)
)
// GetPlugins enumerates the
// GetPlugins enumerates the
func
GetPlugins
()
[]
string
{
func
GetPlugins
()
[]
string
{
...
@@ -59,7 +61,7 @@ func RegisterPlugin(name string, plugin Factory) {
...
@@ -59,7 +61,7 @@ func RegisterPlugin(name string, plugin Factory) {
plugins
[
name
]
=
plugin
plugins
[
name
]
=
plugin
}
}
// Get
Interface
creates an instance of the named plugin, or nil if
// Get
Plugin
creates an instance of the named plugin, or nil if
// the name is not known. The error return is only used if the named provider
// the name is not known. The error return is only used if the named provider
// was known but failed to initialize. The config parameter specifies the
// was known but failed to initialize. The config parameter specifies the
// io.Reader handler of the configuration file for the cloud provider, or nil
// io.Reader handler of the configuration file for the cloud provider, or nil
...
@@ -74,9 +76,12 @@ func GetPlugin(name string, client client.Interface, config io.Reader) (Interfac
...
@@ -74,9 +76,12 @@ func GetPlugin(name string, client client.Interface, config io.Reader) (Interfac
return
f
(
client
,
config
)
return
f
(
client
,
config
)
}
}
// InitPlugin creates an instance of the named interface
// InitPlugin creates an instance of the named interface
.
func
InitPlugin
(
name
string
,
client
client
.
Interface
,
configFilePath
string
)
Interface
{
func
InitPlugin
(
name
string
,
client
client
.
Interface
,
configFilePath
string
)
Interface
{
var
config
*
os
.
File
var
(
config
*
os
.
File
err
error
)
if
name
==
""
{
if
name
==
""
{
glog
.
Info
(
"No admission plugin specified."
)
glog
.
Info
(
"No admission plugin specified."
)
...
@@ -84,8 +89,6 @@ func InitPlugin(name string, client client.Interface, configFilePath string) Int
...
@@ -84,8 +89,6 @@ func InitPlugin(name string, client client.Interface, configFilePath string) Int
}
}
if
configFilePath
!=
""
{
if
configFilePath
!=
""
{
var
err
error
config
,
err
=
os
.
Open
(
configFilePath
)
config
,
err
=
os
.
Open
(
configFilePath
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Fatalf
(
"Couldn't open admission plugin configuration %s: %#v"
,
glog
.
Fatalf
(
"Couldn't open admission plugin configuration %s: %#v"
,
...
...
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