From 1a8183d2620ce37299eda3eefd8f6715e8ea6b7a Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Fri, 21 Feb 2020 21:22:44 -0800 Subject: [PATCH] tests: Adds configurable docker conf for test The image "gcr.io/authenticated-image-pulling/windows-nanoserver:v1" is not a manifest list, and it is only useful for Windows Server 1809, which means that the test "should be able to pull from private registry with secret" will fail for environments with Windows Server 1903, 1909, or any other future version we might want to test. This commit adds the the ability to have an alternative private image to pull by using a configurable docker config file which contains the necessary credentials needed to pull the image. --- hack/ginkgo-e2e.sh | 1 + test/e2e/common/runtime.go | 8 +++++++- test/e2e/framework/test_context.go | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hack/ginkgo-e2e.sh b/hack/ginkgo-e2e.sh index a501cb850aa..b191cda0efd 100755 --- a/hack/ginkgo-e2e.sh +++ b/hack/ginkgo-e2e.sh @@ -169,6 +169,7 @@ export PATH --network="${KUBE_GCE_NETWORK:-${KUBE_GKE_NETWORK:-e2e}}" \ --node-tag="${NODE_TAG:-}" \ --master-tag="${MASTER_TAG:-}" \ + --docker-config-file="${DOCKER_CONFIG_FILE:-}" \ --dns-domain="${KUBE_DNS_DOMAIN:-cluster.local}" \ --ginkgo.slowSpecThreshold="${GINKGO_SLOW_SPEC_THRESHOLD:-300}" \ ${KUBE_CONTAINER_RUNTIME:+"--container-runtime=${KUBE_CONTAINER_RUNTIME}"} \ diff --git a/test/e2e/common/runtime.go b/test/e2e/common/runtime.go index 2c161a355c6..df5a01b717f 100644 --- a/test/e2e/common/runtime.go +++ b/test/e2e/common/runtime.go @@ -19,6 +19,7 @@ package common import ( "context" "fmt" + "io/ioutil" "path" "time" @@ -294,7 +295,12 @@ while true; do sleep 1; done } } }` - + // we might be told to use a different docker config JSON. + if framework.TestContext.DockerConfigFile != "" { + contents, err := ioutil.ReadFile(framework.TestContext.DockerConfigFile) + framework.ExpectNoError(err) + auth = string(contents) + } secret := &v1.Secret{ Data: map[string][]byte{v1.DockerConfigJsonKey: []byte(auth)}, Type: v1.SecretTypeDockerConfigJson, diff --git a/test/e2e/framework/test_context.go b/test/e2e/framework/test_context.go index 90dab94f955..496821f83c3 100644 --- a/test/e2e/framework/test_context.go +++ b/test/e2e/framework/test_context.go @@ -173,6 +173,9 @@ type TestContextType struct { // SpecSummaryOutput is the file to write ginkgo.SpecSummary objects to as tests complete. Useful for debugging and test introspection. SpecSummaryOutput string + + // DockerConfigFile is a file that contains credentials which can be used to pull images from certain private registries, needed for a test. + DockerConfigFile string } // NodeKillerConfig describes configuration of NodeKiller -- a utility to @@ -302,6 +305,7 @@ func RegisterCommonFlags(flags *flag.FlagSet) { flags.StringVar(&TestContext.ProgressReportURL, "progress-report-url", "", "The URL to POST progress updates to as the suite runs to assist in aiding integrations. If empty, no messages sent.") flags.StringVar(&TestContext.SpecSummaryOutput, "spec-dump", "", "The file to dump all ginkgo.SpecSummary to after tests run. If empty, no objects are saved/printed.") + flags.StringVar(&TestContext.DockerConfigFile, "docker-config-file", "", "A file that contains credentials which can be used to pull images from certain private registries, needed for a test.") } // RegisterClusterFlags registers flags specific to the cluster e2e test suite.