Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
ensure ann, label and set owner on updated resrouce
Signed-off-by: YuChen <[email protected]>
  • Loading branch information
YuChen committed Mar 27, 2024
commit 2e86588c565aab21f9d992efece3f1206f1e217f
22 changes: 11 additions & 11 deletions controllers/operandrequest/reconcile_operand.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"strings"
"sync"

"github.com/mohae/deepcopy"
olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/pkg/errors"
authorizationv1 "k8s.io/api/authorization/v1"
Expand Down Expand Up @@ -1059,34 +1060,33 @@ func (r *Reconciler) updateK8sResource(ctx context.Context, existingK8sRes unstr

if k8sResConfig != nil {

k8sResConfigDecoded := make(map[string]interface{})
k8sResConfigUnmarshalErr := json.Unmarshal(k8sResConfig.Raw, &k8sResConfigDecoded)
if k8sResConfigUnmarshalErr != nil {
klog.Errorf("failed to unmarshal k8s Resource Config: %v", k8sResConfigUnmarshalErr)
}

// Convert existing k8s resource spec to string
// Convert existing k8s resource to string
existingK8sResRaw, err := json.Marshal(existingK8sRes.Object)
if err != nil {
klog.Error(err)
return false, err
}

// Merge spec from existing CR and OperandConfig spec
// Merge the existing CR and the CR from the OperandConfig
updatedExistingK8sRes := util.MergeCR(existingK8sResRaw, k8sResConfig.Raw)

// Deep copy the existing k8s resource
originalK8sRes := deepcopy.Copy(existingK8sRes.Object)

// Update the existing k8s resource with the merged CR
existingK8sRes.Object = updatedExistingK8sRes

r.EnsureAnnotation(existingK8sRes, newAnnotations)
r.EnsureLabel(existingK8sRes, newLabels)
if err := r.setOwnerReferences(ctx, &existingK8sRes, ownerReferences); err != nil {
return false, errors.Wrapf(err, "failed to set ownerReferences for k8s resource -- Kind: %s, NamespacedName: %s/%s", kind, namespace, name)
}

if reflect.DeepEqual(existingK8sRes.Object, updatedExistingK8sRes) {
if reflect.DeepEqual(originalK8sRes, existingK8sRes.Object) {
return true, nil
}
klog.Infof("updating k8s resource with apiversion: %s, kind: %s, %s/%s", apiversion, kind, namespace, name)

existingK8sRes.Object = updatedExistingK8sRes
klog.Infof("updating k8s resource with apiversion: %s, kind: %s, %s/%s", apiversion, kind, namespace, name)

CRgeneration := existingK8sRes.GetGeneration()

Expand Down