@@ -105,8 +105,9 @@ func podPreset(objectName, secretName, providerSvcName, consumerSvcName string)
105
105
func (bc * IntegrationCmd ) CreateIntegrationCmd () * cobra.Command {
106
106
cmd := & cobra.Command {
107
107
Use : "integration <consuming_service_instance_id> <providing_service_instance_id>" ,
108
- Short : "integrate certain mobile services together" ,
109
- Long : `create integration allows you to create a binding between mobile services in your namespace.
108
+ Short : "integrate certain mobile services together. mobile get services will show you what can be integrated." ,
109
+ Long : `create integration creates a ServiceBinding from one mobile services and injects it into the consuming service via a pod preset in your namespace and optionally
110
+ redeploys the consuming service.
110
111
To get the IDs of your consuming/providing service instances, run the "mobile get serviceinstances <serviceName>" command from this tool.
111
112
112
113
If both the --no-wait and --auto-redeploy flags are set to true, --auto-redeploy will override --no-wait.` ,
@@ -117,11 +118,14 @@ If both the --no-wait and --auto-redeploy flags are set to true, --auto-redeploy
117
118
if len (args ) != 2 {
118
119
return cmd .Usage ()
119
120
}
121
+ quiet , err := cmd .Flags ().GetBool ("quiet" )
122
+ if err != nil {
123
+ return errors .Wrap (err , "failed to get quiet flag" )
124
+ }
120
125
namespace , err := currentNamespace (cmd .Flags ())
121
126
if err != nil {
122
127
return errors .Wrap (err , "failed to get namespace" )
123
128
}
124
-
125
129
consumerSvcInstName := args [0 ]
126
130
providerSvcInstName := args [1 ]
127
131
providerSvcInst , err := bc .scClient .ServicecatalogV1beta1 ().ServiceInstances (namespace ).Get (providerSvcInstName , metav1.GetOptions {})
@@ -132,15 +136,16 @@ If both the --no-wait and --auto-redeploy flags are set to true, --auto-redeploy
132
136
if err != nil {
133
137
return errors .WithStack (err )
134
138
}
135
- // todo remove the need for these by updating the apbs to read the secrets themselves (https://github.com/feedhenry/keycloak-apb/issues/37)
136
139
consumerSvc := getService (namespace , consumerSvcInst .Labels ["serviceName" ], bc .k8Client ) // the consumer service
137
140
providerSvc := getService (namespace , providerSvcInst .Labels ["serviceName" ], bc .k8Client ) // the provider service
141
+ //TODO review how we build the params
138
142
bindParams := buildBindParams (providerSvc , consumerSvc )
139
143
objectName := objectName (consumerSvcInstName , providerSvcInstName )
140
144
preset := podPreset (objectName , objectName , providerSvcInst .Labels ["serviceName" ], consumerSvcInst .Labels ["serviceName" ])
141
145
if _ , err := bc .k8Client .SettingsV1alpha1 ().PodPresets (namespace ).Create (preset ); err != nil {
142
146
return errors .Wrap (err , "failed to create pod preset for service " )
143
147
}
148
+ // prepare and create our binding
144
149
binding , err := createBindingObject (consumerSvc .Name , providerSvc .Name , objectName , providerSvcInst .Name , bindParams , objectName )
145
150
if err != nil {
146
151
return errors .WithStack (err )
@@ -150,6 +155,7 @@ If both the --no-wait and --auto-redeploy flags are set to true, --auto-redeploy
150
155
return errors .WithStack (err )
151
156
}
152
157
158
+ // check if a redeploy was asked for
153
159
redeploy , err := cmd .PersistentFlags ().GetBool ("auto-redeploy" )
154
160
if err != nil {
155
161
return errors .WithStack (err )
@@ -162,20 +168,24 @@ If both the --no-wait and --auto-redeploy flags are set to true, --auto-redeploy
162
168
fmt .Println ("you will need to redeploy your service/pod to pick up the changes" )
163
169
return nil
164
170
}
165
- id := sb .Spec .ExternalID
166
- w , err := bc .scClient .ServicecatalogV1beta1 ().ServiceBindings (namespace ).Watch (metav1.ListOptions {LabelSelector : "id=" + id })
171
+ w , err := bc .scClient .ServicecatalogV1beta1 ().ServiceBindings (namespace ).Watch (metav1.ListOptions {})
167
172
if err != nil {
168
173
return errors .WithStack (err )
169
174
}
170
175
for u := range w .ResultChan () {
171
176
o := u .Object .(* v1beta1.ServiceBinding )
177
+ if o .Name != sb .Name {
178
+ continue
179
+ }
172
180
switch u .Type {
173
181
case watch .Error :
174
182
w .Stop ()
175
183
return errors .New ("unexpected error watching service binding " + err .Error ())
176
184
case watch .Modified :
177
185
for _ , c := range o .Status .Conditions {
178
- fmt .Println ("status: " + c .Message )
186
+ if ! quiet {
187
+ fmt .Println ("status: " + c .Message )
188
+ }
179
189
if c .Type == "Ready" && c .Status == "True" {
180
190
w .Stop ()
181
191
}
@@ -184,8 +194,11 @@ If both the --no-wait and --auto-redeploy flags are set to true, --auto-redeploy
184
194
return errors .New ("Failed to create integration: " + c .Message )
185
195
}
186
196
}
197
+ case watch .Deleted :
198
+ w .Stop ()
187
199
}
188
200
}
201
+ // once the binding is finished update the deployment to cause a redeploy
189
202
if redeploy {
190
203
191
204
// update the deployment with an annotation
@@ -339,7 +352,7 @@ func buildBindParams(from *Service, to *Service) map[string]interface{} {
339
352
p ["app_key" ] = uuid .NewV4 ().String ()
340
353
p ["service_secret" ] = to .ID
341
354
} else if from .Name == ServiceNameKeycloak {
342
- p ["service_name " ] = to .Name
355
+ p ["service " ] = to .Name
343
356
}
344
357
return p
345
358
}
0 commit comments