forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strategy.go
64 lines (53 loc) · 1.95 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
package image
import (
"fmt"
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/fielderrors"
"github.com/openshift/origin/pkg/image/api"
"github.com/openshift/origin/pkg/image/api/validation"
)
// imageStrategy implements behavior for Images.
type imageStrategy struct {
runtime.ObjectTyper
kapi.NameGenerator
}
// Strategy is the default logic that applies when creating and updating
// Image objects via the REST API.
var Strategy = imageStrategy{kapi.Scheme, kapi.SimpleNameGenerator}
// NamespaceScoped is false for images.
func (imageStrategy) NamespaceScoped() bool {
return false
}
// PrepareForCreate clears fields that are not allowed to be set by end users on creation.
func (imageStrategy) PrepareForCreate(obj runtime.Object) {
}
// Validate validates a new image.
func (imageStrategy) Validate(ctx kapi.Context, obj runtime.Object) fielderrors.ValidationErrorList {
image := obj.(*api.Image)
return validation.ValidateImage(image)
}
// AllowCreateOnUpdate is false for images.
func (imageStrategy) AllowCreateOnUpdate() bool {
return false
}
// MatchImage returns a generic matcher for a given label and field selector.
func MatchImage(label labels.Selector, field fields.Selector) generic.Matcher {
return generic.MatcherFunc(func(obj runtime.Object) (bool, error) {
image, ok := obj.(*api.Image)
if !ok {
return false, fmt.Errorf("not an image")
}
fields := ImageToSelectableFields(image)
return label.Matches(labels.Set(image.Labels)) && field.Matches(fields), nil
})
}
// ImageToSelectableFields returns a label set that represents the object.
func ImageToSelectableFields(image *api.Image) labels.Set {
return labels.Set{
"name": image.Name,
}
}