Skip to content

Commit

Permalink
Adjustments
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Gershkovich <elenage@il.ibm.com>
  • Loading branch information
ELENAGER committed Jun 22, 2023
1 parent 9b8b161 commit 57fa2d9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
23 changes: 11 additions & 12 deletions controllers/drcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"
ctrl "sigs.k8s.io/controller-runtime"
)

Expand Down Expand Up @@ -219,25 +220,23 @@ func updateDRClusterManifestWorkStatus(clusterNamespace string) {
},
},
}
localRetries := 0

var err error
retryErr := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
var err error

err = apiReader.Get(context.TODO(), manifestLookupKey, mw)
if err != nil {
return err
}

for localRetries < updateRetries {
mw.Status = DRClusterStatusConditions

err = k8sClient.Status().Update(context.TODO(), mw)
if errors.IsConflict(err) {
Expect(apiReader.Get(context.TODO(), manifestLookupKey, mw)).To(Succeed())
localRetries++

continue
}

break
}
return err
})

Expect(err).NotTo(HaveOccurred())
Expect(retryErr).NotTo(HaveOccurred())
}

var _ = Describe("DRClusterController", func() {
Expand Down
25 changes: 13 additions & 12 deletions controllers/util/mw_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/client"

dto "github.com/prometheus/client_model/go"
Expand Down Expand Up @@ -504,25 +505,25 @@ func (mwu *MWUtil) createOrUpdateManifestWork(
if !reflect.DeepEqual(foundMW.Spec, mw.Spec) {
mwu.Log.Info("ManifestWork exists.", "name", mw.Name, "namespace", foundMW.Namespace)

for {
mw.Spec.DeepCopyInto(&foundMW.Spec)

err = mwu.Client.Update(mwu.Ctx, foundMW)
if err == nil {
break
}

if !errors.IsConflict(err) {
return err
}
retryErr := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
var err error

err = mwu.Client.Get(mwu.Ctx,
types.NamespacedName{Name: mw.Name, Namespace: managedClusternamespace},
foundMW)

if err != nil {
return err
}

mw.Spec.DeepCopyInto(&foundMW.Spec)

err = mwu.Client.Update(mwu.Ctx, foundMW)

return err
})

if retryErr != nil {
return retryErr
}
}

Expand Down

0 comments on commit 57fa2d9

Please sign in to comment.