...

Source file src/k8s.io/kubernetes/pkg/registry/admissionregistration/validatingwebhookconfiguration/strategy.go

Documentation: k8s.io/kubernetes/pkg/registry/admissionregistration/validatingwebhookconfiguration

     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 validatingwebhookconfiguration
    18  
    19  import (
    20  	"context"
    21  	"reflect"
    22  
    23  	"k8s.io/apimachinery/pkg/runtime"
    24  	"k8s.io/apimachinery/pkg/util/validation/field"
    25  	"k8s.io/apiserver/pkg/storage/names"
    26  	"k8s.io/kubernetes/pkg/api/legacyscheme"
    27  	"k8s.io/kubernetes/pkg/apis/admissionregistration"
    28  	"k8s.io/kubernetes/pkg/apis/admissionregistration/validation"
    29  )
    30  
    31  // validatingWebhookConfigurationStrategy implements verification logic for validatingWebhookConfiguration.
    32  type validatingWebhookConfigurationStrategy struct {
    33  	runtime.ObjectTyper
    34  	names.NameGenerator
    35  }
    36  
    37  // Strategy is the default logic that applies when creating and updating validatingWebhookConfiguration objects.
    38  var Strategy = validatingWebhookConfigurationStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
    39  
    40  // NamespaceScoped returns false because ValidatingWebhookConfiguration is cluster-scoped resource.
    41  func (validatingWebhookConfigurationStrategy) NamespaceScoped() bool {
    42  	return false
    43  }
    44  
    45  // PrepareForCreate clears the status of an validatingWebhookConfiguration before creation.
    46  func (validatingWebhookConfigurationStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
    47  	ic := obj.(*admissionregistration.ValidatingWebhookConfiguration)
    48  	ic.Generation = 1
    49  }
    50  
    51  // PrepareForUpdate clears fields that are not allowed to be set by end users on update.
    52  func (validatingWebhookConfigurationStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
    53  	newIC := obj.(*admissionregistration.ValidatingWebhookConfiguration)
    54  	oldIC := old.(*admissionregistration.ValidatingWebhookConfiguration)
    55  
    56  	// Any changes to the spec increment the generation number, any changes to the
    57  	// status should reflect the generation number of the corresponding object.
    58  	// See metav1.ObjectMeta description for more information on Generation.
    59  	if !reflect.DeepEqual(oldIC.Webhooks, newIC.Webhooks) {
    60  		newIC.Generation = oldIC.Generation + 1
    61  	}
    62  }
    63  
    64  // Validate validates a new validatingWebhookConfiguration.
    65  func (validatingWebhookConfigurationStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
    66  	return validation.ValidateValidatingWebhookConfiguration(obj.(*admissionregistration.ValidatingWebhookConfiguration))
    67  }
    68  
    69  // WarningsOnCreate returns warnings for the creation of the given object.
    70  func (validatingWebhookConfigurationStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
    71  	return nil
    72  }
    73  
    74  // Canonicalize normalizes the object after validation.
    75  func (validatingWebhookConfigurationStrategy) Canonicalize(obj runtime.Object) {
    76  }
    77  
    78  // AllowCreateOnUpdate is true for validatingWebhookConfiguration; this means you may create one with a PUT request.
    79  func (validatingWebhookConfigurationStrategy) AllowCreateOnUpdate() bool {
    80  	return false
    81  }
    82  
    83  // ValidateUpdate is the default update validation for an end user.
    84  func (validatingWebhookConfigurationStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
    85  	return validation.ValidateValidatingWebhookConfigurationUpdate(obj.(*admissionregistration.ValidatingWebhookConfiguration), old.(*admissionregistration.ValidatingWebhookConfiguration))
    86  }
    87  
    88  // WarningsOnUpdate returns warnings for the given update.
    89  func (validatingWebhookConfigurationStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
    90  	return nil
    91  }
    92  
    93  // AllowUnconditionalUpdate is the default update policy for validatingWebhookConfiguration objects. Status update should
    94  // only be allowed if version match.
    95  func (validatingWebhookConfigurationStrategy) AllowUnconditionalUpdate() bool {
    96  	return false
    97  }
    98  

View as plain text