Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Also reconcile repo policy run on repo registration #1029

Merged
merged 4 commits into from
Sep 28, 2023
Merged

Conversation

JAORMX
Copy link
Contributor

@JAORMX JAORMX commented Sep 27, 2023

We used to only evaluate policy for artifacts when we created a repo. This is not
correct. We should also evaluate the repository itself.

@@ -125,7 +147,9 @@ func (e *Reconciler) handleArtifactsReconcilerEvent(ctx context.Context, evt *Re
artifacts, err := cli.ListPackagesByRepository(ctx, isOrg, repository.RepoOwner,
CONTAINER_TYPE, int64(repository.RepoID), 1, 100)
if err != nil {
return fmt.Errorf("error retrieving artifacts: %w", err)
// we do not return error since it's a valid use case for a repository to not have artifacts
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We probably want to explicitly check that the error is a NotFound error

Copy link
Member

Choose a reason for hiding this comment

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

Added a separate 404 check 👍

@@ -132,7 +132,7 @@ func (c *RestClient) ListPackagesByRepository(ctx context.Context, isOrg bool, o
artifacts, resp, err = c.client.Users.ListPackages(ctx, "", opt)
}
if err != nil {
return allContainers, err
return allContainers, resp, err
Copy link
Contributor Author

Choose a reason for hiding this comment

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

An alternative is to just return an empty list if there's a 404 here, and no error. This way we don't need to expose the response. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I wasn't sure, because we do this pagination where we return what we have so far even in the error case. WDYT, should we keep that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively, what about returning a special error code on 404?
Long term I think we want to move to returning a channel from the List functions and paginate inside the API instead of letting the caller do the work.

@JAORMX JAORMX force-pushed the fix-repo-rec branch 2 times, most recently from 3bacc61 to 6b936f8 Compare September 28, 2023 06:23
JAORMX and others added 4 commits September 28, 2023 09:24
We used to only evaluate policy for artifacts when we created a repo. This is not
correct. We should also evaluate the repository itself.
Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
Copy link
Member

@rdimitrov rdimitrov left a comment

Choose a reason for hiding this comment

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

🍻

@JAORMX JAORMX merged commit 892cbec into main Sep 28, 2023
@JAORMX JAORMX deleted the fix-repo-rec branch September 28, 2023 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants