Skip to content

Commit

Permalink
fix(events): Adds config flag. Reduce number of dupe events emitted. (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec authored Jun 16, 2020
1 parent eae8f68 commit ff1627b
Show file tree
Hide file tree
Showing 19 changed files with 167 additions and 318 deletions.
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ type Config struct {
// SSO in settings for single-sign on
SSO sso.Config `json:"sso,omitempty"`

// NodeEvents configures how node events are omitted
NodeEvents NodeEvents `json:"nodeEvents,omitempty"`

// ExecutorImage is the image name of the executor to use when running pods
// DEPRECATED: use --executor-image flag to workflow-controller instead
ExecutorImage string `json:"executorImage,omitempty"`
Expand Down
9 changes: 9 additions & 0 deletions config/node_events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package config

type NodeEvents struct {
Enabled *bool `json:"enabled,omitempty"`
}

func (e NodeEvents) IsEnabled() bool {
return e.Enabled == nil || *e.Enabled
}
14 changes: 14 additions & 0 deletions config/node_events_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package config

import (
"testing"

"github.com/stretchr/testify/assert"
"k8s.io/utils/pointer"
)

func TestNodeEvents_IsEnabled(t *testing.T) {
assert.True(t, NodeEvents{}.IsEnabled())
assert.False(t, NodeEvents{Enabled: pointer.BoolPtr(false)}.IsEnabled())
assert.True(t, NodeEvents{Enabled: pointer.BoolPtr(true)}.IsEnabled())
}
8 changes: 8 additions & 0 deletions docs/workflow-controller-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ data:
# (available since Argo v2.3)
parallelism: 10
# Whether or not to emit events on node completion. These can take a up a lot of space in
# k8s (typically etcd) resulting in errors when trying to create new events:
# "Unable to create audit event: etcdserver: mvcc: database space exceeded"
# This config item allows you to disable this.
# (since v2.9)
nodeEvents:
enabled: true
# uncomment flowing lines if workflow controller runs in a different k8s cluster with the
# workflow workloads, or needs to communicate with the k8s apiserver using an out-of-cluster
# kubeconfig secret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ rules:
- events
verbs:
- create
- patch
- apiGroups:
- "policy"
resources:
Expand Down
1 change: 1 addition & 0 deletions manifests/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ rules:
- events
verbs:
- create
- patch
- apiGroups:
- policy
resources:
Expand Down
1 change: 1 addition & 0 deletions manifests/namespace-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ rules:
- events
verbs:
- create
- patch
- apiGroups:
- policy
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ rules:
- events
verbs:
- create
- patch
- apiGroups:
- "policy"
resources:
Expand Down
1 change: 1 addition & 0 deletions manifests/quick-start-minimal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ rules:
- events
verbs:
- create
- patch
- apiGroups:
- policy
resources:
Expand Down
1 change: 1 addition & 0 deletions manifests/quick-start-mysql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ rules:
- events
verbs:
- create
- patch
- apiGroups:
- policy
resources:
Expand Down
1 change: 1 addition & 0 deletions manifests/quick-start-postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ rules:
- events
verbs:
- create
- patch
- apiGroups:
- policy
resources:
Expand Down
44 changes: 21 additions & 23 deletions test/e2e/fixtures/then.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package fixtures

import (
"testing"
"time"

log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -85,36 +85,34 @@ func (t *Then) ExpectWorkflowList(listOptions metav1.ListOptions, block func(t *
return t
}

func (t *Then) expectAuditEvents(block func(*testing.T, []apiv1.Event)) *Then {
eventList, err := t.kubeClient.CoreV1().Events(Namespace).List(metav1.ListOptions{})
func (t *Then) ExpectAuditEvents(blocks ...func(*testing.T, apiv1.Event)) *Then {
eventList, err := t.kubeClient.CoreV1().Events(Namespace).Watch(metav1.ListOptions{})
if err != nil {
t.t.Fatal(err)
}
var events []apiv1.Event
for _, e := range eventList.Items {
if e.Namespace == Namespace && e.InvolvedObject.Kind == workflow.WorkflowKind {
events = append(events, e)
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
for len(blocks) > 0 {
select {
case <-ticker.C:
t.t.Fatal("timeout waiting for events")
case event := <-eventList.ResultChan():
e, ok := event.Object.(*apiv1.Event)
if !ok {
t.t.Fatal("event is not an event")
}
if e.InvolvedObject.Name == t.workflowName && e.Namespace == Namespace && e.InvolvedObject.Kind == workflow.WorkflowKind {
blocks[0](t.t, *e)
blocks = blocks[1:]
if t.t.Failed() {
t.t.FailNow()
}
}
}
}
log.WithFields(log.Fields{"event": events}).Debug("Events")
block(t.t, events)
if t.t.Failed() {
t.t.FailNow()
}
return t
}

func (t *Then) ExpectAuditEvent(f func(apiv1.Event) bool) *Then {
return t.expectAuditEvents(func(t *testing.T, events []apiv1.Event) {
for _, item := range events {
if f(item) {
return
}
}
assert.Fail(t, "did not see expected event")
})
}

func (t *Then) RunCli(args []string, block func(t *testing.T, output string, err error)) *Then {
output, err := runCli("../../dist/argo", append([]string{"-n", Namespace}, args...)...)
block(t.t, output, err)
Expand Down
77 changes: 42 additions & 35 deletions test/e2e/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package e2e

import (
"regexp"
"strings"
"testing"
"time"

Expand All @@ -11,10 +10,8 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/argoproj/argo/pkg/apis/workflow"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo/test/e2e/fixtures"
"github.com/argoproj/argo/util/argo"
)

type FunctionalSuite struct {
Expand Down Expand Up @@ -187,20 +184,23 @@ func (s *FunctionalSuite) TestEventOnNodeFail() {
Workflow("@expectedfailures/failed-step-event.yaml").
When().
SubmitWorkflow().
WaitForWorkflow(30 * time.Second).
WaitForWorkflow(30*time.Second).
Then().
ExpectAuditEvent(func(e corev1.Event) bool {
return strings.HasPrefix(e.InvolvedObject.Name, "failed-step-event-") &&
e.Reason == argo.EventReasonWorkflowFailed &&
e.Message == "failed with exit code 1"
}).
ExpectAuditEvent(func(e corev1.Event) bool {
return e.InvolvedObject.Kind == workflow.WorkflowKind &&
e.Reason == argo.EventReasonWorkflowNodeFailed &&
strings.HasPrefix(e.Message, "Failed node failed-step-event-") &&
e.Annotations["workflows.argoproj.io/node-type"] == "Pod" &&
strings.Contains(e.Annotations["workflows.argoproj.io/node-name"], "failed-step-event-")
})
ExpectAuditEvents(
func(t *testing.T, e corev1.Event) {
assert.Equal(t, "WorkflowRunning", e.Reason)
},
func(t *testing.T, e corev1.Event) {
assert.Equal(t, e.Reason, "WorkflowNodeFailed")
assert.Contains(t, e.Message, "Failed node failed-step-event-")
assert.Equal(t, e.Annotations["workflows.argoproj.io/node-type"], "Pod")
assert.Contains(t, e.Annotations["workflows.argoproj.io/node-name"], "failed-step-event-")
},
func(t *testing.T, e corev1.Event) {
assert.Equal(t, "WorkflowFailed", e.Reason)
assert.Equal(t, "failed with exit code 1", e.Message)
},
)
}

func (s *FunctionalSuite) TestEventOnWorkflowSuccess() {
Expand All @@ -209,20 +209,23 @@ func (s *FunctionalSuite) TestEventOnWorkflowSuccess() {
Workflow("@functional/success-event.yaml").
When().
SubmitWorkflow().
WaitForWorkflow(60 * time.Second).
WaitForWorkflow(60*time.Second).
Then().
ExpectAuditEvent(func(e corev1.Event) bool {
return strings.HasPrefix(e.InvolvedObject.Name, "success-event-") &&
e.Reason == argo.EventReasonWorkflowSucceeded &&
e.Message == "Workflow completed"
}).
ExpectAuditEvent(func(e corev1.Event) bool {
return e.InvolvedObject.Kind == workflow.WorkflowKind &&
e.Reason == argo.EventReasonWorkflowNodeSucceeded &&
strings.HasPrefix(e.Message, "Succeeded node success-event-") &&
e.Annotations["workflows.argoproj.io/node-type"] == "Pod" &&
strings.Contains(e.Annotations["workflows.argoproj.io/node-name"], "success-event-")
})
ExpectAuditEvents(
func(t *testing.T, e corev1.Event) {
assert.Equal(t, "WorkflowRunning", e.Reason)
},
func(t *testing.T, e corev1.Event) {
assert.Equal(t, "WorkflowNodeSucceeded", e.Reason)
assert.Contains(t, e.Message, "Succeeded node success-event-")
assert.Equal(t, "Pod", e.Annotations["workflows.argoproj.io/node-type"])
assert.Contains(t, e.Annotations["workflows.argoproj.io/node-name"], "success-event-")
},
func(t *testing.T, e corev1.Event) {
assert.Equal(t, "WorkflowSucceeded", e.Reason)
assert.Equal(t, "Workflow completed", e.Message)
},
)
}

func (s *FunctionalSuite) TestEventOnPVCFail() {
Expand All @@ -231,13 +234,17 @@ func (s *FunctionalSuite) TestEventOnPVCFail() {
Workflow("@expectedfailures/volumes-pvc-fail-event.yaml").
When().
SubmitWorkflow().
WaitForWorkflow(120 * time.Second).
WaitForWorkflow(120*time.Second).
Then().
ExpectAuditEvent(func(e corev1.Event) bool {
return strings.HasPrefix(e.InvolvedObject.Name, "volumes-pvc-fail-event-") &&
e.Reason == argo.EventReasonWorkflowFailed &&
strings.Contains(e.Message, "pvc create error")
})
ExpectAuditEvents(
func(t *testing.T, e corev1.Event) {
assert.Equal(t, "WorkflowRunning", e.Reason)
},
func(t *testing.T, e corev1.Event) {
assert.Equal(t, "WorkflowFailed", e.Reason)
assert.Contains(t, e.Message, "pvc create error")
},
)
}

func (s *FunctionalSuite) TestArtifactRepositoryRef() {
Expand Down
Loading

0 comments on commit ff1627b

Please sign in to comment.