// ObjectCountConstraintsFunc returns ConstraintsFunc that returns nil if the // specified resource name is in the required set of resource names func ObjectCountConstraintsFunc(resourceName api.ResourceName) ConstraintsFunc { return func(required []api.ResourceName, item runtime.Object) error { if !quota.Contains(required, resourceName) { return fmt.Errorf("missing %s", resourceName) } return nil } }
// MatchingResources takes the input specified list of resources and returns the set of resources it matches. func (p *pvcEvaluator) MatchingResources(items []api.ResourceName) []api.ResourceName { result := []api.ResourceName{} for _, item := range items { if quota.Contains(pvcResources, item) { result = append(result, item) continue } // match pvc resources scoped by storage class (<storage-class-name>.storage-class.kubernetes.io/<resource>) for _, resource := range pvcResources { byStorageClass := storageClassSuffix + string(resource) if strings.HasSuffix(string(item), byStorageClass) { result = append(result, item) break } } } return result }
// Constraints returns an error if the configured resource name is not in the required set. func (o *ObjectCountEvaluator) Constraints(required []api.ResourceName, item runtime.Object) error { if !quota.Contains(required, o.ResourceName) { return fmt.Errorf("missing %s", o.ResourceName) } return nil }