From 50d0b4295d19a4280763a5deec8bf37d36045f3f Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Thu, 26 Jan 2023 20:37:00 +0100 Subject: [PATCH] dynamic resource allocation: avoid apiserver complaint about list content This fixes the following warning (error?) in the apiserver: E0126 18:10:38.665239 16370 fieldmanager.go:210] "[SHOULD NOT HAPPEN] failed to update managedFields" err="failed to convert new object (test/claim-84; resource.k8s.io/v1alpha1, Kind=ResourceClaim) to smd typed: .status.reservedFor: element 0: associative list without keys has an element that's a map type" VersionKind="/, Kind=" namespace="test" name="claim-84" The root cause is the same as in e50e8a0c919c0e02dc9a0ffaebb685d5348027b4: nothing in Kubernetes outright complains about a list of items where the item type is comparable in Go, but not a simple type. This nonetheless isn't supposed to be done in the API and can causes problems elsewhere. For the ReservedFor field, everything seems to work okay except for the warning. However, it's better to follow conventions and use a map. This is possible in this case because UID is guaranteed to be a unique key. Validation is now stricter than before, which is a good thing: previously, two entries with the same UID were allowed as long as some other field was different, which wasn't a situation that should have been allowed. Kubernetes-commit: b10dce49c3cb782404e09f50547120a736c03969 --- resource/v1alpha1/generated.proto | 3 ++- resource/v1alpha1/types.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/resource/v1alpha1/generated.proto b/resource/v1alpha1/generated.proto index 5fc35e405c..2e814d155b 100644 --- a/resource/v1alpha1/generated.proto +++ b/resource/v1alpha1/generated.proto @@ -248,7 +248,8 @@ message ResourceClaimStatus { // There can be at most 32 such reservations. This may get increased in // the future, but not reduced. // - // +listType=set + // +listType=map + // +listMapKey=uid // +optional repeated ResourceClaimConsumerReference reservedFor = 3; diff --git a/resource/v1alpha1/types.go b/resource/v1alpha1/types.go index 9d7d4a191a..af57038403 100644 --- a/resource/v1alpha1/types.go +++ b/resource/v1alpha1/types.go @@ -112,7 +112,8 @@ type ResourceClaimStatus struct { // There can be at most 32 such reservations. This may get increased in // the future, but not reduced. // - // +listType=set + // +listType=map + // +listMapKey=uid // +optional ReservedFor []ResourceClaimConsumerReference `json:"reservedFor,omitempty" protobuf:"bytes,3,opt,name=reservedFor"`