Skip to content

Commit

Permalink
Merge pull request #217 from kubescape/nogo
Browse files Browse the repository at this point in the history
remove async fetch of repo images
  • Loading branch information
matthyx authored Apr 4, 2024
2 parents a802688 + 9347332 commit acb4c16
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
20 changes: 5 additions & 15 deletions mainhandler/imageregistryhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,9 @@ func (registryScan *registryScan) getImagesForScanning(ctx context.Context, repo
}
logger.L().Info(fmt.Sprintf("GetImagesForScanning: enumerating repos successfully, found %d repos", len(repos)))

reposToTags := make(chan map[string][]string, len(repos))
for _, repo := range repos {
currentRepo := repo
go registryScan.setImageToTagsMap(ctx, currentRepo, reporter, reposToTags)
}
for i := 0; i < len(repos); i++ {
res := <-reposToTags
for k, v := range res {
registryScan.mapImageToTags[k] = v
if err := registryScan.setImageToTagsMap(ctx, repo, reporter, registryScan.mapImageToTags); err != nil {
logger.L().Ctx(ctx).Error("setImageToTagsMap failed", helpers.String("registry", registryScan.registry.hostname), helpers.Error(err))
}
}

Expand All @@ -344,7 +338,7 @@ func (registryScan *registryScan) getImagesForScanning(ctx context.Context, repo
return nil
}

func (registryScan *registryScan) setImageToTagsMap(ctx context.Context, repo string, sender beClientV1.IReportSender, c chan map[string][]string) error {
func (registryScan *registryScan) setImageToTagsMap(ctx context.Context, repo string, sender beClientV1.IReportSender, imageToTags map[string][]string) error {
logger.L().Info(fmt.Sprintf("Fetching repository %s tags", repo))
iRegistry, err := registryScan.makeRegistryInterface()
if err != nil {
Expand Down Expand Up @@ -389,9 +383,7 @@ func (registryScan *registryScan) setImageToTagsMap(ctx context.Context, repo st
}
}
}
c <- map[string][]string{
registryScan.registry.hostname + "/" + repo: tags,
}
imageToTags[registryScan.registry.hostname+"/"+repo] = tags

} else { //fallback to list images lexicographically
logger.L().Ctx(ctx).Error("get latestTags failed, fetching lexicographical list of tags", helpers.String("repository", repo), helpers.Error(err))
Expand All @@ -413,9 +405,7 @@ func (registryScan *registryScan) setImageToTagsMap(ctx context.Context, repo st
break
}
}
c <- map[string][]string{
registryScan.registry.hostname + "/" + repo: tags,
}
imageToTags[registryScan.registry.hostname+"/"+repo] = tags
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion mainhandler/vulnscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (actionHandler *ActionHandler) testRegistryConnect(ctx context.Context, reg

// check that we can pull tags. One is enough
if len(repos) > 0 {
reposToTags := make(chan map[string][]string, 1)
reposToTags := make(map[string][]string)
if err := registry.setImageToTagsMap(ctx, repos[0], sessionObj.Reporter, reposToTags); err != nil {
sessionObj.Reporter.SetDetails(string(testRegistryRetrieveTagsStatus))
return fmt.Errorf("setImageToTagsMap failed with err %v", err)
Expand Down

0 comments on commit acb4c16

Please sign in to comment.