...
1
16
17 package limitrange
18
19 import (
20 "context"
21
22 "k8s.io/apimachinery/pkg/runtime"
23 "k8s.io/apimachinery/pkg/util/uuid"
24 "k8s.io/apimachinery/pkg/util/validation/field"
25 "k8s.io/apiserver/pkg/storage/names"
26 "k8s.io/kubernetes/pkg/api/legacyscheme"
27 api "k8s.io/kubernetes/pkg/apis/core"
28 "k8s.io/kubernetes/pkg/apis/core/validation"
29 )
30
31 type limitrangeStrategy struct {
32 runtime.ObjectTyper
33 names.NameGenerator
34 }
35
36
37
38 var Strategy = limitrangeStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
39
40 func (limitrangeStrategy) NamespaceScoped() bool {
41 return true
42 }
43
44 func (limitrangeStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
45 limitRange := obj.(*api.LimitRange)
46 if len(limitRange.Name) == 0 {
47 limitRange.Name = string(uuid.NewUUID())
48 }
49 }
50
51 func (limitrangeStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
52 }
53
54 func (limitrangeStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
55 limitRange := obj.(*api.LimitRange)
56 return validation.ValidateLimitRange(limitRange)
57 }
58
59
60 func (limitrangeStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
61 return nil
62 }
63
64
65 func (limitrangeStrategy) Canonicalize(obj runtime.Object) {
66 }
67
68 func (limitrangeStrategy) AllowCreateOnUpdate() bool {
69 return true
70 }
71
72 func (limitrangeStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
73 limitRange := obj.(*api.LimitRange)
74 return validation.ValidateLimitRange(limitRange)
75 }
76
77
78 func (limitrangeStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
79 return nil
80 }
81
82 func (limitrangeStrategy) AllowUnconditionalUpdate() bool {
83 return true
84 }
85
View as plain text