Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions controllers/operandrequest/reconcile_operand.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func (r *Reconciler) reconcileCRwithRequest(ctx context.Context, requestInstance
crFromRequest.SetAPIVersion(operand.APIVersion)
crFromRequest.SetKind(operand.Kind)
// Set the OperandRequest as the controller of the CR from request
if err := controllerutil.SetControllerReference(requestInstance, &crFromRequest, r.Scheme); err != nil {
if err := controllerutil.SetOwnerReference(requestInstance, &crFromRequest, r.Scheme); err != nil {
merr.Add(errors.Wrapf(err, "failed to set ownerReference for custom resource %s/%s", requestKey.Namespace, name))
}

Expand All @@ -405,7 +405,7 @@ func (r *Reconciler) reconcileCRwithRequest(ctx context.Context, requestInstance
if r.CheckLabel(crFromRequest, map[string]string{constant.OpreqLabel: "true"}) {
// Update or Delete Custom resource
klog.V(3).Info("Found existing custom resource: " + operand.Kind)
if err := r.updateCustomResource(ctx, crFromRequest, requestKey.Namespace, operand.Kind, operand.Spec.Raw, map[string]interface{}{}); err != nil {
if err := r.updateCustomResource(ctx, crFromRequest, requestKey.Namespace, operand.Kind, operand.Spec.Raw, map[string]interface{}{}, requestInstance); err != nil {
return err
}
statusSpec, err := r.getOperandStatus(crFromRequest)
Expand Down Expand Up @@ -632,7 +632,7 @@ func (r *Reconciler) createCustomResource(ctx context.Context, crTemplate unstru

r.EnsureLabel(crTemplate, map[string]string{constant.OpreqLabel: "true"})

// Creat the CR
// Create the CR
crerr := r.Create(ctx, &crTemplate)
if crerr != nil && !apierrors.IsAlreadyExists(crerr) {
return errors.Wrap(crerr, "failed to create custom resource")
Expand Down Expand Up @@ -667,7 +667,7 @@ func (r *Reconciler) existingCustomResource(ctx context.Context, existingCR unst
return nil
}

func (r *Reconciler) updateCustomResource(ctx context.Context, existingCR unstructured.Unstructured, namespace, crName string, crConfig []byte, configFromALM map[string]interface{}) error {
func (r *Reconciler) updateCustomResource(ctx context.Context, existingCR unstructured.Unstructured, namespace, crName string, crConfig []byte, configFromALM map[string]interface{}, owners ...metav1.Object) error {

kind := existingCR.GetKind()
apiversion := existingCR.GetAPIVersion()
Expand Down Expand Up @@ -695,6 +695,14 @@ func (r *Reconciler) updateCustomResource(ctx context.Context, existingCR unstru
return true, nil
}

forceUpdate := false
for _, owner := range owners {
if err := controllerutil.SetOwnerReference(owner, &existingCR, r.Scheme); err != nil {
return false, errors.Wrapf(err, "failed to set ownerReference for custom resource %s/%s", existingCR.GetNamespace(), existingCR.GetName())
}
forceUpdate = true
}

configFromALMRaw, err := json.Marshal(configFromALM)
if err != nil {
klog.Error(err)
Expand All @@ -721,7 +729,7 @@ func (r *Reconciler) updateCustomResource(ctx context.Context, existingCR unstru

CRgeneration := existingCR.GetGeneration()

if reflect.DeepEqual(existingCR.Object["spec"], updatedCRSpec) {
if reflect.DeepEqual(existingCR.Object["spec"], updatedCRSpec) && !forceUpdate {
return true, nil
}

Expand Down