Skip to content

Commit 2e86588

Browse files
author
YuChen
committed
ensure ann, label and set owner on updated resrouce
Signed-off-by: YuChen <[email protected]>
1 parent b59fd58 commit 2e86588

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

controllers/operandrequest/reconcile_operand.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"strings"
2929
"sync"
3030

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

10601061
if k8sResConfig != nil {
10611062

1062-
k8sResConfigDecoded := make(map[string]interface{})
1063-
k8sResConfigUnmarshalErr := json.Unmarshal(k8sResConfig.Raw, &k8sResConfigDecoded)
1064-
if k8sResConfigUnmarshalErr != nil {
1065-
klog.Errorf("failed to unmarshal k8s Resource Config: %v", k8sResConfigUnmarshalErr)
1066-
}
1067-
1068-
// Convert existing k8s resource spec to string
1063+
// Convert existing k8s resource to string
10691064
existingK8sResRaw, err := json.Marshal(existingK8sRes.Object)
10701065
if err != nil {
10711066
klog.Error(err)
10721067
return false, err
10731068
}
10741069

1075-
// Merge spec from existing CR and OperandConfig spec
1070+
// Merge the existing CR and the CR from the OperandConfig
10761071
updatedExistingK8sRes := util.MergeCR(existingK8sResRaw, k8sResConfig.Raw)
10771072

1073+
// Deep copy the existing k8s resource
1074+
originalK8sRes := deepcopy.Copy(existingK8sRes.Object)
1075+
1076+
// Update the existing k8s resource with the merged CR
1077+
existingK8sRes.Object = updatedExistingK8sRes
1078+
10781079
r.EnsureAnnotation(existingK8sRes, newAnnotations)
10791080
r.EnsureLabel(existingK8sRes, newLabels)
10801081
if err := r.setOwnerReferences(ctx, &existingK8sRes, ownerReferences); err != nil {
10811082
return false, errors.Wrapf(err, "failed to set ownerReferences for k8s resource -- Kind: %s, NamespacedName: %s/%s", kind, namespace, name)
10821083
}
10831084

1084-
if reflect.DeepEqual(existingK8sRes.Object, updatedExistingK8sRes) {
1085+
if reflect.DeepEqual(originalK8sRes, existingK8sRes.Object) {
10851086
return true, nil
10861087
}
1087-
klog.Infof("updating k8s resource with apiversion: %s, kind: %s, %s/%s", apiversion, kind, namespace, name)
10881088

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

10911091
CRgeneration := existingK8sRes.GetGeneration()
10921092

0 commit comments

Comments
 (0)