strategy.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. Copyright 2018 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 lease
  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/coordination"
  21. "k8s.io/kubernetes/pkg/apis/coordination/validation"
  22. )
  23. // leaseStrategy implements verification logic for Leases.
  24. type leaseStrategy struct {
  25. runtime.ObjectTyper
  26. names.NameGenerator
  27. }
  28. // Strategy is the default logic that applies when creating and updating Lease objects.
  29. var Strategy = leaseStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
  30. // NamespaceScoped returns true because all Lease' need to be within a namespace.
  31. func (leaseStrategy) NamespaceScoped() bool {
  32. return true
  33. }
  34. // PrepareForCreate prepares Lease for creation.
  35. func (leaseStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
  36. }
  37. // PrepareForUpdate clears fields that are not allowed to be set by end users on update.
  38. func (leaseStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
  39. }
  40. // Validate validates a new Lease.
  41. func (leaseStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
  42. lease := obj.(*coordination.Lease)
  43. return validation.ValidateLease(lease)
  44. }
  45. // Canonicalize normalizes the object after validation.
  46. func (leaseStrategy) Canonicalize(obj runtime.Object) {
  47. }
  48. // AllowCreateOnUpdate is true for Lease; this means you may create one with a PUT request.
  49. func (leaseStrategy) AllowCreateOnUpdate() bool {
  50. return true
  51. }
  52. // ValidateUpdate is the default update validation for an end user.
  53. func (leaseStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
  54. return validation.ValidateLeaseUpdate(obj.(*coordination.Lease), old.(*coordination.Lease))
  55. }
  56. // AllowUnconditionalUpdate is the default update policy for Lease objects.
  57. func (leaseStrategy) AllowUnconditionalUpdate() bool {
  58. return false
  59. }