mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 02:05:41 +01:00
fix image name extraction (#18992)
* Update replication.go It also could be 'library/bitnami/fluentd:1.13.3-debian-10-r0' so we need to split resource to only 2 parts - possible namespace and image name which may include slashes for example - namespace: library, image: bitnami/fluentd:1.13.3-debian-10-r0 Signed-off-by: Taras Katkov <tkatkov@gmail.com> * Update replication_test.go Adding namespace and resource extraction tests. Signed-off-by: Taras Katkov <tkatkov@gmail.com> * Reformat only Signed-off-by: Taras Katkov <tkatkov@gmail.com> --------- Signed-off-by: Taras Katkov <tkatkov@gmail.com>
This commit is contained in:
parent
7c2158bdf9
commit
da3c85be5a
@ -216,7 +216,9 @@ func constructReplicationPayload(ctx context.Context, event *event.ReplicationEv
|
||||
|
||||
func getMetadataFromResource(resource string) (namespace, nameAndTag string) {
|
||||
// Usually resource format likes 'library/busybox:v1', but it could be 'busybox:v1' in docker registry
|
||||
meta := strings.Split(resource, "/")
|
||||
// It also could be 'library/bitnami/fluentd:1.13.3-debian-10-r0' so we need to split resource to only 2 parts
|
||||
// possible namespace and image name which may include slashes for example: bitnami/fluentd:1.13.3-debian-10-r0
|
||||
meta := strings.SplitN(resource, "/", 2)
|
||||
if len(meta) == 1 {
|
||||
return "", meta[0]
|
||||
}
|
||||
|
@ -146,3 +146,21 @@ func TestIsLocalRegistry(t *testing.T) {
|
||||
}
|
||||
assert.False(t, isLocalRegistry(reg2))
|
||||
}
|
||||
|
||||
func TestReplicationHandler_ShortResourceName(t *testing.T) {
|
||||
namespace, resource := getMetadataFromResource("busybox:v1")
|
||||
assert.Equal(t, "", namespace)
|
||||
assert.Equal(t, "busybox:v1", resource)
|
||||
}
|
||||
|
||||
func TestReplicationHandler_NormalResourceName(t *testing.T) {
|
||||
namespace, resource := getMetadataFromResource("library/busybox:v1")
|
||||
assert.Equal(t, "library", namespace)
|
||||
assert.Equal(t, "busybox:v1", resource)
|
||||
}
|
||||
|
||||
func TestReplicationHandler_LongResourceName(t *testing.T) {
|
||||
namespace, resource := getMetadataFromResource("library/bitnami/fluentd:1.13.3-debian-10-r0")
|
||||
assert.Equal(t, "library", namespace)
|
||||
assert.Equal(t, "bitnami/fluentd:1.13.3-debian-10-r0", resource)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user