Skip to content

Commit 6c7ef9e

Browse files
committed
fix(registry): drop the backing object's UID from remapped error details
WrapPreservingStatus rewrites Group, Kind and Name of a backend status to the aggregated resource but left Details.UID as the HelmRelease's, so a client that keys on details saw an identity the tenant cannot look up. The UID goes with the rest of the remap, and a test pins it. Signed-off-by: Yan Bondarenko <[email protected]> Assisted-by: LLM
1 parent 28acf53 commit 6c7ef9e

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎pkg/registry/errors.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func WrapPreservingStatus(msg string, err error, resource schema.GroupResource,
4040
st.Details.Group = resource.Group
4141
st.Details.Kind = resource.Resource
4242
st.Details.Name = name
43+
st.Details.UID = ""
4344
st.Message = fmt.Sprintf("%s: %s", msg, st.Message)
4445
return &apierrors.StatusError{ErrStatus: *st}
4546
}

‎pkg/registry/errors_test.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ func TestWrapPreservingStatusKeepsBackendErrorUnchanged(t *testing.T) {
5454
}
5555
}
5656

57+
func TestWrapPreservingStatusDropsBackendUID(t *testing.T) {
58+
backend := apierrors.NewConflict(schema.GroupResource{Group: "helm.toolkit.fluxcd.io", Resource: "helmreleases"}, "postgresql-example", errors.New("the object has been modified"))
59+
backend.ErrStatus.Details.UID = "0f4b6a9e-6c5c-4c1c-9d1e-2b1d0c7a5f11"
60+
resource := schema.GroupResource{Group: "apps.cozystack.io", Resource: "postgresqls"}
61+
status := responsewriters.ErrorToAPIStatus(WrapPreservingStatus("failed to update HelmRelease", backend, resource, "example"))
62+
if status.Details == nil || status.Details.UID != "" {
63+
t.Fatalf("wire details = %#v, carry the backing HelmRelease UID into the aggregated status", status.Details)
64+
}
65+
if status.Details.Group != resource.Group || status.Details.Kind != resource.Resource || status.Details.Name != "example" {
66+
t.Fatalf("wire details = %#v, want the requested Application", status.Details)
67+
}
68+
if status.Code != backend.ErrStatus.Code || status.Reason != backend.ErrStatus.Reason {
69+
t.Fatalf("wire status = %#v, lost backend status %#v", status, backend.ErrStatus)
70+
}
71+
}
72+
5773
func TestWrapPreservingStatusKeepsNonStatusCause(t *testing.T) {
5874
backend := errors.New("connection lost")
5975
err := WrapPreservingStatus("failed to update HelmRelease", backend, schema.GroupResource{Group: "apps.cozystack.io", Resource: "postgresqls"}, "example")

0 commit comments

Comments
 (0)