-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add -bootstrap-token-file to provide your own bootstrap token. If provided, server-acl-init will skip ACL bootstrapping of the servers and will not update server policies and set tokens. * The -server-address flag now can also be a cloud auto-join string. This enables us to re-use the same string you would use for retry-join.
- Loading branch information
Showing
8 changed files
with
342 additions
and
102 deletions.
There are no files selected for viewing
This file contains 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,61 @@ | ||
package godiscover | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/consul-k8s/version" | ||
"github.com/hashicorp/go-discover" | ||
discoverk8s "github.com/hashicorp/go-discover/provider/k8s" | ||
"github.com/hashicorp/go-hclog" | ||
) | ||
|
||
// ConsulServerAddresses uses go-discover to discover Consul servers | ||
// provided by the 'discoverString' and returns them. | ||
func ConsulServerAddresses(discoverString string, providers map[string]discover.Provider, logger hclog.Logger) ([]string, error) { | ||
// If it's a cloud-auto join string, discover server addresses through the cloud provider. | ||
// This code was adapted from | ||
// https://github.com/hashicorp/consul/blob/c5fe112e59f6e8b03159ec8f2dbe7f4a026ce823/agent/retry_join.go#L55-L89. | ||
disco, err := newDiscover(providers) | ||
if err != nil { | ||
return nil, err | ||
} | ||
logger.Debug("using cloud auto-join", "server-addr", discoverString) | ||
servers, err := disco.Addrs(discoverString, logger.StandardLogger(&hclog.StandardLoggerOptions{ | ||
InferLevels: true, | ||
})) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// check if we discovered any servers | ||
if len(servers) == 0 { | ||
return nil, fmt.Errorf("could not discover any Consul servers with %q", discoverString) | ||
} | ||
|
||
logger.Debug("discovered servers", "servers", strings.Join(servers, " ")) | ||
|
||
return servers, nil | ||
} | ||
|
||
// newDiscover initializes the new Discover object | ||
// set up with all predefined providers, as well as | ||
// the k8s provider. | ||
// This code was adapted from | ||
// https://github.com/hashicorp/consul/blob/c5fe112e59f6e8b03159ec8f2dbe7f4a026ce823/agent/retry_join.go#L42-L53 | ||
func newDiscover(providers map[string]discover.Provider) (*discover.Discover, error) { | ||
if providers == nil { | ||
providers = make(map[string]discover.Provider) | ||
} | ||
|
||
for k, v := range discover.Providers { | ||
providers[k] = v | ||
} | ||
providers["k8s"] = &discoverk8s.Provider{} | ||
|
||
userAgent := fmt.Sprintf("consul-k8s/%s (https://www.consul.io/)", version.GetHumanVersion()) | ||
return discover.New( | ||
discover.WithUserAgent(userAgent), | ||
discover.WithProviders(providers), | ||
) | ||
} |
This file contains 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
This file contains 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.