Skip to content

Ecr fetcher to collect repositories by region#293

Merged
ofiriro3 merged 12 commits into
elastic:mainfrom
ofiriro3:ecr-retrieve-image-by-region
Jul 25, 2022
Merged

Ecr fetcher to collect repositories by region#293
ofiriro3 merged 12 commits into
elastic:mainfrom
ofiriro3:ecr-retrieve-image-by-region

Conversation

@ofiriro3

@ofiriro3 ofiriro3 commented Jul 22, 2022

Copy link
Copy Markdown
Contributor

@mergify

mergify Bot commented Jul 22, 2022

Copy link
Copy Markdown
Contributor

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b ecr-retrieve-image-by-region upstream/ecr-retrieve-image-by-region
git merge upstream/main
git push upstream ecr-retrieve-image-by-region

@mergify

mergify Bot commented Jul 22, 2022

Copy link
Copy Markdown
Contributor

This pull request does not have a backport label. Could you fix it @ofiriro3? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 8./d branch. /d is the digit
    NOTE: backport-skip has been added to this pull request.

ofiriro3 added 2 commits July 22, 2022 09:38
# Conflicts:
#	resources/fetchers/ecr_fetcher.go
#	resources/fetchers/ecr_fetcher_test.go
@ofiriro3 ofiriro3 changed the title adding region to both ecr_provider and ecr_fetcher + tests Ecr fetcher to collect repositories by region Jul 22, 2022
@ofiriro3 ofiriro3 marked this pull request as ready for review July 22, 2022 07:46
@ofiriro3 ofiriro3 requested a review from a team as a code owner July 22, 2022 07:46
@ofiriro3 ofiriro3 requested a review from oren-zohar July 22, 2022 07:46

@oren-zohar oren-zohar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 🦁

Comment on lines +71 to 72
"^my-account\\.dkr\\.ecr\\.([-\\w]+)\\.amazonaws\\.com\\/([-\\w\\.\\/]+)[:,@]?",
"public\\.ecr\\.aws\\/\\w+\\/([-\\w\\.\\/]+)\\:?",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please add some documentation about this regex, what are we expecting it to parse, and an example string or something?

Comment on lines +38 to 39
PrivateRepoRegexTemplate = "^%s\\.dkr\\.ecr\\.([-\\w]+)\\.amazonaws\\.com\\/([-\\w\\.\\/]+)[:,@]?"
PublicRepoRegex = "public\\.ecr\\.aws\\/\\w+\\/([-\\w\\.\\/]+)\\:?"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please add some documentation about this regex, what are we expecting it to parse, and an example string or something?

Comment thread resources/fetchers/ecr_fetcher.go Outdated
Comment on lines +105 to +109
describedRepo, err := describer.Provider.DescribeRepositories(ctx, f.awsConfig, repositories, region)
if err != nil {
f.log.Errorf("could not retrieve pod's aws repositories for region %s: %w", region, err)
}
awsRepositories = append(awsRepositories, describedRepo.Repositories...)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there's an error it will still add the decribedRepo into awsRepositories. Is this by design?

Comment thread resources/fetchers/ecr_fetcher.go Outdated
}

f.log.Debugf("sending pods to ecrProviders: %v", repositories)
return ""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error instead? we will get no indication if something went wrong here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at other text manipulation examples (for example regex.FindString) and I saw that when there is no match, the method should return an empty string "".

But this case is a bit different, so I am not sure.

Whatever you think - I am ok with both options

Comment thread resources/fetchers/ecr_fetcher.go Outdated
Comment thread resources/fetchers/ecr_fetcher_test.go Outdated
@ofiriro3 ofiriro3 requested a review from oren-zohar July 25, 2022 07:18

@oren-zohar oren-zohar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the coverage report shows a decrease in coverage for the ecr files, can you give it a look?

Comment on lines +42 to 43
// public.ecr.aws/<aws-alias>/<repository>
PublicRepoRegex = "public\\.ecr\\.aws\\/\\w+\\/([-\\w\\.\\/]+)\\:?"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is the expected format, using regex to extract the repo seems like overkill, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using the regex for two things:

  1. Validating the format of the image so I can be sure it's an ECR image.
  2. Extract the repository name out of the format.

Do you have another suggestion?

@ofiriro3

Copy link
Copy Markdown
Contributor Author

the coverage report shows a decrease in coverage for the ecr files, can you give it a look?

I looked at the coverage report, it seems to me that the coverage in the provider was decreased.

image

The provider code is a wrapper for AWS original provider, and it will be a bit complex (if possible at all) to test it.
Since I added code in providers, the coverage was reduced :/

@ofiriro3 ofiriro3 requested a review from oren-zohar July 25, 2022 13:00
@github-actions

Copy link
Copy Markdown

@ofiriro3 ofiriro3 enabled auto-merge (squash) July 25, 2022 16:52
@ofiriro3 ofiriro3 merged commit 298e0d2 into elastic:main Jul 25, 2022
orouz added a commit to orouz/cloudbeat that referenced this pull request Sep 16, 2023
orestisfl pushed a commit to orestisfl/cloudbeat that referenced this pull request Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ECR Retrieve AWS resource by region

2 participants