App Installer: Merge builder and installer admission (#109267)
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/storage/legacysql/dualwrite"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apiserver/pkg/admission"
|
||||
"k8s.io/apiserver/pkg/authorization/authorizer"
|
||||
"k8s.io/apiserver/pkg/registry/generic"
|
||||
genericapiserver "k8s.io/apiserver/pkg/server"
|
||||
@@ -58,27 +59,31 @@ func AddToScheme(
|
||||
return additionalGroupVersions, nil
|
||||
}
|
||||
|
||||
// RegisterAdmissionPlugins registers admission plugins for app installers
|
||||
func RegisterAdmissionPlugins(
|
||||
ctx context.Context,
|
||||
// RegisterAdmission combines the existing admission control from builders.
|
||||
func RegisterAdmission(
|
||||
existingAdmission admission.Interface,
|
||||
appInstallers []appsdkapiserver.AppInstaller,
|
||||
options *grafanaapiserveroptions.Options,
|
||||
) error {
|
||||
logger := logging.FromContext(ctx)
|
||||
) (admission.Interface, error) {
|
||||
controllers := []admission.Interface{}
|
||||
|
||||
for _, installer := range appInstallers {
|
||||
plugin := installer.AdmissionPlugin()
|
||||
if plugin != nil {
|
||||
md := installer.ManifestData()
|
||||
if md == nil {
|
||||
return fmt.Errorf("manifest is not initialized for installer for GroupVersions %v", installer.GroupVersions())
|
||||
}
|
||||
pluginName := md.AppName + " admission"
|
||||
options.RecommendedOptions.Admission.Plugins.Register(pluginName, plugin)
|
||||
logger.Info("Registered admission plugin", "app", md.AppName)
|
||||
factory := installer.AdmissionPlugin()
|
||||
if factory == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
admissionInterface, err := factory(nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create admission plugin: %w", err)
|
||||
}
|
||||
controllers = append(controllers, admissionInterface)
|
||||
}
|
||||
return nil
|
||||
|
||||
if existingAdmission != nil {
|
||||
controllers = append(controllers, existingAdmission)
|
||||
}
|
||||
|
||||
return admission.NewChainHandler(controllers...), nil
|
||||
}
|
||||
|
||||
type AuthorizerRegistrar interface {
|
||||
|
||||
@@ -291,11 +291,6 @@ func (s *service) start(ctx context.Context) error {
|
||||
|
||||
o := grafanaapiserveroptions.NewOptions(s.codecs.LegacyCodec(groupVersions...))
|
||||
|
||||
// Register admission plugins from app installers after options are created
|
||||
if err := appinstaller.RegisterAdmissionPlugins(ctx, s.appInstallers, o); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Register authorizers from app installers
|
||||
appinstaller.RegisterAuthorizers(ctx, s.appInstallers, s.authorizer)
|
||||
|
||||
@@ -367,6 +362,14 @@ func (s *service) start(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
serverConfig.AdmissionControl, err = appinstaller.RegisterAdmission(
|
||||
serverConfig.AdmissionControl,
|
||||
s.appInstallers,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
notFoundHandler := notfoundhandler.New(s.codecs, genericapifilters.NoMuxAndDiscoveryIncompleteKey)
|
||||
|
||||
if err := appinstaller.RegisterPostStartHooks(s.appInstallers, serverConfig); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user