harbor
harbor copied to clipboard
Flattening not working with empty namespace (Replication rule for ECR)
Expected behavior and actual behavior: I expect flattening to work regardless of if a namespace is specified or not.
Actual behavior is that no matter which level of flatenning is chosen, the project name is always being appended to the image, except when a namespace is given, then the project name is properly replaced by the namespace.
Let's take this replication rule for example where the namespace is empty and the flattening is on:
In the following screenshot, I have pushed an image to harbor, which we will try to replicate to ECR in the next step:
After activating manual replication, we can see it fails with the following error:
In the error image, we can observe that it adds the namespace dev to the image repository, even if we specified empty namespace and flattening in the replication rule. Here's what the repository looks like in AWS with no namespace.
In summary we expect harbor to push to repository atlas and not dev/atlas when namespace is empty in the replication rule.
Steps to reproduce the problem: Following these steps, when one starts replication, if my ecr repo is named SOFTWARE, and I create a non-proxy project named DEV, even if I specify Flatten all, harbor will try to push the image as DEV/SOFTWARE, and fail as that repo does not exist in ecr.
If I specify a namespace as TEST in replication, and specify a flatenning level, such as Flatten 1 Level, then the image that's being pushed into ecr is TEST/SOFTWARE, which also fails because no such repo exists, as the repo SOFTWARE is the one in ecr.
I would guess flatten and no namespace would give one the ability to push just SOFTWARE to ecr, without either the project or namespace being attached.
Versions:
- harbor version: 2.9.0
- Deployed by helm chart 1.13.0
I'm guessing the issue comes from this section of the code https://github.com/goharbor/harbor/blob/main/src/controller/replication/flow/stage.go#L161-L164
Following my example, the function replaceNamespace receives the variable repository as DEV/SOFTWARE, but because namespace is empty, it just returns the variable as is, without flatenning.
Created PR to improve that behavior, let me know if it looks ok: https://github.com/goharbor/harbor/pull/19321
In the meanwhile is there a workaround? This is seriously messing with our promotion scheme...
In the meanwhile is there a workaround? This is seriously messing with our promotion scheme...
There's none, I tried to find one, but my PR should fix it, haven't heard back from them about a review tho.
In the meanwhile is there a workaround? This is seriously messing with our promotion scheme...
There's none, I tried to find one, but my PR should fix it, haven't heard back from them about a review tho.
Shoot. Well, I appreciate the response and the PR.
This issue is being marked stale due to a period of inactivity. If this issue is still relevant, please comment or remove the stale label. Otherwise, this issue will close in 30 days.
Commenting to remove stale label
This issue is being marked stale due to a period of inactivity. If this issue is still relevant, please comment or remove the stale label. Otherwise, this issue will close in 30 days.
Commenting to remove stale label
This issue is being marked stale due to a period of inactivity. If this issue is still relevant, please comment or remove the stale label. Otherwise, this issue will close in 30 days.
Commenting to remove stale label
This issue is being marked stale due to a period of inactivity. If this issue is still relevant, please comment or remove the stale label. Otherwise, this issue will close in 30 days.
This issue was closed because it has been stalled for 30 days with no activity. If this issue is still relevant, please re-open a new issue.