Extract function getLimitRangeList
@@ -20,6 +20,7 @@ import (
"github.com/docker/distribution/context"
kapi "k8s.io/kubernetes/pkg/api"
+ kcoreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
imageadmission "github.com/openshift/origin/pkg/image/admission"
)
@@ -136,37 +137,43 @@ func (bw *quotaRestrictedBlobWriter) Commit(ctx context.Context, provisional dis
return bw.BlobWriter.Commit(ctx, provisional)
}
-// admitBlobWrite checks whether the blob does not exceed image limit ranges if set. Returns ErrAccessDenied
-// error if the limit is exceeded.
-func admitBlobWrite(ctx context.Context, repo *repository, size int64) error {
- if size < 1 {
- return nil
- }
-
- var (
- lrs *kapi.LimitRangeList
- err error
- )
-
+// getLimitRangeList returns list of limit ranges for namespace.
+func getLimitRangeList(ctx context.Context, limitClient kcoreclient.LimitRangesGetter, namespace string) (*kapi.LimitRangeList, error) {
if !quotaEnforcing.projectCacheDisabled {
- obj, exists, _ := quotaEnforcing.limitRanges.get(repo.namespace)
+ obj, exists, _ := quotaEnforcing.limitRanges.get(namespace)
if exists {
- lrs = obj.(*kapi.LimitRangeList)
+ return obj.(*kapi.LimitRangeList), nil
}
}
- if lrs == nil {
- context.GetLogger(ctx).Debugf("listing limit ranges in namespace %s", repo.namespace)
- lrs, err = repo.limitClient.LimitRanges(repo.namespace).List(kapi.ListOptions{})
+
+ context.GetLogger(ctx).Debugf("listing limit ranges in namespace %s", namespace)
+
+ lrs, err := limitClient.LimitRanges(namespace).List(kapi.ListOptions{})
if err != nil {
context.GetLogger(ctx).Errorf("failed to list limitranges: %v", err)
- return err
+ return nil, err
}
+
if !quotaEnforcing.projectCacheDisabled {
- err = quotaEnforcing.limitRanges.add(repo.namespace, lrs)
+ err = quotaEnforcing.limitRanges.add(namespace, lrs)
if err != nil {
context.GetLogger(ctx).Errorf("failed to cache limit range list: %v", err)
}
}
+
+ return lrs, nil
+}
+
+// admitBlobWrite checks whether the blob does not exceed image limit ranges if set. Returns ErrAccessDenied
+// error if the limit is exceeded.
+func admitBlobWrite(ctx context.Context, repo *repository, size int64) error {
+ if size < 1 {
+ return nil
+ }
+
+ lrs, err := getLimitRangeList(ctx, repo.limitClient, repo.namespace)
+ if err != nil {
+ return err
}
for _, limitrange := range lrs.Items {
