diff --git a/Makefile b/Makefile index fa6baa2..b0f6ac9 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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="./..." diff --git a/README.md b/README.md index 1e325c4..79aa57f 100644 --- a/README.md +++ b/README.md @@ -66,5 +66,5 @@ spec: path: - Type - name: some-static-value - value: "static value" + value: "" ``` diff --git a/controllers/logging/event_controller.go b/controllers/logging/event_controller.go index d794ac2..264e322 100644 --- a/controllers/logging/event_controller.go +++ b/controllers/logging/event_controller.go @@ -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" @@ -120,7 +119,7 @@ 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 @@ -128,7 +127,7 @@ 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 @@ -136,10 +135,10 @@ 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 } @@ -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) - } diff --git a/controllers/logging/event_controller_test.go b/controllers/logging/event_controller_test.go index d2062b8..b4fdf7c 100644 --- a/controllers/logging/event_controller_test.go +++ b/controllers/logging/event_controller_test.go @@ -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) { @@ -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", }, @@ -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", }, @@ -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", diff --git a/go.sum b/go.sum index c9c4d2f..455c88b 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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=