@@ -538,16 +538,15 @@ func (r *PatternReconciler) updateDeletionPhase(instance *api.Pattern, phase api
538538 return nil
539539}
540540
541- func (r * PatternReconciler ) deleteSpokeApps (instance * api. Pattern , targetApp , app * argoapi.Application , namespace string ) error {
541+ func (r * PatternReconciler ) deleteSpokeApps (targetApp , app * argoapi.Application , namespace string ) error {
542542 log .Printf ("Deletion phase: %s - checking if all child applications are gone from spoke" , api .DeleteSpokeChildApps )
543543
544544 // Update application with deletePattern=DeleteSpokeChildApps to trigger spoke child deletion
545545 if changed , _ := updateApplication (r .argoClient , targetApp , app , namespace ); changed {
546546 return fmt .Errorf ("updated application %q for spoke child deletion" , app .Name )
547547 }
548548
549- //FIXME
550- if _ , err := syncApplication (r .argoClient , app , false ); err != nil {
549+ if err := syncApplication (r .argoClient , app , false ); err != nil {
551550 return err
552551 }
553552
@@ -556,8 +555,8 @@ func (r *PatternReconciler) deleteSpokeApps(instance *api.Pattern, targetApp, ap
556555 return err
557556 }
558557
559- for _ , childApp := range childApps {
560- if _ , err := syncApplication (r .argoClient , & childApp , false ); err != nil {
558+ for _ , childApp := range childApps { //nolint:gocritic // rangeValCopy: each iteration copies 992 bytes
559+ if err := syncApplication (r .argoClient , & childApp , false ); err != nil {
561560 return err
562561 }
563562 }
@@ -569,7 +568,6 @@ func (r *PatternReconciler) deleteSpokeApps(instance *api.Pattern, targetApp, ap
569568 }
570569
571570 if ! allGone {
572- // log.Printf("Waiting for all child applications to be deleted from spoke clusters")
573571 return fmt .Errorf ("waiting for child applications to be deleted from spoke clusters" )
574572 }
575573
@@ -609,13 +607,9 @@ func (r *PatternReconciler) deleteHubApps(targetApp, app *argoapi.Application, n
609607 return fmt .Errorf ("updated application %q for hub deletion" , app .Name )
610608 }
611609
612- _ , err = syncApplication (r .argoClient , app , true )
613- if err != nil {
610+ if err := syncApplication (r .argoClient , app , true ); err != nil {
614611 return err
615612 }
616- // if inProgress {
617- // return fmt.Errorf("sync with prune and force is already in progress for application %q", app.Name)
618- // }
619613
620614 return fmt .Errorf ("waiting %d hub child applications to be removed" , len (childApps ))
621615}
@@ -662,20 +656,20 @@ func (r *PatternReconciler) finalizeObject(instance *api.Pattern) error {
662656 }
663657 }
664658
665- return fmt .Errorf ("Initialized deletion phase, requeue now... " )
659+ return fmt .Errorf ("initialized deletion phase, requeueing now" )
666660 }
667661
668662 // Phase 1: Delete child applications from spoke clusters
669663 if qualifiedInstance .Status .DeletionPhase == api .DeleteSpokeChildApps {
670- if err := r .deleteSpokeApps (qualifiedInstance , targetApp , app , ns ); err != nil {
664+ if err := r .deleteSpokeApps (targetApp , app , ns ); err != nil {
671665 return err
672666 }
673667
674668 if err := r .updateDeletionPhase (qualifiedInstance , api .DeleteSpoke ); err != nil {
675669 return err
676670 }
677671
678- return fmt .Errorf ("All child applications are gone, transitioning to %s phase" , api .DeleteSpoke )
672+ return fmt .Errorf ("all child applications are gone, transitioning to %s phase" , api .DeleteSpoke )
679673 }
680674
681675 // Phase 2: Delete app of apps from spoke
@@ -684,7 +678,7 @@ func (r *PatternReconciler) finalizeObject(instance *api.Pattern) error {
684678 return fmt .Errorf ("updated application %q for spoke app of apps deletion" , app .Name )
685679 }
686680
687- if _ , err := syncApplication (r .argoClient , app , false ); err != nil {
681+ if err := syncApplication (r .argoClient , app , false ); err != nil {
688682 return err
689683 }
690684
@@ -694,8 +688,8 @@ func (r *PatternReconciler) finalizeObject(instance *api.Pattern) error {
694688 }
695689
696690 // We need to prune policies from acm, to initiate app of apps removal from spoke
697- for _ , childApp := range childApps {
698- if _ , err := syncApplication (r .argoClient , & childApp , true ); err != nil {
691+ for _ , childApp := range childApps { //nolint:gocritic // rangeValCopy: each iteration copies 992 bytes
692+ if err := syncApplication (r .argoClient , & childApp , true ); err != nil {
699693 return err
700694 }
701695 }
@@ -709,7 +703,7 @@ func (r *PatternReconciler) finalizeObject(instance *api.Pattern) error {
709703 return err
710704 }
711705
712- return fmt .Errorf ("App of apps are gone from spokes, transitioning to %s phase" , api .DeleteHubChildApps )
706+ return fmt .Errorf ("app of apps are gone from spokes, transitioning to %s phase" , api .DeleteHubChildApps )
713707 }
714708
715709 // Phase 3: Delete applications from hub
@@ -722,11 +716,11 @@ func (r *PatternReconciler) finalizeObject(instance *api.Pattern) error {
722716 return err
723717 }
724718
725- return fmt .Errorf ("Apps are gone from hub, transitioning to %s phase" , api .DeleteHub )
719+ return fmt .Errorf ("apps are gone from hub, transitioning to %s phase" , api .DeleteHub )
726720 }
727721 // Phase 4: Delete app of apps from hub
728722 if qualifiedInstance .Status .DeletionPhase == api .DeleteHub {
729- log .Printf ("Removing the application, and cascading to anything instantiated by ArgoCD" )
723+ log .Printf ("removing the application, and cascading to anything instantiated by ArgoCD" )
730724 if err := removeApplication (r .argoClient , app .Name , ns ); err != nil {
731725 return err
732726 }
@@ -894,7 +888,6 @@ func (r *PatternReconciler) updatePatternCRDetails(input *api.Pattern) (bool, er
894888// The operator runs on the hub cluster and needs to check spoke clusters through ACM Search Service
895889// Returns true if all child applications are gone, false otherwise
896890func (r * PatternReconciler ) checkSpokeApplicationsGone (appOfApps bool ) (bool , error ) {
897-
898891 // Running locally: use localhost with env var set to "https://localhost:4010/searchapi/graphql" and port-forward
899892 // User should run: kubectl port-forward -n open-cluster-management svc/search-search-api 4010:4010
900893 searchURL := os .Getenv ("ACM_SEARCH_API_URL" )
@@ -908,7 +901,7 @@ func (r *PatternReconciler) checkSpokeApplicationsGone(appOfApps bool) (bool, er
908901 var tokenBytes []byte
909902 var err error
910903
911- tokenPath := "/run/secrets/kubernetes.io/serviceaccount/token"
904+ tokenPath := "/run/secrets/kubernetes.io/serviceaccount/token" //nolint:gosec
912905
913906 if tokenBytes , err = os .ReadFile (tokenPath ); err != nil {
914907 return false , fmt .Errorf ("failed to read serviceaccount token: %w" , err )
@@ -920,7 +913,7 @@ func (r *PatternReconciler) checkSpokeApplicationsGone(appOfApps bool) (bool, er
920913 // Filter out local-cluster apps and app of apps (based on namespace)
921914 ns := []string {fmt .Sprintf ("!%s" , getClusterWideArgoNamespace ())}
922915 if appOfApps {
923- ns = []string {fmt . Sprintf ( "%s" , getClusterWideArgoNamespace () )}
916+ ns = []string {getClusterWideArgoNamespace ()}
924917 }
925918 query := map [string ]any {
926919 "operationName" : "searchResult" ,
@@ -960,7 +953,7 @@ func (r *PatternReconciler) checkSpokeApplicationsGone(appOfApps bool) (bool, er
960953 }
961954
962955 // Create HTTP request
963- req , err := http .NewRequest ( "POST" , searchURL , bytes .NewBuffer (queryJSON ))
956+ req , err := http .NewRequestWithContext ( context . Background (), "POST" , searchURL , bytes .NewBuffer (queryJSON ))
964957 if err != nil {
965958 return false , fmt .Errorf ("failed to create HTTP request: %w" , err )
966959 }
@@ -972,16 +965,16 @@ func (r *PatternReconciler) checkSpokeApplicationsGone(appOfApps bool) (bool, er
972965
973966 // Create HTTP client
974967 // Use insecure TLS (self-signed certs)
975- client := & http.Client {
968+ httpClient := & http.Client {
976969 Transport : & http.Transport {
977970 TLSClientConfig : & tls.Config {
978- InsecureSkipVerify : true ,
971+ InsecureSkipVerify : true , //nolint:gosec
979972 },
980973 },
981974 }
982975
983976 // Make the request
984- resp , err := client .Do (req )
977+ resp , err := httpClient .Do (req )
985978 if err != nil {
986979 return false , fmt .Errorf ("failed to make HTTP request to search service: %w" , err )
987980 }
0 commit comments