diff --git a/pkg/storage/unified/resource/cdk_backend.go b/pkg/storage/unified/resource/cdk_backend.go index 3d3415131ff..c37ce5c518c 100644 --- a/pkg/storage/unified/resource/cdk_backend.go +++ b/pkg/storage/unified/resource/cdk_backend.go @@ -167,15 +167,11 @@ func (s *cdkBackend) Read(ctx context.Context, req *ReadRequest) (*ReadResponse, } raw, err := s.bucket.ReadAll(ctx, path) - if err == nil && bytes.Contains(raw, []byte(`"DeletedMarker"`)) { - tmp := &unstructured.Unstructured{} - err = tmp.UnmarshalJSON(raw) - if err == nil && tmp.GetKind() == "DeletedMarker" { - return nil, apierrors.NewNotFound(schema.GroupResource{ - Group: req.Key.Group, - Resource: req.Key.Resource, - }, req.Key.Name) - } + if err == nil && isDeletedMarker(raw) { + return nil, apierrors.NewNotFound(schema.GroupResource{ + Group: req.Key.Group, + Resource: req.Key.Resource, + }, req.Key.Name) } return &ReadResponse{ @@ -184,6 +180,17 @@ func (s *cdkBackend) Read(ctx context.Context, req *ReadRequest) (*ReadResponse, }, err } +func isDeletedMarker(raw []byte) bool { + if bytes.Contains(raw, []byte(`"DeletedMarker"`)) { + tmp := &unstructured.Unstructured{} + err := tmp.UnmarshalJSON(raw) + if err == nil && tmp.GetKind() == "DeletedMarker" { + return true + } + } + return false +} + // List implements AppendingStore. func (s *cdkBackend) PrepareList(ctx context.Context, req *ListRequest) (*ListResponse, error) { resources, err := buildTree(ctx, s, req.Options.Key) @@ -198,10 +205,12 @@ func (s *cdkBackend) PrepareList(ctx context.Context, req *ListRequest) (*ListRe if err != nil { return nil, err } - rsp.Items = append(rsp.Items, &ResourceWrapper{ - ResourceVersion: latest.rv, - Value: raw, - }) + if !isDeletedMarker(raw) { + rsp.Items = append(rsp.Items, &ResourceWrapper{ + ResourceVersion: latest.rv, + Value: raw, + }) + } } return rsp, nil } diff --git a/pkg/storage/unified/resource/server_test.go b/pkg/storage/unified/resource/server_test.go index 6b21c259f27..4589b071dcc 100644 --- a/pkg/storage/unified/resource/server_test.go +++ b/pkg/storage/unified/resource/server_test.go @@ -132,6 +132,16 @@ func TestSimpleServer(t *testing.T) { require.NoError(t, err) require.NotNil(t, found.Status) require.Equal(t, int32(404), found.Status.Code) + + // And the deleted value should not be in the results + all, err = server.List(ctx, &ListRequest{Options: &ListOptions{ + Key: &ResourceKey{ + Group: key.Group, + Resource: key.Resource, + }, + }}) + require.NoError(t, err) + require.Len(t, all.Items, 0) // empty }) }