mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 03:33:56 +00:00
dra API: ensure that pod status contains no duplicate resource claims
This is a follow-up to https://github.com/kubernetes/kubernetes/pull/117351 which just got merged.
This commit is contained in:
parent
745cfa35bd
commit
ddc0d94790
@ -4871,6 +4871,7 @@ func validatePodConditions(conditions []core.PodCondition, fldPath *field.Path)
|
|||||||
func validatePodResourceClaimStatuses(statuses []core.PodResourceClaimStatus, podClaims []core.PodResourceClaim, fldPath *field.Path) field.ErrorList {
|
func validatePodResourceClaimStatuses(statuses []core.PodResourceClaimStatus, podClaims []core.PodResourceClaim, fldPath *field.Path) field.ErrorList {
|
||||||
var allErrs field.ErrorList
|
var allErrs field.ErrorList
|
||||||
|
|
||||||
|
claimNames := sets.New[string]()
|
||||||
for i, status := range statuses {
|
for i, status := range statuses {
|
||||||
idxPath := fldPath.Index(i)
|
idxPath := fldPath.Index(i)
|
||||||
// There's no need to check the content of the name. If it matches an entry,
|
// There's no need to check the content of the name. If it matches an entry,
|
||||||
@ -4878,6 +4879,11 @@ func validatePodResourceClaimStatuses(statuses []core.PodResourceClaimStatus, po
|
|||||||
if !havePodClaim(podClaims, status.Name) {
|
if !havePodClaim(podClaims, status.Name) {
|
||||||
allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), status.Name, "must match the name of an entry in `spec.resourceClaims`"))
|
allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), status.Name, "must match the name of an entry in `spec.resourceClaims`"))
|
||||||
}
|
}
|
||||||
|
if claimNames.Has(status.Name) {
|
||||||
|
allErrs = append(allErrs, field.Duplicate(idxPath.Child("name"), status.Name))
|
||||||
|
} else {
|
||||||
|
claimNames.Insert(status.Name)
|
||||||
|
}
|
||||||
if status.ResourceClaimName != nil {
|
if status.ResourceClaimName != nil {
|
||||||
for _, detail := range ValidateResourceClaimName(*status.ResourceClaimName, false) {
|
for _, detail := range ValidateResourceClaimName(*status.ResourceClaimName, false) {
|
||||||
allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), status.ResourceClaimName, detail))
|
allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), status.ResourceClaimName, detail))
|
||||||
|
@ -13675,6 +13675,37 @@ func TestValidatePodStatusUpdate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
`status.resourceClaimStatuses[0].name: Invalid value: "%$!#": a lowercase RFC 1123 subdomain must consist of`,
|
`status.resourceClaimStatuses[0].name: Invalid value: "%$!#": a lowercase RFC 1123 subdomain must consist of`,
|
||||||
"Invalid ResourceClaim name",
|
"Invalid ResourceClaim name",
|
||||||
|
}, {
|
||||||
|
core.Pod{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "foo",
|
||||||
|
},
|
||||||
|
Spec: core.PodSpec{
|
||||||
|
ResourceClaims: []core.PodResourceClaim{
|
||||||
|
{Name: "my-claim"},
|
||||||
|
{Name: "my-other-claim"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Status: core.PodStatus{
|
||||||
|
ResourceClaimStatuses: []core.PodResourceClaimStatus{
|
||||||
|
{Name: "my-claim", ResourceClaimName: utilpointer.String("foo-my-claim-12345")},
|
||||||
|
{Name: "my-other-claim", ResourceClaimName: nil},
|
||||||
|
{Name: "my-other-claim", ResourceClaimName: nil},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
core.Pod{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "foo",
|
||||||
|
},
|
||||||
|
Spec: core.PodSpec{
|
||||||
|
ResourceClaims: []core.PodResourceClaim{
|
||||||
|
{Name: "my-claim"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
`status.resourceClaimStatuses[2].name: Duplicate value: "my-other-claim"`,
|
||||||
|
"Duplicate ResourceClaimStatuses.Name",
|
||||||
}, {
|
}, {
|
||||||
core.Pod{
|
core.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Loading…
Reference in New Issue
Block a user