chore(config): remove deprecated controllers field (#5125)

* chore(config): remove deprecated controllers field
pull/4847/merge
Irena Rindos 2 years ago committed by GitHub
parent 79bf12bd23
commit 35679c6a5b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -13,7 +13,7 @@
# description = "A default worker created demonstration"
# # Workers must be able to reach controllers on :9201
# controllers = [
# initial_upstreams = [
# "10.0.0.1",
# "10.0.0.2",
# "10.0.0.3",

@ -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](https://github.com/hashicorp/boundary/pull/5125))
## 0.17.2 (Unreleased)
### Changes

@ -13,7 +13,7 @@ worker {
description = "Enos Boundary worker ${id}"
# Workers must be able to reach controllers on :9201
controllers = ${controller_ips}
initial_upstreams = ${controller_ips}
public_addr = "${public_addr}"

@ -13,7 +13,7 @@ worker {
description = "Enos Boundary worker ${id}"
# Workers must be able to reach controllers on :9201
controllers = ${controller_ips}
initial_upstreams = ${controller_ips}
public_addr = "${public_addr}"

@ -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())

@ -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
@ -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 {
@ -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)
}

@ -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,
@ -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,
@ -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,
@ -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,

@ -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 {

Loading…
Cancel
Save