Skip to content

Commit 022d90a

Browse files
authored
Merge pull request #477 from openSUSE/registry-prefix
Add registry prefix option
2 parents deb8d24 + 6af299e commit 022d90a

File tree

12 files changed

+1447
-3
lines changed

12 files changed

+1447
-3
lines changed

cmd/critest/cri_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func TestCRISuite(t *testing.T) {
130130

131131
if *isBenchMark {
132132
flag.Set("ginkgo.focus", "benchmark")
133+
flag.Set("ginkgo.succinct", "true")
133134
} else {
134135
// Skip benchmark measurements for validation tests.
135136
flag.Set("ginkgo.skipMeasurements", "true")

pkg/framework/test_context.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@ type TestContextType struct {
4242

4343
// Test configuration.
4444
IsLcow bool
45+
46+
RegistryPrefix string
4547
}
4648

4749
// TestContext is a test context.
4850
var TestContext TestContextType
4951

52+
// DefaultRegistryPrefix specifies the default prefix used for images
53+
const DefaultRegistryPrefix = "docker.io/library"
54+
5055
// RegisterFlags registers flags to e2e test suites.
5156
func RegisterFlags() {
5257
// Turn on verbose by default to get spec names
@@ -77,4 +82,5 @@ func RegisterFlags() {
7782
} else {
7883
TestContext.IsLcow = false
7984
}
85+
flag.StringVar(&TestContext.RegistryPrefix, "registry-prefix", DefaultRegistryPrefix, "A possible registry prefix added to all images, like 'localhost:5000/'")
8086
}

pkg/framework/util.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"sync"
2424
"time"
2525

26+
"github.com/docker/distribution/reference"
2627
"github.com/pborman/uuid"
2728
internalapi "k8s.io/cri-api/pkg/apis"
2829
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
@@ -297,9 +298,26 @@ func ListImage(c internalapi.ImageManagerService, filter *runtimeapi.ImageFilter
297298

298299
// PullPublicImage pulls the public image named imageName.
299300
func PullPublicImage(c internalapi.ImageManagerService, imageName string, podConfig *runtimeapi.PodSandboxConfig) string {
300-
if !strings.Contains(imageName, ":") {
301-
imageName = imageName + ":latest"
302-
Logf("Use latest as default image tag.")
301+
302+
ref, err := reference.ParseNamed(imageName)
303+
if err == nil {
304+
// Modify the image if it's a fully qualified image name
305+
if TestContext.RegistryPrefix != DefaultRegistryPrefix {
306+
r := fmt.Sprintf("%s/%s", TestContext.RegistryPrefix, reference.Path(ref))
307+
ref, err = reference.ParseNamed(r)
308+
ExpectNoError(err, "failed to parse new image name: %v", err)
309+
}
310+
imageName = ref.String()
311+
312+
if !strings.Contains(imageName, ":") {
313+
imageName = imageName + ":latest"
314+
Logf("Use latest as default image tag.")
315+
}
316+
} else if err == reference.ErrNameNotCanonical {
317+
// Non canonical images can simply be prefixed
318+
imageName = fmt.Sprintf("%s/%s", TestContext.RegistryPrefix, imageName)
319+
} else {
320+
Failf("Unable to parse imageName: %v", err)
303321
}
304322

305323
By("Pull image : " + imageName)

vendor.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
github.com/Azure/go-ansiterm d6e3b3328b783f23731bc4d058875b0371ff8109
22
github.com/docker/docker a9fbbdc8dd8794b20af358382ab780559bca589d
3+
github.com/docker/distribution v2.7.1
34
github.com/docker/go-units 9e638d38cf6977a37a8ea0078f3ee75a7cdb2dd1
45
github.com/docker/spdystream 449fdfce4d962303d702fec724ef0ad181c92528
56
github.com/fsnotify/fsnotify f12c6236fe7b5cf6bcf30e5935d08cb079d78334

vendor/github.com/docker/distribution/LICENSE

Lines changed: 202 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)