@@ -28,6 +28,7 @@ package controller
2828import (
2929 "context"
3030 "fmt"
31+ "strings"
3132 "time"
3233
3334 "github.com/pkg/errors"
@@ -39,6 +40,7 @@ import (
3940
4041 pdoknlv3 "github.com/pdok/atom-operator/api/v3"
4142 smoothoperatorv1 "github.com/pdok/smooth-operator/api/v1"
43+ smoothoperatorstatus "github.com/pdok/smooth-operator/pkg/status"
4244 smoothutil "github.com/pdok/smooth-operator/pkg/util"
4345
4446 traefikiov1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
@@ -51,12 +53,6 @@ import (
5153 logf "sigs.k8s.io/controller-runtime/pkg/log"
5254)
5355
54- const (
55- reconciledConditionType = "Reconciled"
56- reconciledConditionReasonSuccess = "Success"
57- reconciledConditionReasonError = "Error"
58- )
59-
6056const (
6157 appLabelKey = "pdok.nl/app"
6258 appName = "atom-service"
@@ -87,6 +83,7 @@ type AtomReconciler struct {
8783// +kubebuilder:rbac:groups=pdok.nl,resources=ownerinfo,verbs=get;list;watch
8884// +kubebuilder:rbac:groups=pdok.nl,resources=ownerinfo/status,verbs=get
8985// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;delete
86+ // +kubebuilder:rbac:groups=apps,resources=replicasets,verbs=get;list;watch;
9087// +kubebuilder:rbac:groups=core,resources=configmaps;services,verbs=watch;create;get;update;list;delete
9188// +kubebuilder:rbac:groups=traefik.io,resources=ingressroutes;middlewares,verbs=get;list;watch;create;update;delete
9289// +kubebuilder:rbac:groups=policy,resources=poddisruptionbudgets,verbs=create;update;delete;list;watch
@@ -138,7 +135,7 @@ func (r *AtomReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul
138135 defer func () {
139136 if rec := recover (); rec != nil {
140137 err = recoveredPanicToError (rec )
141- r . logAndUpdateStatusError (ctx , atom , err )
138+ smoothoperatorstatus . LogAndUpdateStatusError (ctx , r . Client , atom , err )
142139 }
143140 }()
144141
@@ -153,11 +150,11 @@ func (r *AtomReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul
153150 operationResults , err := r .createOrUpdateAllForAtom (ctx , atom , ownerInfo )
154151 if err != nil {
155152 lgr .Info ("failed creating resources for atom" , "atom" , atom )
156- r . logAndUpdateStatusError (ctx , atom , err )
153+ smoothoperatorstatus . LogAndUpdateStatusError (ctx , r . Client , atom , err )
157154 return result , err
158155 }
159156 lgr .Info ("finished creating resources for atom" , "atom" , atom )
160- r . logAndUpdateStatusFinished (ctx , atom , operationResults )
157+ smoothoperatorstatus . LogAndUpdateStatusFinished (ctx , r . Client , atom , operationResults )
161158
162159 return result , err
163160}
@@ -186,7 +183,7 @@ func (r *AtomReconciler) createOrUpdateAllForAtom(ctx context.Context, atom *pdo
186183 operationResults [smoothutil .GetObjectFullName (r .Client , deployment )], err = controllerutil .CreateOrUpdate (ctx , r .Client , deployment , func () error {
187184 return r .mutateDeployment (atom , deployment , configMap .GetName ())
188185 })
189- if err != nil {
186+ if err != nil && ! strings . Contains ( err . Error (), "the object has been modified; please apply your changes to the latest version and try again" ) {
190187 return operationResults , fmt .Errorf ("unable to create/update resource %s: %w" , smoothutil .GetObjectFullName (c , deployment ), err )
191188 }
192189 // endregion
@@ -267,6 +264,7 @@ func (r *AtomReconciler) SetupWithManager(mgr ctrl.Manager) error {
267264 Owns (& traefikiov1alpha1.IngressRoute {}, builder .WithPredicates (predicate.GenerationChangedPredicate {})).
268265 Owns (& policyv1.PodDisruptionBudget {}, builder .WithPredicates (predicate.GenerationChangedPredicate {})).
269266 Owns (& smoothoperatorv1.OwnerInfo {}, builder .WithPredicates (predicate.GenerationChangedPredicate {})).
267+ Watches (& appsv1.ReplicaSet {}, smoothoperatorstatus .GetReplicaSetEventHandlerForObj (mgr , "Atom" )).
270268 Complete (r )
271269}
272270
0 commit comments