// NewImageStreamMappingEvaluator computes resource usage for ImageStreamMapping objects. This particular kind
// is a virtual resource. It depends on ImageStream usage evaluator to compute image numbers before the
// the admission can work.
func NewImageStreamMappingEvaluator(osClient osclient.Interface) kquota.Evaluator {
	computeResources := []kapi.ResourceName{
		imageapi.ResourceImages,
	}

	matchesScopeFunc := func(kapi.ResourceQuotaScope, runtime.Object) bool { return true }

	return quotautil.NewSharedContextEvaluator(
		imageStreamMappingName,
		kapi.Kind("ImageStreamMapping"),
		map[admission.Operation][]kapi.ResourceName{admission.Create: computeResources},
		computeResources,
		matchesScopeFunc,
		nil,
		nil,
		imageStreamMappingConstraintsFunc,
		makeImageStreamMappingUsageComputerFactory(osClient))
}
// NewImageStreamTagEvaluator computes resource usage of ImageStreamsTags. Its sole purpose is to handle
// UPDATE admission operations on imageStreamTags resource.
func NewImageStreamTagEvaluator(osClient osclient.Interface) kquota.Evaluator {
	computeResources := []kapi.ResourceName{
		imageapi.ResourceImages,
	}

	matchesScopeFunc := func(kapi.ResourceQuotaScope, runtime.Object) bool { return true }
	getFuncByNamespace := func(namespace, id string) (runtime.Object, error) {
		nameParts := strings.SplitN(id, ":", 2)
		if len(nameParts) != 2 {
			return nil, fmt.Errorf("%q is an invalid id for an imagestreamtag. Must be in form <name>:<tag>.", id)
		}

		obj, err := osClient.ImageStreamTags(namespace).Get(nameParts[0], nameParts[1])
		if err != nil {
			if !kerrors.IsNotFound(err) {
				return nil, err
			}
			obj = &imageapi.ImageStreamTag{
				ObjectMeta: kapi.ObjectMeta{
					Namespace: namespace,
					Name:      id,
				},
			}
		}
		return obj, nil
	}

	return quotautil.NewSharedContextEvaluator(
		imageStreamTagEvaluatorName,
		kapi.Kind("ImageStreamTag"),
		map[admission.Operation][]kapi.ResourceName{admission.Update: computeResources},
		computeResources,
		matchesScopeFunc,
		getFuncByNamespace,
		nil,
		imageStreamTagConstraintsFunc,
		makeImageStreamTagUsageComputerFactory(osClient))
}
예제 #3
0
// NewImageStreamEvaluator computes resource usage of ImageStreams. Instantiating this is necessary for
// resource quota admission controller to properly work on image stream related objects.
func NewImageStreamEvaluator(osClient osclient.Interface) kquota.Evaluator {
	computeResources := []kapi.ResourceName{
		imageapi.ResourceImages,
	}

	matchesScopeFunc := func(kapi.ResourceQuotaScope, runtime.Object) bool { return true }
	getFuncByNamespace := func(namespace, name string) (runtime.Object, error) {
		return osClient.ImageStreams(namespace).Get(name)
	}
	listFuncByNamespace := func(namespace string, options kapi.ListOptions) (runtime.Object, error) {
		return osClient.ImageStreams(namespace).List(options)
	}

	return quotautil.NewSharedContextEvaluator(
		imageStreamEvaluatorName,
		kapi.Kind("ImageStream"),
		nil,
		computeResources,
		matchesScopeFunc,
		getFuncByNamespace,
		listFuncByNamespace,
		imageStreamConstraintsFunc,
		makeImageStreamUsageComputerFactory(osClient))
}