Skip to content

Commit 6956f7d

Browse files
committed
finish up integration command and add a quiet flag
1 parent 0987392 commit 6956f7d

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

pkg/cmd/convert.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ func convertSecretToMobileService(s v1.Secret) *Service {
3737
ID: s.Name,
3838
External: external,
3939
Labels: s.Labels,
40-
Name: strings.TrimSpace(string(s.Data["name"])),
40+
Name: s.Name,
4141
DisplayName: strings.TrimSpace(retrieveDisplayNameFromSecret(s)),
42-
Type: strings.TrimSpace(string(s.Data["type"])),
4342
Host: string(s.Data["uri"]),
4443
Params: params,
4544
Integrations: map[string]*ServiceIntegration{},

pkg/cmd/integration.go

+21-8
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ func podPreset(objectName, secretName, providerSvcName, consumerSvcName string)
105105
func (bc *IntegrationCmd) CreateIntegrationCmd() *cobra.Command {
106106
cmd := &cobra.Command{
107107
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.
110111
To get the IDs of your consuming/providing service instances, run the "mobile get serviceinstances <serviceName>" command from this tool.
111112
112113
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
117118
if len(args) != 2 {
118119
return cmd.Usage()
119120
}
121+
quiet, err := cmd.Flags().GetBool("quiet")
122+
if err != nil {
123+
return errors.Wrap(err, "failed to get quiet flag")
124+
}
120125
namespace, err := currentNamespace(cmd.Flags())
121126
if err != nil {
122127
return errors.Wrap(err, "failed to get namespace")
123128
}
124-
125129
consumerSvcInstName := args[0]
126130
providerSvcInstName := args[1]
127131
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
132136
if err != nil {
133137
return errors.WithStack(err)
134138
}
135-
// todo remove the need for these by updating the apbs to read the secrets themselves (https://github.com/feedhenry/keycloak-apb/issues/37)
136139
consumerSvc := getService(namespace, consumerSvcInst.Labels["serviceName"], bc.k8Client) // the consumer service
137140
providerSvc := getService(namespace, providerSvcInst.Labels["serviceName"], bc.k8Client) // the provider service
141+
//TODO review how we build the params
138142
bindParams := buildBindParams(providerSvc, consumerSvc)
139143
objectName := objectName(consumerSvcInstName, providerSvcInstName)
140144
preset := podPreset(objectName, objectName, providerSvcInst.Labels["serviceName"], consumerSvcInst.Labels["serviceName"])
141145
if _, err := bc.k8Client.SettingsV1alpha1().PodPresets(namespace).Create(preset); err != nil {
142146
return errors.Wrap(err, "failed to create pod preset for service ")
143147
}
148+
// prepare and create our binding
144149
binding, err := createBindingObject(consumerSvc.Name, providerSvc.Name, objectName, providerSvcInst.Name, bindParams, objectName)
145150
if err != nil {
146151
return errors.WithStack(err)
@@ -150,6 +155,7 @@ If both the --no-wait and --auto-redeploy flags are set to true, --auto-redeploy
150155
return errors.WithStack(err)
151156
}
152157

158+
// check if a redeploy was asked for
153159
redeploy, err := cmd.PersistentFlags().GetBool("auto-redeploy")
154160
if err != nil {
155161
return errors.WithStack(err)
@@ -162,20 +168,24 @@ If both the --no-wait and --auto-redeploy flags are set to true, --auto-redeploy
162168
fmt.Println("you will need to redeploy your service/pod to pick up the changes")
163169
return nil
164170
}
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{})
167172
if err != nil {
168173
return errors.WithStack(err)
169174
}
170175
for u := range w.ResultChan() {
171176
o := u.Object.(*v1beta1.ServiceBinding)
177+
if o.Name != sb.Name {
178+
continue
179+
}
172180
switch u.Type {
173181
case watch.Error:
174182
w.Stop()
175183
return errors.New("unexpected error watching service binding " + err.Error())
176184
case watch.Modified:
177185
for _, c := range o.Status.Conditions {
178-
fmt.Println("status: " + c.Message)
186+
if !quiet {
187+
fmt.Println("status: " + c.Message)
188+
}
179189
if c.Type == "Ready" && c.Status == "True" {
180190
w.Stop()
181191
}
@@ -184,8 +194,11 @@ If both the --no-wait and --auto-redeploy flags are set to true, --auto-redeploy
184194
return errors.New("Failed to create integration: " + c.Message)
185195
}
186196
}
197+
case watch.Deleted:
198+
w.Stop()
187199
}
188200
}
201+
// once the binding is finished update the deployment to cause a redeploy
189202
if redeploy {
190203

191204
// update the deployment with an annotation
@@ -339,7 +352,7 @@ func buildBindParams(from *Service, to *Service) map[string]interface{} {
339352
p["app_key"] = uuid.NewV4().String()
340353
p["service_secret"] = to.ID
341354
} else if from.Name == ServiceNameKeycloak {
342-
p["service_name"] = to.Name
355+
p["service"] = to.Name
343356
}
344357
return p
345358
}

pkg/cmd/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func NewRootCmd() *cobra.Command {
3333
}
3434
root.PersistentFlags().String("namespace", "", "--namespace=myproject")
3535
root.PersistentFlags().StringP("output", "o", "table", "-o=json -o=template")
36+
root.PersistentFlags().BoolP("quiet", "q", false, "-q all non essential output will be stopped")
3637
cobra.OnInitialize(initConfig)
3738
return root
3839
}

0 commit comments

Comments
 (0)