Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

admission: cleanup admission #4652

Merged
merged 1 commit into from
Feb 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/admission/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import (
// chainAdmissionHandler is an instance of admission.Interface that performs admission control using a chain of admission handlers
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 {
plugins := []Interface{}
for _, pluginName := range pluginNames {
Expand All @@ -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
func (admissionHandler chainAdmissionHandler) Admit(a Attributes) (err error) {
func (admissionHandler chainAdmissionHandler) Admit(a Attributes) error {
for _, handler := range admissionHandler {
err := handler.Admit(a)
if err != nil {
Expand Down
19 changes: 11 additions & 8 deletions pkg/admission/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ import (
"github.com/golang/glog"
)

// Factory is a function that returns a Interface for admission decisions.
// Factory is a function that returns an Interface for admission decisions.
// The config parameter provides an io.Reader handler to the factory in
// order to load specific configurations. If no configuration is provided
// the parameter is nil.
type Factory func(client client.Interface, config io.Reader) (Interface, error)

// All registered admission options.
var pluginsMutex sync.Mutex
var plugins = make(map[string]Factory)
var (
pluginsMutex sync.Mutex
plugins = make(map[string]Factory)
)

// GetPlugins enumerates the
func GetPlugins() []string {
Expand All @@ -59,7 +61,7 @@ func RegisterPlugin(name string, plugin Factory) {
plugins[name] = plugin
}

// GetInterface creates an instance of the named plugin, or nil if
// GetPlugin 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
// was known but failed to initialize. The config parameter specifies the
// io.Reader handler of the configuration file for the cloud provider, or nil
Expand All @@ -74,18 +76,19 @@ func GetPlugin(name string, client client.Interface, config io.Reader) (Interfac
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 {
var config *os.File
var (
config *os.File
err error
)

if name == "" {
glog.Info("No admission plugin specified.")
return nil
}

if configFilePath != "" {
var err error

config, err = os.Open(configFilePath)
if err != nil {
glog.Fatalf("Couldn't open admission plugin configuration %s: %#v",
Expand Down