...
1
16
17 package configmap
18
19 import (
20 "context"
21 "fmt"
22
23 "k8s.io/apimachinery/pkg/fields"
24 "k8s.io/apimachinery/pkg/labels"
25 "k8s.io/apimachinery/pkg/runtime"
26 "k8s.io/apimachinery/pkg/util/validation/field"
27 "k8s.io/apiserver/pkg/registry/generic"
28 "k8s.io/apiserver/pkg/registry/rest"
29 pkgstorage "k8s.io/apiserver/pkg/storage"
30 "k8s.io/apiserver/pkg/storage/names"
31 "k8s.io/kubernetes/pkg/api/legacyscheme"
32 api "k8s.io/kubernetes/pkg/apis/core"
33 "k8s.io/kubernetes/pkg/apis/core/validation"
34 )
35
36
37 type strategy struct {
38 runtime.ObjectTyper
39 names.NameGenerator
40 }
41
42
43
44 var Strategy = strategy{legacyscheme.Scheme, names.SimpleNameGenerator}
45
46
47 var _ rest.RESTCreateStrategy = Strategy
48
49
50 var _ rest.RESTUpdateStrategy = Strategy
51
52 func (strategy) NamespaceScoped() bool {
53 return true
54 }
55
56 func (strategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
57 configMap := obj.(*api.ConfigMap)
58 dropDisabledFields(configMap, nil)
59 }
60
61 func (strategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
62 cfg := obj.(*api.ConfigMap)
63
64 return validation.ValidateConfigMap(cfg)
65 }
66
67
68 func (strategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string { return nil }
69
70
71 func (strategy) Canonicalize(obj runtime.Object) {
72 }
73
74 func (strategy) AllowCreateOnUpdate() bool {
75 return false
76 }
77
78 func (strategy) PrepareForUpdate(ctx context.Context, newObj, oldObj runtime.Object) {
79 oldConfigMap := oldObj.(*api.ConfigMap)
80 newConfigMap := newObj.(*api.ConfigMap)
81 dropDisabledFields(newConfigMap, oldConfigMap)
82 }
83
84 func (strategy) ValidateUpdate(ctx context.Context, newObj, oldObj runtime.Object) field.ErrorList {
85 oldCfg, newCfg := oldObj.(*api.ConfigMap), newObj.(*api.ConfigMap)
86
87 return validation.ValidateConfigMapUpdate(newCfg, oldCfg)
88 }
89
90
91 func (strategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string { return nil }
92
93 func dropDisabledFields(configMap *api.ConfigMap, oldConfigMap *api.ConfigMap) {
94 }
95
96 func (strategy) AllowUnconditionalUpdate() bool {
97 return true
98 }
99
100
101 func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) {
102 configMap, ok := obj.(*api.ConfigMap)
103 if !ok {
104 return nil, nil, fmt.Errorf("not a configmap")
105 }
106 return labels.Set(configMap.Labels), SelectableFields(configMap), nil
107 }
108
109
110 func Matcher(label labels.Selector, field fields.Selector) pkgstorage.SelectionPredicate {
111 return pkgstorage.SelectionPredicate{
112 Label: label,
113 Field: field,
114 GetAttrs: GetAttrs,
115 }
116 }
117
118
119 func SelectableFields(obj *api.ConfigMap) fields.Set {
120 return generic.ObjectMetaFieldsSet(&obj.ObjectMeta, true)
121 }
122
View as plain text