-
Notifications
You must be signed in to change notification settings - Fork 334
refactor: make space for v2 controllers #2832
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
Merged
Changes from all commits
Commits
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
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 |
|---|---|---|
| @@ -1,40 +1,26 @@ | ||
| package consul | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/hashicorp/consul-server-connection-manager/discovery" | ||
| "github.com/hashicorp/consul/proto-public/pbresource" | ||
| "github.com/hashicorp/go-hclog" | ||
| ) | ||
|
|
||
| // NewResourceServiceClient creates a pbresource.ResourceServiceClient for creating V2 Consul resources. | ||
| // It is initialized with a consul-server-connection-manager discovery config to continuously find Consul | ||
| // It is initialized with a consul-server-connection-manager Watcher to continuously find Consul | ||
| // server addresses. | ||
| // The caller should make sure to Stop() the returned `watcher` (preferably with a `defer`) to clean up the gRPC | ||
| // connection and the discovery client. | ||
| // The caller can also set `config.ServerWatchDisabled=false` to prevent subscribing to Consul server address | ||
| // changes, as is the case with single-shot operations. | ||
| func NewResourceServiceClient(ctx context.Context, config discovery.Config, logger hclog.Logger, hack int) (pbresource.ResourceServiceClient, *discovery.Watcher, error) { | ||
|
|
||
| watcher, err := discovery.NewWatcher(ctx, config, logger.Named("consul-server-connection-manager")) | ||
| if err != nil { | ||
| return nil, nil, fmt.Errorf("unable to create Consul server watcher: %w", err) | ||
| } | ||
|
|
||
| go watcher.Run() | ||
| func NewResourceServiceClient(watcher *discovery.Watcher) (pbresource.ResourceServiceClient, error) { | ||
|
|
||
| // We recycle the GRPC connection from the discovery client because it | ||
| // should have all the necessary dial options, including the resolver that | ||
| // continuously updates Consul server addresses. Otherwise, a lot of code from consul-server-connection-manager | ||
| // would need to be duplicated | ||
| state, err := watcher.State() | ||
| if err != nil { | ||
| watcher.Stop() | ||
| return nil, nil, fmt.Errorf("unable to get connection manager state: %w", err) | ||
| return nil, fmt.Errorf("unable to get connection manager state: %w", err) | ||
| } | ||
| resourceClient := pbresource.NewResourceServiceClient(state.GRPCConn) | ||
|
|
||
| return resourceClient, watcher, nil | ||
| return resourceClient, nil | ||
| } |
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
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.