@@ -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 (cdk8sAppProxy , logger )
92+ appSourcePath , err := r .prepareSource (cdk8sAppProxy , logger )
9393 if err != nil {
9494 return ctrl.Result {}, err
9595 }
@@ -108,10 +108,9 @@ func (r *Reconciler) reconcileNormal(ctx context.Context, cdk8sAppProxy *addonsv
108108 }
109109
110110 // Determine if apply is needed
111- _ , clusterList , err := r .applyNeeded (ctx , cdk8sAppProxy , parsedResources , logger )
111+ clusterList , err := r .applyNeeded (ctx , cdk8sAppProxy , parsedResources , logger )
112112 if err != nil {
113113 logger .Error (err , "Failed to determine if apply is needed" )
114- //return ctrl.Result{}, err
115114 }
116115
117116 _ , err = r .applyResourcesToClusters (ctx , cdk8sAppProxy , parsedResources , clusterList , proxyNamespacedName , logger )
@@ -146,7 +145,7 @@ func (r *Reconciler) reconcileNormal(ctx context.Context, cdk8sAppProxy *addonsv
146145 }
147146 if polling {
148147 logger .Info ("Detected changes in git repository, proceeding with reconciliation." )
149- appSourcePath , _ , err = r .prepareSource (cdk8sAppProxy , logger )
148+ appSourcePath , err = r .prepareSource (cdk8sAppProxy , logger )
150149 if err != nil {
151150 logger .Error (err , "Prepare source for reconciliation" )
152151 }
@@ -169,17 +168,17 @@ func (r *Reconciler) reconcileNormal(ctx context.Context, cdk8sAppProxy *addonsv
169168 if len (parsedResources ) == 0 {
170169 if err := r .handleNoResources (ctx , cdk8sAppProxy , logger ); err != nil {
171170 logger .Error (err , "Failed to handle no resources case" )
171+
172172 return
173173 }
174174
175175 logger .Info ("No valid Kubernetes resources parsed from manifest files, skipping apply." )
176176 }
177177
178178 // Determine if apply is needed
179- _ , clusterList , err := r .applyNeeded (ctx , cdk8sAppProxy , parsedResources , logger )
179+ clusterList , err := r .applyNeeded (ctx , cdk8sAppProxy , parsedResources , logger )
180180 if err != nil {
181181 logger .Error (err , "Failed to determine if apply is needed" )
182- //return ctrl.Result{}, err
183182 }
184183
185184 _ , err = r .applyResourcesToClusters (ctx , cdk8sAppProxy , parsedResources , clusterList , proxyNamespacedName , logger )
@@ -191,6 +190,7 @@ func (r *Reconciler) reconcileNormal(ctx context.Context, cdk8sAppProxy *addonsv
191190 }
192191 case <- ctx .Done ():
193192 logger .Info ("Stopping git repository polling loop due to context cancellation." )
193+
194194 return
195195 }
196196 }
@@ -228,16 +228,16 @@ func (r *Reconciler) handleNoResources(ctx context.Context, cdk8sAppProxy *addon
228228 return nil
229229}
230230
231- func (r * Reconciler ) applyNeeded (ctx context.Context , cdk8sAppProxy * addonsv1alpha1.Cdk8sAppProxy , parsedResources []* unstructured.Unstructured , logger logr.Logger ) (bool , clusterv1.ClusterList , error ) {
231+ func (r * Reconciler ) applyNeeded (ctx context.Context , cdk8sAppProxy * addonsv1alpha1.Cdk8sAppProxy , parsedResources []* unstructured.Unstructured , logger logr.Logger ) (clusterv1.ClusterList , error ) {
232232 var clusterList clusterv1.ClusterList
233233
234234 _ , list , err := r .verifyResourcesOnClusters (ctx , cdk8sAppProxy , parsedResources , logger )
235235 if err != nil {
236- return false , clusterList , err
236+ return clusterList , err
237237 }
238238 clusterList = list
239239
240- return true , clusterList , nil
240+ return clusterList , nil
241241}
242242
243243func (r * Reconciler ) verifyResourcesOnClusters (ctx context.Context , cdk8sAppProxy * addonsv1alpha1.Cdk8sAppProxy , parsedResources []* unstructured.Unstructured , logger logr.Logger ) (bool , clusterv1.ClusterList , error ) {
@@ -305,107 +305,6 @@ func (r *Reconciler) verifyResourcesOnClusters(ctx context.Context, cdk8sAppProx
305305 return foundMissingResourcesOnAnyCluster , clusterList , nil
306306}
307307
308- func (r * Reconciler ) checkGitOrAnnotationTriggers (cdk8sAppProxy * addonsv1alpha1.Cdk8sAppProxy , currentCommitHash string , forceSynthAndApplyDueToDeletion bool , logger logr.Logger ) bool {
309- // Check for periodic git poller trigger
310- if cdk8sAppProxy .Status .LastRemoteGitHash != "" &&
311- cdk8sAppProxy .Status .LastRemoteGitHash != cdk8sAppProxy .Status .LastProcessedGitHash &&
312- cdk8sAppProxy .Status .LastRemoteGitHash != currentCommitHash {
313- logger .Info ("Reconciliation proceeding due to change detected by git poller." ,
314- "lastRemoteGitHash" , cdk8sAppProxy .Status .LastRemoteGitHash ,
315- "lastProcessedGitHash" , cdk8sAppProxy .Status .LastProcessedGitHash ,
316- "currentCommitHash" , currentCommitHash )
317-
318- return true
319- }
320-
321- // Check for git repository changes
322- if cdk8sAppProxy .Spec .GitRepository != nil && cdk8sAppProxy .Spec .GitRepository .URL != "" {
323- if currentCommitHash == "" {
324- logger .Info ("currentCommitHash is unexpectedly empty for Git source; proceeding with update as a precaution." )
325-
326- return true
327- }
328-
329- lastProcessedGitHash := cdk8sAppProxy .Status .LastProcessedGitHash
330- gitSpecRef := cdk8sAppProxy .Spec .GitRepository .Reference
331- repositoryHasChanged := currentCommitHash != lastProcessedGitHash
332- isInitialDeployment := lastProcessedGitHash == ""
333-
334- if isInitialDeployment {
335- logger .Info ("Initial deployment or no last processed hash found. Proceeding with cdk8s synth and apply." , "currentCommitHash" , currentCommitHash , "reference" , gitSpecRef )
336-
337- return true
338- }
339- if repositoryHasChanged {
340- logger .Info ("Git repository has changed (current clone vs last processed), proceeding with update." , "currentCommitHash" , currentCommitHash , "lastProcessedGitHash" , lastProcessedGitHash , "reference" , gitSpecRef )
341-
342- return true
343- }
344- logger .Info ("No new Git changes detected (current clone matches last processed, and no pending poller detection)." , "commitHash" , currentCommitHash , "reference" , gitSpecRef )
345- } else if cdk8sAppProxy .Status .ObservedGeneration == 0 {
346- logger .Info ("Initial processing for source type without explicit change detection. Proceeding with cdk8s synth and apply." )
347-
348- return true
349- }
350-
351- // Check for deletion trigger
352- if forceSynthAndApplyDueToDeletion {
353- logger .Info ("Forcing synth and apply because reconciliation was triggered by a resource deletion" )
354-
355- return true
356- }
357-
358- return false
359- }
360-
361- func (r * Reconciler ) reestablishWatchesForExistingResources (ctx context.Context , cdk8sAppProxy * addonsv1alpha1.Cdk8sAppProxy , logger logr.Logger ) error {
362- // Get the source and parse resources to know what should be watched
363- appSourcePath , _ , err := r .prepareSource (cdk8sAppProxy , logger )
364- if err != nil {
365- return err
366- }
367-
368- parsedResources , err := r .synthesizeAndParseResources (appSourcePath , logger )
369- if err != nil {
370- return err
371- }
372-
373- // Get target clusters
374- selector , err := metav1 .LabelSelectorAsSelector (& cdk8sAppProxy .Spec .ClusterSelector )
375- if err != nil {
376- return err
377- }
378-
379- var clusterList clusterv1.ClusterList
380- if err := r .List (ctx , & clusterList , client.MatchingLabelsSelector {Selector : selector }); err != nil {
381- return err
382- }
383-
384- proxyNamespacedName := types.NamespacedName {Name : cdk8sAppProxy .Name , Namespace : cdk8sAppProxy .Namespace }
385-
386- // Re-establish watches for each resource on each cluster
387- for _ , cluster := range clusterList .Items {
388- dynamicClient , err := r .getDynamicClientForCluster (ctx , cluster .Namespace , cluster .Name )
389- if err != nil {
390- logger .Error (err , "Failed to get dynamic client for watch re-establishment" , "cluster" , cluster .Name )
391-
392- continue
393- }
394-
395- for _ , resource := range parsedResources {
396- gvk := resource .GroupVersionKind ()
397-
398- if err := r .WatchManager .StartWatch (ctx , dynamicClient , gvk , resource .GetNamespace (), resource .GetName (), proxyNamespacedName ); err != nil {
399- logger .Error (err , "Failed to re-establish watch" , "cluster" , cluster .Name , "resource" , resource .GetName ())
400- } else {
401- logger .Info ("Re-established watch for existing resource" , "cluster" , cluster .Name , "resource" , resource .GetName ())
402- }
403- }
404- }
405-
406- return nil
407- }
408-
409308//nolint:unparam // ctrl.Result is required for controller-runtime reconciler pattern
410309func (r * Reconciler ) applyResourcesToClusters (ctx context.Context , cdk8sAppProxy * addonsv1alpha1.Cdk8sAppProxy , parsedResources []* unstructured.Unstructured , clusterList clusterv1.ClusterList , proxyNamespacedName types.NamespacedName , logger logr.Logger ) (ctrl.Result , error ) {
411310 logger .Info ("Proceeding with application of resources to target clusters." )
@@ -440,7 +339,6 @@ func (r *Reconciler) applyResourcesToClusters(ctx context.Context, cdk8sAppProxy
440339 cdk8sAppProxy .Status .ObservedGeneration = cdk8sAppProxy .Generation
441340 conditions .MarkTrue (cdk8sAppProxy , addonsv1alpha1 .DeploymentProgressingCondition )
442341 if cdk8sAppProxy .Spec .GitRepository != nil && cdk8sAppProxy .Spec .GitRepository .URL != "" {
443- //cdk8sAppProxy.Status.LastProcessedGitHash = currentCommitHash
444342 }
445343 if err := r .Status ().Update (ctx , cdk8sAppProxy ); err != nil {
446344 logger .Error (err , "Failed to update status when no resources to apply" )
@@ -504,8 +402,6 @@ func (r *Reconciler) applyResourcesToClusters(ctx context.Context, cdk8sAppProxy
504402
505403 // If we reach here, the overallSuccess is true.
506404 if cdk8sAppProxy .Spec .GitRepository != nil && cdk8sAppProxy .Spec .GitRepository .URL != "" {
507- //cdk8sAppProxy.Status.LastProcessedGitHash = currentCommitHash
508- //logger.Info("Successfully updated LastProcessedGitHash in status after application", "hash", currentCommitHash)
509405 }
510406
511407 cdk8sAppProxy .Status .ObservedGeneration = cdk8sAppProxy .Generation
0 commit comments