k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/pkg/controlplane/apiserver/admission/config.go (about)

     1  /*
     2  Copyright 2024 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package admission
    18  
    19  import (
    20  	"net/http"
    21  
    22  	"go.opentelemetry.io/otel/trace"
    23  
    24  	"k8s.io/apiserver/pkg/admission"
    25  	webhookinit "k8s.io/apiserver/pkg/admission/plugin/webhook/initializer"
    26  	egressselector "k8s.io/apiserver/pkg/server/egressselector"
    27  	"k8s.io/apiserver/pkg/util/webhook"
    28  	externalinformers "k8s.io/client-go/informers"
    29  	"k8s.io/client-go/rest"
    30  	"k8s.io/kubernetes/pkg/kubeapiserver/admission/exclusion"
    31  	quotainstall "k8s.io/kubernetes/pkg/quota/v1/install"
    32  )
    33  
    34  // Config holds the configuration needed to for initialize the admission plugins
    35  type Config struct {
    36  	LoopbackClientConfig *rest.Config
    37  	ExternalInformers    externalinformers.SharedInformerFactory
    38  }
    39  
    40  // New sets up the plugins and admission start hooks needed for admission
    41  func (c *Config) New(proxyTransport *http.Transport, egressSelector *egressselector.EgressSelector, serviceResolver webhook.ServiceResolver, tp trace.TracerProvider) ([]admission.PluginInitializer, error) {
    42  	webhookAuthResolverWrapper := webhook.NewDefaultAuthenticationInfoResolverWrapper(proxyTransport, egressSelector, c.LoopbackClientConfig, tp)
    43  	webhookPluginInitializer := webhookinit.NewPluginInitializer(webhookAuthResolverWrapper, serviceResolver)
    44  
    45  	kubePluginInitializer := NewPluginInitializer(
    46  		quotainstall.NewQuotaConfigurationForAdmission(),
    47  		exclusion.Excluded(),
    48  	)
    49  
    50  	return []admission.PluginInitializer{webhookPluginInitializer, kubePluginInitializer}, nil
    51  }