-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Read(...) endpoint for the resource service #16655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
analogue
merged 33 commits into
main
from
spatel/NET-2687-resource-service-read-endpoint
Mar 27, 2023
Merged
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 ae28bc8
storage: add conformance test suite
boxofrad 531e995
storage: implement in-memory backend
boxofrad 74eef9a
storage: better error messages
boxofrad 2731ba8
storage: owner references should be anchored to a specific uid
boxofrad c25a7ec
Remove unused test function
boxofrad d5733f9
storage: clarify List docs
boxofrad 56c4c3a
storage: fix potential out-of-order events
boxofrad 033b612
storage: clarify WatchList consistency model
boxofrad f54bcb8
storage: s/Check-And-Set/Compare-And-Swap/
boxofrad 0167a5b
storage: move event construction into publishEvent
boxofrad 048712d
storage: document Read-Modify-Write patterns
boxofrad fbbbec9
storage: add clarifying comment about resource creation
boxofrad e17b50b
storage: clarify OwnerReferences consistency
boxofrad 5238caa
Read() endpoint for the ressource service
analogue d82ef1f
Move Read(...) and tests to their own files
analogue f441187
storage: separate ErrConflict into two errors
boxofrad 84ff540
storage: make backends responsible for managing the version
boxofrad d7ac1c6
storage: make consistency an argument to Read
boxofrad ba94207
storage: add consistency parameter to List
boxofrad 6e39fd5
storage: more correct consistency documentation
boxofrad 4580e51
storage: fix integer alignment in inmem backend
boxofrad 0748073
storage: support eventual consistency in conformance tests
boxofrad 0a49eff
storage: correct eventLock comment
boxofrad 8c75333
storage: rearrange inmem store files
boxofrad 8bc4a80
storage: fix bug where watches could emit duplicate events
boxofrad 8e803f4
Merge branch 'boxofrad/storage-backend' into test-merge
analogue c5784cb
nix the mock registry in read tests
analogue 5e3c998
nix mockBackend from read tests
analogue d5cd617
TIL errors.[Is|As]
analogue 5d8dffb
Use mockBackend to verify ReadConsistency arg set properly
analogue 973da84
Fix imports with goimports
analogue 87ad694
Merge branch 'main' into spatel/NET-2687-resource-service-read-endpoint
analogue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.