mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Merge pull request #76875 from JieJhih/proxy/file
handle file close error
This commit is contained in:
commit
b9fbed1324
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user