...

Source file src/k8s.io/kubernetes/pkg/registry/apps/controllerrevision/strategy.go

Documentation: k8s.io/kubernetes/pkg/registry/apps/controllerrevision

     1  /*
     2  Copyright 2017 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 controllerrevision
    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/apps"
    28  	"k8s.io/kubernetes/pkg/apis/apps/validation"
    29  )
    30  
    31  // strategy implements behavior for ConfigMap objects
    32  type strategy struct {
    33  	runtime.ObjectTyper
    34  	names.NameGenerator
    35  }
    36  
    37  // Strategy is the default logic that applies when creating and updating ControllerRevision
    38  // objects via the REST API.
    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  func (strategy) NamespaceScoped() bool {
    48  	return true
    49  }
    50  
    51  func (strategy) Canonicalize(obj runtime.Object) {
    52  }
    53  
    54  func (strategy) AllowCreateOnUpdate() bool {
    55  	return false
    56  }
    57  
    58  func (strategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
    59  	_ = obj.(*apps.ControllerRevision)
    60  }
    61  
    62  func (strategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
    63  	revision := obj.(*apps.ControllerRevision)
    64  
    65  	return validation.ValidateControllerRevision(revision)
    66  }
    67  
    68  // WarningsOnCreate returns warnings for the creation of the given object.
    69  func (strategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string { return nil }
    70  
    71  func (strategy) PrepareForUpdate(ctx context.Context, newObj, oldObj runtime.Object) {
    72  	_ = oldObj.(*apps.ControllerRevision)
    73  	_ = newObj.(*apps.ControllerRevision)
    74  }
    75  
    76  func (strategy) AllowUnconditionalUpdate() bool {
    77  	return true
    78  }
    79  
    80  func (strategy) ValidateUpdate(ctx context.Context, newObj, oldObj runtime.Object) field.ErrorList {
    81  	oldRevision, newRevision := oldObj.(*apps.ControllerRevision), newObj.(*apps.ControllerRevision)
    82  	return validation.ValidateControllerRevisionUpdate(newRevision, oldRevision)
    83  }
    84  
    85  // WarningsOnUpdate returns warnings for the given update.
    86  func (strategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string { return nil }
    87  

View as plain text