Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e8b49f8
storage: add backend interface and related types
boxofrad Mar 6, 2023
ae28bc8
storage: add conformance test suite
boxofrad Mar 6, 2023
531e995
storage: implement in-memory backend
boxofrad Mar 6, 2023
74eef9a
storage: better error messages
boxofrad Mar 6, 2023
2731ba8
storage: owner references should be anchored to a specific uid
boxofrad Mar 13, 2023
c25a7ec
Remove unused test function
boxofrad Mar 13, 2023
d5733f9
storage: clarify List docs
boxofrad Mar 14, 2023
56c4c3a
storage: fix potential out-of-order events
boxofrad Mar 14, 2023
033b612
storage: clarify WatchList consistency model
boxofrad Mar 15, 2023
f54bcb8
storage: s/Check-And-Set/Compare-And-Swap/
boxofrad Mar 15, 2023
0167a5b
storage: move event construction into publishEvent
boxofrad Mar 15, 2023
048712d
storage: document Read-Modify-Write patterns
boxofrad Mar 15, 2023
fbbbec9
storage: add clarifying comment about resource creation
boxofrad Mar 15, 2023
e17b50b
storage: clarify OwnerReferences consistency
boxofrad Mar 16, 2023
5238caa
Read() endpoint for the ressource service
analogue Mar 16, 2023
d82ef1f
Move Read(...) and tests to their own files
analogue Mar 16, 2023
f441187
storage: separate ErrConflict into two errors
boxofrad Mar 17, 2023
84ff540
storage: make backends responsible for managing the version
boxofrad Mar 17, 2023
d7ac1c6
storage: make consistency an argument to Read
boxofrad Mar 17, 2023
ba94207
storage: add consistency parameter to List
boxofrad Mar 17, 2023
6e39fd5
storage: more correct consistency documentation
boxofrad Mar 17, 2023
4580e51
storage: fix integer alignment in inmem backend
boxofrad Mar 17, 2023
0748073
storage: support eventual consistency in conformance tests
boxofrad Mar 20, 2023
0a49eff
storage: correct eventLock comment
boxofrad Mar 20, 2023
8c75333
storage: rearrange inmem store files
boxofrad Mar 20, 2023
8bc4a80
storage: fix bug where watches could emit duplicate events
boxofrad Mar 21, 2023
8e803f4
Merge branch 'boxofrad/storage-backend' into test-merge
analogue Mar 21, 2023
c5784cb
nix the mock registry in read tests
analogue Mar 21, 2023
5e3c998
nix mockBackend from read tests
analogue Mar 21, 2023
d5cd617
TIL errors.[Is|As]
analogue Mar 22, 2023
5d8dffb
Use mockBackend to verify ReadConsistency arg set properly
analogue Mar 22, 2023
973da84
Fix imports with goimports
analogue Mar 22, 2023
87ad694
Merge branch 'main' into spatel/NET-2687-resource-service-read-endpoint
analogue Mar 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 176 additions & 0 deletions agent/grpc-external/services/resource/mock_Backend.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions agent/grpc-external/services/resource/read.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package resource

import (
"context"
"errors"
"fmt"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"

"github.com/hashicorp/consul/internal/resource"
"github.com/hashicorp/consul/internal/storage"
"github.com/hashicorp/consul/proto-public/pbresource"
)

func (s *Server) Read(ctx context.Context, req *pbresource.ReadRequest) (*pbresource.ReadResponse, error) {
// check type exists
_, ok := s.registry.Resolve(req.Id.Type)
if !ok {
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("resource type %s not registered", resource.ToGVK(req.Id.Type)))
}

consistency := storage.EventualConsistency
if isConsistentRead(ctx) {
consistency = storage.StrongConsistency
}

resource, err := s.backend.Read(ctx, consistency, req.Id)
if err != nil {
if errors.Is(err, storage.ErrNotFound) {
return nil, status.Error(codes.NotFound, err.Error())
}
if errors.As(err, &storage.GroupVersionMismatchError{}) {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
return nil, err
}
return &pbresource.ReadResponse{Resource: resource}, nil
}

func isConsistentRead(ctx context.Context) bool {
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
return false
}

vals := md.Get("x-consul-consistency-mode")
if len(vals) == 0 {
return false
}

return vals[0] == "consistent"
}
Loading