diff --git a/pkg/volume/emptydir/empty_dir.go b/pkg/volume/emptydir/empty_dir.go index 4f1061a439e..c42b68ac145 100644 --- a/pkg/volume/emptydir/empty_dir.go +++ b/pkg/volume/emptydir/empty_dir.go @@ -246,7 +246,7 @@ func (ed *emptyDir) SetUpAt(dir string, mounterArgs volume.MounterArgs) error { klog.V(3).Infof("Unable to check for quota support on %s: %s", dir, err.Error()) } else if hasQuotas { klog.V(4).Infof("emptydir trying to assign quota %v on %s", mounterArgs.DesiredSize, dir) - err := fsquota.AssignQuota(ed.mounter, dir, mounterArgs.PodUID, mounterArgs.DesiredSize) + err := fsquota.AssignQuota(ed.mounter, dir, ed.pod.UID, mounterArgs.DesiredSize) if err != nil { klog.V(3).Infof("Set quota on %s failed %s", dir, err.Error()) } diff --git a/pkg/volume/util/fsquota/BUILD b/pkg/volume/util/fsquota/BUILD index e5a73e0e63c..b10fa34e5a5 100644 --- a/pkg/volume/util/fsquota/BUILD +++ b/pkg/volume/util/fsquota/BUILD @@ -14,6 +14,7 @@ go_library( "//pkg/features:go_default_library", "//pkg/util/mount:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/types:go_default_library", "//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library", ] + select({ "@io_bazel_rules_go//go/platform:linux": [ @@ -36,6 +37,7 @@ go_test( "//pkg/util/mount:go_default_library", "//pkg/volume/util/fsquota/common:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/types:go_default_library", "//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library", "//staging/src/k8s.io/component-base/featuregate/testing:go_default_library", ], diff --git a/pkg/volume/util/fsquota/quota.go b/pkg/volume/util/fsquota/quota.go index 1db1595c18a..877b8fe9d28 100644 --- a/pkg/volume/util/fsquota/quota.go +++ b/pkg/volume/util/fsquota/quota.go @@ -18,6 +18,7 @@ package fsquota import ( "k8s.io/apimachinery/pkg/api/resource" + "k8s.io/apimachinery/pkg/types" utilfeature "k8s.io/apiserver/pkg/util/feature" "k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/pkg/util/mount" @@ -29,7 +30,7 @@ type Interface interface { SupportsQuotas(m mount.Interface, path string) (bool, error) // Assign a quota (picked by the quota mechanism) to a path, // and return it. - AssignQuota(m mount.Interface, path string, poduid string, bytes *resource.Quantity) error + AssignQuota(m mount.Interface, path string, poduid types.UID, bytes *resource.Quantity) error // Get the quota-based storage consumption for the path GetConsumption(path string) (*resource.Quantity, error) @@ -40,7 +41,7 @@ type Interface interface { // Remove the quota from a path // Implementations may assume that any data covered by the // quota has already been removed. - ClearQuota(m mount.Interface, path string, poduid string) error + ClearQuota(m mount.Interface, path string) error } func enabledQuotasForMonitoring() bool { diff --git a/pkg/volume/util/fsquota/quota_linux.go b/pkg/volume/util/fsquota/quota_linux.go index 3b502dd33fe..65c24c52070 100644 --- a/pkg/volume/util/fsquota/quota_linux.go +++ b/pkg/volume/util/fsquota/quota_linux.go @@ -26,6 +26,7 @@ import ( "sync" "k8s.io/apimachinery/pkg/api/resource" + "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/klog" "k8s.io/kubernetes/pkg/util/mount" @@ -33,16 +34,16 @@ import ( ) // Pod -> ID -var podQuotaMap = make(map[string]common.QuotaID) +var podQuotaMap = make(map[types.UID]common.QuotaID) // Dir -> ID (for convenience) var dirQuotaMap = make(map[string]common.QuotaID) // ID -> pod -var quotaPodMap = make(map[common.QuotaID]string) +var quotaPodMap = make(map[common.QuotaID]types.UID) // Directory -> pod -var dirPodMap = make(map[string]string) +var dirPodMap = make(map[string]types.UID) // Backing device -> applier // This is *not* cleaned up; its size will be bounded. @@ -53,7 +54,7 @@ var dirApplierMap = make(map[string]common.LinuxVolumeQuotaApplier) var dirApplierLock sync.RWMutex // Pod -> refcount -var podDirCountMap = make(map[string]int) +var podDirCountMap = make(map[types.UID]int) // ID -> size var quotaSizeMap = make(map[common.QuotaID]int64) @@ -296,7 +297,7 @@ func SupportsQuotas(m mount.Interface, path string) (bool, error) { // AssignQuota chooses the quota ID based on the pod UID and path. // If the pod UID is identical to another one known, it may (but presently // doesn't) choose the same quota ID as other volumes in the pod. -func AssignQuota(m mount.Interface, path string, poduid string, bytes *resource.Quantity) error { +func AssignQuota(m mount.Interface, path string, poduid types.UID, bytes *resource.Quantity) error { if bytes == nil { return fmt.Errorf("Attempting to assign null quota to %s", path) } @@ -311,7 +312,7 @@ func AssignQuota(m mount.Interface, path string, poduid string, bytes *resource. // volumes in a pod, we can simply remove this line of code. // If and when we decide permanently that we're going to adop // one quota per volume, we can rip all of the pod code out. - poduid = string(uuid.NewUUID()) + poduid = types.UID(uuid.NewUUID()) if pod, ok := dirPodMap[path]; ok && pod != poduid { return fmt.Errorf("Requesting quota on existing directory %s but different pod %s %s", path, pod, poduid) } diff --git a/pkg/volume/util/fsquota/quota_linux_test.go b/pkg/volume/util/fsquota/quota_linux_test.go index a34b25450ed..06119c738b5 100644 --- a/pkg/volume/util/fsquota/quota_linux_test.go +++ b/pkg/volume/util/fsquota/quota_linux_test.go @@ -22,6 +22,7 @@ import ( "fmt" "io/ioutil" "k8s.io/apimachinery/pkg/api/resource" + "k8s.io/apimachinery/pkg/types" utilfeature "k8s.io/apiserver/pkg/util/feature" featuregatetesting "k8s.io/component-base/featuregate/testing" "k8s.io/kubernetes/pkg/features" @@ -389,7 +390,7 @@ func fakeSupportsQuotas(path string) (bool, error) { return SupportsQuotas(dummyQuotaTest(), path) } -func fakeAssignQuota(path string, poduid string, bytes int64) error { +func fakeAssignQuota(path string, poduid types.UID, bytes int64) error { dummySetFSInfo(path) return AssignQuota(dummyQuotaTest(), path, poduid, resource.NewQuantity(bytes, resource.DecimalSI)) } @@ -401,7 +402,7 @@ func fakeClearQuota(path string) error { type quotaTestCase struct { path string - poduid string + poduid types.UID bytes int64 op string expectedProjects string diff --git a/pkg/volume/util/fsquota/quota_unsupported.go b/pkg/volume/util/fsquota/quota_unsupported.go index 84892ca9e64..f1ae4cdd1f4 100644 --- a/pkg/volume/util/fsquota/quota_unsupported.go +++ b/pkg/volume/util/fsquota/quota_unsupported.go @@ -21,6 +21,7 @@ package fsquota import ( "errors" "k8s.io/apimachinery/pkg/api/resource" + "k8s.io/apimachinery/pkg/types" "k8s.io/kubernetes/pkg/util/mount" ) @@ -35,7 +36,7 @@ func SupportsQuotas(_ mount.Interface, _ string) (bool, error) { } // AssignQuota -- dummy implementation -func AssignQuota(_ mount.Interface, _ string, _ string, _ *resource.Quantity) error { +func AssignQuota(_ mount.Interface, _ string, _ types.UID, _ *resource.Quantity) error { return errNotImplemented } diff --git a/pkg/volume/util/operationexecutor/operation_generator.go b/pkg/volume/util/operationexecutor/operation_generator.go index 354ae638968..74b8b02ef8a 100644 --- a/pkg/volume/util/operationexecutor/operation_generator.go +++ b/pkg/volume/util/operationexecutor/operation_generator.go @@ -704,7 +704,6 @@ func (og *operationGenerator) GenerateMountVolumeFunc( mountErr := volumeMounter.SetUp(volume.MounterArgs{ FsGroup: fsGroup, DesiredSize: volumeToMount.DesiredSizeLimit, - PodUID: string(volumeToMount.Pod.UID), }) if mountErr != nil { // On failure, return error. Caller will log and retry. diff --git a/pkg/volume/volume.go b/pkg/volume/volume.go index bfc4b31d656..cb78d94515a 100644 --- a/pkg/volume/volume.go +++ b/pkg/volume/volume.go @@ -105,7 +105,6 @@ type Attributes struct { type MounterArgs struct { FsGroup *int64 DesiredSize *resource.Quantity - PodUID string } // Mounter interface provides methods to set up/mount the volume.