mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
admission: cleanup admission
This commit is contained in:
parent
984fb2e675
commit
041c0a6f2b
@ -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
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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 {
|
||||||
|
@ -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 an 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) {
|
|||||||
plugins[name] = plugin
|
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
|
// 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
|
|||||||
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
|
|||||||
}
|
}
|
||||||
|
|
||||||
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",
|
||||||
|
Loading…
Reference in New Issue
Block a user