...

Source file src/k8s.io/kubernetes/plugin/pkg/admission/admit/admission.go

Documentation: k8s.io/kubernetes/plugin/pkg/admission/admit

     1  /*
     2  Copyright 2014 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 admit
    18  
    19  import (
    20  	"context"
    21  	"io"
    22  
    23  	"k8s.io/apiserver/pkg/admission"
    24  	"k8s.io/klog/v2"
    25  )
    26  
    27  // PluginName indicates name of admission plugin.
    28  const PluginName = "AlwaysAdmit"
    29  
    30  // Register registers a plugin
    31  func Register(plugins *admission.Plugins) {
    32  	plugins.Register(PluginName, func(config io.Reader) (admission.Interface, error) {
    33  		return NewAlwaysAdmit(), nil
    34  	})
    35  }
    36  
    37  // alwaysAdmit is an implementation of admission.Interface which always says yes to an admit request.
    38  type alwaysAdmit struct{}
    39  
    40  var _ admission.MutationInterface = alwaysAdmit{}
    41  var _ admission.ValidationInterface = alwaysAdmit{}
    42  
    43  // Admit makes an admission decision based on the request attributes
    44  func (alwaysAdmit) Admit(ctx context.Context, a admission.Attributes, o admission.ObjectInterfaces) (err error) {
    45  	return nil
    46  }
    47  
    48  // Validate makes an admission decision based on the request attributes.  It is NOT allowed to mutate.
    49  func (alwaysAdmit) Validate(ctx context.Context, a admission.Attributes, o admission.ObjectInterfaces) (err error) {
    50  	return nil
    51  }
    52  
    53  // Handles returns true if this admission controller can handle the given operation
    54  // where operation can be one of CREATE, UPDATE, DELETE, or CONNECT
    55  func (alwaysAdmit) Handles(operation admission.Operation) bool {
    56  	return true
    57  }
    58  
    59  // NewAlwaysAdmit creates a new always admit admission handler
    60  func NewAlwaysAdmit() admission.Interface {
    61  	// DEPRECATED: AlwaysAdmit admit all admission request, it is no use.
    62  	klog.Warningf("%s admission controller is deprecated. "+
    63  		"Please remove this controller from your configuration files and scripts.", PluginName)
    64  	return new(alwaysAdmit)
    65  }
    66  

View as plain text