Skip to content

Commit 1e8fad1

Browse files
committed
fix strip logic for /library in image and chart rewrite
1 parent f91e729 commit 1e8fad1

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

cmd/hauler/cli/store/add.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,12 @@ func rewriteReference(ctx context.Context, s *store.Layout, oldRef name.Referenc
605605
// index.docker.io. Preserve the original registry when the source is non-docker.
606606
if newRegistry == "index.docker.io" && !strings.HasPrefix(rawRewrite, "docker.io") && !strings.HasPrefix(rawRewrite, "index.docker.io") {
607607
newRegistry = oldRegistry
608-
if !strings.HasPrefix(newRepo, "library/") {
609-
newRepo = strings.TrimPrefix(newRepo, "library/") //if rewritten reference has library/ prefix in path it is stripped off unless registry specified in rewrite
608+
rewriteRepo := strings.TrimPrefix(rawRewrite, "/")
609+
if i := strings.LastIndex(rewriteRepo, ":"); i != -1 {
610+
rewriteRepo = rewriteRepo[:i]
611+
}
612+
if !strings.HasPrefix(rewriteRepo, "library/") {
613+
newRepo = strings.TrimPrefix(newRepo, "library/")
610614
}
611615
}
612616
oldTotal := oldRepo + ":" + oldTag
@@ -1427,6 +1431,7 @@ func fetchChart(ctx context.Context, s *store.Layout, j chartJob, tempRoot strin
14271431
// rewrite. A rewrite that omits a tag inherits ref's.
14281432
func rewriteChartReference(ctx context.Context, s *store.Layout, ref name.Reference, rewrite string) error {
14291433
rewrite = strings.TrimPrefix(rewrite, "/")
1434+
rawRewrite := rewrite
14301435
newRef, err := name.ParseReference(rewrite)
14311436
if err != nil {
14321437
// error... don't continue with a bad reference
@@ -1449,6 +1454,13 @@ func rewriteChartReference(ctx context.Context, s *store.Layout, ref name.Refere
14491454
// rename chart name in store
14501455
oldRepo := ref.Context().RepositoryStr()
14511456
newRepo := newRef.Context().RepositoryStr()
1457+
rewriteRepo := rawRewrite
1458+
if i := strings.LastIndex(rewriteRepo, ":"); i != -1 {
1459+
rewriteRepo = rewriteRepo[:i]
1460+
}
1461+
if !strings.HasPrefix(rewriteRepo, "library/") {
1462+
newRepo = strings.TrimPrefix(newRepo, "library/")
1463+
}
14521464
newTag := newRef.Identifier()
14531465
if tag, ok := newRef.(name.Tag); ok {
14541466
newTag = tag.TagStr()

0 commit comments

Comments
 (0)