forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
registry.go
51 lines (47 loc) · 2.79 KB
/
registry.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
// Package image implements evaluators of usage for imagestreams and images. They are supposed
// to be passed to resource quota controller and origin resource quota admission plugin.
package image
import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/kubernetes/pkg/quota"
"k8s.io/kubernetes/pkg/quota/generic"
imageapi "github.com/openshift/origin/pkg/image/apis/image"
imageinternalversion "github.com/openshift/origin/pkg/image/generated/informers/internalversion/image/internalversion"
imageclient "github.com/openshift/origin/pkg/image/generated/internalclientset/typed/image/internalversion"
)
// NewImageQuotaRegistry returns a registry for quota evaluation of OpenShift resources related to images in
// internal registry. It evaluates only image streams and related virtual resources that can cause a creation
// of new image stream objects.
func NewImageQuotaRegistry(isInformer imageinternalversion.ImageStreamInformer, imageClient imageclient.ImageStreamTagsGetter) quota.Registry {
imageStream := NewImageStreamEvaluator(isInformer.Lister())
imageStreamTag := NewImageStreamTagEvaluator(isInformer.Lister(), imageClient)
imageStreamImport := NewImageStreamImportEvaluator(isInformer.Lister())
return &generic.GenericRegistry{
InternalEvaluators: map[schema.GroupKind]quota.Evaluator{
imageStream.GroupKind(): imageStream,
imageStreamTag.GroupKind(): imageStreamTag,
imageStreamImport.GroupKind(): imageStreamImport,
},
}
}
// NewImageQuotaRegistryForAdmission returns a registry for quota evaluation of OpenShift resources related to images in
// internal registry. It evaluates only image streams and related virtual resources that can cause a creation
// of new image stream objects.
// This is different that is used for reconciliation because admission has to check all forms of a resource (legacy and groupified), but
// reconciliation only has to check one.
func NewImageQuotaRegistryForAdmission(isInformer imageinternalversion.ImageStreamInformer, imageClient imageclient.ImageStreamTagsGetter) quota.Registry {
imageStream := NewImageStreamEvaluator(isInformer.Lister())
imageStreamTag := NewImageStreamTagEvaluator(isInformer.Lister(), imageClient)
imageStreamImport := NewImageStreamImportEvaluator(isInformer.Lister())
return &generic.GenericRegistry{
// TODO remove the LegacyKind entries below when the legacy api group is no longer supported
InternalEvaluators: map[schema.GroupKind]quota.Evaluator{
imageapi.LegacyKind("ImageStream"): imageStream,
imageStream.GroupKind(): imageStream,
imageapi.LegacyKind("ImageStreamTag"): imageStreamTag,
imageStreamTag.GroupKind(): imageStreamTag,
imageapi.LegacyKind("ImageStreamImport"): imageStreamImport,
imageStreamImport.GroupKind(): imageStreamImport,
},
}
}