@@ -89,7 +89,7 @@ func (r *Reconciler) reconcileNormal(ctx context.Context, cdk8sAppProxy *addonsv
8989 }
9090
9191 // Prepare a source path and get current commit hash
92- appSourcePath , _ , err := r .prepareSource (ctx , cdk8sAppProxy , proxyNamespacedName , logger , OperationNormal )
92+ appSourcePath , _ , err := r .prepareSource (cdk8sAppProxy , logger )
9393 if err != nil {
9494 return ctrl.Result {}, err
9595 }
@@ -146,7 +146,7 @@ func (r *Reconciler) reconcileNormal(ctx context.Context, cdk8sAppProxy *addonsv
146146 }
147147 if polling {
148148 logger .Info ("Detected changes in git repository, proceeding with reconciliation." )
149- appSourcePath , _ , err = r .prepareSource (ctx , cdk8sAppProxy , proxyNamespacedName , logger , OperationNormal )
149+ appSourcePath , _ , err = r .prepareSource (cdk8sAppProxy , logger )
150150 if err != nil {
151151 logger .Error (err , "Prepare source for reconciliation" )
152152 }
@@ -195,34 +195,6 @@ func (r *Reconciler) reconcileNormal(ctx context.Context, cdk8sAppProxy *addonsv
195195 return ctrl.Result {}, nil
196196}
197197
198- func (r * Reconciler ) handleDeletionTriggerAnnotation (ctx context.Context , cdk8sAppProxy * addonsv1alpha1.Cdk8sAppProxy , logger logr.Logger ) (bool , error ) {
199- deletionTriggerAnnotationKey := "cdk8s.addons.cluster.x-k8s.io/reconcile-on-delete-trigger"
200- forceSynthAndApplyDueToDeletion := false
201-
202- if cdk8sAppProxy .Annotations != nil {
203- if _ , ok := cdk8sAppProxy .Annotations [deletionTriggerAnnotationKey ]; ok {
204- forceSynthAndApplyDueToDeletion = true
205- logger .Info ("Reconciliation was triggered by a resource deletion annotation." , "annotationKey" , deletionTriggerAnnotationKey )
206-
207- // Clear the annotation
208- logger .Info ("Attempting to clear the resource deletion trigger annotation." , "annotationKey" , deletionTriggerAnnotationKey )
209- delete (cdk8sAppProxy .Annotations , deletionTriggerAnnotationKey )
210- if len (cdk8sAppProxy .Annotations ) == 0 {
211- cdk8sAppProxy .Annotations = nil
212- }
213-
214- if err := r .Update (ctx , cdk8sAppProxy ); err != nil {
215- logger .Error (err , "Failed to clear the resource deletion trigger annotation. Requeuing." , "annotationKey" , deletionTriggerAnnotationKey )
216-
217- return false , err
218- }
219- logger .Info ("Successfully cleared the resource deletion trigger annotation." , "annotationKey" , deletionTriggerAnnotationKey )
220- }
221- }
222-
223- return forceSynthAndApplyDueToDeletion , nil
224- }
225-
226198func (r * Reconciler ) ensureFinalizer (ctx context.Context , cdk8sAppProxy * addonsv1alpha1.Cdk8sAppProxy , logger logr.Logger ) (bool , error ) {
227199 if ! controllerutil .ContainsFinalizer (cdk8sAppProxy , Finalizer ) {
228200 logger .Info ("Adding finalizer" , "finalizer" , Finalizer )
@@ -252,26 +224,6 @@ func (r *Reconciler) handleNoResources(ctx context.Context, cdk8sAppProxy *addon
252224 return nil
253225}
254226
255- func (r * Reconciler ) determineIfApplyNeeded (ctx context.Context , cdk8sAppProxy * addonsv1alpha1.Cdk8sAppProxy , parsedResources []* unstructured.Unstructured , currentCommitHash string , forceSynthAndApplyDueToDeletion bool , logger logr.Logger ) (bool , clusterv1.ClusterList , error ) {
256- var clusterList clusterv1.ClusterList
257-
258- // Check for git or annotation triggers
259- triggeredByGitOrAnnotation := r .checkGitOrAnnotationTriggers (cdk8sAppProxy , currentCommitHash , forceSynthAndApplyDueToDeletion , logger )
260-
261- if ! triggeredByGitOrAnnotation {
262- // Check if resources are missing on clusters
263- foundMissingResources , list , err := r .verifyResourcesOnClusters (ctx , cdk8sAppProxy , parsedResources , logger )
264- if err != nil {
265- return false , clusterList , err
266- }
267- clusterList = list
268-
269- return foundMissingResources , clusterList , nil
270- }
271-
272- return true , clusterList , nil
273- }
274-
275227func (r * Reconciler ) applyNeeded (ctx context.Context , cdk8sAppProxy * addonsv1alpha1.Cdk8sAppProxy , parsedResources []* unstructured.Unstructured , logger logr.Logger ) (bool , clusterv1.ClusterList , error ) {
276228 var clusterList clusterv1.ClusterList
277229
@@ -402,34 +354,9 @@ func (r *Reconciler) checkGitOrAnnotationTriggers(cdk8sAppProxy *addonsv1alpha1.
402354 return false
403355}
404356
405- func (r * Reconciler ) handleSkipApply (ctx context.Context , cdk8sAppProxy * addonsv1alpha1.Cdk8sAppProxy , currentCommitHash string , logger logr.Logger ) error {
406- logger .Info ("Skipping resource application: no Git changes, no deletion annotation, and all resources verified present." )
407-
408- // Re-establish watches for existing resources after controller restart
409- if err := r .reestablishWatchesForExistingResources (ctx , cdk8sAppProxy , logger ); err != nil {
410- logger .Error (err , "Failed to re-establish watches for existing resources" )
411- }
412-
413- cdk8sAppProxy .Status .ObservedGeneration = cdk8sAppProxy .Generation
414- conditions .MarkTrue (cdk8sAppProxy , addonsv1alpha1 .DeploymentProgressingCondition )
415-
416- if cdk8sAppProxy .Spec .GitRepository != nil && cdk8sAppProxy .Spec .GitRepository .URL != "" && currentCommitHash != "" {
417- cdk8sAppProxy .Status .LastProcessedGitHash = currentCommitHash
418- logger .Info ("Updated LastProcessedGitHash to current commit hash as no changes or missing resources were found." , "hash" , currentCommitHash )
419- }
420-
421- if err := r .Status ().Update (ctx , cdk8sAppProxy ); err != nil {
422- logger .Error (err , "Failed to update status after skipping resource application." )
423-
424- return err
425- }
426-
427- return nil
428- }
429-
430357func (r * Reconciler ) reestablishWatchesForExistingResources (ctx context.Context , cdk8sAppProxy * addonsv1alpha1.Cdk8sAppProxy , logger logr.Logger ) error {
431358 // Get the source and parse resources to know what should be watched
432- appSourcePath , _ , err := r .prepareSource (ctx , cdk8sAppProxy , types. NamespacedName { Name : cdk8sAppProxy . Name , Namespace : cdk8sAppProxy . Namespace }, logger , OperationNormal )
359+ appSourcePath , _ , err := r .prepareSource (cdk8sAppProxy , logger )
433360 if err != nil {
434361 return err
435362 }
@@ -588,27 +515,3 @@ func (r *Reconciler) applyResourcesToClusters(ctx context.Context, cdk8sAppProxy
588515
589516 return ctrl.Result {}, nil
590517}
591-
592- func (r * Reconciler ) triggerReconciliation (ctx context.Context , proxyName types.NamespacedName , logger logr.Logger ) error {
593- proxyToAnnotate := & addonsv1alpha1.Cdk8sAppProxy {}
594- if err := r .Get (ctx , proxyName , proxyToAnnotate ); err != nil {
595- logger .Error (err , "Failed to get latest Cdk8sAppProxy for annotation update" )
596-
597- return err
598- }
599-
600- if proxyToAnnotate .Annotations == nil {
601- proxyToAnnotate .Annotations = make (map [string ]string )
602- }
603- proxyToAnnotate .Annotations ["cdk8s.addons.cluster.x-k8s.io/git-poll-trigger" ] = time .Now ().Format (time .RFC3339Nano )
604-
605- if err := r .Update (ctx , proxyToAnnotate ); err != nil {
606- logger .Error (err , "Failed to update Cdk8sAppProxy annotations to trigger reconciliation" )
607-
608- return err
609- }
610-
611- logger .Info ("Successfully updated annotations to trigger reconciliation." )
612-
613- return nil
614- }
0 commit comments