Skip to content
This repository was archived by the owner on Oct 10, 2023. It is now read-only.

Commit 9cc9029

Browse files
author
Anuj Chaudhari
committed
Update GetFile, GetFiles in registry pkg to take full image as param
1 parent 6a2b881 commit 9cc9029

File tree

7 files changed

+16
-28
lines changed

7 files changed

+16
-28
lines changed

pkg/v1/cli/carvelhelpers/registry.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ func GetFilesMapFromImage(imageWithTag string) (map[string][]byte, error) {
2727
if err != nil {
2828
return nil, errors.Wrapf(err, "unable to initialize registry")
2929
}
30-
image, tag, err := getImageRepoAndTag(imageWithTag)
31-
if err != nil {
32-
return nil, err
33-
}
34-
return reg.GetFiles(image, tag)
30+
return reg.GetFiles(imageWithTag)
3531
}
3632

3733
// ReadImageAndSaveFilesToTempDir reads OCI image and saves file to temp dir
@@ -56,15 +52,7 @@ func ReadImageAndSaveFilesToTempDir(imageWithTag string) (string, error) {
5652
return tmpDir, nil
5753
}
5854

59-
func getImageRepoAndTag(imageWithTag string) (string, string, error) {
60-
// Support providing image with tag as well as support image with sha256
61-
idx := strings.LastIndex(imageWithTag, ":")
62-
if idx == -1 {
63-
return "", "", errors.Errorf("invalid artifact image '%s'", imageWithTag)
64-
}
65-
return imageWithTag[0:idx], imageWithTag[idx+1:], nil
66-
}
67-
55+
// newRegistry returns new
6856
func newRegistry() (registry.Registry, error) {
6957
verifyCerts := true
7058
skipVerifyCerts := os.Getenv(constants.ConfigVariableCustomImageRepositorySkipTLSVerify)

pkg/v1/tkg/tkgconfigbom/bom.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ func (c *client) DownloadDefaultBOMFilesFromRegistry(bomRegistry registry.Regist
436436
}
437437

438438
log.Infof("Downloading the TKG Bill of Materials (BOM) file from '%s'", fmt.Sprintf("%s:%s", tkgBOMImagePath, tkgBOMImageTag))
439-
tkgBOMContent, err := bomRegistry.GetFile(tkgBOMImagePath, tkgBOMImageTag, "")
439+
tkgBOMContent, err := bomRegistry.GetFile(fmt.Sprintf("%s:%s", tkgBOMImagePath, tkgBOMImageTag), "")
440440
if err != nil {
441441
return errors.Errorf(errorDownloadingDefaultBOMFiles, fmt.Sprintf("%s:%s", tkgBOMImagePath, tkgBOMImageTag), err, tkgconfigpath)
442442
}
@@ -473,7 +473,7 @@ func (c *client) DownloadDefaultBOMFilesFromRegistry(bomRegistry registry.Regist
473473
defaultTKRImagePath := tkrBOMImageRepo + "/" + bomConfiguration.TKRBOM.ImagePath
474474

475475
log.Infof("Downloading the TKr Bill of Materials (BOM) file from '%s'", fmt.Sprintf("%s:%s", defaultTKRImagePath, tkrBOMTagName))
476-
tkrBOMContent, err := bomRegistry.GetFile(defaultTKRImagePath, tkrBOMTagName, "")
476+
tkrBOMContent, err := bomRegistry.GetFile(fmt.Sprintf("%s:%s", defaultTKRImagePath, tkrBOMTagName), "")
477477
if err != nil {
478478
return errors.Errorf(errorDownloadingDefaultBOMFiles, fmt.Sprintf("%s:%s", defaultTKRImagePath, tkrBOMTagName), err, tkgconfigpath)
479479
}
@@ -531,7 +531,7 @@ func (c *client) DownloadTKGCompatibilityFileFromRegistry(bomRegistry registry.R
531531
return err
532532
}
533533

534-
tkgCompatibilityContent, err := bomRegistry.GetFile(tkgCompatibilityImagePath, tagName, "")
534+
tkgCompatibilityContent, err := bomRegistry.GetFile(fmt.Sprintf("%s:%s", tkgCompatibilityImagePath, tagName), "")
535535
if err != nil {
536536
return errors.Errorf(errorDownloadingTKGCompatibilityFile, fmt.Sprintf("%s:%s", tkgCompatibilityImagePath, tagName), err, tkgconfigpath)
537537
}

pkg/v1/tkg/tkgconfigupdater/ensure.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ func (c *client) saveProvidersFromRemoteRepo(providerDirPath string) error {
297297

298298
fullImagePath := tkgconfigbom.GetFullImagePath(providerTemplateImage, tkgBomConfig.ImageConfig.ImageRepository)
299299
imageTag := providerTemplateImage.Tag
300-
filesMap, err := bomRegistry.GetFiles(fullImagePath, imageTag)
300+
filesMap, err := bomRegistry.GetFiles(fmt.Sprintf("%s:%s", fullImagePath, imageTag))
301301
if err != nil {
302302
return errors.Wrap(err, "failed to get providers files from repository")
303303
}

pkg/v1/tkr/controllers/source/tkr_source_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func eventFilter(p func(eventMeta metav1.Object) bool) *predicate.Funcs {
176176

177177
func (r *reconciler) createBOMConfigMap(ctx context.Context, tag string) error {
178178
r.log.Info("Fetching BOM", "image", r.bomImage, "tag", tag)
179-
bomContent, err := r.registry.GetFile(r.bomImage, tag, "")
179+
bomContent, err := r.registry.GetFile(fmt.Sprintf("%s:%s", r.bomImage, tag), "")
180180
if err != nil {
181181
return errors.Wrapf(err, "failed to get the BOM file from image %s:%s", r.bomImage, tag)
182182
}
@@ -387,7 +387,7 @@ func (r *reconciler) fetchCompatibilityMetadata() (*types.CompatibilityMetadata,
387387
for i := len(tagNum) - 1; i >= 0; i-- {
388388
tagName := fmt.Sprintf("v%d", tagNum[i])
389389
r.log.Info("Fetching BOM metadata image", "image", r.compatibilityMetadataImage, "tag", tagName)
390-
metadataContent, err = r.registry.GetFile(r.compatibilityMetadataImage, tagName, "")
390+
metadataContent, err = r.registry.GetFile(fmt.Sprintf("%s:%s", r.compatibilityMetadataImage, tagName), "")
391391
if err == nil {
392392
if err = yaml.Unmarshal(metadataContent, &metadata); err == nil {
393393
break

pkg/v1/tkr/pkg/registry/client.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package registry
55

66
import (
77
"archive/tar"
8-
"fmt"
98
"io"
109

1110
regname "github.com/google/go-containerregistry/pkg/name"
@@ -43,8 +42,8 @@ func (r *registry) ListImageTags(imageName string) ([]string, error) {
4342

4443
// GetFile gets the file content bundled in the given image:tag.
4544
// If filename is empty, it will get the first file.
46-
func (r *registry) GetFile(image, tag, filename string) ([]byte, error) {
47-
ref, err := regname.ParseReference(fmt.Sprintf("%s:%s", image, tag), regname.WeakValidation)
45+
func (r *registry) GetFile(imageWithTag, filename string) ([]byte, error) {
46+
ref, err := regname.ParseReference(imageWithTag, regname.WeakValidation)
4847
if err != nil {
4948
return nil, err
5049
}
@@ -115,8 +114,8 @@ func getFileFromLayer(stream io.Reader, files map[string][]byte) error {
115114
}
116115

117116
// GetFiles get all the files content bundled in the given image:tag.
118-
func (r *registry) GetFiles(image, tag string) (map[string][]byte, error) {
119-
ref, err := regname.ParseReference(fmt.Sprintf("%s:%s", image, tag), regname.WeakValidation)
117+
func (r *registry) GetFiles(imageWithTag string) (map[string][]byte, error) {
118+
ref, err := regname.ParseReference(imageWithTag, regname.WeakValidation)
120119
if err != nil {
121120
return nil, err
122121
}

pkg/v1/tkr/pkg/registry/client_integ_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package registry
55

66
import (
7+
"fmt"
78
"os"
89
"strconv"
910
"testing"
@@ -45,7 +46,7 @@ func TestRegistryPullBOM(t *testing.T) {
4546

4647
t.Log(tags[0])
4748

48-
content, err := reg.GetFile(bomRegistry, tags[0], "")
49+
content, err := reg.GetFile(fmt.Sprintf("%s:%s", bomRegistry, tags[0]), "")
4950
if err != nil {
5051
t.Fatalf("error getting image content should not occurs %s", err.Error())
5152
}

pkg/v1/tkr/pkg/registry/interface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type Registry interface {
1111
ListImageTags(imageName string) ([]string, error)
1212
// GetFile gets the file content bundled in the given image:tag.
1313
// If filename is empty, it will get the first file.
14-
GetFile(image string, tag string, filename string) ([]byte, error)
14+
GetFile(imageWithTag string, filename string) ([]byte, error)
1515
// GetFiles get all the files content bundled in the given image:tag.
16-
GetFiles(image string, tag string) (map[string][]byte, error)
16+
GetFiles(imageWithTag string) (map[string][]byte, error)
1717
}

0 commit comments

Comments
 (0)