IBM / cloud-operators

Provision and bind IBM Cloud services to your Kubernetes cluster in a Kubernetes-native way
Apache License 2.0
42 stars 33 forks source link

There should be the possibility to create Binding without ownerReference to Service. #254

Closed arturobrzut closed 3 years ago

arturobrzut commented 3 years ago

There should be the possibility to create Binding without ownerReference to Service

we use the Crossplane to create IBM Cloud Operator CR like Service and Binding

Currently, Binding contains ownerReference to Service set by IBM Cloud Operator

In our case: Crossplane create Binding CR and even if the Crossplane set they own OwnerReference to Binding CR, the Binding CR will contain two OwnerReferences:

The binding contains credentials for service login, requested by clients. If one client requests a credential, cross-plane creates CR which creates Binding CR. But for us, it is crucial to remove Binding CR if we removed Crossplane CR (it is like client remove)

We can do that if there will be the possibility to skip creation ownerReference in Binding CR by IBM Cloud Operator. We can pass this information through Binding CR inside parameters

spec:
  parameters:
    - name: skipOwnerReferences
      value: 'true'
  secretName: my-secret
  serviceName: my-service

and we can read this parameter in the binding Reconciliation loop

    // Set an owner reference if service and binding are in the same namespace
    // and if there is not parameter skipOwnerReferences='true' inside Binding CR
    if serviceInstance.Namespace == instance.Namespace {
        parameters, err := r.getParams(ctx, instance)
        if err != nil {
            r.Log.Error(err, "Instance ", instance.ObjectMeta.Name, " has problems with its parameters")
            return ctrl.Result{}, err
        }
        if parameters["skipOwnerReferences"] != "true" {
            if err := r.SetControllerReference(serviceInstance, instance, r.Scheme); err != nil {
                logt.Info("Binding could not update controller reference", instance.Name, err.Error())
                return ctrl.Result{}, err
            }

            if err := r.Update(ctx, instance); err != nil {
                logt.Info("Error setting controller reference", instance.Name, err.Error())
                return ctrl.Result{}, nil
            }
        }
    }
arturobrzut commented 3 years ago

I want to work on it