...

Source file src/k8s.io/kubernetes/pkg/registry/rbac/rolebinding/strategy.go

Documentation: k8s.io/kubernetes/pkg/registry/rbac/rolebinding

     1  /*
     2  Copyright 2016 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 rolebinding
    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  	"k8s.io/kubernetes/pkg/apis/rbac"
    28  	"k8s.io/kubernetes/pkg/apis/rbac/validation"
    29  )
    30  
    31  // strategy implements behavior for RoleBindings
    32  type strategy struct {
    33  	runtime.ObjectTyper
    34  	names.NameGenerator
    35  }
    36  
    37  // strategy is the default logic that applies when creating and updating
    38  // RoleBinding 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 true for RoleBindings.
    48  func (strategy) NamespaceScoped() bool {
    49  	return true
    50  }
    51  
    52  // AllowCreateOnUpdate is true for RoleBindings.
    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  	_ = obj.(*rbac.RoleBinding)
    61  }
    62  
    63  // PrepareForUpdate clears fields that are not allowed to be set by end users on update.
    64  func (strategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
    65  	newRoleBinding := obj.(*rbac.RoleBinding)
    66  	oldRoleBinding := old.(*rbac.RoleBinding)
    67  
    68  	_, _ = newRoleBinding, oldRoleBinding
    69  }
    70  
    71  // Validate validates a new RoleBinding. Validation must check for a correct signature.
    72  func (strategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
    73  	roleBinding := obj.(*rbac.RoleBinding)
    74  	return validation.ValidateRoleBinding(roleBinding)
    75  }
    76  
    77  // WarningsOnCreate returns warnings for the creation of the given object.
    78  func (strategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string { return nil }
    79  
    80  // Canonicalize normalizes the object after validation.
    81  func (strategy) Canonicalize(obj runtime.Object) {
    82  	_ = obj.(*rbac.RoleBinding)
    83  }
    84  
    85  // ValidateUpdate is the default update validation for an end user.
    86  func (strategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
    87  	newObj := obj.(*rbac.RoleBinding)
    88  	errorList := validation.ValidateRoleBinding(newObj)
    89  	return append(errorList, validation.ValidateRoleBindingUpdate(newObj, old.(*rbac.RoleBinding))...)
    90  }
    91  
    92  // WarningsOnUpdate returns warnings for the given update.
    93  func (strategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
    94  	return nil
    95  }
    96  
    97  // If AllowUnconditionalUpdate() is true and the object specified by
    98  // the user does not have a resource version, then generic Update()
    99  // populates it with the latest version. Else, it checks that the
   100  // version specified by the user matches the version of latest etcd
   101  // object.
   102  func (strategy) AllowUnconditionalUpdate() bool {
   103  	return true
   104  }
   105  

View as plain text