Skip to content

Commit d9213f8

Browse files
authored
[deckhouse-cli] fix extra push (#221)
Signed-off-by: Pavel Okhlopkov <[email protected]>
1 parent 7212776 commit d9213f8

File tree

4 files changed

+26
-49
lines changed

4 files changed

+26
-49
lines changed

pkg/libmirror/layouts/pull.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func PullImageSet(
256256
layout.WithPlatform(v1.Platform{Architecture: "amd64", OS: "linux"}),
257257
layout.WithAnnotations(map[string]string{
258258
"org.opencontainers.image.ref.name": imageReferenceString,
259-
"io.deckhouse.image.short_tag": extractExtraImageShortTag(imageReferenceString),
259+
"io.deckhouse.image.short_tag": tag,
260260
}),
261261
)
262262
if err != nil {
@@ -281,20 +281,6 @@ func splitImageRefByRepoAndTag(imageReferenceString string) (string, string) {
281281
return repo, tag
282282
}
283283

284-
// extractExtraImageShortTag extracts the image name and tag for extra images
285-
func extractExtraImageShortTag(imageReferenceString string) string {
286-
const extraPrefix = "/extra/"
287-
288-
if extraIndex := strings.LastIndex(imageReferenceString, extraPrefix); extraIndex != -1 {
289-
// Extra image: return "imageName:tag" part after "/extra/"
290-
return imageReferenceString[extraIndex+len(extraPrefix):]
291-
}
292-
293-
// Regular image: return just the tag
294-
_, tag := splitImageRefByRepoAndTag(imageReferenceString)
295-
return tag
296-
}
297-
298284
type pullImageSetOptions struct {
299285
tagToDigestMapper TagToDigestMappingFunc
300286
allowMissingTags bool

pkg/libmirror/layouts/push.go

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package layouts
1919
import (
2020
"context"
2121
"fmt"
22-
"strings"
2322
"sync"
2423
"time"
2524

@@ -62,21 +61,6 @@ func PushLayoutToRepo(
6261
)
6362
}
6463

65-
// buildExtraImageRef builds the correct image reference for extra images
66-
func buildExtraImageRef(registryRepo, tag string) string {
67-
if strings.Contains(registryRepo, "/extra") && strings.Contains(tag, ":") {
68-
// This is an extra image with format "imageName:tag"
69-
// Split tag into image name and actual tag
70-
parts := strings.SplitN(tag, ":", 2)
71-
if len(parts) == 2 {
72-
imageName, imageTag := parts[0], parts[1]
73-
return registryRepo + "/" + imageName + ":" + imageTag
74-
}
75-
}
76-
// Regular image or fallback
77-
return registryRepo + ":" + tag
78-
}
79-
8064
func PushLayoutToRepoContext(
8165
ctx context.Context,
8266
client pkg.RegistryClient,
@@ -112,7 +96,9 @@ func PushLayoutToRepoContext(
11296
for _, manifestSet := range batches {
11397
if parallelismConfig.Images == 1 {
11498
tag := manifestSet[0].Annotations["io.deckhouse.image.short_tag"]
115-
imageRef := buildExtraImageRef(registryRepo, tag)
99+
100+
imageRef := registryRepo + ":" + tag
101+
116102
logger.Infof("[%d / %d] Pushing image %s", imagesCount, len(indexManifest.Manifests), imageRef)
117103
if err = pushImage(ctx, client, registryRepo, index, manifestSet[0], refOpts, remoteOpts, logger); err != nil {
118104
return fmt.Errorf("Push Image: %w", err)
@@ -125,7 +111,7 @@ func PushLayoutToRepoContext(
125111
logger.InfoLn("Images in batch:")
126112
for _, manifest := range manifestSet {
127113
tag := manifest.Annotations["io.deckhouse.image.short_tag"]
128-
logger.Infof("- %s", buildExtraImageRef(registryRepo, tag))
114+
logger.Infof("- %s", registryRepo+":"+tag)
129115
}
130116

131117
errMu := &sync.Mutex{}
@@ -161,7 +147,7 @@ func pushImage(
161147
_ params.Logger,
162148
) error {
163149
tag := manifest.Annotations["io.deckhouse.image.short_tag"]
164-
imageRef := buildExtraImageRef(registryRepo, tag)
150+
imageRef := registryRepo + ":" + tag
165151
img, err := index.Image(manifest.Digest)
166152
if err != nil {
167153
return fmt.Errorf("Read image: %v", err)

pkg/libmirror/modules/modules.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ func getModulesForRepo(
8282

8383
result := make([]Module, 0, len(modules))
8484
for _, module := range modules {
85+
// if len(flags.ModulesWhitelist) > 0 {
86+
// isWhitelisted := false
87+
88+
// for _, whitelisted := range flags.ModulesWhitelist {
89+
// if module == whitelisted {
90+
// isWhitelisted = true
91+
// }
92+
// }
93+
94+
// if !isWhitelisted {
95+
// continue
96+
// }
97+
// }
98+
8599
m := Module{
86100
Name: module,
87101
RegistryPath: path.Join(repo, module),
@@ -295,6 +309,8 @@ func FindModuleExtraImages(
295309

296310
// Convert to full registry paths with tags
297311
for imageName, tagValue := range extraImagesRaw {
312+
logger.Debugf("Found extra image %s with tag %v", imageName, tagValue)
313+
298314
var imageTag string
299315

300316
switch v := tagValue.(type) {
@@ -307,6 +323,9 @@ func FindModuleExtraImages(
307323
}
308324

309325
fullImagePath := path.Join(mod.RegistryPath, "extra", imageName) + ":" + imageTag
326+
327+
logger.Debugf("Constructed full extra image path: %s", fullImagePath)
328+
310329
extraImages[fullImagePath] = struct{}{}
311330
}
312331

pkg/registry/image/layout.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (l *ImageLayout) AddImage(img pkg.RegistryImage, tag string) error {
109109
layout.WithPlatform(l.defaultPlatform),
110110
layout.WithAnnotations(map[string]string{
111111
AnnotationImageReferenceName: meta.GetTagReference(),
112-
AnnotationImageShortTag: extractExtraImageShortTag(meta.GetTagReference()),
112+
AnnotationImageShortTag: tag,
113113
}),
114114
)
115115
if err != nil {
@@ -199,17 +199,3 @@ func SplitImageRefByRepoAndTag(imageReferenceString string) (string, string) {
199199

200200
return repo, tag
201201
}
202-
203-
func extractExtraImageShortTag(imageReferenceString string) string {
204-
const extraPrefix = "/extra/"
205-
206-
if extraIndex := strings.LastIndex(imageReferenceString, extraPrefix); extraIndex != -1 {
207-
// Extra image: return "imageName:tag" part after "/extra/"
208-
return imageReferenceString[extraIndex+len(extraPrefix):]
209-
}
210-
211-
// Regular image: return just the tag
212-
_, tag := SplitImageRefByRepoAndTag(imageReferenceString)
213-
214-
return tag
215-
}

0 commit comments

Comments
 (0)