Merge pull request #6225 from cjcullen/cloudprovider

Fix typed-nil passing in cloudprovider/plugins
pull/6/head
Victor Marmol 2015-03-31 13:04:11 -07:00
commit c93cd4a0d1
1 changed files with 8 additions and 5 deletions

View File

@ -64,26 +64,29 @@ func GetCloudProvider(name string, config io.Reader) (Interface, error) {
// InitCloudProvider creates an instance of the named cloud provider. // InitCloudProvider creates an instance of the named cloud provider.
func InitCloudProvider(name string, configFilePath string) Interface { func InitCloudProvider(name string, configFilePath string) Interface {
var config *os.File var cloud Interface
if name == "" { if name == "" {
glog.Info("No cloud provider specified.") glog.Info("No cloud provider specified.")
return nil return nil
} }
var err error
if configFilePath != "" { if configFilePath != "" {
var err error config, err := os.Open(configFilePath)
config, err = os.Open(configFilePath)
if err != nil { if err != nil {
glog.Fatalf("Couldn't open cloud provider configuration %s: %#v", glog.Fatalf("Couldn't open cloud provider configuration %s: %#v",
configFilePath, err) configFilePath, err)
} }
defer config.Close() defer config.Close()
cloud, err = GetCloudProvider(name, config)
} else {
// Pass explicit nil so plugins can actually check for nil. See
// "Why is my nil error value not equal to nil?" in golang.org/doc/faq.
cloud, err = GetCloudProvider(name, nil)
} }
cloud, err := GetCloudProvider(name, config)
if err != nil { if err != nil {
glog.Fatalf("Couldn't init cloud provider %q: %v", name, err) glog.Fatalf("Couldn't init cloud provider %q: %v", name, err)
} }