feat(worker): allow hcp cluster id to be sourced from env var (#3709)

* feat(worker): allow hcp cluster id to be sourced from env var
pull/3714/head
Irena Rindos 3 years ago committed by GitHub
parent 6f10a0ac87
commit 7bd2d2c913
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,6 +11,8 @@ Canonical reference for changes, improvements, and bugfixes for Boundary.
([PR](https://github.com/hashicorp/boundary/pull/3679)).
* feat: add worker upstream connection status to ops health check
([PR](https://github.com/hashicorp/boundary/pull/3650)).
* feat: allow HCP cluster id to be sourced from file or env variable
([PR](https://github.com/hashicorp/boundary/pull/3709)).
### Bug Fixes

@ -363,11 +363,15 @@ func (c *Command) Run(args []string) int {
c.UI.Error(fmt.Errorf("Initial upstreams and HCPB cluster ID are mutually exclusive fields").Error())
return base.CommandUserError
}
clusterId := c.Config.HcpbClusterId
clusterId, err := parseutil.ParsePath(c.Config.HcpbClusterId)
if err != nil && !errors.Is(err, parseutil.ErrNotAUrl) {
c.UI.Error(fmt.Errorf("Failed to parse HCP Boundary cluster ID %q: %w", clusterId, err).Error())
return base.CommandUserError
}
if strings.HasPrefix(clusterId, "int-") {
clusterId = strings.TrimPrefix(clusterId, "int-")
}
_, err := uuid.ParseUUID(clusterId)
_, err = uuid.ParseUUID(clusterId)
if err != nil {
c.UI.Error(fmt.Errorf("Invalid HCP Boundary cluster ID %q: %w", clusterId, err).Error())
return base.CommandUserError

@ -34,6 +34,7 @@ import (
"github.com/hashicorp/boundary/internal/util"
"github.com/hashicorp/boundary/version"
"github.com/hashicorp/go-secure-stdlib/base62"
"github.com/hashicorp/go-secure-stdlib/parseutil"
"github.com/hashicorp/nodeenrollment"
"github.com/hashicorp/nodeenrollment/multihop"
"github.com/hashicorp/nodeenrollment/protocol"
@ -72,7 +73,11 @@ func (w *Worker) StartControllerConnections() error {
if len(initialAddrs) == 0 {
if w.conf.RawConfig.HcpbClusterId != "" && HandleHcpbClusterId != nil {
clusterAddress := HandleHcpbClusterId(w.conf.RawConfig.HcpbClusterId)
clusterId, err := parseutil.ParsePath(w.conf.RawConfig.HcpbClusterId)
if err != nil && !errors.Is(err, parseutil.ErrNotAUrl) {
return fmt.Errorf("failed to parse HCP Boundary cluster ID: %q: %w", clusterId, err)
}
clusterAddress := HandleHcpbClusterId(clusterId)
initialAddrs = append(initialAddrs, clusterAddress)
event.WriteSysEvent(w.baseContext, op, fmt.Sprintf("Setting HCP Boundary cluster address %s as upstream address", clusterAddress))
} else {

@ -17,6 +17,7 @@ import (
pbs "github.com/hashicorp/boundary/internal/gen/controller/servers/services"
"github.com/hashicorp/boundary/internal/server"
"github.com/hashicorp/boundary/version"
"github.com/hashicorp/go-secure-stdlib/parseutil"
"github.com/hashicorp/go-secure-stdlib/strutil"
"google.golang.org/grpc/connectivity"
)
@ -249,8 +250,13 @@ func (w *Worker) sendWorkerStatus(cancelCtx context.Context, sessionManager sess
if len(w.conf.RawConfig.Worker.InitialUpstreams) > 0 {
addrs = append(addrs, w.conf.RawConfig.Worker.InitialUpstreams...)
} else if HandleHcpbClusterId != nil && len(w.conf.RawConfig.HcpbClusterId) > 0 {
clusterAddress := HandleHcpbClusterId(w.conf.RawConfig.HcpbClusterId)
addrs = append(addrs, clusterAddress)
clusterId, err := parseutil.ParsePath(w.conf.RawConfig.HcpbClusterId)
if err != nil && !errors.Is(err, parseutil.ErrNotAUrl) {
event.WriteError(cancelCtx, op, err, event.WithInfoMsg("failed to parse HCP Boundary cluster ID"))
} else {
clusterAddress := HandleHcpbClusterId(clusterId)
addrs = append(addrs, clusterAddress)
}
}
addrs = strutil.RemoveDuplicates(addrs, false)

Loading…
Cancel
Save