-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
strategy.go
97 lines (77 loc) · 2.55 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
package imagestreamtag
import (
"fmt"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/registry/generic"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/validation/field"
"github.com/openshift/origin/pkg/image/api"
"github.com/openshift/origin/pkg/image/api/validation"
)
// strategy implements behavior for ImageStreamTags.
type strategy struct {
runtime.ObjectTyper
}
var Strategy = &strategy{
ObjectTyper: kapi.Scheme,
}
func (s *strategy) NamespaceScoped() bool {
return true
}
func (s *strategy) PrepareForCreate(obj runtime.Object) {
newIST := obj.(*api.ImageStreamTag)
newIST.Conditions = nil
newIST.Image = api.Image{}
}
func (s *strategy) GenerateName(base string) string {
return base
}
func (s *strategy) Validate(ctx kapi.Context, obj runtime.Object) field.ErrorList {
istag := obj.(*api.ImageStreamTag)
return validation.ValidateImageStreamTag(istag)
}
func (s *strategy) AllowCreateOnUpdate() bool {
return false
}
func (*strategy) AllowUnconditionalUpdate() bool {
return false
}
// Canonicalize normalizes the object after validation.
func (strategy) Canonicalize(obj runtime.Object) {
}
func (s *strategy) PrepareForUpdate(obj, old runtime.Object) {
newIST := obj.(*api.ImageStreamTag)
oldIST := old.(*api.ImageStreamTag)
// for backwards compatibility, callers can't be required to set both annotation locations when
// doing a GET and then update.
if newIST.Tag != nil {
newIST.Tag.Annotations = newIST.Annotations
}
newIST.Conditions = oldIST.Conditions
newIST.SelfLink = oldIST.SelfLink
newIST.Image = oldIST.Image
}
func (s *strategy) ValidateUpdate(ctx kapi.Context, obj, old runtime.Object) field.ErrorList {
newIST := obj.(*api.ImageStreamTag)
oldIST := old.(*api.ImageStreamTag)
return validation.ValidateImageStreamTagUpdate(newIST, oldIST)
}
// MatchImageStreamTag returns a generic matcher for a given label and field selector.
func MatchImageStreamTag(label labels.Selector, field fields.Selector) generic.Matcher {
return generic.MatcherFunc(func(obj runtime.Object) (bool, error) {
target, ok := obj.(*api.ImageStreamTag)
if !ok {
return false, fmt.Errorf("not an ImageStreamTag")
}
fields := ImageStreamToSelectableFields(target)
return label.Matches(labels.Set(target.Labels)) && field.Matches(fields), nil
})
}
// ImageStreamToSelectableFields returns a label set that represents the object.
func ImageStreamToSelectableFields(target *api.ImageStreamTag) labels.Set {
return labels.Set{
"metadata.name": target.Name,
}
}