...

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

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

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

View as plain text