diff --git a/controllers/controller_util.go b/controllers/controller_util.go index ecddf6d6..869cdbf2 100644 --- a/controllers/controller_util.go +++ b/controllers/controller_util.go @@ -3,6 +3,9 @@ package controllers import ( "encoding/json" "strings" + + "github.com/go-logr/logr" + v1 "k8s.io/api/authentication/v1" ) func normalizeCredentials(credentialsJSON json.RawMessage) (map[string][]byte, error) { @@ -27,3 +30,16 @@ func normalizeCredentials(credentialsJSON json.RawMessage) (map[string][]byte, e } return normalized, nil } + +func buildUserInfo(userInfo *v1.UserInfo, log logr.Logger) string { + if userInfo == nil { + return "" + } + userInfoStr, err := json.Marshal(userInfo) + if err != nil { + log.Error(err, "failed to prepare user info") + return "" + } + + return string(userInfoStr) +} diff --git a/controllers/servicebinding_controller.go b/controllers/servicebinding_controller.go index 575a0421..b1ae2bf3 100644 --- a/controllers/servicebinding_controller.go +++ b/controllers/servicebinding_controller.go @@ -198,7 +198,7 @@ func (r *ServiceBindingReconciler) createBinding(ctx context.Context, smClient s }, ServiceInstanceID: serviceInstance.Status.InstanceID, Parameters: bindingParameters, - }, nil, serviceBinding.Spec.UserInfo.Username) + }, nil, buildUserInfo(serviceBinding.Spec.UserInfo, log)) if bindErr != nil { log.Error(err, "failed to create service binding", "serviceInstanceID", serviceInstance.Status.InstanceID) @@ -273,7 +273,7 @@ func (r *ServiceBindingReconciler) delete(ctx context.Context, smClient sm.Clien } log.Info(fmt.Sprintf("Deleting binding with id %v from SM", serviceBinding.Status.BindingID)) - operationURL, unbindErr := smClient.Unbind(serviceBinding.Status.BindingID, nil, serviceBinding.Spec.UserInfo.Username) + operationURL, unbindErr := smClient.Unbind(serviceBinding.Status.BindingID, nil, buildUserInfo(serviceBinding.Spec.UserInfo, log)) if unbindErr != nil { log.Error(unbindErr, "failed to delete binding") if isTransientError(unbindErr, log) { diff --git a/controllers/serviceinstance_controller.go b/controllers/serviceinstance_controller.go index 705c894e..1e531531 100644 --- a/controllers/serviceinstance_controller.go +++ b/controllers/serviceinstance_controller.go @@ -191,7 +191,7 @@ func (r *ServiceInstanceReconciler) createInstance(ctx context.Context, smClient k8sNameLabel: []string{serviceInstance.Name}, clusterIDLabel: []string{r.Config.ClusterID}, }, - }, serviceInstance.Spec.ServiceOfferingName, serviceInstance.Spec.ServicePlanName, nil, serviceInstance.Spec.UserInfo.Username) + }, serviceInstance.Spec.ServiceOfferingName, serviceInstance.Spec.ServicePlanName, nil, buildUserInfo(serviceInstance.Spec.UserInfo, log)) if provisionErr != nil { log.Error(provisionErr, "failed to create service instance", "serviceOfferingName", serviceInstance.Spec.ServiceOfferingName, @@ -235,7 +235,7 @@ func (r *ServiceInstanceReconciler) updateInstance(ctx context.Context, smClient Name: serviceInstance.Spec.ExternalName, ServicePlanID: serviceInstance.Spec.ServicePlanID, Parameters: instanceParameters, - }, serviceInstance.Spec.ServiceOfferingName, serviceInstance.Spec.ServicePlanName, nil, serviceInstance.Spec.UserInfo.Username) + }, serviceInstance.Spec.ServiceOfferingName, serviceInstance.Spec.ServicePlanName, nil, buildUserInfo(serviceInstance.Spec.UserInfo, log)) if err != nil { log.Error(err, fmt.Sprintf("failed to update service instance with ID %s", serviceInstance.Status.InstanceID)) if isTransientError(err, log) { @@ -281,7 +281,7 @@ func (r *ServiceInstanceReconciler) deleteInstance(ctx context.Context, smClient } log.Info(fmt.Sprintf("Deleting instance with id %v from SM", serviceInstance.Status.InstanceID)) - operationURL, deprovisionErr := smClient.Deprovision(serviceInstance.Status.InstanceID, nil, serviceInstance.Spec.UserInfo.Username) + operationURL, deprovisionErr := smClient.Deprovision(serviceInstance.Status.InstanceID, nil, buildUserInfo(serviceInstance.Spec.UserInfo, log)) if deprovisionErr != nil { if isTransientError(deprovisionErr, log) { return r.markAsTransientError(ctx, smTypes.DELETE, deprovisionErr.Error(), serviceInstance, log)