Skip to content
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

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

Merged
merged 5 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions internal/cmd/commands/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion internal/daemon/worker/controller_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 8 additions & 2 deletions internal/daemon/worker/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down