This repository has been archived by the owner on Jul 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
strategy.go
120 lines (92 loc) · 3.27 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
package clusterresourcequota
import (
"fmt"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/storage"
"k8s.io/kubernetes/pkg/util/validation/field"
quotaapi "github.com/openshift/origin/pkg/quota/api"
"github.com/openshift/origin/pkg/quota/api/validation"
)
type strategy struct {
runtime.ObjectTyper
}
var Strategy = strategy{kapi.Scheme}
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 kapi.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 kapi.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 kapi.Context, obj runtime.Object) field.ErrorList {
return validation.ValidateClusterResourceQuota(obj.(*quotaapi.ClusterResourceQuota))
}
func (strategy) ValidateUpdate(ctx kapi.Context, obj, old runtime.Object) field.ErrorList {
return validation.ValidateClusterResourceQuotaUpdate(obj.(*quotaapi.ClusterResourceQuota), old.(*quotaapi.ClusterResourceQuota))
}
// 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: func(obj runtime.Object) (labels.Set, fields.Set, error) {
quota, ok := obj.(*quotaapi.ClusterResourceQuota)
if !ok {
return nil, nil, fmt.Errorf("not a quota")
}
return labels.Set(quota.ObjectMeta.Labels), quotaapi.ClusterResourceQuotaToSelectableFields(quota), nil
},
}
}
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 kapi.Context, obj runtime.Object) {
}
func (statusStrategy) PrepareForUpdate(ctx kapi.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 kapi.Context, obj runtime.Object) field.ErrorList {
return validation.ValidateClusterResourceQuota(obj.(*quotaapi.ClusterResourceQuota))
}
func (statusStrategy) ValidateUpdate(ctx kapi.Context, obj, old runtime.Object) field.ErrorList {
return validation.ValidateClusterResourceQuotaUpdate(obj.(*quotaapi.ClusterResourceQuota), old.(*quotaapi.ClusterResourceQuota))
}