Skip to content

Commit

Permalink
chore(config): remove deprecated controllers field
Browse files Browse the repository at this point in the history
  • Loading branch information
irenarindos committed Sep 23, 2024
1 parent 79bf12b commit c113869
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 63 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Canonical reference for changes, improvements, and bugfixes for Boundary.

## Next

* Remove deprecated `controllers` field from the worker config, which was deprecated for
`initial_upstreams`([PR]())

## 0.17.2 (Unreleased)

### Changes
Expand Down
3 changes: 0 additions & 3 deletions internal/cmd/commands/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,6 @@ func (c *Command) Run(args []string) int {
c.UI.Error(`Config activates worker but no listener with "proxy" purpose found`)
return base.CommandUserError
}
if c.Config.Worker.ControllersRaw != nil {
c.UI.Warn("The \"controllers\" field for worker config is deprecated. Please use \"initial_upstreams\" instead.")
}

if err := c.SetupWorkerPublicAddress(c.Config, ""); err != nil {
c.UI.Error(err.Error())
Expand Down
25 changes: 3 additions & 22 deletions internal/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,6 @@ type Worker struct {
InitialUpstreams []string `hcl:"-"`
InitialUpstreamsRaw any `hcl:"initial_upstreams"`

// The ControllersRaw field is deprecated and users should use InitialUpstreamsRaw instead.
// TODO: remove this field when support is discontinued.
ControllersRaw any `hcl:"controllers"`

// We use a raw interface for parsing so that people can use JSON-like
// syntax that maps directly to the filter input or possibly more familiar
// key=value syntax, as well as accepting a string denoting an env or file
Expand Down Expand Up @@ -1056,17 +1052,6 @@ func Parse(d string) (*Config, error) {
return result, nil
}

// supportControllersRawConfig returns either initialUpstreamsRaw or controllersRaw depending on which is populated. Errors when both fields are populated.
func supportControllersRawConfig(initialUpstreamsRaw, controllersRaw any) (any, error) {
switch {
case initialUpstreamsRaw == nil && controllersRaw != nil:
return controllersRaw, nil
case initialUpstreamsRaw != nil && controllersRaw != nil:
return nil, fmt.Errorf("both initial_upstreams and controllers fields are populated")
}
return initialUpstreamsRaw, nil
}

func parseApiRateLimits(node ast.Node) (ratelimit.Configs, error) {
list, ok := node.(*ast.ObjectList)
if !ok {
Expand Down Expand Up @@ -1103,19 +1088,15 @@ func parseWorkerUpstreams(c *Config) ([]string, error) {
if c == nil || c.Worker == nil {
return nil, fmt.Errorf("config or worker field is nil")
}
if c.Worker.InitialUpstreamsRaw == nil && c.Worker.ControllersRaw == nil {
if c.Worker.InitialUpstreamsRaw == nil {
// return nil here so that other address sources can be provided outside of config
return nil, nil
}
rawUpstreams, err := supportControllersRawConfig(c.Worker.InitialUpstreamsRaw, c.Worker.ControllersRaw)
if err != nil {
return nil, err
}

switch t := rawUpstreams.(type) {
switch t := c.Worker.InitialUpstreamsRaw.(type) {
case []any:
var upstreams []string
err := mapstructure.WeakDecode(rawUpstreams, &upstreams)
err := mapstructure.WeakDecode(c.Worker.InitialUpstreamsRaw, &upstreams)
if err != nil {
return nil, fmt.Errorf("failed to decode worker initial_upstreams block into config field: %w", err)
}
Expand Down
4 changes: 0 additions & 4 deletions internal/cmd/config/config_load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ func TestLoad(t *testing.T) {
PublicAddr: "",
InitialUpstreams: []string{"boundary:9201"},
InitialUpstreamsRaw: []any{"boundary:9201"},
ControllersRaw: nil,
Tags: nil,
TagsRaw: nil,
SuccessfulStatusGracePeriodDuration: 0,
Expand Down Expand Up @@ -810,7 +809,6 @@ func TestLoad(t *testing.T) {
PublicAddr: "",
InitialUpstreams: []string{"boundary:9201"},
InitialUpstreamsRaw: []any{"boundary:9201"},
ControllersRaw: nil,
Tags: nil,
TagsRaw: nil,
SuccessfulStatusGracePeriodDuration: 0,
Expand Down Expand Up @@ -1232,7 +1230,6 @@ func TestLoad(t *testing.T) {
PublicAddr: "",
InitialUpstreams: []string{"boundary:9201"},
InitialUpstreamsRaw: []any{"boundary:9201"},
ControllersRaw: nil,
Tags: nil,
TagsRaw: nil,
SuccessfulStatusGracePeriodDuration: 0,
Expand Down Expand Up @@ -1673,7 +1670,6 @@ func TestLoad(t *testing.T) {
PublicAddr: "",
InitialUpstreams: []string{"boundary:9201"},
InitialUpstreamsRaw: []any{"boundary:9201"},
ControllersRaw: nil,
Tags: nil,
TagsRaw: nil,
SuccessfulStatusGracePeriodDuration: 0,
Expand Down
34 changes: 0 additions & 34 deletions internal/cmd/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1609,40 +1609,6 @@ func TestWorkerUpstreams(t *testing.T) {
expErr: true,
expErrIs: parseutil.ErrNotAUrl,
},
{
name: "Worker using deprecated controllers field",
in: `
worker {
name = "test"
controllers = ["127.0.0.1", "127.0.0.2", "127.0.0.3"]
}`,
expWorkerUpstreams: []string{"127.0.0.1", "127.0.0.2", "127.0.0.3"},
expErr: false,
},
{
name: "Different values in controllers and initial_upstreams field",
in: `
worker {
name = "test"
controllers = ["127.0.0.1", "127.0.0.2", "127.0.0.3"]
initial_upstreams = ["127.0.0.1"]
}`,
expWorkerUpstreams: nil,
expErr: true,
expErrStr: "Failed to parse worker upstreams: both initial_upstreams and controllers fields are populated",
},
{
name: "Identical values in controllers and initial_upstreams field",
in: `
worker {
name = "test"
controllers = ["127.0.0.1"]
initial_upstreams = ["127.0.0.1"]
}`,
expWorkerUpstreams: nil,
expErr: true,
expErrStr: "Failed to parse worker upstreams: both initial_upstreams and controllers fields are populated",
},
}

for _, tt := range tests {
Expand Down

0 comments on commit c113869

Please sign in to comment.