Skip to content

Commit 2a62da8

Browse files
committed
fix: linting errors
1 parent 9f7d2e9 commit 2a62da8

2 files changed

Lines changed: 25 additions & 32 deletions

File tree

internal/controller/argo.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,10 +1064,10 @@ func updateHelmParameter(goal api.PatternParameter, actual []argoapi.HelmParamet
10641064
}
10651065

10661066
// syncApplication syncs the application with prune and force options if such a sync is not already in progress.
1067-
// Returns true if a sync with prune and force is already in progress, false otherwise
1068-
func syncApplication(client argoclient.Interface, app *argoapi.Application, withPrune bool) (bool, error) {
1067+
// Returns nil if a sync is already in progress, error otherwise
1068+
func syncApplication(client argoclient.Interface, app *argoapi.Application, withPrune bool) error {
10691069
if app.Operation != nil && app.Operation.Sync != nil && app.Operation.Sync.Prune == withPrune && slices.Contains(app.Operation.Sync.SyncOptions, "Force=true") {
1070-
return true, nil
1070+
return nil
10711071
}
10721072

10731073
app.Operation = &argoapi.Operation{
@@ -1079,10 +1079,10 @@ func syncApplication(client argoclient.Interface, app *argoapi.Application, with
10791079

10801080
_, err := client.ArgoprojV1alpha1().Applications(app.Namespace).Update(context.Background(), app, metav1.UpdateOptions{})
10811081
if err != nil {
1082-
return false, fmt.Errorf("failed to sync application %q with prune: %w", app.Name, err)
1082+
return fmt.Errorf("failed to sync application %q with 'prune: %t': %w", app.Name, withPrune, err)
10831083
}
10841084

1085-
return true, nil
1085+
return nil
10861086
}
10871087

10881088
// returns the child applications owned by the app-of-apps parentApp

internal/controller/pattern_controller.go

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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
896890
func (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

Comments
 (0)