-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace MasterURL with AggregatorURL in WorkerConfig (#1141)
We renamed the `master` command to `aggregator` in #847 (released in v0.15.3). However, we left some of the existing uses in place to prevent backwards incompatibility. This change renames the `MasterURL` field in `WorkerConfig` to `AggregatorURL` in keeping with our terminology elsewhere. Worker containers are configured using environment variables. This change renames the environment variable but also adds some compatibility for the original environment variable to still be processed. It is possible for different image versions to be used for the aggregator and the worker (although it would have to be explicitly set in the generated manifest). This changes allows older versions of Sonobuoy to be used as the aggregator image but does not allow older versions to be used as the worker image. Although some compatibility is broken, this seems acceptable as we don't recommend mixing versions of images within a single sonobuoy run. Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
- Loading branch information
Showing
7 changed files
with
108 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package worker | ||
|
||
import ( | ||
"github.com/spf13/viper" | ||
"github.com/vmware-tanzu/sonobuoy/pkg/plugin" | ||
"os" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
expectedCfg *plugin.WorkerConfig | ||
env map[string]string | ||
}{ | ||
{ | ||
desc: "No environment variables results in default config values", | ||
expectedCfg: &plugin.WorkerConfig{ | ||
ResultsDir: "/tmp/results", | ||
ProgressUpdatesPort: "8099", | ||
}, | ||
}, | ||
{ | ||
desc: "Aggregator URL is set in config if env var is set", | ||
expectedCfg: &plugin.WorkerConfig{ | ||
AggregatorURL: "aggregator", | ||
ResultsDir: plugin.ResultsDir, | ||
ProgressUpdatesPort: defaultProgressUpdatesPort, | ||
}, | ||
env: map[string]string{ | ||
"AGGREGATOR_URL": "aggregator", | ||
}, | ||
}, | ||
{ | ||
desc: "Aggregator URL is set in config if only deprecated master url env var is set", | ||
expectedCfg: &plugin.WorkerConfig{ | ||
AggregatorURL: "master", | ||
ResultsDir: plugin.ResultsDir, | ||
ProgressUpdatesPort: defaultProgressUpdatesPort, | ||
}, | ||
env: map[string]string{ | ||
"MASTER_URL": "master", | ||
}, | ||
}, | ||
{ | ||
desc: "Aggregator URL env var takes precedence if both new and deprecated env vars set", | ||
expectedCfg: &plugin.WorkerConfig{ | ||
AggregatorURL: "aggregator", | ||
ResultsDir: plugin.ResultsDir, | ||
ProgressUpdatesPort: defaultProgressUpdatesPort, | ||
}, | ||
env: map[string]string{ | ||
"MASTER_URL": "master", | ||
"AGGREGATOR_URL": "aggregator", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.desc, func(t *testing.T) { | ||
viper.Reset() | ||
for k, v := range tc.env { | ||
if err := os.Setenv(k, v); err != nil { | ||
t.Fatalf("unable to set environment variable %q to value %q", k, v) | ||
} | ||
} | ||
defer func() { | ||
for k := range tc.env { | ||
if err := os.Unsetenv(k); err != nil { | ||
t.Fatalf("unable to unset environment variable %q", k) | ||
} | ||
} | ||
}() | ||
|
||
cfg, err := LoadConfig() | ||
if err != nil { | ||
t.Fatalf("unexepected err from LoadConfig %q", err) | ||
} | ||
if !reflect.DeepEqual(cfg, tc.expectedCfg) { | ||
t.Fatalf("expected config to be %q, got %q", tc.expectedCfg, cfg) | ||
} | ||
}) | ||
} | ||
} |