From 622adf38635d2c4cf33800583ebf7d8c805dd2a9 Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Tue, 1 Dec 2020 19:10:38 +0100 Subject: [PATCH] test: e2e: configurable pull policy In some cases (CI) it is useful to run NFD e2e tests using ephemeral clusters. To save time and bandwidth, it is also useful to prime the ephemeral cluster with the images under test. In these circumstances there is no risk of running a stale image, and having a `Always` PullPolicy hardcoded actually makes the whole exercise null. So we add a new option, disabled by default, to make the e2e manifest use the `IfNotPresent` pull policy, to effectively cover this use case. Signed-off-by: Francesco Romani --- Makefile | 11 +++++++++-- docs/advanced/developer-guide.md | 1 + test/e2e/utils/pod.go | 14 ++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 4f8562e39..5349f92e0 100644 --- a/Makefile +++ b/Makefile @@ -55,6 +55,7 @@ HOSTMOUNT_PREFIX ?= / KUBECONFIG ?= E2E_TEST_CONFIG ?= +E2E_PULL_IF_NOT_PRESENT ?= false LDFLAGS = -ldflags "-s -w -X sigs.k8s.io/node-feature-discovery/pkg/version.version=$(VERSION) -X sigs.k8s.io/node-feature-discovery/source.pathPrefix=$(HOSTMOUNT_PREFIX)" @@ -167,10 +168,16 @@ test: e2e-test: @if [ -z ${KUBECONFIG} ]; then echo "[ERR] KUBECONFIG missing, must be defined"; exit 1; fi $(GO_CMD) test -v ./test/e2e/ -args -nfd.repo=$(IMAGE_REPO) -nfd.tag=$(IMAGE_TAG_NAME) \ - -kubeconfig=$(KUBECONFIG) -nfd.e2e-config=$(E2E_TEST_CONFIG) -ginkgo.focus="\[kubernetes-sigs\]" \ + -kubeconfig=$(KUBECONFIG) \ + -nfd.e2e-config=$(E2E_TEST_CONFIG) \ + -nfd.pull-if-not-present=$(E2E_PULL_IF_NOT_PRESENT) \ + -ginkgo.focus="\[kubernetes-sigs\]" \ $(if $(OPENSHIFT),-nfd.openshift,) $(GO_CMD) test -v ./test/e2e/ -args -nfd.repo=$(IMAGE_REPO) -nfd.tag=$(IMAGE_TAG_NAME)-minimal \ - -kubeconfig=$(KUBECONFIG) -nfd.e2e-config=$(E2E_TEST_CONFIG) -ginkgo.focus="\[kubernetes-sigs\]" \ + -kubeconfig=$(KUBECONFIG) \ + -nfd.e2e-config=$(E2E_TEST_CONFIG) \ + -nfd.pull-if-not-present=$(E2E_PULL_IF_NOT_PRESENT) \ + -ginkgo.focus="\[kubernetes-sigs\]" \ $(if $(OPENSHIFT),-nfd.openshift,) push: diff --git a/docs/advanced/developer-guide.md b/docs/advanced/developer-guide.md index d320d06c6..b154e552b 100644 --- a/docs/advanced/developer-guide.md +++ b/docs/advanced/developer-guide.md @@ -124,6 +124,7 @@ makefile overrides. | K8S_NAMESPACE | nfd-master and nfd-worker namespace | node-feature-discovery | KUBECONFIG | Kubeconfig for running e2e-tests | *empty* | E2E_TEST_CONFIG | Parameterization file of e2e-tests (see [example][e2e-config-sample]) | *empty* +| E2E_PULL_IF_NOT_PRESENT | True-ish value makes the image pull policy IfNotPresent (to be used only in e2e tests) | false | OPENSHIFT | Non-empty value enables OpenShift specific support (currently only effective in e2e tests) | *empty* | BASE_IMAGE_FULL | Container base image for target image full (--target full) | debian:buster-slim | BASE_IMAGE_MINIMAL | Container base image for target image minimal (--target minimal) | gcr.io/distroless/base diff --git a/test/e2e/utils/pod.go b/test/e2e/utils/pod.go index bab9914c9..599f68a62 100644 --- a/test/e2e/utils/pod.go +++ b/test/e2e/utils/pod.go @@ -18,6 +18,7 @@ package utils import ( "context" + "flag" "time" appsv1 "k8s.io/api/apps/v1" @@ -30,6 +31,8 @@ import ( "k8s.io/kubectl/pkg/util/podutils" ) +var pullIfNotPresent = flag.Bool("nfd.pull-if-not-present", false, "Pull Images if not present - not always") + // NFDMasterPod provide NFD master pod definition func NFDMasterPod(image string, onMasterNode bool) *v1.Pod { p := &v1.Pod{ @@ -42,7 +45,7 @@ func NFDMasterPod(image string, onMasterNode bool) *v1.Pod { { Name: "node-feature-discovery", Image: image, - ImagePullPolicy: v1.PullAlways, + ImagePullPolicy: pullPolicy(), Command: []string{"nfd-master"}, Env: []v1.EnvVar{ { @@ -121,7 +124,7 @@ func nfdWorkerPodSpec(image string, extraArgs []string) *v1.PodSpec { { Name: "node-feature-discovery", Image: image, - ImagePullPolicy: v1.PullAlways, + ImagePullPolicy: pullPolicy(), Command: []string{"nfd-worker"}, Args: append([]string{"-server=nfd-master-e2e:8080"}, extraArgs...), Env: []v1.EnvVar{ @@ -242,3 +245,10 @@ func WaitForPodsReady(c clientset.Interface, ns, name string, minReadySeconds in return true, nil }) } + +func pullPolicy() v1.PullPolicy { + if *pullIfNotPresent { + return v1.PullIfNotPresent + } + return v1.PullAlways +}