@@ -31,39 +31,29 @@ import (
3131 tokens3 "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens"
3232 "gopkg.in/gcfg.v1"
3333
34+ openstack_provider "git.openstack.org/openstack/openstack-cloud-controller-manager/pkg/cloudprovider/providers/openstack"
35+
3436 "github.com/golang/glog"
3537 netutil "k8s.io/apimachinery/pkg/util/net"
3638 certutil "k8s.io/client-go/util/cert"
3739)
3840
3941type cinderConfig struct {
40- Global cinderConfigGlobal
41- }
42-
43- type cinderConfigGlobal struct {
44- CinderEndpoint string `gcfg:"cinder-endpoint"`
45- AuthURL string `gcfg:"auth-url"`
46- Username string
47- UserID string `gcfg:"user-id"`
48- Password string
49- TenantID string `gcfg:"tenant-id"`
50- TenantName string `gcfg:"tenant-name"`
51- TrustID string `gcfg:"trust-id"`
52- DomainID string `gcfg:"domain-id"`
53- DomainName string `gcfg:"domain-name"`
54- Region string
55- CAFile string `gcfg:"ca-file"`
42+ openstack_provider.Config
43+ Cinder struct {
44+ Endpoint string `gcfg:"endpoint"`
45+ }
5646}
5747
5848func (cfg cinderConfig ) toAuthOptions () gophercloud.AuthOptions {
5949 return gophercloud.AuthOptions {
60- IdentityEndpoint : cfg .Global .AuthURL ,
50+ IdentityEndpoint : cfg .Global .AuthUrl ,
6151 Username : cfg .Global .Username ,
62- UserID : cfg .Global .UserID ,
52+ UserID : cfg .Global .UserId ,
6353 Password : cfg .Global .Password ,
64- TenantID : cfg .Global .TenantID ,
54+ TenantID : cfg .Global .TenantId ,
6555 TenantName : cfg .Global .TenantName ,
66- DomainID : cfg .Global .DomainID ,
56+ DomainID : cfg .Global .DomainId ,
6757 DomainName : cfg .Global .DomainName ,
6858
6959 // Persistent service, so we need to be able to renew tokens.
@@ -73,11 +63,11 @@ func (cfg cinderConfig) toAuthOptions() gophercloud.AuthOptions {
7363
7464func (cfg cinderConfig ) toAuth3Options () tokens3.AuthOptions {
7565 return tokens3.AuthOptions {
76- IdentityEndpoint : cfg .Global .AuthURL ,
66+ IdentityEndpoint : cfg .Global .AuthUrl ,
7767 Username : cfg .Global .Username ,
78- UserID : cfg .Global .UserID ,
68+ UserID : cfg .Global .UserId ,
7969 Password : cfg .Global .Password ,
80- DomainID : cfg .Global .DomainID ,
70+ DomainID : cfg .Global .DomainId ,
8171 DomainName : cfg .Global .DomainName ,
8272 AllowReauth : true ,
8373 }
@@ -90,22 +80,13 @@ func getConfigFromEnv() cinderConfig {
9080 return cinderConfig {}
9181 }
9282
93- return cinderConfig {
94- Global : cinderConfigGlobal {
95- AuthURL : authURL ,
96- Username : os .Getenv ("OS_USERNAME" ),
97- Password : os .Getenv ("OS_PASSWORD" ), // TODO: Replace with secret
98- TenantID : os .Getenv ("OS_TENANT_ID" ),
99- Region : os .Getenv ("OS_REGION_NAME" ),
100- DomainName : os .Getenv ("OS_USER_DOMAIN_NAME" ),
101- },
102- }
83+ return cinderConfig {}
10384}
10485
10586func getConfig (configFilePath string ) (cinderConfig , error ) {
87+ config := getConfigFromEnv ()
10688 if configFilePath != "" {
10789 var configFile * os.File
108- var config cinderConfig
10990 configFile , err := os .Open (configFilePath )
11091 if err != nil {
11192 glog .Fatalf ("Couldn't open configuration %s: %#v" ,
@@ -122,10 +103,6 @@ func getConfig(configFilePath string) (cinderConfig, error) {
122103 }
123104 return config , nil
124105 }
125- envConfig := getConfigFromEnv ()
126- if envConfig != (cinderConfig {}) {
127- return envConfig , nil
128- }
129106
130107 // Pass explicit nil so plugins can actually check for nil. See
131108 // "Why is my nil error value not equal to nil?" in golang.org/doc/faq.
@@ -135,7 +112,7 @@ func getConfig(configFilePath string) (cinderConfig, error) {
135112}
136113
137114func getKeystoneVolumeService (cfg cinderConfig ) (* gophercloud.ServiceClient , error ) {
138- provider , err := openstack .NewClient (cfg .Global .AuthURL )
115+ provider , err := openstack .NewClient (cfg .Global .AuthUrl )
139116 if err != nil {
140117 return nil , err
141118 }
@@ -150,10 +127,10 @@ func getKeystoneVolumeService(cfg cinderConfig) (*gophercloud.ServiceClient, err
150127 provider .HTTPClient .Transport = netutil .SetOldTransportDefaults (& http.Transport {TLSClientConfig : config })
151128
152129 }
153- if cfg .Global .TrustID != "" {
130+ if cfg .Global .TrustId != "" {
154131 opts := cfg .toAuth3Options ()
155132 authOptsExt := trusts.AuthOptsExt {
156- TrustID : cfg .Global .TrustID ,
133+ TrustID : cfg .Global .TrustId ,
157134 AuthOptionsBuilder : & opts ,
158135 }
159136 err = openstack .AuthenticateV3 (provider , authOptsExt , gophercloud.EndpointOpts {})
@@ -185,7 +162,7 @@ func getNoAuthVolumeService(cfg cinderConfig) (*gophercloud.ServiceClient, error
185162 }
186163
187164 client , err := noauth .NewBlockStorageNoAuth (provider , noauth.EndpointOpts {
188- CinderEndpoint : cfg .Global . CinderEndpoint ,
165+ CinderEndpoint : cfg .Cinder . Endpoint ,
189166 })
190167 if err != nil {
191168 return nil , fmt .Errorf ("failed to get volume service: %v" , err )
@@ -202,7 +179,7 @@ func GetVolumeService(configFilePath string) (*gophercloud.ServiceClient, error)
202179 return nil , err
203180 }
204181
205- if config .Global . CinderEndpoint != "" {
182+ if config .Cinder . Endpoint != "" {
206183 return getNoAuthVolumeService (config )
207184 }
208185 return getKeystoneVolumeService (config )
0 commit comments