Skip to content

Commit

Permalink
Repo-agnostic retag in PullImages (#154)
Browse files Browse the repository at this point in the history
* Repo-agnostic retag in PullImages

* Lints
  • Loading branch information
kke authored Aug 5, 2020
1 parent dcd3134 commit 70f7fd6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/phase/pull_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (p *PullImages) Run(c *api.ClusterConfig) error {
// Store map of original --> custom repo images
imageMap := make(map[string]string, len(images))
for index, i := range images {
newImage := strings.Replace(i, "docker/", fmt.Sprintf("%s/", c.Spec.Ucp.ImageRepo), 1)
newImage := p.ImageFromCustomRepo(i, c.Spec.Ucp.ImageRepo)
imageMap[i] = newImage
images[index] = newImage
}
Expand All @@ -56,7 +56,11 @@ func (p *PullImages) Run(c *api.ClusterConfig) error {
return runParallelOnHosts(c.Spec.Managers(), c, func(h *api.Host, c *api.ClusterConfig) error {
return p.pullImages(h, images)
})
}

// ImageFromCustomRepo will replace the organization part in an image name
func (p *PullImages) ImageFromCustomRepo(image, repo string) string {
return fmt.Sprintf("%s%s", repo, image[strings.IndexByte(image, '/'):])
}

func (p *PullImages) listImages(config *api.ClusterConfig) ([]string, error) {
Expand Down
12 changes: 12 additions & 0 deletions pkg/phase/pull_images_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package phase

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestPullImagesCustomRepo(t *testing.T) {
phase := PullImages{}
require.Equal(t, "xyz/foofoo:1.2.3-latest", phase.ImageFromCustomRepo("docker/foofoo:1.2.3-latest", "xyz"))
}

0 comments on commit 70f7fd6

Please sign in to comment.