Repository: argoproj/argo
Pull request #3354 (2020-06-30 18:17:52)

test: Add e2e tags
Checklist:

* [x] Either (a) I've created an [enhancement proposal](https://github.com/argoproj/argo/issues/new/choose) and discussed it with the community, (b) this is a bug fix, or (c) this is a chore.
* [x] The title of the PR is (a) [conventional](https://www.conventionalcommits.org/en/v1.0.0/), (b) states what changed, and (c) suffixes the related issues number. E.g. `"fix(controller): Updates such and such. Fixes #1234"`.  
* [x] I've signed the CLA.
* [x] I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
* [ ] My builds are green. Try syncing with master if they are not. 
* [x] My organization is added to [USERS.md](https://github.com/argoproj/argo/blob/master/USERS.md).



Patch:
diff --git a/Makefile b/Makefile
index 15e622e19..101e12705 100644
--- a/Makefile
+++ b/Makefile
@@ -319,7 +319,7 @@ endif
 .PHONY: test
 test: server/static/files.go
 	@mkdir -p test-results
-	go test -v $(TEST_OPTS) `go list ./... | grep -v 'test/e2e'` 2>&1 | tee test-results/test.out
+	go test -v $(TEST_OPTS) ./... 2>&1 | tee test-results/test.out
 
 test-results/test-report.json: test-results/test.out
 	cat test-results/test.out | go tool test2json > test-results/test-report.json
@@ -430,30 +430,19 @@ mysql-cli:
 test-e2e: test-images cli
 	# Run E2E tests
 	@mkdir -p test-results
-	go test -timeout 15m -v -count 1 -p 1 --short ./test/e2e/... 2>&1 | tee test-results/test.out
+	go test -timeout 15m -v -count 1 --tags e2e -p 1 --short ./test/e2e 2>&1 | tee test-results/test.out
 
 .PHONY: test-e2e-cron
 test-e2e-cron: test-images cli
 	# Run E2E tests
 	@mkdir -p test-results
-	go test -timeout 5m -v -count 1 -parallel 10 -run CronSuite ./test/e2e 2>&1 | tee test-results/test.out
+	go test -timeout 5m -v -count 1 --tags e2e -parallel 10 -run CronSuite ./test/e2e 2>&1 | tee test-results/test.out
 
 .PHONY: smoke
 smoke: test-images
 	# Run smoke tests
 	@mkdir -p test-results
-	go test -timeout 1m -v -count 1 -p 1 -run SmokeSuite ./test/e2e 2>&1 | tee test-results/test.out
-
-.PHONY: test-api
-test-api:
-	# Run API tests
-	go test -timeout 1m -v -count 1 -p 1 -run ArgoServerSuite ./test/e2e
-
-.PHONY: test-cli
-test-cli: cli
-	# Run CLI tests
-	go test -timeout 2m -v -count 1 -p 1 -run CLISuite ./test/e2e
-	go test -timeout 2m -v -count 1 -p 1 -run CLIWithServerSuite ./test/e2e
+	go test -timeout 1m -v -count 1 --tags e2e -p 1 -run SmokeSuite ./test/e2e 2>&1 | tee test-results/test.out
 
 # clean
 
@@ -523,7 +512,7 @@ docs: swagger
 # pre-push
 
 .PHONY: pre-commit
-pre-commit: test lint codegen manifests start smoke test-api test-cli
+pre-commit: test lint codegen start
 
 # release - targets only available on release branch
 ifneq ($(findstring release,$(GIT_BRANCH)),)
diff --git a/workflow/controller/controller.go b/workflow/controller/controller.go
index 184dd5411..8a0d8ecb1 100644
--- a/workflow/controller/controller.go
+++ b/workflow/controller/controller.go
@@ -22,11 +22,8 @@ import (
 	"k8s.io/apimachinery/pkg/util/wait"
 	"k8s.io/apimachinery/pkg/watch"
 	"k8s.io/client-go/kubernetes"
-	"k8s.io/client-go/kubernetes/scheme"
-	typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
 	"k8s.io/client-go/rest"
 	"k8s.io/client-go/tools/cache"
-	"k8s.io/client-go/tools/record"
 	"k8s.io/client-go/util/workqueue"
 	"upper.io/db.v3/lib/sqlbuilder"
 
@@ -84,7 +81,7 @@ type WorkflowController struct {
 	hydrator              hydrator.Interface
 	wfArchive             sqldb.WorkflowArchive
 	metrics               metrics.Metrics
-	eventRecorder         record.EventRecorder
+	eventRecorderManager  EventRecorderManager
 	archiveLabelSelector  labels.Selector
 }
 
@@ -97,10 +94,6 @@ const (
 
 // NewWorkflowController instantiates a new WorkflowController
 func NewWorkflowController(restConfig *rest.Config, kubeclientset kubernetes.Interface, wfclientset wfclientset.Interface, namespace string, managedNamespace string, executorImage, executorImagePullPolicy, containerRuntimeExecutor, configMap string) *WorkflowController {
-	eventBroadcaster := record.NewBroadcaster()
-	eventBroadcaster.StartLogging(log.Debugf)
-	eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: kubeclientset.CoreV1().Events(namespace)})
-	eventRecorder := eventBroadcaster.NewRecorder(scheme.Scheme, apiv1.EventSource{Component: "workflow-controller"})
 	wfc := WorkflowController{
 		restConfig:                 restConfig,
 		kubeclientset:              kubeclientset,
@@ -115,7 +108,7 @@ func NewWorkflowController(restConfig *rest.Config, kubeclientset kubernetes.Int
 		configController:           config.NewController(namespace, configMap, kubeclientset),
 		completedPods:              make(chan string, 512),
 		gcPods:                     make(chan string, 512),
-		eventRecorder:              eventRecorder,
+		eventRecorderManager:       newEventRecorderManager(kubeclientset),
 	}
 	wfc.throttler = NewThrottler(0, wfc.wfQueue)
 	wfc.UpdateConfig()
diff --git a/workflow/controller/event_recorder_manager.go b/workflow/controller/event_recorder_manager.go
new file mode 100644
index 000000000..4988bb093
--- /dev/null
+++ b/workflow/controller/event_recorder_manager.go
@@ -0,0 +1,45 @@
+package controller
+
+import (
+	"sync"
+
+	log "github.com/sirupsen/logrus"
+	apiv1 "k8s.io/api/core/v1"
+	"k8s.io/client-go/kubernetes"
+	"k8s.io/client-go/kubernetes/scheme"
+	typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
+	"k8s.io/client-go/tools/record"
+)
+
+type EventRecorderManager interface {
+	Get(namespace string) record.EventRecorder
+}
+
+type eventRecorderManager struct {
+	kubernetes     kubernetes.Interface
+	lock           sync.Mutex
+	eventRecorders map[string]record.EventRecorder
+}
+
+func (m *eventRecorderManager) Get(namespace string) record.EventRecorder {
+	m.lock.Lock()
+	defer m.lock.Unlock()
+	eventRecorder, ok := m.eventRecorders[namespace]
+	if ok {
+		return eventRecorder
+	}
+	eventBroadcaster := record.NewBroadcaster()
+	eventBroadcaster.StartLogging(log.Debugf)
+	eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: m.kubernetes.CoreV1().Events(namespace)})
+	m.eventRecorders[namespace] = eventBroadcaster.NewRecorder(scheme.Scheme, apiv1.EventSource{Component: "workflow-controller"})
+	return m.eventRecorders[namespace]
+
+}
+
+func newEventRecorderManager(kubernetes kubernetes.Interface) EventRecorderManager {
+	return &eventRecorderManager{
+		kubernetes:     kubernetes,
+		lock:           sync.Mutex{},
+		eventRecorders: make(map[string]record.EventRecorder),
+	}
+}
diff --git a/workflow/controller/operator.go b/workflow/controller/operator.go
index db2d12cc2..c935bbd9b 100644
--- a/workflow/controller/operator.go
+++ b/workflow/controller/operator.go
@@ -131,7 +131,7 @@ func newWorkflowOperationCtx(wf *wfv1.Workflow, wfc *WorkflowController) *wfOper
 		completedPods:          make(map[string]bool),
 		succeededPods:          make(map[string]bool),
 		deadline:               time.Now().UTC().Add(maxOperationTime),
-		eventRecorder:          wfc.eventRecorder,
+		eventRecorder:          wfc.eventRecorderManager.Get(wf.Namespace),
 		preExecutionNodePhases: make(map[string]wfv1.NodePhase),
 	}
 


Test patch:
diff --git a/test/e2e/argo_server_test.go b/test/e2e/argo_server_test.go
index 16888e93b..53845847f 100644
--- a/test/e2e/argo_server_test.go
+++ b/test/e2e/argo_server_test.go
@@ -1,3 +1,5 @@
+// +build e2e
+
 package e2e
 
 import (
diff --git a/test/e2e/cli_test.go b/test/e2e/cli_test.go
index 1a7790007..98decdbc7 100644
--- a/test/e2e/cli_test.go
+++ b/test/e2e/cli_test.go
@@ -1,3 +1,5 @@
+// +build e2e
+
 package e2e
 
 import (
diff --git a/test/e2e/cli_with_server_test.go b/test/e2e/cli_with_server_test.go
index 941863d51..5e5c34fc0 100644
--- a/test/e2e/cli_with_server_test.go
+++ b/test/e2e/cli_with_server_test.go
@@ -1,3 +1,5 @@
+// +build e2e
+
 package e2e
 
 import (
diff --git a/test/e2e/cluster_workflow_template_test.go b/test/e2e/cluster_workflow_template_test.go
index 56c8fa434..5122b9e43 100644
--- a/test/e2e/cluster_workflow_template_test.go
+++ b/test/e2e/cluster_workflow_template_test.go
@@ -1,3 +1,5 @@
+// +build e2e
+
 package e2e
 
 import (
diff --git a/test/e2e/cron_test.go b/test/e2e/cron_test.go
index 8fa794813..dce1d1daa 100644
--- a/test/e2e/cron_test.go
+++ b/test/e2e/cron_test.go
@@ -1,3 +1,5 @@
+// +build e2e
+
 package e2e
 
 import (
diff --git a/test/e2e/functional_test.go b/test/e2e/functional_test.go
index e09f13764..31f74b049 100644
--- a/test/e2e/functional_test.go
+++ b/test/e2e/functional_test.go
@@ -1,3 +1,5 @@
+// +build e2e
+
 package e2e
 
 import (
diff --git a/test/e2e/metrics_test.go b/test/e2e/metrics_test.go
index d4491a81b..26300b57e 100644
--- a/test/e2e/metrics_test.go
+++ b/test/e2e/metrics_test.go
@@ -1,3 +1,5 @@
+// +build e2e
+
 package e2e
 
 import (
diff --git a/test/e2e/smoke_test.go b/test/e2e/smoke_test.go
index 774caa98e..04670e269 100644
--- a/test/e2e/smoke_test.go
+++ b/test/e2e/smoke_test.go
@@ -1,3 +1,5 @@
+// +build e2e
+
 package e2e
 
 import (
diff --git a/test/e2e/workflow_template_test.go b/test/e2e/workflow_template_test.go
index 0277e6bc3..e22a004f5 100644
--- a/test/e2e/workflow_template_test.go
+++ b/test/e2e/workflow_template_test.go
@@ -1,3 +1,5 @@
+// +build e2e
+
 package e2e
 
 import (
diff --git a/workflow/controller/controller_test.go b/workflow/controller/controller_test.go
index b85bc1405..171a2d065 100644
--- a/workflow/controller/controller_test.go
+++ b/workflow/controller/controller_test.go
@@ -6,6 +6,7 @@ import (
 	"time"
 
 	"k8s.io/apimachinery/pkg/labels"
+	"k8s.io/client-go/tools/record"
 
 	"github.com/stretchr/testify/assert"
 	authorizationv1 "k8s.io/api/authorization/v1"
@@ -16,7 +17,6 @@ import (
 	"k8s.io/client-go/kubernetes/fake"
 	k8stesting "k8s.io/client-go/testing"
 	"k8s.io/client-go/tools/cache"
-	"k8s.io/client-go/tools/record"
 	"k8s.io/client-go/util/workqueue"
 	"sigs.k8s.io/yaml"
 
@@ -102,6 +102,16 @@ spec:
       args: ["hello world"]
 `
 
+type testEventRecorderManager struct {
+	eventRecorder *record.FakeRecorder
+}
+
+func (t testEventRecorderManager) Get(string) record.EventRecorder {
+	return t.eventRecorder
+}
+
+var _ EventRecorderManager = &testEventRecorderManager{}
+
 func newController(objects ...runtime.Object) (context.CancelFunc, *WorkflowController) {
 	wfclientset := fakewfclientset.NewSimpleClientset(objects...)
 	informerFactory := wfextv.NewSharedInformerFactory(wfclientset, 10*time.Minute)
@@ -133,7 +143,7 @@ func newController(objects ...runtime.Object) (context.CancelFunc, *WorkflowCont
 		wfArchive:            sqldb.NullWorkflowArchive,
 		hydrator:             hydratorfake.Noop,
 		metrics:              metrics.New(metrics.ServerConfig{}, metrics.ServerConfig{}),
-		eventRecorder:        record.NewFakeRecorder(16),
+		eventRecorderManager: &testEventRecorderManager{eventRecorder: record.NewFakeRecorder(16)},
 		archiveLabelSelector: labels.Everything(),
 	}
 	return cancel, controller
diff --git a/workflow/controller/operator_test.go b/workflow/controller/operator_test.go
index 349821c26..71ea4d4c0 100644
--- a/workflow/controller/operator_test.go
+++ b/workflow/controller/operator_test.go
@@ -13,7 +13,6 @@ import (
 	apiv1 "k8s.io/api/core/v1"
 	"k8s.io/apimachinery/pkg/api/resource"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
-	"k8s.io/client-go/tools/record"
 	"sigs.k8s.io/yaml"
 
 	"github.com/argoproj/argo/config"
@@ -2736,7 +2735,7 @@ func TestEventInvalidSpec(t *testing.T) {
 }
 
 func getEvents(controller *WorkflowController, num int) []string {
-	c := controller.eventRecorder.(*record.FakeRecorder).Events
+	c := controller.eventRecorderManager.(*testEventRecorderManager).eventRecorder.Events
 	events := make([]string, num)
 	for i := 0; i < num; i++ {
 		events[i] = <-c