Add worker tagging (#862)

This allows workers to have tags assigned to them, which can then be filtered to control which targets they are allowed to serve.
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2021-01-21 16:27:20 -05:00
1 parent 595a86508e
commit 717a3b52ee
54 files changed
+2150 -666

No files matched your search

+2 -2
View File
@@ -544,7 +544,7 @@ func (c *Command) WaitForInterrupt() int {
shutdownTriggered = true
case <-c.SighupCh:
c.UI.Output("==> Boundary controller reload triggered")
c.UI.Output("==> Boundary server reload triggered")
// Check for new log level
var level hclog.Level
@@ -589,7 +589,7 @@ func (c *Command) WaitForInterrupt() int {
RUNRELOADFUNCS:
if err := c.Reload(); err != nil {
c.UI.Error(fmt.Errorf("Error(s) were encountered during controller reload: %w", err).Error())
c.UI.Error(fmt.Errorf("Error(s) were encountered during server reload: %w", err).Error())
}
case <-c.SigUSR2Ch:
+3
View File
@@ -41,6 +41,9 @@ func generateTargetTableOutput(in *targets.Target) string {
if in.Description != "" {
nonAttributeMap["Description"] = in.Description
}
if in.WorkerFilter != "" {
nonAttributeMap["Worker Filter"] = in.WorkerFilter
}
maxLength := base.MaxAttributesLength(nonAttributeMap, in.Attributes, keySubstMap)
+22 -2
View File
@@ -11,6 +11,7 @@ import (
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/cmd/common"
"github.com/hashicorp/boundary/sdk/strutil"
"github.com/hashicorp/go-bexpr"
"github.com/mitchellh/cli"
"github.com/posener/complete"
)
@@ -27,6 +28,7 @@ type TcpCommand struct {
flagDefaultPort string
flagSessionMaxSeconds string
flagSessionConnectionLimit string
flagWorkerFilter string
}
func (c *TcpCommand) Synopsis() string {
@@ -34,8 +36,8 @@ func (c *TcpCommand) Synopsis() string {
}
var tcpFlagsMap = map[string][]string{
"create": {"scope-id", "name", "description", "default-port", "session-max-seconds", "session-connection-limit"},
"update": {"id", "name", "description", "version", "default-port", "session-max-seconds", "session-connection-limit"},
"create": {"scope-id", "name", "description", "default-port", "session-max-seconds", "session-connection-limit", "worker-filter"},
"update": {"id", "name", "description", "version", "default-port", "session-max-seconds", "session-connection-limit", "worker-filter"},
}
func (c *TcpCommand) Help() string {
@@ -91,6 +93,12 @@ func (c *TcpCommand) Flags() *base.FlagSets {
Target: &c.flagSessionConnectionLimit,
Usage: "The maximum number of connections allowed for a session. -1 means unlimited.",
})
case "worker-filter":
f.StringVar(&base.StringVar{
Name: "worker-filter",
Target: &c.flagWorkerFilter,
Usage: "A boolean expression to filter which workers can handle sessions for this target.",
})
}
}
@@ -196,6 +204,18 @@ func (c *TcpCommand) Run(args []string) int {
opts = append(opts, targets.WithSessionConnectionLimit(int32(limit)))
}
switch c.flagWorkerFilter {
case "":
case "null":
opts = append(opts, targets.DefaultWorkerFilter())
default:
if _, err := bexpr.CreateEvaluator(c.flagWorkerFilter); err != nil {
c.UI.Error(fmt.Sprintf("Unable to successfully parse filter expression: %s", err))
return 1
}
opts = append(opts, targets.WithWorkerFilter(c.flagWorkerFilter))
}
targetClient := targets.NewClient(client)
// Perform check-and-set when needed