@@ -18,11 +18,11 @@ package broker
18
18
19
19
import (
20
20
"fmt"
21
+ "github.com/golang/glog"
22
+ "github.com/rs/xid"
21
23
"io/ioutil"
22
24
"net/http"
23
25
"sync"
24
- "github.com/golang/glog"
25
- "github.com/rs/xid"
26
26
27
27
"github.com/kubernetes-incubator/service-catalog/pkg/brokerapi"
28
28
"github.com/minio/minio-go"
@@ -35,10 +35,10 @@ const (
35
35
BUCKET_ENDPOINT = "bucketEndpoint"
36
36
BUCKET_NAME = "bucketName"
37
37
BUCKET_ID = "bucketID"
38
- BUCKET_PWORD = "bucketPword "
38
+ BUCKET_PASS = "bucketPass "
39
39
)
40
40
41
- type serviceInstance struct {
41
+ type s3ServiceInstance struct {
42
42
// k8s namespace
43
43
Namespace string
44
44
// binding credential created during Bind()
@@ -47,27 +47,27 @@ type serviceInstance struct {
47
47
48
48
type broker struct {
49
49
// rwMutex controls concurrent R and RW access
50
- rwMutex sync.RWMutex
50
+ rwMutex sync.RWMutex
51
51
// instanceMap maps instanceIDs to the ID's userProvidedServiceInstance values
52
- instanceMap map [string ]* serviceInstance
52
+ instanceMap map [string ]* s3ServiceInstance
53
53
// client used to access s3 API
54
- s3Client * minio.Client
54
+ s3Client * minio.Client
55
55
// s3 server ip and port
56
- s3url string // includes ":port"
57
- s3ID string
58
- s3Pwd string
56
+ s3url string // includes ":port"
57
+ s3ID string
58
+ s3Pass string
59
59
// client used to access kubernetes
60
- kubeClient * clientset.Clientset
60
+ kubeClient * clientset.Clientset
61
61
}
62
62
63
- // CreateBroker initializes the service broker. This function is called by server.Start()
63
+ // Initialize the s3-gluster service broker. This function is called by ` server.Start()`.
64
64
func CreateBroker () Broker {
65
65
const S3_BROKER_POD_LABEL = "glusterfs=s3-pod"
66
- var instanceMap = make (map [string ]* serviceInstance )
67
- glog .Info ("Generating new broker." )
66
+ var instanceMap = make (map [string ]* s3ServiceInstance )
67
+ glog .Info ("Generating new s3-gluster broker." )
68
68
s3ip , err := getExternalIP ()
69
69
if err != nil {
70
- glog .Errorf ("Failed to get external IP: %v" , err )
70
+ glog .Fatalf ("Failed to get external IP: %v" , err )
71
71
}
72
72
73
73
// get the kubernetes client
@@ -76,8 +76,8 @@ func CreateBroker() Broker {
76
76
glog .Fatalf ("failed to get kubernetes client: %v\n " , err )
77
77
}
78
78
79
- // get the s3 deployment pod created via the `gk-deploy` script
80
- // need to get this pod using label selectors since its name is generated
79
+ // Get the s3 deployment pod created via the `gk-deploy` script. Need to
80
+ // get this pod using label selectors since its name is generated.
81
81
ns := "default"
82
82
podList , err := cs .CoreV1 ().Pods (ns ).List (metav1.ListOptions {
83
83
LabelSelector : S3_BROKER_POD_LABEL ,
@@ -116,17 +116,18 @@ func CreateBroker() Broker {
116
116
if err != nil {
117
117
glog .Fatalf ("failed to get minio-s3 client: %v\n " , err )
118
118
}
119
- glog .Infof ("New Broker for s3 endpoint: %s" , s3endpoint )
119
+ glog .Infof ("New Broker for s3-gluster endpoint: %s" , s3endpoint )
120
120
return & broker {
121
121
instanceMap : instanceMap ,
122
122
s3Client : s3c ,
123
123
s3url : s3endpoint ,
124
124
kubeClient : cs ,
125
125
s3ID : fmt .Sprintf ("%s:%s" , acct , user ),
126
- s3Pwd : pass ,
126
+ s3Pass : pass ,
127
127
}
128
128
}
129
129
130
+ // Implements the `Catalog` interface method.
130
131
func (b * broker ) Catalog () (* brokerapi.Catalog , error ) {
131
132
return & brokerapi.Catalog {
132
133
Services : []* brokerapi.Service {
@@ -148,11 +149,15 @@ func (b *broker) Catalog() (*brokerapi.Catalog, error) {
148
149
}, nil
149
150
}
150
151
152
+ // The `GetServiceInstanceLastOperation` interface method is not implemented.
151
153
func (b * broker ) GetServiceInstanceLastOperation (instanceID , serviceID , planID , operation string ) (* brokerapi.LastOperationResponse , error ) {
152
154
glog .Info ("GetServiceInstanceLastOperation not yet implemented." )
153
155
return nil , nil
154
156
}
155
157
158
+ // Implements the `CreateServiceInstance` interface method by creating (provisioning) a s3 bucket.
159
+ // Note: (nil, nil) is returned for success, meaning the CreateServiceInstanceResponse is ignored by
160
+ // the caller.
156
161
func (b * broker ) CreateServiceInstance (instanceID string , req * brokerapi.CreateServiceInstanceRequest ) (* brokerapi.CreateServiceInstanceResponse , error ) {
157
162
glog .Infof ("CreateServiceInstance called. instanceID: %s" , instanceID )
158
163
b .rwMutex .Lock ()
@@ -164,7 +169,7 @@ func (b *broker) CreateServiceInstance(instanceID string, req *brokerapi.CreateS
164
169
}
165
170
// Check required parameter "bucketName"
166
171
bucketName , ok := req .Parameters ["bucketName" ].(string )
167
- if ! ok {
172
+ if ! ok {
168
173
glog .Errorf ("Bucket name not provided, generating random name." )
169
174
bucketName = xid .New ().String ()
170
175
}
@@ -181,24 +186,25 @@ func (b *broker) CreateServiceInstance(instanceID string, req *brokerapi.CreateS
181
186
if err := b .provisionBucket (bucketName ); err != nil {
182
187
return nil , err
183
188
}
184
- b .instanceMap [instanceID ] = & serviceInstance {
189
+ b .instanceMap [instanceID ] = & s3ServiceInstance {
185
190
Namespace : req .ContextProfile .Namespace ,
186
191
Credential : brokerapi.Credential {
187
192
BUCKET_NAME : bucketName ,
188
193
BUCKET_ENDPOINT : b .s3url ,
189
194
BUCKET_ID : b .s3ID ,
190
- BUCKET_PWORD : b . s3Pwd ,
195
+ BUCKET_PASS : b . s3Pass ,
191
196
},
192
197
}
193
198
return nil , nil
194
199
}
195
200
201
+ // Implements the `RemoveServiceInstance` interface method.
196
202
func (b * broker ) RemoveServiceInstance (instanceID , serviceID , planID string , acceptsIncomplete bool ) (* brokerapi.DeleteServiceInstanceResponse , error ) {
197
203
glog .Infof ("RemoveServiceInstance called. instanceID: %s" , instanceID )
198
204
b .rwMutex .Lock ()
199
205
defer b .rwMutex .Unlock ()
200
206
instance , ok := b .instanceMap [instanceID ]
201
- if ! ok {
207
+ if ! ok {
202
208
glog .Errorf ("InstanceID %q not found." , instanceID )
203
209
return nil , fmt .Errorf ("Broker cannot find instanceID %q." , instanceID )
204
210
}
@@ -219,10 +225,11 @@ func (b *broker) RemoveServiceInstance(instanceID, serviceID, planID string, acc
219
225
return nil , nil
220
226
}
221
227
228
+ // Implements the `Bind` interface method.
222
229
func (b * broker ) Bind (instanceID , bindingID string , req * brokerapi.BindingRequest ) (* brokerapi.CreateServiceBindingResponse , error ) {
223
230
glog .Infof ("Bind called. instanceID: %q" , instanceID )
224
231
instance , ok := b .instanceMap [instanceID ]
225
- if ! ok {
232
+ if ! ok {
226
233
glog .Errorf ("Instance ID %q not found." )
227
234
return nil , fmt .Errorf ("Instance ID %q not found." , instanceID )
228
235
}
@@ -237,11 +244,13 @@ func (b *broker) Bind(instanceID, bindingID string, req *brokerapi.BindingReques
237
244
}
238
245
239
246
// nothing to do here
247
+ // The `UnBind` interface method is not implemented.
240
248
func (b * broker ) UnBind (instanceID , bindingID , serviceID , planID string ) error {
241
249
glog .Info ("UnBind not yet implemented." )
242
250
return nil
243
251
}
244
252
253
+ // Creates an s3 compatible bucket of the passed-in name.
245
254
func (b * broker ) provisionBucket (bucketName string ) error {
246
255
glog .Infof ("Creating bucket %q" , bucketName )
247
256
location := "" // ignored for now...
@@ -255,8 +264,9 @@ func (b *broker) provisionBucket(bucketName string) error {
255
264
return nil
256
265
}
257
266
258
- // TODO (copejon) long way of checking for bucket name collision. gluster-swift does not support the api call that
259
- // minio.BucketExists() maps to; always fails with "400 bad request".
267
+ // Returns true if the passed-in bucket exists.
268
+ // TODO: long way of checking for bucket name collision. gluster-swift does not support
269
+ // the api call that minio.BucketExists() maps to; always fails with "400 bad request".
260
270
func (b * broker ) checkBucketExists (bucketName string ) (bool , error ) {
261
271
glog .Infof ("Checking if bucket name %q already exists." , bucketName )
262
272
buckets , err := b .s3Client .ListBuckets ()
@@ -274,7 +284,7 @@ func (b *broker) checkBucketExists(bucketName string) (bool, error) {
274
284
return exists , nil
275
285
}
276
286
277
- // getS3Client returns a minio api client
287
+ // Returns a minio api client.
278
288
func getS3Client (acct , user , pass , ip string ) (* minio.Client , error ) {
279
289
glog .Infof ("Creating s3 client based on: \" %s:%s\" on ip %s" , acct , user , ip )
280
290
@@ -287,7 +297,7 @@ func getS3Client(acct, user, pass, ip string) (*minio.Client, error) {
287
297
return minioClient , nil
288
298
}
289
299
290
- // getKubeClient returns a k8s api client
300
+ // Returns a k8s api client.
291
301
func getKubeClient () (* clientset.Clientset , error ) {
292
302
glog .Info ("Getting k8s API Client config" )
293
303
kubeClientConfig , err := k8sRest .InClusterConfig ()
@@ -299,6 +309,7 @@ func getKubeClient() (*clientset.Clientset, error) {
299
309
return cs , err
300
310
}
301
311
312
+ // Returns the external ip of the gce master node.
302
313
func getExternalIP () (string , error ) {
303
314
c := http.Client {}
304
315
glog .Info ("Requesting external IP." )
@@ -310,7 +321,7 @@ func getExternalIP() (string, error) {
310
321
req .Header .Add ("Metadata-Flavor" , " Google" )
311
322
resp , err := c .Do (req )
312
323
if err != nil {
313
- glog .Errorf ("Failed to sent http request: %v" , err )
324
+ glog .Errorf ("Failed to send http request: %v" , err )
314
325
return "" , err
315
326
}
316
327
defer resp .Body .Close ()
0 commit comments