...

Source file src/k8s.io/kubernetes/pkg/kubeapiserver/admission/config.go

Documentation: k8s.io/kubernetes/pkg/kubeapiserver/admission

     1  /*
     2  Copyright 2018 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  	"os"
    22  
    23  	"k8s.io/klog/v2"
    24  
    25  	"go.opentelemetry.io/otel/trace"
    26  
    27  	"k8s.io/apiserver/pkg/admission"
    28  	webhookinit "k8s.io/apiserver/pkg/admission/plugin/webhook/initializer"
    29  	"k8s.io/apiserver/pkg/server/egressselector"
    30  	"k8s.io/apiserver/pkg/util/webhook"
    31  	externalinformers "k8s.io/client-go/informers"
    32  	"k8s.io/client-go/rest"
    33  	"k8s.io/kubernetes/pkg/kubeapiserver/admission/exclusion"
    34  	quotainstall "k8s.io/kubernetes/pkg/quota/v1/install"
    35  )
    36  
    37  // Config holds the configuration needed to for initialize the admission plugins
    38  type Config struct {
    39  	CloudConfigFile      string
    40  	LoopbackClientConfig *rest.Config
    41  	ExternalInformers    externalinformers.SharedInformerFactory
    42  }
    43  
    44  // New sets up the plugins and admission start hooks needed for admission
    45  func (c *Config) New(proxyTransport *http.Transport, egressSelector *egressselector.EgressSelector, serviceResolver webhook.ServiceResolver, tp trace.TracerProvider) ([]admission.PluginInitializer, error) {
    46  	webhookAuthResolverWrapper := webhook.NewDefaultAuthenticationInfoResolverWrapper(proxyTransport, egressSelector, c.LoopbackClientConfig, tp)
    47  	webhookPluginInitializer := webhookinit.NewPluginInitializer(webhookAuthResolverWrapper, serviceResolver)
    48  
    49  	var cloudConfig []byte
    50  	if c.CloudConfigFile != "" {
    51  		var err error
    52  		cloudConfig, err = os.ReadFile(c.CloudConfigFile)
    53  		if err != nil {
    54  			klog.Fatalf("Error reading from cloud configuration file %s: %#v", c.CloudConfigFile, err)
    55  		}
    56  	}
    57  	kubePluginInitializer := NewPluginInitializer(
    58  		cloudConfig,
    59  		quotainstall.NewQuotaConfigurationForAdmission(),
    60  		exclusion.Excluded(),
    61  	)
    62  
    63  	return []admission.PluginInitializer{webhookPluginInitializer, kubePluginInitializer}, nil
    64  }
    65  

View as plain text