Skip to content

Commit

Permalink
Makefile: add env var controls to make test targets configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
  • Loading branch information
ArangoGutierrez committed Dec 7, 2023
1 parent bdfef6d commit 0188ffd
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 deletions.
24 changes: 15 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ HOSTMOUNT_PREFIX ?= /
KUBECONFIG ?= ${HOME}/.kube/config
E2E_TEST_CONFIG ?=
E2E_PULL_IF_NOT_PRESENT ?= false
E2E_TEST_FULL_IMAGE ?= false
E2E_GINKGO_LABEL_FILTER ?= "e2e-test"

BUILD_FLAGS = -tags osusergo,netgo \
-ldflags "-s -w -extldflags=-static -X sigs.k8s.io/node-feature-discovery/pkg/version.version=$(VERSION) -X sigs.k8s.io/node-feature-discovery/pkg/utils/hostpath.pathPrefix=$(HOSTMOUNT_PREFIX)"

TEST_FLAGS = -covermode=atomic -coverprofile=coverage.out

# multi-arch build with buildx
IMAGE_ALL_PLATFORMS ?= linux/amd64,linux/arm64

Expand Down Expand Up @@ -183,24 +187,26 @@ helm-lint:
helm lint --strict deployment/helm/node-feature-discovery/

test:
$(GO_CMD) test -covermode=atomic -coverprofile=coverage.out ./cmd/... ./pkg/... ./source/...
$(GO_CMD) test $(TEST_FLAGS) ./cmd/... ./pkg/... ./source/...

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) \
-nfd.pull-if-not-present=$(E2E_PULL_IF_NOT_PRESENT) \
-ginkgo.focus="\[kubernetes-sigs\]" \
-test.timeout=1h \
$(if $(OPENSHIFT),-nfd.openshift,)
$(GO_CMD) test -v ./test/e2e/ -args -nfd.repo=$(IMAGE_REPO) -nfd.tag=$(IMAGE_TAG_NAME)-full \
-kubeconfig=$(KUBECONFIG) \
-nfd.e2e-config=$(E2E_TEST_CONFIG) \
-nfd.pull-if-not-present=$(E2E_PULL_IF_NOT_PRESENT) \
-ginkgo.focus="\[kubernetes-sigs\]" \
-ginkgo.label-filter=$(E2E_GINKGO_LABEL_FILTER) \
-test.timeout=1h \
$(if $(OPENSHIFT),-nfd.openshift,)
@if [ "$(RUN_FULL_E2E)" = "true" ]; then \
$(GO_CMD) test -v ./test/e2e/ -args -nfd.repo=$(IMAGE_REPO) -nfd.tag=$(IMAGE_TAG_NAME)-full \
-kubeconfig=$(KUBECONFIG) \
-nfd.e2e-config=$(E2E_TEST_CONFIG) \
-nfd.pull-if-not-present=$(E2E_PULL_IF_NOT_PRESENT) \
-ginkgo.label-filter=$(E2E_GINKGO_LABEL_FILTER) \
-test.timeout=1h \
$(if $(OPENSHIFT),-nfd.openshift,)
fi

push:
$(IMAGE_PUSH_CMD) $(IMAGE_TAG)
Expand Down
7 changes: 3 additions & 4 deletions test/e2e/framework.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 The Kubernetes Authors.
Copyright 2023 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,6 @@ package e2e

import "github.com/onsi/ginkgo/v2"

// SIGDescribe annotates the test with the SIG label.
func SIGDescribe(text string, body func()) bool {
return ginkgo.Describe("[kubernetes-sigs] "+text, body)
func NFDDescribe(args ...interface{}) bool {
return ginkgo.Describe("[k8s-sigs/node-feature-discovery]", args...)
}
6 changes: 3 additions & 3 deletions test/e2e/nfd_gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
)

// Actual test suite
var _ = SIGDescribe("NFD GC", func() {
var _ = NFDDescribe(Label("e2e-test", "nfd-gc"), func() {
f := framework.NewDefaultFramework("nfd-gc")

Context("when deploying nfd-gc", Ordered, func() {
Expand Down Expand Up @@ -117,7 +117,7 @@ var _ = SIGDescribe("NFD GC", func() {
// Test GC at startup
//
Context("with pre-existing NodeFeature and NodeResourceTopology objects", func() {
It("it should delete stale objects at startup", func(ctx context.Context) {
It("it should delete stale objects at startup", Label("gc-startup"), func(ctx context.Context) {
nodes, err := f.ClientSet.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
Expect(err).NotTo(HaveOccurred())
targetNodeNames := []string{nodes.Items[0].GetName()}
Expand Down Expand Up @@ -153,7 +153,7 @@ var _ = SIGDescribe("NFD GC", func() {
// Test periodic GC
//
Context("with stale NodeFeature and NodeResourceTopology objects appearing", func() {
It("it should remove stale objects", func(ctx context.Context) {
It("it should remove stale objects", Label("gc-periodic"), func(ctx context.Context) {
nodes, err := f.ClientSet.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
Expect(err).NotTo(HaveOccurred())
targetNodeNames := []string{nodes.Items[0].GetName()}
Expand Down
18 changes: 9 additions & 9 deletions test/e2e/node_feature_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func cleanupCRs(ctx context.Context, cli *nfdclient.Clientset, namespace string)
}

// Actual test suite
var _ = SIGDescribe("NFD master and worker", func() {
var _ = NFDDescribe(Label("e2e-test", "master-and-worker"), func() {
f := framework.NewDefaultFramework("node-feature-discovery")

nfdTestSuite := func(useNodeFeatureApi bool) {
Expand Down Expand Up @@ -272,7 +272,7 @@ var _ = SIGDescribe("NFD master and worker", func() {
// Simple test with only the fake source enabled
//
Context("and a single worker pod with fake source enabled", func() {
It("it should decorate the node with the fake feature labels", func(ctx context.Context) {
It("it should decorate the node with the fake feature labels", Label("nfd-worker"), func(ctx context.Context) {
nodes, err := getNonControlPlaneNodes(ctx, f.ClientSet)
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -315,7 +315,7 @@ var _ = SIGDescribe("NFD master and worker", func() {
// More comprehensive test when --e2e-node-config is enabled
//
Context("and nfd-workers as a daemonset with default sources enabled", func() {
It("the node labels and annotations listed in the e2e config should be present", func(ctx context.Context) {
It("the node labels and annotations listed in the e2e config should be present", Label("nfd-worker"), func(ctx context.Context) {
cfg, err := testutils.GetConfig()
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -407,7 +407,7 @@ var _ = SIGDescribe("NFD master and worker", func() {
// Test custom nodename source configured in 2 additional ConfigMaps
//
Context("and nfd-workers as a daemonset with 2 additional configmaps for the custom source configured", func() {
It("the nodename matching features listed in the configmaps should be present", func(ctx context.Context) {
It("the nodename matching features listed in the configmaps should be present", Label("nfd-worker"), func(ctx context.Context) {
By("Getting a worker node")

// We need a valid nodename for the configmap
Expand Down Expand Up @@ -496,7 +496,7 @@ var _ = SIGDescribe("NFD master and worker", func() {
//
// Test NodeFeature
//
Context("and NodeFeature objects deployed", func() {
Context("and NodeFeature objects deployed", Label("nfd-worker"), func() {
BeforeEach(func(ctx context.Context) {
extraMasterPodSpecOpts = []testpod.SpecOption{
testpod.SpecWithContainerExtraArgs(
Expand All @@ -505,7 +505,7 @@ var _ = SIGDescribe("NFD master and worker", func() {
),
}
})
It("labels from the NodeFeature objects should be created", func(ctx context.Context) {
It("labels from the NodeFeature objects should be created", Label("nfd-worker"), func(ctx context.Context) {
if !useNodeFeatureApi {
Skip("NodeFeature API not enabled")
}
Expand Down Expand Up @@ -664,7 +664,7 @@ var _ = SIGDescribe("NFD master and worker", func() {
testpod.SpecWithTolerations(testTolerations),
}
})
It("custom features from the NodeFeatureRule rules should be created", func(ctx context.Context) {
It("custom features from the NodeFeatureRule rules should be created", Label("nfd-worker"), func(ctx context.Context) {
nodes, err := getNonControlPlaneNodes(ctx, f.ClientSet)
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -850,7 +850,7 @@ denyLabelNs: ["*.denied.ns","random.unwanted.ns"]
_, err := f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(ctx, cm, metav1.CreateOptions{})
Expect(err).NotTo(HaveOccurred())
})
It("master configuration should take place", func(ctx context.Context) {
It("master configuration should take place", Label("nfd-master"), func(ctx context.Context) {
// deploy node feature object
if !useNodeFeatureApi {
Skip("NodeFeature API not enabled")
Expand Down Expand Up @@ -911,7 +911,7 @@ resyncPeriod: "1s"
_, err := f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(ctx, cm, metav1.CreateOptions{})
Expect(err).NotTo(HaveOccurred())
})
It("labels should be restored to the original ones", func(ctx context.Context) {
It("labels should be restored to the original ones", Label("nfd-master"), func(ctx context.Context) {
// deploy node feature object
if !useNodeFeatureApi {
Skip("NodeFeature API not enabled")
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/topology_updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import (
testpod "sigs.k8s.io/node-feature-discovery/test/e2e/utils/pod"
)

var _ = SIGDescribe("NFD topology updater", func() {
var _ = NFDDescribe(Label("e2e-test", "nfd-topology-updater"), func() {
var (
extClient *extclient.Clientset
topologyClient *topologyclientset.Clientset
Expand Down

0 comments on commit 0188ffd

Please sign in to comment.