Skip to content

Commit

Permalink
fix: send err to a closed channel
Browse files Browse the repository at this point in the history
Signed-off-by: minhthong582000 <[email protected]>
  • Loading branch information
minhthong582000 committed Sep 7, 2023
1 parent 03ee704 commit 0ac43bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
24 changes: 13 additions & 11 deletions cmd/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,29 @@ var addonsCmd = &cobra.Command{

var wg sync.WaitGroup
errChan := make(chan error)
defer close(errChan)

updater := updater.NewEKSUpdater(awsClient.EKS())
for _, addon := range addonsList {
wg.Add(1)

go func(addon string) {
errChan <- updater.UpdateAddon(ctx, &clusterName, &addon, &wg)
}(addon)
go func(addon string, wg *sync.WaitGroup) {
defer wg.Done()

errChan <- updater.UpdateAddon(ctx, &clusterName, &addon)
}(addon, &wg)
}

var errResult error
go func() {
for err := range errChan {
if err != nil {
errResult = errors.Join(errResult, err)
}
}
wg.Wait()
close(errChan)
}()

wg.Wait()
var errResult error
for err := range errChan {
if err != nil {
errResult = errors.Join(errResult, err)
}
}

// Return all of the errors that were sent to the errChan channel
if errResult != nil {
Expand Down
5 changes: 1 addition & 4 deletions internal/updater/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package updater

import (
"context"
"sync"

"github.com/armory-io/eks-auto-updater/pkg/aws/eks"
)
Expand All @@ -28,9 +27,7 @@ func (u EKSUpdater) UpdateClusterNodeGroup(ctx context.Context, clusterName *str
}

// UpdateAddon updates the addon of a cluster to the latest version
func (u EKSUpdater) UpdateAddon(ctx context.Context, clusterName *string, addonName *string, wg *sync.WaitGroup) (err error) {
defer wg.Done()

func (u EKSUpdater) UpdateAddon(ctx context.Context, clusterName *string, addonName *string) (err error) {
err = u.client.UpdateAddon(ctx, clusterName, addonName)
if err != nil {
return err
Expand Down

0 comments on commit 0ac43bc

Please sign in to comment.