Commit 8679a8f5 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #50163 from jingxu97/Aug/sizeLimit

Automatic merge from submit-queue (batch tested with PRs 51707, 51662, 51723, 50163, 51633) Change SizeLimit to a pointer This PR fixes issue #50121 ```release-note The `emptyDir.sizeLimit` field is now correctly omitted from API requests and responses when unset. ```
parents 11529382 e1460efc
...@@ -651,7 +651,7 @@ type EmptyDirVolumeSource struct { ...@@ -651,7 +651,7 @@ type EmptyDirVolumeSource struct {
// The default is nil which means that the limit is undefined. // The default is nil which means that the limit is undefined.
// More info: http://kubernetes.io/docs/user-guide/volumes#emptydir // More info: http://kubernetes.io/docs/user-guide/volumes#emptydir
// +optional // +optional
SizeLimit resource.Quantity SizeLimit *resource.Quantity
} }
// StorageMedium defines ways that storage can be allocated to a volume. // StorageMedium defines ways that storage can be allocated to a volume.
......
...@@ -23,6 +23,7 @@ go_library( ...@@ -23,6 +23,7 @@ go_library(
"//pkg/util/parsers:go_default_library", "//pkg/util/parsers:go_default_library",
"//pkg/util/pointer:go_default_library", "//pkg/util/pointer:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library", "//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library", "//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
......
...@@ -22,6 +22,7 @@ package v1 ...@@ -22,6 +22,7 @@ package v1
import ( import (
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
resource "k8s.io/apimachinery/pkg/api/resource"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
conversion "k8s.io/apimachinery/pkg/conversion" conversion "k8s.io/apimachinery/pkg/conversion"
runtime "k8s.io/apimachinery/pkg/runtime" runtime "k8s.io/apimachinery/pkg/runtime"
...@@ -1329,7 +1330,7 @@ func Convert_api_DownwardAPIVolumeSource_To_v1_DownwardAPIVolumeSource(in *api.D ...@@ -1329,7 +1330,7 @@ func Convert_api_DownwardAPIVolumeSource_To_v1_DownwardAPIVolumeSource(in *api.D
func autoConvert_v1_EmptyDirVolumeSource_To_api_EmptyDirVolumeSource(in *v1.EmptyDirVolumeSource, out *api.EmptyDirVolumeSource, s conversion.Scope) error { func autoConvert_v1_EmptyDirVolumeSource_To_api_EmptyDirVolumeSource(in *v1.EmptyDirVolumeSource, out *api.EmptyDirVolumeSource, s conversion.Scope) error {
out.Medium = api.StorageMedium(in.Medium) out.Medium = api.StorageMedium(in.Medium)
out.SizeLimit = in.SizeLimit out.SizeLimit = (*resource.Quantity)(unsafe.Pointer(in.SizeLimit))
return nil return nil
} }
...@@ -1340,7 +1341,7 @@ func Convert_v1_EmptyDirVolumeSource_To_api_EmptyDirVolumeSource(in *v1.EmptyDir ...@@ -1340,7 +1341,7 @@ func Convert_v1_EmptyDirVolumeSource_To_api_EmptyDirVolumeSource(in *v1.EmptyDir
func autoConvert_api_EmptyDirVolumeSource_To_v1_EmptyDirVolumeSource(in *api.EmptyDirVolumeSource, out *v1.EmptyDirVolumeSource, s conversion.Scope) error { func autoConvert_api_EmptyDirVolumeSource_To_v1_EmptyDirVolumeSource(in *api.EmptyDirVolumeSource, out *v1.EmptyDirVolumeSource, s conversion.Scope) error {
out.Medium = v1.StorageMedium(in.Medium) out.Medium = v1.StorageMedium(in.Medium)
out.SizeLimit = in.SizeLimit out.SizeLimit = (*resource.Quantity)(unsafe.Pointer(in.SizeLimit))
return nil return nil
} }
......
...@@ -386,10 +386,13 @@ func validateVolumeSource(source *api.VolumeSource, fldPath *field.Path, volName ...@@ -386,10 +386,13 @@ func validateVolumeSource(source *api.VolumeSource, fldPath *field.Path, volName
if source.EmptyDir != nil { if source.EmptyDir != nil {
numVolumes++ numVolumes++
if !utilfeature.DefaultFeatureGate.Enabled(features.LocalStorageCapacityIsolation) { if !utilfeature.DefaultFeatureGate.Enabled(features.LocalStorageCapacityIsolation) {
unsetSizeLimit := resource.Quantity{} if source.EmptyDir.SizeLimit != nil && source.EmptyDir.SizeLimit.Cmp(resource.Quantity{}) != 0 {
if unsetSizeLimit.Cmp(source.EmptyDir.SizeLimit) != 0 {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("emptyDir").Child("sizeLimit"), "SizeLimit field disabled by feature-gate for EmptyDir volumes")) allErrs = append(allErrs, field.Forbidden(fldPath.Child("emptyDir").Child("sizeLimit"), "SizeLimit field disabled by feature-gate for EmptyDir volumes"))
} }
} else {
if source.EmptyDir.SizeLimit != nil && source.EmptyDir.SizeLimit.Cmp(resource.Quantity{}) < 0 {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("emptyDir").Child("sizeLimit"), "SizeLimit field must be a valid resource quantity"))
}
} }
} }
if source.HostPath != nil { if source.HostPath != nil {
......
...@@ -2656,7 +2656,7 @@ func TestValidateVolumes(t *testing.T) { ...@@ -2656,7 +2656,7 @@ func TestValidateVolumes(t *testing.T) {
func TestAlphaLocalStorageCapacityIsolation(t *testing.T) { func TestAlphaLocalStorageCapacityIsolation(t *testing.T) {
testCases := []api.VolumeSource{ 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 // Enable alpha feature LocalStorageCapacityIsolation
err := utilfeature.DefaultFeatureGate.Set("LocalStorageCapacityIsolation=true") err := utilfeature.DefaultFeatureGate.Set("LocalStorageCapacityIsolation=true")
......
...@@ -21,6 +21,7 @@ limitations under the License. ...@@ -21,6 +21,7 @@ limitations under the License.
package api package api
import ( import (
resource "k8s.io/apimachinery/pkg/api/resource"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
conversion "k8s.io/apimachinery/pkg/conversion" conversion "k8s.io/apimachinery/pkg/conversion"
runtime "k8s.io/apimachinery/pkg/runtime" runtime "k8s.io/apimachinery/pkg/runtime"
...@@ -1787,7 +1788,15 @@ func (in *DownwardAPIVolumeSource) DeepCopy() *DownwardAPIVolumeSource { ...@@ -1787,7 +1788,15 @@ func (in *DownwardAPIVolumeSource) DeepCopy() *DownwardAPIVolumeSource {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *EmptyDirVolumeSource) DeepCopyInto(out *EmptyDirVolumeSource) { func (in *EmptyDirVolumeSource) DeepCopyInto(out *EmptyDirVolumeSource) {
*out = *in *out = *in
out.SizeLimit = in.SizeLimit.DeepCopy() if in.SizeLimit != nil {
in, out := &in.SizeLimit, &out.SizeLimit
if *in == nil {
*out = nil
} else {
*out = new(resource.Quantity)
**out = (*in).DeepCopy()
}
}
return return
} }
......
...@@ -496,7 +496,7 @@ func (m *managerImpl) emptyDirLimitEviction(podStats statsapi.PodStats, pod *v1. ...@@ -496,7 +496,7 @@ func (m *managerImpl) emptyDirLimitEviction(podStats statsapi.PodStats, pod *v1.
if source.EmptyDir != nil { if source.EmptyDir != nil {
size := source.EmptyDir.SizeLimit size := source.EmptyDir.SizeLimit
used := podVolumeUsed[pod.Spec.Volumes[i].Name] 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 // 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())) return m.evictPod(pod, v1.ResourceName("EmptyDir"), fmt.Sprintf("emptyDir usage exceeds the limit %q", size.String()))
} }
......
...@@ -124,7 +124,7 @@ func addStorageLimit(pod *v1.Pod, sizeLimit int64, medium v1.StorageMedium) *v1. ...@@ -124,7 +124,7 @@ func addStorageLimit(pod *v1.Pod, sizeLimit int64, medium v1.StorageMedium) *v1.
Name: "emptyDirVolumeName", Name: "emptyDirVolumeName",
VolumeSource: v1.VolumeSource{ VolumeSource: v1.VolumeSource{
EmptyDir: &v1.EmptyDirVolumeSource{ EmptyDir: &v1.EmptyDirVolumeSource{
SizeLimit: *resource.NewQuantity(sizeLimit, resource.BinarySI), SizeLimit: resource.NewQuantity(sizeLimit, resource.BinarySI),
Medium: medium, Medium: medium,
}, },
}, },
......
...@@ -21,7 +21,6 @@ syntax = 'proto2'; ...@@ -21,7 +21,6 @@ syntax = 'proto2';
package k8s.io.api.autoscaling.v2alpha1; package k8s.io.api.autoscaling.v2alpha1;
import "k8s.io/api/autoscaling/v1/generated.proto";
import "k8s.io/api/core/v1/generated.proto"; import "k8s.io/api/core/v1/generated.proto";
import "k8s.io/apimachinery/pkg/api/resource/generated.proto"; import "k8s.io/apimachinery/pkg/api/resource/generated.proto";
import "k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto"; import "k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto";
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -11638,7 +11638,7 @@ func (x *EmptyDirVolumeSource) CodecEncodeSelf(e *codec1978.Encoder) { ...@@ -11638,7 +11638,7 @@ func (x *EmptyDirVolumeSource) CodecEncodeSelf(e *codec1978.Encoder) {
_, _, _ = yysep2, yyq2, yy2arr2 _, _, _ = yysep2, yyq2, yy2arr2
const yyr2 bool = false const yyr2 bool = false
yyq2[0] = x.Medium != "" yyq2[0] = x.Medium != ""
yyq2[1] = true yyq2[1] = x.SizeLimit != nil
var yynn2 int var yynn2 int
if yyr2 || yy2arr2 { if yyr2 || yy2arr2 {
r.EncodeArrayStart(2) r.EncodeArrayStart(2)
...@@ -11670,15 +11670,18 @@ func (x *EmptyDirVolumeSource) CodecEncodeSelf(e *codec1978.Encoder) { ...@@ -11670,15 +11670,18 @@ func (x *EmptyDirVolumeSource) CodecEncodeSelf(e *codec1978.Encoder) {
if yyr2 || yy2arr2 { if yyr2 || yy2arr2 {
z.EncSendContainerState(codecSelfer_containerArrayElem1234) z.EncSendContainerState(codecSelfer_containerArrayElem1234)
if yyq2[1] { if yyq2[1] {
yy7 := &x.SizeLimit if x.SizeLimit == nil {
yym8 := z.EncBinary() r.EncodeNil()
_ = yym8 } else {
yym7 := z.EncBinary()
_ = yym7
if false { if false {
} else if z.HasExtensions() && z.EncExt(yy7) { } else if z.HasExtensions() && z.EncExt(x.SizeLimit) {
} else if !yym8 && z.IsJSONHandle() { } else if !yym7 && z.IsJSONHandle() {
z.EncJSONMarshal(yy7) z.EncJSONMarshal(x.SizeLimit)
} else { } else {
z.EncFallback(yy7) z.EncFallback(x.SizeLimit)
}
} }
} else { } else {
r.EncodeNil() r.EncodeNil()
...@@ -11688,15 +11691,18 @@ func (x *EmptyDirVolumeSource) CodecEncodeSelf(e *codec1978.Encoder) { ...@@ -11688,15 +11691,18 @@ func (x *EmptyDirVolumeSource) CodecEncodeSelf(e *codec1978.Encoder) {
z.EncSendContainerState(codecSelfer_containerMapKey1234) z.EncSendContainerState(codecSelfer_containerMapKey1234)
r.EncodeString(codecSelferC_UTF81234, string("sizeLimit")) r.EncodeString(codecSelferC_UTF81234, string("sizeLimit"))
z.EncSendContainerState(codecSelfer_containerMapValue1234) z.EncSendContainerState(codecSelfer_containerMapValue1234)
yy9 := &x.SizeLimit if x.SizeLimit == nil {
yym10 := z.EncBinary() r.EncodeNil()
_ = yym10 } else {
yym8 := z.EncBinary()
_ = yym8
if false { if false {
} else if z.HasExtensions() && z.EncExt(yy9) { } else if z.HasExtensions() && z.EncExt(x.SizeLimit) {
} else if !yym10 && z.IsJSONHandle() { } else if !yym8 && z.IsJSONHandle() {
z.EncJSONMarshal(yy9) z.EncJSONMarshal(x.SizeLimit)
} else { } else {
z.EncFallback(yy9) z.EncFallback(x.SizeLimit)
}
} }
} }
} }
...@@ -11770,17 +11776,21 @@ func (x *EmptyDirVolumeSource) codecDecodeSelfFromMap(l int, d *codec1978.Decode ...@@ -11770,17 +11776,21 @@ func (x *EmptyDirVolumeSource) codecDecodeSelfFromMap(l int, d *codec1978.Decode
} }
case "sizeLimit": case "sizeLimit":
if r.TryDecodeAsNil() { if r.TryDecodeAsNil() {
x.SizeLimit = pkg3_resource.Quantity{} if x.SizeLimit != nil {
x.SizeLimit = nil
}
} else { } else {
yyv5 := &x.SizeLimit if x.SizeLimit == nil {
x.SizeLimit = new(pkg3_resource.Quantity)
}
yym6 := z.DecBinary() yym6 := z.DecBinary()
_ = yym6 _ = yym6
if false { if false {
} else if z.HasExtensions() && z.DecExt(yyv5) { } else if z.HasExtensions() && z.DecExt(x.SizeLimit) {
} else if !yym6 && z.IsJSONHandle() { } else if !yym6 && z.IsJSONHandle() {
z.DecJSONUnmarshal(yyv5) z.DecJSONUnmarshal(x.SizeLimit)
} else { } else {
z.DecFallback(yyv5, false) z.DecFallback(x.SizeLimit, false)
} }
} }
default: default:
...@@ -11826,17 +11836,21 @@ func (x *EmptyDirVolumeSource) codecDecodeSelfFromArray(l int, d *codec1978.Deco ...@@ -11826,17 +11836,21 @@ func (x *EmptyDirVolumeSource) codecDecodeSelfFromArray(l int, d *codec1978.Deco
} }
z.DecSendContainerState(codecSelfer_containerArrayElem1234) z.DecSendContainerState(codecSelfer_containerArrayElem1234)
if r.TryDecodeAsNil() { if r.TryDecodeAsNil() {
x.SizeLimit = pkg3_resource.Quantity{} if x.SizeLimit != nil {
x.SizeLimit = nil
}
} else { } else {
yyv9 := &x.SizeLimit if x.SizeLimit == nil {
x.SizeLimit = new(pkg3_resource.Quantity)
}
yym10 := z.DecBinary() yym10 := z.DecBinary()
_ = yym10 _ = yym10
if false { if false {
} else if z.HasExtensions() && z.DecExt(yyv9) { } else if z.HasExtensions() && z.DecExt(x.SizeLimit) {
} else if !yym10 && z.IsJSONHandle() { } else if !yym10 && z.IsJSONHandle() {
z.DecJSONUnmarshal(yyv9) z.DecJSONUnmarshal(x.SizeLimit)
} else { } else {
z.DecFallback(yyv9, false) z.DecFallback(x.SizeLimit, false)
} }
} }
for { for {
...@@ -739,7 +739,7 @@ type EmptyDirVolumeSource struct { ...@@ -739,7 +739,7 @@ type EmptyDirVolumeSource struct {
// The default is nil which means that the limit is undefined. // The default is nil which means that the limit is undefined.
// More info: http://kubernetes.io/docs/user-guide/volumes#emptydir // More info: http://kubernetes.io/docs/user-guide/volumes#emptydir
// +optional // +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. // Represents a Glusterfs mount that lasts the lifetime of a pod.
......
...@@ -21,6 +21,7 @@ limitations under the License. ...@@ -21,6 +21,7 @@ limitations under the License.
package v1 package v1
import ( import (
resource "k8s.io/apimachinery/pkg/api/resource"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
conversion "k8s.io/apimachinery/pkg/conversion" conversion "k8s.io/apimachinery/pkg/conversion"
runtime "k8s.io/apimachinery/pkg/runtime" runtime "k8s.io/apimachinery/pkg/runtime"
...@@ -1787,7 +1788,15 @@ func (in *DownwardAPIVolumeSource) DeepCopy() *DownwardAPIVolumeSource { ...@@ -1787,7 +1788,15 @@ func (in *DownwardAPIVolumeSource) DeepCopy() *DownwardAPIVolumeSource {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *EmptyDirVolumeSource) DeepCopyInto(out *EmptyDirVolumeSource) { func (in *EmptyDirVolumeSource) DeepCopyInto(out *EmptyDirVolumeSource) {
*out = *in *out = *in
out.SizeLimit = in.SizeLimit.DeepCopy() if in.SizeLimit != nil {
in, out := &in.SizeLimit, &out.SizeLimit
if *in == nil {
*out = nil
} else {
*out = new(resource.Quantity)
**out = (*in).DeepCopy()
}
}
return return
} }
......
...@@ -75,7 +75,7 @@ var _ = framework.KubeDescribe("LocalStorageCapacityIsolationEviction [Slow] [Se ...@@ -75,7 +75,7 @@ var _ = framework.KubeDescribe("LocalStorageCapacityIsolationEviction [Slow] [Se
Name: emptyDirVolumeName, Name: emptyDirVolumeName,
VolumeSource: v1.VolumeSource{ VolumeSource: v1.VolumeSource{
EmptyDir: &v1.EmptyDirVolumeSource{ EmptyDir: &v1.EmptyDirVolumeSource{
SizeLimit: *resource.NewQuantity(int64(1000), resource.BinarySI), SizeLimit: resource.NewQuantity(int64(1000), resource.BinarySI),
}, },
}, },
}, },
...@@ -112,7 +112,7 @@ var _ = framework.KubeDescribe("LocalStorageCapacityIsolationEviction [Slow] [Se ...@@ -112,7 +112,7 @@ var _ = framework.KubeDescribe("LocalStorageCapacityIsolationEviction [Slow] [Se
VolumeSource: v1.VolumeSource{ VolumeSource: v1.VolumeSource{
EmptyDir: &v1.EmptyDirVolumeSource{ EmptyDir: &v1.EmptyDirVolumeSource{
Medium: "Memory", Medium: "Memory",
SizeLimit: *resource.NewQuantity(int64(10000), resource.BinarySI), SizeLimit: resource.NewQuantity(int64(10000), resource.BinarySI),
}, },
}, },
}, },
...@@ -148,7 +148,7 @@ var _ = framework.KubeDescribe("LocalStorageCapacityIsolationEviction [Slow] [Se ...@@ -148,7 +148,7 @@ var _ = framework.KubeDescribe("LocalStorageCapacityIsolationEviction [Slow] [Se
Name: emptyDirVolumeName, Name: emptyDirVolumeName,
VolumeSource: v1.VolumeSource{ VolumeSource: v1.VolumeSource{
EmptyDir: &v1.EmptyDirVolumeSource{ EmptyDir: &v1.EmptyDirVolumeSource{
SizeLimit: *resource.NewQuantity(int64(100000), resource.BinarySI), SizeLimit: resource.NewQuantity(int64(100000), resource.BinarySI),
}, },
}, },
}, },
...@@ -218,7 +218,7 @@ var _ = framework.KubeDescribe("LocalStorageCapacityIsolationEviction [Slow] [Se ...@@ -218,7 +218,7 @@ var _ = framework.KubeDescribe("LocalStorageCapacityIsolationEviction [Slow] [Se
Name: emptyDirVolumeName, Name: emptyDirVolumeName,
VolumeSource: v1.VolumeSource{ VolumeSource: v1.VolumeSource{
EmptyDir: &v1.EmptyDirVolumeSource{ EmptyDir: &v1.EmptyDirVolumeSource{
SizeLimit: *resource.NewQuantity(int64(100000), resource.BinarySI), SizeLimit: resource.NewQuantity(int64(100000), resource.BinarySI),
}, },
}, },
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment