Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Volume resource requirements #118653

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 21 additions & 1 deletion api/openapi-spec/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 31 additions & 1 deletion api/openapi-spec/v3/api__v1_openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4195,7 +4195,7 @@
"resources": {
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.api.core.v1.ResourceRequirements"
"$ref": "#/components/schemas/io.k8s.api.core.v1.VolumeResourceRequirements"
}
],
"default": {},
Expand Down Expand Up @@ -7981,6 +7981,36 @@
},
"type": "object"
},
"io.k8s.api.core.v1.VolumeResourceRequirements": {
"description": "VolumeResourceRequirements describes the storage resource requirements for a volume.",
"properties": {
"limits": {
"additionalProperties": {
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity"
}
],
"default": {}
},
"description": "Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/",
"type": "object"
},
"requests": {
"additionalProperties": {
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity"
}
],
"default": {}
},
"description": "Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. Requests cannot exceed Limits. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/",
"type": "object"
}
},
"type": "object"
},
"io.k8s.api.core.v1.VsphereVirtualDiskVolumeSource": {
"description": "Represents a vSphere volume resource.",
"properties": {
Expand Down
32 changes: 31 additions & 1 deletion api/openapi-spec/v3/apis__apps__v1_openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3054,7 +3054,7 @@
"resources": {
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.api.core.v1.ResourceRequirements"
"$ref": "#/components/schemas/io.k8s.api.core.v1.VolumeResourceRequirements"
}
],
"default": {},
Expand Down Expand Up @@ -4986,6 +4986,36 @@
},
"type": "object"
},
"io.k8s.api.core.v1.VolumeResourceRequirements": {
"description": "VolumeResourceRequirements describes the storage resource requirements for a volume.",
"properties": {
"limits": {
"additionalProperties": {
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity"
}
],
"default": {}
},
"description": "Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/",
"type": "object"
},
"requests": {
"additionalProperties": {
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity"
}
],
"default": {}
},
"description": "Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. Requests cannot exceed Limits. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/",
"type": "object"
}
},
"type": "object"
},
"io.k8s.api.core.v1.VsphereVirtualDiskVolumeSource": {
"description": "Represents a vSphere volume resource.",
"properties": {
Expand Down
32 changes: 31 additions & 1 deletion api/openapi-spec/v3/apis__batch__v1_openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2311,7 +2311,7 @@
"resources": {
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.api.core.v1.ResourceRequirements"
"$ref": "#/components/schemas/io.k8s.api.core.v1.VolumeResourceRequirements"
}
],
"default": {},
Expand Down Expand Up @@ -4178,6 +4178,36 @@
},
"type": "object"
},
"io.k8s.api.core.v1.VolumeResourceRequirements": {
"description": "VolumeResourceRequirements describes the storage resource requirements for a volume.",
"properties": {
"limits": {
"additionalProperties": {
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity"
}
],
"default": {}
},
"description": "Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/",
"type": "object"
},
"requests": {
"additionalProperties": {
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity"
}
],
"default": {}
},
"description": "Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. Requests cannot exceed Limits. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/",
"type": "object"
}
},
"type": "object"
},
"io.k8s.api.core.v1.VsphereVirtualDiskVolumeSource": {
"description": "Represents a vSphere volume resource.",
"properties": {
Expand Down
4 changes: 0 additions & 4 deletions pkg/api/persistentvolumeclaim/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ func DropDisabledFields(pvcSpec, oldPVCSpec *core.PersistentVolumeClaimSpec) {
pvcSpec.DataSourceRef = nil
}
}

// Setting VolumeClaimTemplate.Resources.Claims should have been caught by validation when
// extending ResourceRequirements in 1.26. Now we can only accept it and drop the field.
pvcSpec.Resources.Claims = nil
}

// EnforceDataSourceBackwardsCompatibility drops the data source field under certain conditions
Expand Down
14 changes: 4 additions & 10 deletions pkg/api/persistentvolumeclaim/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,7 @@ func TestDataSourceFilter(t *testing.T) {
spec: core.PersistentVolumeClaimSpec{DataSourceRef: xnsVolumeDataSourceRef},
oldSpec: core.PersistentVolumeClaimSpec{DataSourceRef: volumeDataSourceRef},
anyEnabled: true,
wantRef: xnsVolumeDataSourceRef, // existing field isn't dropped.
},
"clear Resources.Claims": {
spec: core.PersistentVolumeClaimSpec{Resources: core.ResourceRequirements{Claims: []core.ResourceClaim{{Name: "dra"}}}},
wantRef: xnsVolumeDataSourceRef, // existing field isn't dropped.8
},
}

Expand All @@ -282,9 +279,6 @@ func TestDataSourceFilter(t *testing.T) {
t.Errorf("expected condition was not met, test: %s, anyEnabled: %v, xnsEnabled: %v, spec: %+v, expected DataSourceRef: %+v",
testName, test.anyEnabled, test.xnsEnabled, test.spec, test.wantRef)
}
if test.spec.Resources.Claims != nil {
t.Errorf("expected Resources.Claims to be cleared")
}
})
}
}
Expand Down Expand Up @@ -515,7 +509,7 @@ func TestWarnings(t *testing.T) {
name: "200Mi requests no warning",
template: &core.PersistentVolumeClaim{
Spec: core.PersistentVolumeClaimSpec{
Resources: core.ResourceRequirements{
Resources: core.VolumeResourceRequirements{
Requests: core.ResourceList{
core.ResourceStorage: resource.MustParse("200Mi"),
},
Expand All @@ -531,7 +525,7 @@ func TestWarnings(t *testing.T) {
name: "200m warning",
template: &core.PersistentVolumeClaim{
Spec: core.PersistentVolumeClaimSpec{
Resources: core.ResourceRequirements{
Resources: core.VolumeResourceRequirements{
Requests: core.ResourceList{
core.ResourceStorage: resource.MustParse("200m"),
},
Expand All @@ -550,7 +544,7 @@ func TestWarnings(t *testing.T) {
name: "integer no warning",
template: &core.PersistentVolumeClaim{
Spec: core.PersistentVolumeClaimSpec{
Resources: core.ResourceRequirements{
Resources: core.VolumeResourceRequirements{
Requests: core.ResourceList{
core.ResourceStorage: resource.MustParse("200"),
},
Expand Down
10 changes: 0 additions & 10 deletions pkg/api/pod/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,16 +608,6 @@ func dropDisabledDynamicResourceAllocationFields(podSpec, oldPodSpec *api.PodSpe
dropEphemeralResourceClaimRequests(podSpec.EphemeralContainers)
podSpec.ResourceClaims = nil
}

// Setting VolumeClaimTemplate.Resources.Claims should have been
// treated as an error by validation when extending
// ResourceRequirements in 1.26. Now we can only accept it and drop the
// field.
for i := range podSpec.Volumes {
if podSpec.Volumes[i].Ephemeral != nil && podSpec.Volumes[i].Ephemeral.VolumeClaimTemplate != nil {
podSpec.Volumes[i].Ephemeral.VolumeClaimTemplate.Spec.Resources.Claims = nil
}
}
}

func dynamicResourceAllocationInUse(podSpec *api.PodSpec) bool {
Expand Down
38 changes: 0 additions & 38 deletions pkg/api/pod/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1889,44 +1889,6 @@ func TestValidateTopologySpreadConstraintLabelSelectorOption(t *testing.T) {
}
}

func TestDropVolumesClaimField(t *testing.T) {
pod := &api.Pod{
Spec: api.PodSpec{
Volumes: []api.Volume{
{},
{
VolumeSource: api.VolumeSource{
Ephemeral: &api.EphemeralVolumeSource{},
},
},
{
VolumeSource: api.VolumeSource{
Ephemeral: &api.EphemeralVolumeSource{
VolumeClaimTemplate: &api.PersistentVolumeClaimTemplate{
Spec: api.PersistentVolumeClaimSpec{
Resources: api.ResourceRequirements{
Claims: []api.ResourceClaim{
{Name: "dra"},
},
},
},
},
},
},
},
},
},
}

DropDisabledPodFields(pod, nil)

for i, volume := range pod.Spec.Volumes {
if volume.Ephemeral != nil && volume.Ephemeral.VolumeClaimTemplate != nil && volume.Ephemeral.VolumeClaimTemplate.Spec.Resources.Claims != nil {
t.Errorf("volume #%d: Resources.Claim should be nil", i)
}
}
}

func TestDropInPlacePodVerticalScaling(t *testing.T) {
podWithInPlaceVerticalScaling := func() *api.Pod {
return &api.Pod{
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/pod/warnings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ func TestWarnings(t *testing.T) {
Spec: api.PodSpec{Volumes: []api.Volume{
{Name: "ephemeral-volume", VolumeSource: api.VolumeSource{Ephemeral: &api.EphemeralVolumeSource{
VolumeClaimTemplate: &api.PersistentVolumeClaimTemplate{
Spec: api.PersistentVolumeClaimSpec{Resources: api.ResourceRequirements{
Spec: api.PersistentVolumeClaimSpec{Resources: api.VolumeResourceRequirements{
Requests: api.ResourceList{api.ResourceStorage: resource.MustParse("200Mi")}}},
},
}}}}},
Expand All @@ -518,7 +518,7 @@ func TestWarnings(t *testing.T) {
Spec: api.PodSpec{Volumes: []api.Volume{
{Name: "ephemeral-volume", VolumeSource: api.VolumeSource{Ephemeral: &api.EphemeralVolumeSource{
VolumeClaimTemplate: &api.PersistentVolumeClaimTemplate{
Spec: api.PersistentVolumeClaimSpec{Resources: api.ResourceRequirements{
Spec: api.PersistentVolumeClaimSpec{Resources: api.VolumeResourceRequirements{
Requests: api.ResourceList{api.ResourceStorage: resource.MustParse("200m")}}},
},
}}}}},
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/apps/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ func TestValidateStatefulSetUpdate(t *testing.T) {
},
Spec: api.PersistentVolumeClaimSpec{
StorageClassName: &storageClass,
Resources: api.ResourceRequirements{
Resources: api.VolumeResourceRequirements{
Requests: api.ResourceList{
api.ResourceStorage: resource.MustParse("1Gi"),
},
Expand All @@ -800,7 +800,7 @@ func TestValidateStatefulSetUpdate(t *testing.T) {
},
Spec: api.PersistentVolumeClaimSpec{
StorageClassName: &storageClass2,
Resources: api.ResourceRequirements{
Resources: api.VolumeResourceRequirements{
Requests: api.ResourceList{
api.ResourceStorage: resource.MustParse("2Gi"),
},
Expand Down
14 changes: 13 additions & 1 deletion pkg/apis/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ type PersistentVolumeClaimSpec struct {
// that are lower than previous value but must still be higher than capacity recorded in the
// status field of the claim.
// +optional
Resources ResourceRequirements
Resources VolumeResourceRequirements
// VolumeName is the binding reference to the PersistentVolume backing this
// claim. When set to non-empty value Selector is not evaluated
// +optional
Expand Down Expand Up @@ -2282,6 +2282,18 @@ type ResourceRequirements struct {
Claims []ResourceClaim
}

// VolumeResourceRequirements describes the storage resource requirements for a volume.
type VolumeResourceRequirements struct {
// Limits describes the maximum amount of compute resources allowed.
// +optional
Limits ResourceList
// Requests describes the minimum amount of compute resources required.
// If Request is omitted for a container, it defaults to Limits if that is explicitly specified,
// otherwise to an implementation-defined value
// +optional
Requests ResourceList
}

// ResourceClaim references one entry in PodSpec.ResourceClaims.
type ResourceClaim struct {
// Name must match the name of one entry in pod.spec.resourceClaims of
Expand Down