forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strategy.go
129 lines (99 loc) · 3.68 KB
/
strategy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package clusterresourcequota
import (
"fmt"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
apirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/storage"
kapi "k8s.io/kubernetes/pkg/api"
quotaapi "github.com/openshift/origin/pkg/quota/apis/quota"
"github.com/openshift/origin/pkg/quota/apis/quota/validation"
)
type strategy struct {
runtime.ObjectTyper
}
var Strategy = strategy{kapi.Scheme}
func (strategy) DefaultGarbageCollectionPolicy() rest.GarbageCollectionPolicy {
return rest.Unsupported
}
func (strategy) NamespaceScoped() bool {
return false
}
func (strategy) AllowCreateOnUpdate() bool {
return false
}
func (strategy) AllowUnconditionalUpdate() bool {
return false
}
func (strategy) GenerateName(base string) string {
return base
}
func (strategy) PrepareForCreate(ctx apirequest.Context, obj runtime.Object) {
quota := obj.(*quotaapi.ClusterResourceQuota)
quota.Status = quotaapi.ClusterResourceQuotaStatus{}
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func (strategy) PrepareForUpdate(ctx apirequest.Context, obj, old runtime.Object) {
curr := obj.(*quotaapi.ClusterResourceQuota)
prev := old.(*quotaapi.ClusterResourceQuota)
curr.Status = prev.Status
}
// Canonicalize normalizes the object after validation.
func (strategy) Canonicalize(obj runtime.Object) {
}
func (strategy) Validate(ctx apirequest.Context, obj runtime.Object) field.ErrorList {
return validation.ValidateClusterResourceQuota(obj.(*quotaapi.ClusterResourceQuota))
}
func (strategy) ValidateUpdate(ctx apirequest.Context, obj, old runtime.Object) field.ErrorList {
return validation.ValidateClusterResourceQuotaUpdate(obj.(*quotaapi.ClusterResourceQuota), old.(*quotaapi.ClusterResourceQuota))
}
// GetAttrs returns labels and fields of a given object for filtering purposes
func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, bool, error) {
quota, ok := obj.(*quotaapi.ClusterResourceQuota)
if !ok {
return nil, nil, false, fmt.Errorf("not a ClusterResourceQuota")
}
return labels.Set(quota.ObjectMeta.Labels), quotaapi.ClusterResourceQuotaToSelectableFields(quota), quota.Initializers != nil, nil
}
// Matcher returns a generic matcher for a given label and field selector.
func Matcher(label labels.Selector, field fields.Selector) storage.SelectionPredicate {
return storage.SelectionPredicate{
Label: label,
Field: field,
GetAttrs: GetAttrs,
}
}
type statusStrategy struct {
runtime.ObjectTyper
}
var StatusStrategy = statusStrategy{kapi.Scheme}
func (statusStrategy) NamespaceScoped() bool {
return false
}
func (statusStrategy) AllowCreateOnUpdate() bool {
return false
}
func (statusStrategy) AllowUnconditionalUpdate() bool {
return false
}
func (statusStrategy) GenerateName(base string) string {
return base
}
func (statusStrategy) PrepareForCreate(ctx apirequest.Context, obj runtime.Object) {
}
func (statusStrategy) PrepareForUpdate(ctx apirequest.Context, obj, old runtime.Object) {
curr := obj.(*quotaapi.ClusterResourceQuota)
prev := old.(*quotaapi.ClusterResourceQuota)
curr.Spec = prev.Spec
}
func (statusStrategy) Canonicalize(obj runtime.Object) {
}
func (statusStrategy) Validate(ctx apirequest.Context, obj runtime.Object) field.ErrorList {
return validation.ValidateClusterResourceQuota(obj.(*quotaapi.ClusterResourceQuota))
}
func (statusStrategy) ValidateUpdate(ctx apirequest.Context, obj, old runtime.Object) field.ErrorList {
return validation.ValidateClusterResourceQuotaUpdate(obj.(*quotaapi.ClusterResourceQuota), old.(*quotaapi.ClusterResourceQuota))
}