mirror of
https://github.com/grafana/grafana.git
synced 2025-01-08 15:13:30 -06:00
check for deleted
This commit is contained in:
parent
ddcbc753d3
commit
d09979b332
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user