mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-03 03:38:15 +00:00
api: drop Resources.Claims from PVC and PVC template
PVC and containers share the same ResourceRequirements struct. The Claims field in it only makes sense when used in containers. When used in a PVC, the field should have been rejected by validation. This was overlooked when introducing it, so now persisted objects might have it set and/or people may have started to rely on it being accepted even when it has no effect. Therefore we cannot reject it in validation anymore, but we can still strip it out on create or update.
This commit is contained in:
@@ -2236,3 +2236,41 @@ 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user