Skip to content

Commit

Permalink
Add registry prefix option
Browse files Browse the repository at this point in the history
This allows to pre-pull the images and running benchmarks against a
local registry.

Signed-off-by: Sascha Grunert <[email protected]>
  • Loading branch information
saschagrunert committed Jun 27, 2019
1 parent 93aa03a commit c43c4aa
Show file tree
Hide file tree
Showing 15 changed files with 1,452 additions and 11 deletions.
1 change: 1 addition & 0 deletions cmd/critest/cri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func TestCRISuite(t *testing.T) {

if *isBenchMark {
flag.Set("ginkgo.focus", "benchmark")
flag.Set("ginkgo.succinct", "true")
} else {
// Skip benchmark measurements for validation tests.
flag.Set("ginkgo.skipMeasurements", "true")
Expand Down
10 changes: 5 additions & 5 deletions pkg/benchmark/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ var _ = framework.KubeDescribe("Container", func() {
var err error

testImageList := []string{
"busybox:1.26.2-uclibc",
"busybox:1-uclibc",
"busybox:1",
"busybox:1-glibc",
"busybox:1-musl",
"docker.io/library/busybox:1.26.2-uclibc",
"docker.io/library/busybox:1-uclibc",
"docker.io/library/busybox:1",
"docker.io/library/busybox:1-glibc",
"docker.io/library/busybox:1-musl",
}

AfterEach(func() {
Expand Down
3 changes: 3 additions & 0 deletions pkg/framework/test_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type TestContextType struct {

// Test configuration.
IsLcow bool

RegistryPrefix string
}

// TestContext is a test context.
Expand Down Expand Up @@ -77,4 +79,5 @@ func RegisterFlags() {
} else {
TestContext.IsLcow = false
}
flag.StringVar(&TestContext.RegistryPrefix, "registry-prefix", "", "A possible registry prefix added to all images, like 'localhost:5000/'")
}
26 changes: 22 additions & 4 deletions pkg/framework/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"sync"
"time"

"github.com/docker/distribution/reference"
"github.com/pborman/uuid"
internalapi "k8s.io/kubernetes/pkg/kubelet/apis/cri"
runtimeapi "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
Expand Down Expand Up @@ -83,7 +84,7 @@ const (
DefaultStopContainerTimeout int64 = 60

// DefaultLinuxContainerImage default container image for Linux
DefaultLinuxContainerImage string = "busybox:1.28"
DefaultLinuxContainerImage string = "docker.io/library/busybox:1.28"

// DefaultWindowsContainerImage default container image for Windows
DefaultWindowsContainerImage string = "mcr.microsoft.com/windows/servercore:ltsc2019"
Expand Down Expand Up @@ -297,9 +298,26 @@ func ListImage(c internalapi.ImageManagerService, filter *runtimeapi.ImageFilter

// PullPublicImage pulls the public image named imageName.
func PullPublicImage(c internalapi.ImageManagerService, imageName string, podConfig *runtimeapi.PodSandboxConfig) string {
if !strings.Contains(imageName, ":") {
imageName = imageName + ":latest"
Logf("Use latest as default image tag.")

ref, err := reference.ParseNamed(imageName)
if err == nil {
// Modify the image if it's a fully qualified image name
if TestContext.RegistryPrefix != "" {
r := fmt.Sprintf("%s/%s", TestContext.RegistryPrefix, reference.Path(ref))
ref, err = reference.ParseNamed(r)
ExpectNoError(err, "failed to parse new image name: %v", err)
}
imageName = ref.String()

if !strings.Contains(imageName, ":") {
imageName = imageName + ":latest"
Logf("Use latest as default image tag.")
}
} else if err == reference.ErrNameNotCanonical {
// Non canonical images can simply be prefixed
imageName = fmt.Sprintf("%s/%s", TestContext.RegistryPrefix, imageName)
} else {
Failf("Unable to parse imageName: %v", err)
}

By("Pull image : " + imageName)
Expand Down
2 changes: 1 addition & 1 deletion pkg/validate/multi_container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (

const (
httpdContainerPort = 80
httpdImage = "httpd"
httpdImage = "docker.io/library/httpd"
)

var _ = framework.KubeDescribe("Multiple Containers [Conformance]", func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/validate/security_context_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
)

const (
nginxContainerImage string = "nginx"
nginxContainerImage string = "docker.io/library/nginx"
localhost string = "localhost/"
noNewPrivsImage string = "gcr.io/google_containers/nonewprivs:1.2"
)
Expand Down
1 change: 1 addition & 0 deletions vendor.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
github.com/Azure/go-ansiterm d6e3b3328b783f23731bc4d058875b0371ff8109
github.com/docker/docker a9fbbdc8dd8794b20af358382ab780559bca589d
github.com/docker/distribution v2.7.1
github.com/docker/go-units 9e638d38cf6977a37a8ea0078f3ee75a7cdb2dd1
github.com/docker/spdystream 449fdfce4d962303d702fec724ef0ad181c92528
github.com/fsnotify/fsnotify f12c6236fe7b5cf6bcf30e5935d08cb079d78334
Expand Down
202 changes: 202 additions & 0 deletions vendor/github.com/docker/distribution/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c43c4aa

Please sign in to comment.