Skip to content

Commit

Permalink
Update code after comments
Browse files Browse the repository at this point in the history
  • Loading branch information
clamoriniere committed Nov 29, 2019
1 parent 6788551 commit 9f0ac49
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
33 changes: 18 additions & 15 deletions pkg/autodiscovery/configresolver/configresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,33 +95,36 @@ func Resolve(tpl integration.Config, svc listeners.Service) (integration.Config,
return resolvedConfig, errors.New("unable to resolve, service not ready")
}

tags := []string{}
var err error
if !tpl.IgnoreListenerTags {
tags, err = svc.GetTags()
if err != nil {
return resolvedConfig, err
}
}

err = SubstituteTemplateVariables(&resolvedConfig, templateVariables, svc)
if err != nil {
if err := SubstituteTemplateVariables(&resolvedConfig, templateVariables, svc); err != nil {
return resolvedConfig, err
}

err = SubstituteTemplateEnvVars(&resolvedConfig)
if err != nil {
if err := SubstituteTemplateEnvVars(&resolvedConfig); err != nil {
// We add the service name to the error here, since SubstituteTemplateEnvVars doesn't know about that
return resolvedConfig, fmt.Errorf("%s, skipping service %s", err, svc.GetEntity())
}

if !tpl.IgnoreListenerTags {
if err := addServiceTags(&resolvedConfig, svc); err != nil {
return resolvedConfig, fmt.Errorf("unable to add tags for service '%s', err: %s", svc.GetEntity(), err)
}
}

return resolvedConfig, nil
}

func addServiceTags(resolvedConfig *integration.Config, svc listeners.Service) error {
tags, err := svc.GetTags()
if err != nil {
return err
}
for i := 0; i < len(resolvedConfig.Instances); i++ {
err = resolvedConfig.Instances[i].MergeAdditionalTags(tags)
if err != nil {
return resolvedConfig, err
return err
}
}
return resolvedConfig, nil
return nil
}

func getHost(tplVar []byte, svc listeners.Service) ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/autodiscovery/configresolver/configresolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ func TestResolve(t *testing.T) {
ADIdentifiers: []string{"redis"},
Instances: []integration.Data{integration.Data("host: %%FOO%%")},
},
errorString: "yaml: found character that cannot start any token",
errorString: "unable to add tags for service 'a5901276aed1', err: yaml: found character that cannot start any token",
},
}
validTemplates := 0
Expand Down

0 comments on commit 9f0ac49

Please sign in to comment.