Skip to content

Commit

Permalink
Change SizeLimit to a pointer
Browse files Browse the repository at this point in the history
This PR fixes issue kubernetes#50121
  • Loading branch information
jingxu97 committed Aug 4, 2017
1 parent 04b2c29 commit ca40158
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ type EmptyDirVolumeSource struct {
// The default is nil which means that the limit is undefined.
// More info: http://kubernetes.io/docs/user-guide/volumes#emptydir
// +optional
SizeLimit resource.Quantity
SizeLimit *resource.Quantity
}

// StorageMedium defines ways that storage can be allocated to a volume.
Expand Down
3 changes: 1 addition & 2 deletions pkg/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,7 @@ func validateVolumeSource(source *api.VolumeSource, fldPath *field.Path) field.E
if source.EmptyDir != nil {
numVolumes++
if !utilfeature.DefaultFeatureGate.Enabled(features.LocalStorageCapacityIsolation) {
unsetSizeLimit := resource.Quantity{}
if unsetSizeLimit.Cmp(source.EmptyDir.SizeLimit) != 0 {
if source.EmptyDir.SizeLimit != nil {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("emptyDir").Child("sizeLimit"), "SizeLimit field disabled by feature-gate for EmptyDir volumes"))
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2418,7 +2418,7 @@ func TestValidateVolumes(t *testing.T) {
func TestAlphaLocalStorageCapacityIsolation(t *testing.T) {

testCases := []api.VolumeSource{
{EmptyDir: &api.EmptyDirVolumeSource{SizeLimit: *resource.NewQuantity(int64(5), resource.BinarySI)}},
{EmptyDir: &api.EmptyDirVolumeSource{SizeLimit: resource.NewQuantity(int64(5), resource.BinarySI)}},
}
// Enable alpha feature LocalStorageCapacityIsolation
err := utilfeature.DefaultFeatureGate.Set("LocalStorageCapacityIsolation=true")
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/eviction/eviction_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func (m *managerImpl) emptyDirLimitEviction(podStats statsapi.PodStats, pod *v1.
if source.EmptyDir != nil {
size := source.EmptyDir.SizeLimit
used := podVolumeUsed[pod.Spec.Volumes[i].Name]
if used != nil && size.Sign() == 1 && used.Cmp(size) > 0 {
if used != nil && size != nil && size.Sign() == 1 && used.Cmp(*size) > 0 {
// the emptyDir usage exceeds the size limit, evict the pod
return m.evictPod(pod, v1.ResourceName("EmptyDir"), fmt.Sprintf("emptyDir usage exceeds the limit %q", size.String()))
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/pkg/scheduler/algorithm/predicates/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ func GetResourceRequest(pod *v1.Pod) *schedulercache.Resource {
// Account for storage requested by emptydir volumes
// If the storage medium is memory, should exclude the size
for _, vol := range pod.Spec.Volumes {
if vol.EmptyDir != nil && vol.EmptyDir.Medium != v1.StorageMediumMemory {
if vol.EmptyDir != nil && vol.EmptyDir.Medium != v1.StorageMediumMemory && vol.EmptyDir.SizeLimit != nil {
result.StorageScratch += vol.EmptyDir.SizeLimit.Value()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func addStorageLimit(pod *v1.Pod, sizeLimit int64, medium v1.StorageMedium) *v1.
Name: "emptyDirVolumeName",
VolumeSource: v1.VolumeSource{
EmptyDir: &v1.EmptyDirVolumeSource{
SizeLimit: *resource.NewQuantity(sizeLimit, resource.BinarySI),
SizeLimit: resource.NewQuantity(sizeLimit, resource.BinarySI),
Medium: medium,
},
},
Expand Down
2 changes: 1 addition & 1 deletion plugin/pkg/scheduler/schedulercache/node_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ func calculateResource(pod *v1.Pod) (res Resource, non0_cpu int64, non0_mem int6
// Account for storage requested by emptydir volumes
// If the storage medium is memory, should exclude the size
for _, vol := range pod.Spec.Volumes {
if vol.EmptyDir != nil && vol.EmptyDir.Medium != v1.StorageMediumMemory {
if vol.EmptyDir != nil && vol.EmptyDir.Medium != v1.StorageMediumMemory && vol.EmptyDir.SizeLimit != nil {
res.StorageScratch += vol.EmptyDir.SizeLimit.Value()
}
}
Expand Down
2 changes: 1 addition & 1 deletion staging/src/k8s.io/api/core/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ type EmptyDirVolumeSource struct {
// The default is nil which means that the limit is undefined.
// More info: http://kubernetes.io/docs/user-guide/volumes#emptydir
// +optional
SizeLimit resource.Quantity `json:"sizeLimit,omitempty" protobuf:"bytes,2,opt,name=sizeLimit"`
SizeLimit *resource.Quantity `json:"sizeLimit,omitempty" protobuf:"bytes,2,opt,name=sizeLimit"`
}

// Represents a Glusterfs mount that lasts the lifetime of a pod.
Expand Down
6 changes: 3 additions & 3 deletions test/e2e_node/local_storage_isolation_eviction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var _ = framework.KubeDescribe("LocalStorageCapacityIsolationEviction [Slow] [Se
Name: emptyDirVolumeName,
VolumeSource: v1.VolumeSource{
EmptyDir: &v1.EmptyDirVolumeSource{
SizeLimit: *resource.NewQuantity(int64(1000), resource.BinarySI),
SizeLimit: resource.NewQuantity(int64(1000), resource.BinarySI),
},
},
},
Expand Down Expand Up @@ -112,7 +112,7 @@ var _ = framework.KubeDescribe("LocalStorageCapacityIsolationEviction [Slow] [Se
VolumeSource: v1.VolumeSource{
EmptyDir: &v1.EmptyDirVolumeSource{
Medium: "Memory",
SizeLimit: *resource.NewQuantity(int64(10000), resource.BinarySI),
SizeLimit: resource.NewQuantity(int64(10000), resource.BinarySI),
},
},
},
Expand Down Expand Up @@ -148,7 +148,7 @@ var _ = framework.KubeDescribe("LocalStorageCapacityIsolationEviction [Slow] [Se
Name: emptyDirVolumeName,
VolumeSource: v1.VolumeSource{
EmptyDir: &v1.EmptyDirVolumeSource{
SizeLimit: *resource.NewQuantity(int64(100000), resource.BinarySI),
SizeLimit: resource.NewQuantity(int64(100000), resource.BinarySI),
},
},
},
Expand Down

0 comments on commit ca40158

Please sign in to comment.