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

Remove agent domain/name duplication in the config #39

Merged
merged 2 commits into from
Aug 22, 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: 1 addition & 1 deletion api/update_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type UpdateAgent interface {

// UpdateManagerConfig holds configuration properties for an update manager.
type UpdateManagerConfig struct {
Name string
Name string `json:"-"`
RebootRequired bool `json:"rebootRequired"`
ReadTimeout string `json:"readTimeout"`
}
Expand Down
4 changes: 4 additions & 0 deletions config/config_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func LoadConfig(version string) (*Config, error) {
func prepareAgentsConfig(cfg *Config, domains map[string]bool) {
if cfg.Agents == nil {
cfg.Agents = newDefaultAgentsConfig()
} else {
for name, agent := range cfg.Agents {
agent.Name = name
}
}
if len(domains) > 0 {
for name := range cfg.Agents {
Expand Down
3 changes: 0 additions & 3 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,14 @@ func TestLoadConfigFromFile(t *testing.T) {

expectedAgentValues := map[string]*api.UpdateManagerConfig{
"self-update": {
Name: "testSUname",
RebootRequired: false,
ReadTimeout: "20s",
},
"containers": {
Name: "testContainersName",
RebootRequired: true,
ReadTimeout: "30s",
},
"test-domain": {
Name: "testDomainName",
RebootRequired: true,
ReadTimeout: "50s",
},
Expand Down
14 changes: 7 additions & 7 deletions config/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,17 @@ func TestParseFlags(t *testing.T) {
testConfigPath := "../config/testdata/config.json"
expectedAgentsFromConfigFile := map[string]*api.UpdateManagerConfig{
"self-update": {
Name: "testSUname",
Name: "self-update",
RebootRequired: false,
ReadTimeout: "20s",
},
"containers": {
Name: "testContainersName",
Name: "containers",
RebootRequired: true,
ReadTimeout: "30s",
},
"test-domain": {
Name: "testDomainName",
Name: "test-domain",
RebootRequired: true,
ReadTimeout: "50s",
},
Expand Down Expand Up @@ -306,24 +306,24 @@ func TestParseFlags(t *testing.T) {
reconfiguredRTO := "2m"
expectedAgentsFromConfigFile := map[string]*api.UpdateManagerConfig{
"self-update": {
Name: "testSUname",
Name: "self-update",
RebootRequired: false,
ReadTimeout: reconfiguredRTO,
},
"containers": {
Name: "testContainersName",
Name: "containers",
RebootRequired: true,
ReadTimeout: "30s",
},
"test-domain": {
Name: "testDomainName",
Name: "test-domain",
RebootRequired: true,
ReadTimeout: "50s",
},
}

os.Args = []string{oldArgs[0], fmt.Sprintf("--%s=%s", configFileFlagID, testConfigPath),
fmt.Sprintf("--%s=%s", "testSUname-read-timeout", reconfiguredRTO)}
fmt.Sprintf("--%s=%s", "self-update-read-timeout", reconfiguredRTO)}
cfg := newDefaultConfig()
configFilePath := ParseConfigFilePath()
if configFilePath != "" {
Expand Down
3 changes: 0 additions & 3 deletions config/testdata/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@
"phaseTimeout": "2m",
"agents": {
"self-update": {
"name": "testSUname",
"rebootRequired": false,
"readTimeout": "20s"
},
"containers": {
"name": "testContainersName",
"rebootRequired": true,
"readTimeout": "30s"
},
"test-domain": {
"name": "testDomainName",
"rebootRequired": true,
"readTimeout": "50s"
}
Expand Down
1 change: 0 additions & 1 deletion resources/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"domain": "device",
"agents": {
"containers": {
"name": "containers",
"rebootRequired": false,
"readTimeout": "30s"
}
Expand Down