Skip to content

Commit 411ff1a

Browse files
authored
fix: reconciler reace condition on write to CM (#56)
* fix: reconciler reace condition on write to CM Signed-off-by: Georgy Khromov <[email protected]> * fix: bump operator version Signed-off-by: Georgy Khromov <[email protected]> --------- Signed-off-by: Georgy Khromov <[email protected]>
1 parent 60a27ee commit 411ff1a

File tree

5 files changed

+53
-24
lines changed

5 files changed

+53
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Go Report Card](https://goreportcard.com/badge/github.com/argoproj-labs/argocd-rbac-operator)](https://goreportcard.com/report/github.com/argoproj-labs/argocd-rbac-operator)
44
[![go.mod Go version](https://img.shields.io/github/go-mod/go-version/argoproj-labs/argocd-rbac-operator)](https://github.com/argoproj-labs/argocd-rbac-operator)
5-
[![GitHub Release](https://img.shields.io/github/v/release/argoproj-labs/argocd-rbac-operator)](https://github.com/argoproj-labs/argocd-rbac-operator/releases/tag/v0.2.3)
5+
[![GitHub Release](https://img.shields.io/github/v/release/argoproj-labs/argocd-rbac-operator)](https://github.com/argoproj-labs/argocd-rbac-operator/releases/tag/v0.2.4)
66
[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/argocd-rbac-operator)](https://artifacthub.io/packages/search?repo=argocd-rbac-operator)
77

88
Kubernetes Operator for Argo CD RBAC Management.

helm/argocd-rbac-operator/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
apiVersion: v2
2-
appVersion: v0.2.3
2+
appVersion: v0.2.4
33
name: argocd-rbac-operator
44
description: A Helm chart for Argo CD RBAC Operator, a Kubernetes Operator for Argo CD RBAC Management.
55
type: application
6-
version: 0.4.4
6+
version: 0.4.5
77
keywords:
88
- argocd
99
- operator

helm/argocd-rbac-operator/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Go Report Card](https://goreportcard.com/badge/github.com/argoproj-labs/argocd-rbac-operator)](https://goreportcard.com/report/github.com/argoproj-labs/argocd-rbac-operator)
44
[![go.mod Go version](https://img.shields.io/github/go-mod/go-version/argoproj-labs/argocd-rbac-operator)](https://github.com/argoproj-labs/argocd-rbac-operator)
5-
[![GitHub Release](https://img.shields.io/github/v/release/argoproj-labs/argocd-rbac-operator)](https://github.com/argoproj-labs/argocd-rbac-operator/releases/tag/v0.2.3)
5+
[![GitHub Release](https://img.shields.io/github/v/release/argoproj-labs/argocd-rbac-operator)](https://github.com/argoproj-labs/argocd-rbac-operator/releases/tag/v0.2.4)
66
[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/argocd-rbac-operator)](https://artifacthub.io/packages/search?repo=argocd-rbac-operator)
77

88
Kubernetes Operator for Argo CD RBAC Management.

internal/controller/argocdrole_controller.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"k8s.io/apimachinery/pkg/api/errors"
2626
"k8s.io/apimachinery/pkg/runtime"
2727
"k8s.io/apimachinery/pkg/types"
28+
"k8s.io/client-go/util/retry"
2829
ctrl "sigs.k8s.io/controller-runtime"
2930
"sigs.k8s.io/controller-runtime/pkg/client"
3031
"sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -126,10 +127,19 @@ func (r *ArgoCDRoleReconciler) Reconcile(ctx context.Context, req ctrl.Request)
126127
}
127128

128129
r.Log.Info("Reconciling RBAC ConfigMap")
129-
if err := r.reconcileRBACConfigMapWithRoleBinding(cm, &role, &rb); err != nil {
130+
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
131+
// Fetch the latest version of the ConfigMap
132+
cm := newConfigMap(r.ArgoCDRBACConfigMapName, r.ArgoCDRBACConfigMapNamespace)
133+
if err := r.Get(ctx, client.ObjectKeyFromObject(cm), cm); err != nil {
134+
return err
135+
}
136+
return r.reconcileRBACConfigMapWithRoleBinding(cm, &role, &rb)
137+
})
138+
139+
if err != nil {
130140
role.SetConditions(rbacoperatorv1alpha1.ReconcileError(err))
131-
if err := r.Client.Status().Update(ctx, &role); err != nil {
132-
r.Log.Error(err, "Failed to update ArgoCDRole status", "name", req.Name)
141+
if updateErr := r.Client.Status().Update(ctx, &role); updateErr != nil {
142+
r.Log.Error(updateErr, "Failed to update ArgoCDRole status", "name", req.Name)
133143
}
134144
return ctrl.Result{}, err
135145
}
@@ -142,14 +152,20 @@ func (r *ArgoCDRoleReconciler) Reconcile(ctx context.Context, req ctrl.Request)
142152
}
143153

144154
r.Log.Info("Reconciling RBAC ConfigMap")
145-
if err := r.reconcileRBACConfigMap(cm, &role); err != nil {
146-
if errors.IsConflict(err) {
147-
r.Log.Info("Conflict while reconciling RBAC ConfigMap, requeuing ArgoCDRole", "name", req.Name)
148-
return ctrl.Result{RequeueAfter: time.Second}, nil
155+
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
156+
// Fetch the latest version of the ConfigMap
157+
cm := newConfigMap(r.ArgoCDRBACConfigMapName, r.ArgoCDRBACConfigMapNamespace)
158+
if err := r.Get(ctx, client.ObjectKeyFromObject(cm), cm); err != nil {
159+
return err
149160
}
161+
162+
return r.reconcileRBACConfigMap(cm, &role)
163+
})
164+
165+
if err != nil {
150166
role.SetConditions(rbacoperatorv1alpha1.ReconcileError(err))
151-
if err := r.Client.Status().Update(ctx, &role); err != nil {
152-
r.Log.Error(err, "Failed to update ArgoCDRole status", "name", req.Name)
167+
if updateErr := r.Client.Status().Update(ctx, &role); updateErr != nil {
168+
r.Log.Error(updateErr, "Failed to update ArgoCDRole status", "name", req.Name)
153169
}
154170
return ctrl.Result{}, err
155171
}

internal/controller/argocdrolebinding_controller.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"k8s.io/apimachinery/pkg/api/errors"
2626
"k8s.io/apimachinery/pkg/runtime"
2727
"k8s.io/apimachinery/pkg/types"
28+
"k8s.io/client-go/util/retry"
2829
ctrl "sigs.k8s.io/controller-runtime"
2930
"sigs.k8s.io/controller-runtime/pkg/client"
3031

@@ -127,10 +128,18 @@ func (r *ArgoCDRoleBindingReconciler) Reconcile(ctx context.Context, req ctrl.Re
127128
}
128129

129130
r.Log.Info("Reconciling RBAC ConfigMap")
130-
if err := r.reconcileRBACConfigMap(cm, &rb, &role); err != nil {
131-
rb.SetConditions(rbacoperatorv1alpha1.ReconcileError(err))
132-
if err := r.Client.Status().Update(ctx, &rb); err != nil {
133-
r.Log.Error(err, "Failed to update ArgoCDRoleBinding status", "name", req.Name)
131+
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
132+
cm := newConfigMap(r.ArgoCDRBACConfigMapName, r.ArgoCDRBACConfigMapNamespace)
133+
if err := r.Get(ctx, client.ObjectKeyFromObject(cm), cm); err != nil {
134+
return err
135+
}
136+
return r.reconcileRBACConfigMap(cm, &rb, &role)
137+
})
138+
139+
if err != nil {
140+
role.SetConditions(rbacoperatorv1alpha1.ReconcileError(err))
141+
if updateErr := r.Client.Status().Update(ctx, &rb); updateErr != nil {
142+
r.Log.Error(updateErr, "Failed to update ArgoCDRoleBinding status", "name", req.Name)
134143
}
135144
return ctrl.Result{}, err
136145
}
@@ -160,14 +169,18 @@ func (r *ArgoCDRoleBindingReconciler) Reconcile(ctx context.Context, req ctrl.Re
160169
}
161170

162171
r.Log.Info("Reconciling RBAC ConfigMap")
163-
if err := r.reconcileRBACConfigMapForBuiltInRole(cm, &rb, role); err != nil {
164-
if errors.IsConflict(err) {
165-
r.Log.Info("Conflict while reconciling RBAC ConfigMap, requeuing ArgoCDRoleBinding", "name", req.Name)
166-
return ctrl.Result{RequeueAfter: time.Second}, nil
172+
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
173+
cm := newConfigMap(r.ArgoCDRBACConfigMapName, r.ArgoCDRBACConfigMapNamespace)
174+
if err := r.Get(ctx, client.ObjectKeyFromObject(cm), cm); err != nil {
175+
return err
167176
}
168-
rb.SetConditions(rbacoperatorv1alpha1.ReconcileError(err))
169-
if err := r.Client.Status().Update(ctx, &rb); err != nil {
170-
r.Log.Error(err, "Failed to update ArgoCDRoleBinding status", "name", req.Name)
177+
return r.reconcileRBACConfigMapForBuiltInRole(cm, &rb, role)
178+
})
179+
180+
if err != nil {
181+
role.SetConditions(rbacoperatorv1alpha1.ReconcileError(err))
182+
if updateErr := r.Client.Status().Update(ctx, &rb); updateErr != nil {
183+
r.Log.Error(updateErr, "Failed to update ArgoCDRoleBinding status", "name", req.Name)
171184
}
172185
return ctrl.Result{}, err
173186
}

0 commit comments

Comments
 (0)