...

Source file src/k8s.io/kubernetes/pkg/registry/networking/ingressclass/strategy.go

Documentation: k8s.io/kubernetes/pkg/registry/networking/ingressclass

     1  /*
     2  Copyright 2020 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 ingressclass
    18  
    19  import (
    20  	"context"
    21  
    22  	apiequality "k8s.io/apimachinery/pkg/api/equality"
    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/networking"
    28  	"k8s.io/kubernetes/pkg/apis/networking/validation"
    29  )
    30  
    31  // ingressClassStrategy implements verification logic for IngressClass
    32  // resources.
    33  type ingressClassStrategy struct {
    34  	runtime.ObjectTyper
    35  	names.NameGenerator
    36  }
    37  
    38  // Strategy is the default logic that applies when creating and updating
    39  // IngressClass objects.
    40  var Strategy = ingressClassStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
    41  
    42  // NamespaceScoped returns false because IngressClass is a non-namespaced
    43  // resource.
    44  func (ingressClassStrategy) NamespaceScoped() bool {
    45  	return false
    46  }
    47  
    48  // PrepareForCreate prepares an IngressClass for creation.
    49  func (ingressClassStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
    50  	ingressClass := obj.(*networking.IngressClass)
    51  	ingressClass.Generation = 1
    52  }
    53  
    54  // PrepareForUpdate clears fields that are not allowed to be set by end users on
    55  // update.
    56  func (ingressClassStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
    57  	newIngressClass := obj.(*networking.IngressClass)
    58  	oldIngressClass := old.(*networking.IngressClass)
    59  
    60  	// Any changes to the spec increment the generation number.
    61  	// See metav1.ObjectMeta description for more information on Generation.
    62  	if !apiequality.Semantic.DeepEqual(oldIngressClass.Spec, newIngressClass.Spec) {
    63  		newIngressClass.Generation = oldIngressClass.Generation + 1
    64  	}
    65  }
    66  
    67  // Validate validates a new IngressClass.
    68  func (ingressClassStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
    69  	ingressClass := obj.(*networking.IngressClass)
    70  	return validation.ValidateIngressClass(ingressClass)
    71  }
    72  
    73  // WarningsOnCreate returns warnings for the creation of the given object.
    74  func (ingressClassStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
    75  	return nil
    76  }
    77  
    78  // Canonicalize normalizes the object after validation.
    79  func (ingressClassStrategy) Canonicalize(obj runtime.Object) {
    80  }
    81  
    82  // AllowCreateOnUpdate is false for IngressClass; this means POST is needed to
    83  // create one.
    84  func (ingressClassStrategy) AllowCreateOnUpdate() bool {
    85  	return false
    86  }
    87  
    88  // ValidateUpdate is the default update validation for an end user.
    89  func (ingressClassStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
    90  	newIngressClass := obj.(*networking.IngressClass)
    91  	oldIngressClass := old.(*networking.IngressClass)
    92  
    93  	return validation.ValidateIngressClassUpdate(newIngressClass, oldIngressClass)
    94  }
    95  
    96  // WarningsOnUpdate returns warnings for the given update.
    97  func (ingressClassStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
    98  	return nil
    99  }
   100  
   101  // AllowUnconditionalUpdate is the default update policy for IngressClass
   102  // objects.
   103  func (ingressClassStrategy) AllowUnconditionalUpdate() bool {
   104  	return true
   105  }
   106  

View as plain text