Skip to content

Commit

Permalink
[go function] fix: go function should parse conf content first (apach…
Browse files Browse the repository at this point in the history
…e#4746)

### Motivation

`pulsar-function-go/conf` package apply `instance-conf-path` with default value `HOME_PATH+github.com/apache/pulsar/pulsar-function-go/conf/conf.yaml`, once function deployed, the running node may not have the yaml conf file exist, then go function will panic with `not found conf file` error. 

This PR changed the logic of config parsing, parse `confContent` first, then parse `confFilePath` if `confContent` empty.
  • Loading branch information
freeznet authored and sijie committed Jul 21, 2019
1 parent f13af48 commit 8a3b3af
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions pulsar-function-go/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,24 @@ func (c *Conf) GetConf() *Conf {
flag.Usage()
}

if confContent == "" && confFilePath == "" {
log.Errorf("no yaml file or conf content provided")
return nil
}

if confFilePath != "" {
yamlFile, err := ioutil.ReadFile(confFilePath)
if err != nil {
log.Errorf("not found conf file, err:%s", err.Error())
if err == nil {
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
log.Errorf("unmarshal yaml file error:%s", err.Error())
return nil
}
} else if err != nil && os.IsNotExist(err) && confContent == "" {
log.Errorf("conf file not found, no config content provided, err:%s", err.Error())
return nil
}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
log.Errorf("unmarshal yaml file error:%s", err.Error())
} else if err != nil && !os.IsNotExist(err) {
log.Errorf("load conf file failed, err:%s", err.Error())
return nil
}
}
Expand All @@ -107,6 +116,7 @@ func (c *Conf) GetConf() *Conf {
return nil
}
}

return c
}

Expand Down

0 comments on commit 8a3b3af

Please sign in to comment.