Merge pull request #76875 from JieJhih/proxy/file

handle file close error
This commit is contained in:
Kubernetes Prow Robot 2019-04-29 22:49:35 -07:00 committed by GitHub
commit b9fbed1324
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -341,7 +341,7 @@ func (o *Options) runLoop() error {
}
}
func (o *Options) writeConfigFile() error {
func (o *Options) writeConfigFile() (err error) {
const mediaType = runtime.ContentTypeYAML
info, ok := runtime.SerializerInfoForMediaType(o.codecs.SupportedMediaTypes(), mediaType)
if !ok {
@ -354,10 +354,15 @@ func (o *Options) writeConfigFile() error {
if err != nil {
return err
}
// TODO handle error
defer configFile.Close()
if err := encoder.Encode(o.config, configFile); err != nil {
defer func() {
ferr := configFile.Close()
if ferr != nil && err == nil {
err = ferr
}
}()
if err = encoder.Encode(o.config, configFile); err != nil {
return err
}