k8s.io/kubernetes@v1.29.3/pkg/registry/storage/csinode/strategy.go (about) 1 /* 2 Copyright 2019 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 csinode 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 // csiNodeStrategy implements behavior for CSINode objects 31 type csiNodeStrategy struct { 32 runtime.ObjectTyper 33 names.NameGenerator 34 } 35 36 // Strategy is the default logic that applies when creating and updating 37 // CSINode objects via the REST API. 38 var Strategy = csiNodeStrategy{legacyscheme.Scheme, names.SimpleNameGenerator} 39 40 func (csiNodeStrategy) NamespaceScoped() bool { 41 return false 42 } 43 44 // PrepareForCreate clears fields that are not allowed to be set on creation. 45 func (csiNodeStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) { 46 } 47 48 func (csiNodeStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList { 49 csiNode := obj.(*storage.CSINode) 50 validateOptions := validation.CSINodeValidationOptions{ 51 AllowLongNodeID: true, 52 } 53 54 errs := validation.ValidateCSINode(csiNode, validateOptions) 55 56 return errs 57 } 58 59 // WarningsOnCreate returns warnings for the creation of the given object. 60 func (csiNodeStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string { return nil } 61 62 // Canonicalize normalizes the object after validation. 63 func (csiNodeStrategy) Canonicalize(obj runtime.Object) { 64 } 65 66 func (csiNodeStrategy) AllowCreateOnUpdate() bool { 67 return false 68 } 69 70 // PrepareForUpdate sets the driver's Allocatable fields that are not allowed to be set by an end user updating a CSINode. 71 func (csiNodeStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) { 72 } 73 74 func (csiNodeStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList { 75 newCSINodeObj := obj.(*storage.CSINode) 76 oldCSINodeObj := old.(*storage.CSINode) 77 validateOptions := validation.CSINodeValidationOptions{ 78 AllowLongNodeID: true, 79 } 80 81 errorList := validation.ValidateCSINode(newCSINodeObj, validateOptions) 82 return append(errorList, validation.ValidateCSINodeUpdate(newCSINodeObj, oldCSINodeObj, validateOptions)...) 83 } 84 85 // WarningsOnUpdate returns warnings for the given update. 86 func (csiNodeStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string { 87 return nil 88 } 89 90 func (csiNodeStrategy) AllowUnconditionalUpdate() bool { 91 return false 92 }