...

Source file src/k8s.io/kubernetes/pkg/registry/storage/volumeattributesclass/strategy.go

Documentation: k8s.io/kubernetes/pkg/registry/storage/volumeattributesclass

     1  /*
     2  Copyright 2023 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 volumeattributesclass
    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/storage"
    27  	"k8s.io/kubernetes/pkg/apis/storage/validation"
    28  )
    29  
    30  // volumeAttributesClassStrategy implements behavior for VolumeAttributesClassStrategy objects
    31  type volumeAttributesClassStrategy struct {
    32  	runtime.ObjectTyper
    33  	names.NameGenerator
    34  }
    35  
    36  // Strategy is the default logic that applies when creating and updating
    37  // VolumeAttributesClass objects via the REST API.
    38  var Strategy = volumeAttributesClassStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
    39  
    40  func (volumeAttributesClassStrategy) NamespaceScoped() bool {
    41  	return false
    42  }
    43  
    44  // ResetBeforeCreate clears the Status field which is not allowed to be set by end users on creation.
    45  func (volumeAttributesClassStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
    46  }
    47  
    48  func (volumeAttributesClassStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
    49  	volumeAttributesClass := obj.(*storage.VolumeAttributesClass)
    50  	return validation.ValidateVolumeAttributesClass(volumeAttributesClass)
    51  }
    52  
    53  // WarningsOnCreate returns warnings for the creation of the given object.
    54  func (volumeAttributesClassStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
    55  	return nil
    56  }
    57  
    58  // Canonicalize normalizes the object after validation.
    59  func (volumeAttributesClassStrategy) Canonicalize(obj runtime.Object) {
    60  }
    61  
    62  func (volumeAttributesClassStrategy) AllowCreateOnUpdate() bool {
    63  	return false
    64  }
    65  
    66  // PrepareForUpdate sets the Status fields which is not allowed to be set by an end user updating a PV
    67  func (volumeAttributesClassStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
    68  }
    69  
    70  func (volumeAttributesClassStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
    71  	errorList := validation.ValidateVolumeAttributesClass(obj.(*storage.VolumeAttributesClass))
    72  	return append(errorList, validation.ValidateVolumeAttributesClassUpdate(obj.(*storage.VolumeAttributesClass), old.(*storage.VolumeAttributesClass))...)
    73  }
    74  
    75  // WarningsOnUpdate returns warnings for the given update.
    76  func (volumeAttributesClassStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
    77  	return nil
    78  }
    79  
    80  func (volumeAttributesClassStrategy) AllowUnconditionalUpdate() bool {
    81  	return true
    82  }
    83  

View as plain text