1 /* 2 Copyright 2018 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package fsquota 18 19 import ( 20 "k8s.io/mount-utils" 21 22 "k8s.io/apimachinery/pkg/api/resource" 23 "k8s.io/apimachinery/pkg/types" 24 utilfeature "k8s.io/apiserver/pkg/util/feature" 25 "k8s.io/kubernetes/pkg/features" 26 "k8s.io/kubernetes/pkg/volume/util/fsquota/common" 27 ) 28 29 // Interface -- quota interface 30 type Interface interface { 31 // GetQuotaOnDir gets the quota ID (if any) that applies to 32 // this directory 33 GetQuotaOnDir(m mount.Interface, path string) (common.QuotaID, error) 34 35 // Does the path provided support quotas, and if so, what types 36 SupportsQuotas(m mount.Interface, path string) (bool, error) 37 // Assign a quota (picked by the quota mechanism) to a path, 38 // and return it. 39 AssignQuota(m mount.Interface, path string, poduid types.UID, bytes *resource.Quantity) error 40 41 // Get the quota-based storage consumption for the path 42 GetConsumption(path string) (*resource.Quantity, error) 43 44 // Get the quota-based inode consumption for the path 45 GetInodes(path string) (*resource.Quantity, error) 46 47 // Remove the quota from a path 48 // Implementations may assume that any data covered by the 49 // quota has already been removed. 50 ClearQuota(m mount.Interface, path string) error 51 } 52 53 func enabledQuotasForMonitoring() bool { 54 return utilfeature.DefaultFeatureGate.Enabled(features.LocalStorageCapacityIsolationFSQuotaMonitoring) 55 } 56