Skip to content

Commit

Permalink
backport
Browse files Browse the repository at this point in the history
  • Loading branch information
bakito committed Jan 28, 2021
1 parent 45c7654 commit abf8ab6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ endif
all: manager

# Run tests
test: generate fmt vet manifests
test: generate tidy fmt vet manifests
go test ./... -coverprofile cover.out

# Build manager binary
Expand Down Expand Up @@ -52,6 +52,11 @@ fmt:
vet:
go vet ./...

# go mod tidy
tidy:
go mod tidy


# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ spec:
path:
- Type
- name: some-static-value
value: "static value"
value: ""
```
10 changes: 4 additions & 6 deletions controllers/logging/event_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -120,26 +119,26 @@ func (p loggingPredicate) Create(e event.CreateEvent) bool {
if _, ok := e.Object.(*eventloggerv1.EventLogger); ok {
return p.Config.matches(e.Meta)
}
return p.logEvent(e.Meta, e.Object)
return p.logEvent(e.Object)
}

// Update implements Predicate
func (p loggingPredicate) Update(e event.UpdateEvent) bool {
if _, ok := e.ObjectOld.(*eventloggerv1.EventLogger); ok {
return p.Config.matches(e.MetaNew)
}
return p.logEvent(e.MetaNew, e.ObjectNew)
return p.logEvent(e.ObjectNew)
}

// Delete implements Predicate
func (p loggingPredicate) Delete(e event.DeleteEvent) bool {
if _, ok := e.Object.(*eventloggerv1.EventLogger); ok {
return p.Config.matches(e.Meta)
}
return p.logEvent(e.Meta, e.Object)
return false
}

func (p loggingPredicate) logEvent(_ metav1.Object, e runtime.Object) bool {
func (p loggingPredicate) logEvent(e runtime.Object) bool {
if p.Config == nil || p.Config.filter == nil {
return false
}
Expand Down Expand Up @@ -256,5 +255,4 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager, namespace string) error
Watches(&source.Kind{Type: &corev1.Event{}}, &handler.Funcs{}).
WithEventFilter(&loggingPredicate{Config: r.Config, lastVersion: lv}).
Complete(r)

}
8 changes: 4 additions & 4 deletions controllers/logging/event_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func Test_logEvent_no_filter(t *testing.T) {
mock.EXPECT().WithValues().Times(0)

lp := &loggingPredicate{}
lp.logEvent(&metav1.ObjectMeta{Namespace: testNamespace}, &corev1.Event{})
lp.logEvent(&corev1.Event{})
}

func Test_logEvent_wrong_resource_version(t *testing.T) {
Expand All @@ -176,7 +176,7 @@ func Test_logEvent_wrong_resource_version(t *testing.T) {
lastVersion: "2",
}

lp.logEvent(&metav1.ObjectMeta{Namespace: testNamespace}, &corev1.Event{
lp.logEvent(&corev1.Event{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "1",
},
Expand All @@ -198,7 +198,7 @@ func Test_logEvent_true(t *testing.T) {
Config: &Config{filter: &Filter{}},
}

lp.logEvent(&metav1.ObjectMeta{Namespace: testNamespace}, &corev1.Event{
lp.logEvent(&corev1.Event{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "3",
},
Expand Down Expand Up @@ -229,7 +229,7 @@ func Test_logEvent_true_custom_fields(t *testing.T) {
},
}

lp.logEvent(&metav1.ObjectMeta{Namespace: testNamespace}, &corev1.Event{
lp.logEvent(&corev1.Event{
ObjectMeta: metav1.ObjectMeta{
ResourceVersion: "3",
Name: "test-event-name",
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5I
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.9.0+incompatible h1:kLcOMZeuLAJvL2BPWLMIj5oaZQobrkAqrL+WFZwQses=
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
Expand Down Expand Up @@ -259,6 +260,7 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
Expand Down

0 comments on commit abf8ab6

Please sign in to comment.