...

Source file src/k8s.io/kubernetes/pkg/registry/node/runtimeclass/strategy.go

Documentation: k8s.io/kubernetes/pkg/registry/node/runtimeclass

     1  /*
     2  Copyright 2019 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 runtimeclass
    18  
    19  import (
    20  	"context"
    21  
    22  	"k8s.io/apimachinery/pkg/runtime"
    23  	"k8s.io/apimachinery/pkg/util/validation/field"
    24  	"k8s.io/apiserver/pkg/registry/rest"
    25  	"k8s.io/apiserver/pkg/storage/names"
    26  	"k8s.io/kubernetes/pkg/api/legacyscheme"
    27  	nodeapi "k8s.io/kubernetes/pkg/api/node"
    28  	"k8s.io/kubernetes/pkg/apis/node"
    29  	"k8s.io/kubernetes/pkg/apis/node/validation"
    30  )
    31  
    32  // strategy implements verification logic for RuntimeClass.
    33  type strategy struct {
    34  	runtime.ObjectTyper
    35  	names.NameGenerator
    36  }
    37  
    38  // Strategy is the default logic that applies when creating and updating RuntimeClass objects.
    39  var Strategy = strategy{legacyscheme.Scheme, names.SimpleNameGenerator}
    40  
    41  // Strategy should implement rest.RESTCreateStrategy
    42  var _ rest.RESTCreateStrategy = Strategy
    43  
    44  // Strategy should implement rest.RESTUpdateStrategy
    45  var _ rest.RESTUpdateStrategy = Strategy
    46  
    47  // NamespaceScoped is false for RuntimeClasses
    48  func (strategy) NamespaceScoped() bool {
    49  	return false
    50  }
    51  
    52  // AllowCreateOnUpdate is true for RuntimeClasses.
    53  func (strategy) AllowCreateOnUpdate() bool {
    54  	return true
    55  }
    56  
    57  // PrepareForCreate clears fields that are not allowed to be set by end users
    58  // on creation.
    59  func (strategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
    60  }
    61  
    62  // PrepareForUpdate clears fields that are not allowed to be set by end users on update.
    63  func (strategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
    64  	newRuntimeClass := obj.(*node.RuntimeClass)
    65  	oldRuntimeClass := old.(*node.RuntimeClass)
    66  
    67  	_, _ = newRuntimeClass, oldRuntimeClass
    68  }
    69  
    70  // Validate validates a new RuntimeClass. Validation must check for a correct signature.
    71  func (strategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
    72  	runtimeClass := obj.(*node.RuntimeClass)
    73  	return validation.ValidateRuntimeClass(runtimeClass)
    74  }
    75  
    76  // WarningsOnCreate returns warnings for the creation of the given object.
    77  func (strategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
    78  	return nodeapi.GetWarningsForRuntimeClass(obj.(*node.RuntimeClass))
    79  }
    80  
    81  // Canonicalize normalizes the object after validation.
    82  func (strategy) Canonicalize(obj runtime.Object) {
    83  	_ = obj.(*node.RuntimeClass)
    84  }
    85  
    86  // ValidateUpdate is the default update validation for an end user.
    87  func (strategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
    88  	newObj := obj.(*node.RuntimeClass)
    89  	errorList := validation.ValidateRuntimeClass(newObj)
    90  	return append(errorList, validation.ValidateRuntimeClassUpdate(newObj, old.(*node.RuntimeClass))...)
    91  }
    92  
    93  // WarningsOnUpdate returns warnings for the given update.
    94  func (strategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
    95  	return nodeapi.GetWarningsForRuntimeClass(obj.(*node.RuntimeClass))
    96  }
    97  
    98  // If AllowUnconditionalUpdate() is true and the object specified by
    99  // the user does not have a resource version, then generic Update()
   100  // populates it with the latest version. Else, it checks that the
   101  // version specified by the user matches the version of latest etcd
   102  // object.
   103  func (strategy) AllowUnconditionalUpdate() bool {
   104  	return false
   105  }
   106  

View as plain text