...

Source file src/k8s.io/kubernetes/pkg/registry/resource/resourceclass/strategy.go

Documentation: k8s.io/kubernetes/pkg/registry/resource/resourceclass

     1  /*
     2  Copyright 2022 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 resourceclass
    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/storage/names"
    25  	"k8s.io/kubernetes/pkg/api/legacyscheme"
    26  	"k8s.io/kubernetes/pkg/apis/resource"
    27  	"k8s.io/kubernetes/pkg/apis/resource/validation"
    28  )
    29  
    30  // resourceClassStrategy implements behavior for ResourceClass objects
    31  type resourceClassStrategy struct {
    32  	runtime.ObjectTyper
    33  	names.NameGenerator
    34  }
    35  
    36  var Strategy = resourceClassStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
    37  
    38  func (resourceClassStrategy) NamespaceScoped() bool {
    39  	return false
    40  }
    41  
    42  func (resourceClassStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
    43  }
    44  
    45  func (resourceClassStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
    46  	resourceClass := obj.(*resource.ResourceClass)
    47  	return validation.ValidateClass(resourceClass)
    48  }
    49  
    50  func (resourceClassStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
    51  	return nil
    52  }
    53  
    54  func (resourceClassStrategy) Canonicalize(obj runtime.Object) {
    55  }
    56  
    57  func (resourceClassStrategy) AllowCreateOnUpdate() bool {
    58  	return false
    59  }
    60  
    61  func (resourceClassStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
    62  }
    63  
    64  func (resourceClassStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
    65  	errorList := validation.ValidateClass(obj.(*resource.ResourceClass))
    66  	return append(errorList, validation.ValidateClassUpdate(obj.(*resource.ResourceClass), old.(*resource.ResourceClass))...)
    67  }
    68  
    69  func (resourceClassStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
    70  	return nil
    71  }
    72  
    73  func (resourceClassStrategy) AllowUnconditionalUpdate() bool {
    74  	return true
    75  }
    76  

View as plain text