Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 20 additions & 4 deletions controllers/operandbindinfo/operandbindinfo_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ func (r *Reconciler) copySecret(ctx context.Context, sourceName, targetName, sou
Data: secret.Data,
StringData: secret.StringData,
}
// Set the OperandRequest as the controller of the Secret
if err := controllerutil.SetControllerReference(requestInstance, secretCopy, r.Scheme); err != nil {
// Set the OperandRequest as the owner of the Secret
if err := controllerutil.SetOwnerReference(requestInstance, secretCopy, r.Scheme); err != nil {
return false, errors.Wrapf(err, "failed to set OperandRequest %s as the owner of Secret %s", requestInstance.Name, targetName)
}

Expand All @@ -310,6 +310,14 @@ func (r *Reconciler) copySecret(ctx context.Context, sourceName, targetName, sou
if err := r.Client.Get(ctx, types.NamespacedName{Namespace: targetNs, Name: targetName}, existingSecret); err != nil {
return false, errors.Wrapf(err, "failed to get secret %s/%s", targetNs, targetName)
}

// Copy the owner reference from the existing secret to the new secret
secretCopy.SetOwnerReferences(existingSecret.GetOwnerReferences())
// Set the OperandRequest as the owner of the new Secret
if err := controllerutil.SetOwnerReference(requestInstance, secretCopy, r.Scheme); err != nil {
return false, errors.Wrapf(err, "failed to set OperandRequest %s as the owner of Secret %s", requestInstance.Name, targetName)
}

if needUpdate := util.CompareSecret(secretCopy, existingSecret); needUpdate {
podRefreshment = true
if err := r.Update(ctx, secretCopy); err != nil {
Expand Down Expand Up @@ -389,8 +397,8 @@ func (r *Reconciler) copyConfigmap(ctx context.Context, sourceName, targetName,
Data: cm.Data,
BinaryData: cm.BinaryData,
}
// Set the OperandRequest as the controller of the configmap
if err := controllerutil.SetControllerReference(requestInstance, cmCopy, r.Scheme); err != nil {
// Set OperandRequest as the owners of the configmap
if err := controllerutil.SetOwnerReference(requestInstance, cmCopy, r.Scheme); err != nil {
return false, errors.Wrapf(err, "failed to set OperandRequest %s as the owner of ConfigMap %s", requestInstance.Name, sourceName)
}

Expand All @@ -403,6 +411,14 @@ func (r *Reconciler) copyConfigmap(ctx context.Context, sourceName, targetName,
if err := r.Client.Get(ctx, types.NamespacedName{Namespace: targetNs, Name: targetName}, existingCm); err != nil {
return false, errors.Wrapf(err, "failed to get ConfigMap %s/%s", targetNs, targetName)
}

// Copy the owner reference from the existing secret to the new configmap
cmCopy.SetOwnerReferences(existingCm.GetOwnerReferences())
// Set the OperandRequest as the owner of the new configmap
if err := controllerutil.SetOwnerReference(requestInstance, cmCopy, r.Scheme); err != nil {
return false, errors.Wrapf(err, "failed to set OperandRequest %s as the owner of ConfigMap %s", requestInstance.Name, targetName)
}

if needUpdate := util.CompareConfigMap(cmCopy, existingCm); needUpdate {
podRefreshment = true
if err := r.Update(ctx, cmCopy); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion controllers/operandrequest/reconcile_operand.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func (r *Reconciler) reconcileCRwithRequest(ctx context.Context, requestInstance
crFromRequest.SetNamespace(requestKey.Namespace)
crFromRequest.SetAPIVersion(operand.APIVersion)
crFromRequest.SetKind(operand.Kind)
// Set the OperandRequest as the controller of the CR from request
// Set the OperandRequest as the owner of the CR from request
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 Down
11 changes: 9 additions & 2 deletions controllers/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,18 @@ func EnsureLabelsForService(s *corev1.Service, labels map[string]string) {
}

func CompareSecret(secret *corev1.Secret, existingSecret *corev1.Secret) (needUpdate bool) {
return !equality.Semantic.DeepEqual(secret.GetLabels(), existingSecret.GetLabels()) || !equality.Semantic.DeepEqual(secret.Type, existingSecret.Type) || !equality.Semantic.DeepEqual(secret.Data, existingSecret.Data) || !equality.Semantic.DeepEqual(secret.StringData, existingSecret.StringData)
return !equality.Semantic.DeepEqual(secret.GetLabels(), existingSecret.GetLabels()) ||
!equality.Semantic.DeepEqual(secret.Type, existingSecret.Type) ||
!equality.Semantic.DeepEqual(secret.Data, existingSecret.Data) ||
!equality.Semantic.DeepEqual(secret.StringData, existingSecret.StringData) ||
!equality.Semantic.DeepEqual(secret.GetOwnerReferences(), existingSecret.GetOwnerReferences())
}

func CompareConfigMap(configMap *corev1.ConfigMap, existingConfigMap *corev1.ConfigMap) (needUpdate bool) {
return !equality.Semantic.DeepEqual(configMap.GetLabels(), existingConfigMap.GetLabels()) || !equality.Semantic.DeepEqual(configMap.Data, existingConfigMap.Data) || !equality.Semantic.DeepEqual(configMap.BinaryData, existingConfigMap.BinaryData)
return !equality.Semantic.DeepEqual(configMap.GetLabels(), existingConfigMap.GetLabels()) ||
!equality.Semantic.DeepEqual(configMap.Data, existingConfigMap.Data) ||
!equality.Semantic.DeepEqual(configMap.BinaryData, existingConfigMap.BinaryData) ||
!equality.Semantic.DeepEqual(configMap.GetOwnerReferences(), existingConfigMap.GetOwnerReferences())
}

// SanitizeObjectString takes a string, i.e. .metadata.namespace, and a K8s object
Expand Down