Skip to content

Commit

Permalink
adding logs for binding recovery (#55)
Browse files Browse the repository at this point in the history
* adding logs for binding recovery

* fix nil

* fix
  • Loading branch information
kerenlahav authored Jun 18, 2021
1 parent 9ed4145 commit 4bb8798
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions controllers/servicebinding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,25 +490,28 @@ func (r *ServiceBindingReconciler) deleteBindingSecret(ctx context.Context, bind
}

func (r *ServiceBindingReconciler) getBindingForRecovery(smClient sm.Client, serviceBinding *v1alpha1.ServiceBinding, log logr.Logger) (*smclientTypes.ServiceBinding, error) {
nameQuery := fmt.Sprintf("name eq '%s'", serviceBinding.Spec.ExternalName)
clusterIDQuery := fmt.Sprintf("context/clusterid eq '%s'", r.Config.ClusterID)
namespaceQuery := fmt.Sprintf("context/namespace eq '%s'", serviceBinding.Namespace)
k8sNameQuery := fmt.Sprintf("%s eq '%s'", k8sNameLabel, serviceBinding.Name)
parameters := sm.Parameters{
FieldQuery: []string{
fmt.Sprintf("name eq '%s'", serviceBinding.Spec.ExternalName),
fmt.Sprintf("context/clusterid eq '%s'", r.Config.ClusterID),
fmt.Sprintf("context/namespace eq '%s'", serviceBinding.Namespace)},
LabelQuery: []string{
fmt.Sprintf("%s eq '%s'", k8sNameLabel, serviceBinding.Name)},
FieldQuery: []string{nameQuery, clusterIDQuery, namespaceQuery},
LabelQuery: []string{k8sNameQuery},
GeneralParams: []string{"attach_last_operations=true"},
}
log.Info(fmt.Sprintf("binding recovery query params: %s, %s, %s, %s", nameQuery, clusterIDQuery, namespaceQuery, k8sNameQuery))

bindings, err := smClient.ListBindings(&parameters)
if err != nil {
log.Error(err, "failed to list bindings in SM")
return nil, err
}
if bindings != nil && len(bindings.ServiceBindings) == 1 {
return &bindings.ServiceBindings[0], nil
if bindings != nil {
log.Info(fmt.Sprintf("found %d bindings", len(bindings.ServiceBindings)))
if len(bindings.ServiceBindings) == 1 {
return &bindings.ServiceBindings[0], nil
}
}

return nil, nil
}

Expand Down

0 comments on commit 4bb8798

Please sign in to comment.