1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

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 <fromani@redhat.com>
This commit is contained in:
Francesco Romani 2020-12-01 19:10:38 +01:00
parent b78f65e9ee
commit 622adf3863
3 changed files with 22 additions and 4 deletions

View file

@ -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:

View file

@ -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

View file

@ -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
}