Commit 76ce7bcb authored by deads2k's avatar deads2k

stop hardcoding api registry and codecs in webhook

parent d76295b5
......@@ -19,6 +19,7 @@ go_library(
deps = [
"//pkg/api:go_default_library",
"//pkg/apis/imagepolicy/install:go_default_library",
"//pkg/apis/imagepolicy/v1alpha1:go_default_library",
"//vendor:github.com/golang/glog",
"//vendor:k8s.io/apimachinery/pkg/api/errors",
"//vendor:k8s.io/apimachinery/pkg/runtime/schema",
......@@ -26,8 +27,6 @@ go_library(
"//vendor:k8s.io/apiserver/pkg/admission",
"//vendor:k8s.io/apiserver/pkg/util/cache",
"//vendor:k8s.io/apiserver/pkg/util/webhook",
"//vendor:k8s.io/client-go/pkg/apis/imagepolicy/install",
"//vendor:k8s.io/client-go/pkg/apis/imagepolicy/v1alpha1",
"//vendor:k8s.io/client-go/rest",
],
)
......
......@@ -35,13 +35,12 @@ import (
"k8s.io/apiserver/pkg/admission"
"k8s.io/apiserver/pkg/util/cache"
"k8s.io/apiserver/pkg/util/webhook"
"k8s.io/client-go/pkg/apis/imagepolicy/v1alpha1"
"k8s.io/client-go/rest"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/imagepolicy/v1alpha1"
// install the clientgo image policy API for use with api registry
_ "k8s.io/client-go/pkg/apis/imagepolicy/install"
_ "k8s.io/kubernetes/pkg/apis/imagepolicy/install"
)
......@@ -228,7 +227,7 @@ func NewImagePolicyWebhook(configFile io.Reader) (admission.Interface, error) {
return nil, err
}
gw, err := webhook.NewGenericWebhook(whConfig.KubeConfigFile, groupVersions, whConfig.RetryBackoff)
gw, err := webhook.NewGenericWebhook(api.Registry, api.Codecs, whConfig.KubeConfigFile, groupVersions, whConfig.RetryBackoff)
if err != nil {
return nil, err
}
......
......@@ -22,15 +22,14 @@ import (
"time"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apimachinery/registered"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/pkg/api"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
_ "k8s.io/client-go/pkg/apis/authorization/install"
)
type GenericWebhook struct {
......@@ -39,9 +38,9 @@ type GenericWebhook struct {
}
// NewGenericWebhook creates a new GenericWebhook from the provided kubeconfig file.
func NewGenericWebhook(kubeConfigFile string, groupVersions []schema.GroupVersion, initialBackoff time.Duration) (*GenericWebhook, error) {
func NewGenericWebhook(registry *registered.APIRegistrationManager, codecFactory serializer.CodecFactory, kubeConfigFile string, groupVersions []schema.GroupVersion, initialBackoff time.Duration) (*GenericWebhook, error) {
for _, groupVersion := range groupVersions {
if !api.Registry.IsEnabledVersion(groupVersion) {
if !registry.IsEnabledVersion(groupVersion) {
return nil, fmt.Errorf("webhook plugin requires enabling extension resource: %s", groupVersion)
}
}
......@@ -54,7 +53,7 @@ func NewGenericWebhook(kubeConfigFile string, groupVersions []schema.GroupVersio
if err != nil {
return nil, err
}
codec := api.Codecs.LegacyCodec(groupVersions...)
codec := codecFactory.LegacyCodec(groupVersions...)
clientConfig.ContentConfig.NegotiatedSerializer = runtimeserializer.NegotiatedSerializerWrapper(runtime.SerializerInfo{Serializer: codec})
restClient, err := rest.UnversionedRESTClientFor(clientConfig)
......
......@@ -26,6 +26,7 @@ import (
"k8s.io/apiserver/pkg/util/cache"
"k8s.io/apiserver/pkg/util/webhook"
authenticationclient "k8s.io/client-go/kubernetes/typed/authentication/v1beta1"
"k8s.io/client-go/pkg/api"
authentication "k8s.io/client-go/pkg/apis/authentication/v1beta1"
_ "k8s.io/client-go/pkg/apis/authentication/install"
......@@ -112,7 +113,7 @@ func (w *WebhookTokenAuthenticator) AuthenticateToken(token string) (user.Info,
// and returns a TokenReviewInterface that uses that client. Note that the client submits TokenReview
// requests to the exact path specified in the kubeconfig file, so arbitrary non-API servers can be targeted.
func tokenReviewInterfaceFromKubeconfig(kubeConfigFile string) (authenticationclient.TokenReviewInterface, error) {
gw, err := webhook.NewGenericWebhook(kubeConfigFile, groupVersions, 0)
gw, err := webhook.NewGenericWebhook(api.Registry, api.Codecs, kubeConfigFile, groupVersions, 0)
if err != nil {
return nil, err
}
......
......@@ -26,11 +26,11 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apiserver/pkg/authorization/authorizer"
"k8s.io/apiserver/pkg/util/cache"
"k8s.io/apiserver/pkg/util/webhook"
authorizationclient "k8s.io/client-go/kubernetes/typed/authorization/v1beta1"
"k8s.io/client-go/pkg/api"
authorization "k8s.io/client-go/pkg/apis/authorization/v1beta1"
"k8s.io/apiserver/pkg/util/webhook"
_ "k8s.io/client-go/pkg/apis/authorization/install"
)
......@@ -211,7 +211,7 @@ func convertToSARExtra(extra map[string][]string) map[string]authorization.Extra
// and returns a SubjectAccessReviewInterface that uses that client. Note that the client submits SubjectAccessReview
// requests to the exact path specified in the kubeconfig file, so arbitrary non-API servers can be targeted.
func subjectAccessReviewInterfaceFromKubeconfig(kubeConfigFile string) (authorizationclient.SubjectAccessReviewInterface, error) {
gw, err := webhook.NewGenericWebhook(kubeConfigFile, groupVersions, 0)
gw, err := webhook.NewGenericWebhook(api.Registry, api.Codecs, kubeConfigFile, groupVersions, 0)
if err != nil {
return nil, err
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment