strategy.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. Copyright 2019 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package csinode
  14. import (
  15. "context"
  16. "k8s.io/apimachinery/pkg/runtime"
  17. "k8s.io/apimachinery/pkg/util/validation/field"
  18. "k8s.io/apiserver/pkg/storage/names"
  19. "k8s.io/kubernetes/pkg/api/legacyscheme"
  20. "k8s.io/kubernetes/pkg/apis/storage"
  21. "k8s.io/kubernetes/pkg/apis/storage/validation"
  22. )
  23. // csiNodeStrategy implements behavior for CSINode objects
  24. type csiNodeStrategy struct {
  25. runtime.ObjectTyper
  26. names.NameGenerator
  27. }
  28. // Strategy is the default logic that applies when creating and updating
  29. // CSINode objects via the REST API.
  30. var Strategy = csiNodeStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
  31. func (csiNodeStrategy) NamespaceScoped() bool {
  32. return false
  33. }
  34. // ResetBeforeCreate clears the Status field which is not allowed to be set by end users on creation.
  35. func (csiNodeStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
  36. }
  37. func (csiNodeStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
  38. csiNode := obj.(*storage.CSINode)
  39. errs := validation.ValidateCSINode(csiNode)
  40. errs = append(errs, validation.ValidateCSINode(csiNode)...)
  41. return errs
  42. }
  43. // Canonicalize normalizes the object after validation.
  44. func (csiNodeStrategy) Canonicalize(obj runtime.Object) {
  45. }
  46. func (csiNodeStrategy) AllowCreateOnUpdate() bool {
  47. return false
  48. }
  49. // PrepareForUpdate sets the Status fields which is not allowed to be set by an end user updating a CSINode
  50. func (csiNodeStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
  51. }
  52. func (csiNodeStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
  53. newCSINodeObj := obj.(*storage.CSINode)
  54. oldCSINodeObj := old.(*storage.CSINode)
  55. errorList := validation.ValidateCSINode(newCSINodeObj)
  56. return append(errorList, validation.ValidateCSINodeUpdate(newCSINodeObj, oldCSINodeObj)...)
  57. }
  58. func (csiNodeStrategy) AllowUnconditionalUpdate() bool {
  59. return false
  60. }