strategy.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Copyright 2017 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 controllerrevision
  14. import (
  15. "context"
  16. "k8s.io/apimachinery/pkg/runtime"
  17. "k8s.io/apimachinery/pkg/util/validation/field"
  18. "k8s.io/apiserver/pkg/registry/rest"
  19. "k8s.io/apiserver/pkg/storage/names"
  20. "k8s.io/kubernetes/pkg/api/legacyscheme"
  21. "k8s.io/kubernetes/pkg/apis/apps"
  22. "k8s.io/kubernetes/pkg/apis/apps/validation"
  23. )
  24. // strategy implements behavior for ConfigMap objects
  25. type strategy struct {
  26. runtime.ObjectTyper
  27. names.NameGenerator
  28. }
  29. // Strategy is the default logic that applies when creating and updating ControllerRevision
  30. // objects via the REST API.
  31. var Strategy = strategy{legacyscheme.Scheme, names.SimpleNameGenerator}
  32. // Strategy should implement rest.RESTCreateStrategy
  33. var _ rest.RESTCreateStrategy = Strategy
  34. // Strategy should implement rest.RESTUpdateStrategy
  35. var _ rest.RESTUpdateStrategy = Strategy
  36. func (strategy) NamespaceScoped() bool {
  37. return true
  38. }
  39. func (strategy) Canonicalize(obj runtime.Object) {
  40. }
  41. func (strategy) AllowCreateOnUpdate() bool {
  42. return false
  43. }
  44. func (strategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
  45. _ = obj.(*apps.ControllerRevision)
  46. }
  47. func (strategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
  48. revision := obj.(*apps.ControllerRevision)
  49. return validation.ValidateControllerRevision(revision)
  50. }
  51. func (strategy) PrepareForUpdate(ctx context.Context, newObj, oldObj runtime.Object) {
  52. _ = oldObj.(*apps.ControllerRevision)
  53. _ = newObj.(*apps.ControllerRevision)
  54. }
  55. func (strategy) AllowUnconditionalUpdate() bool {
  56. return true
  57. }
  58. func (strategy) ValidateUpdate(ctx context.Context, newObj, oldObj runtime.Object) field.ErrorList {
  59. oldRevision, newRevision := oldObj.(*apps.ControllerRevision), newObj.(*apps.ControllerRevision)
  60. return validation.ValidateControllerRevisionUpdate(newRevision, oldRevision)
  61. }