From 258cc6071d9ef1357197a5ed26724f74c04b9813 Mon Sep 17 00:00:00 2001 From: Rafael Franzke Date: Wed, 20 Jul 2022 13:10:42 +0200 Subject: [PATCH] Drop custom `predicateutils.Or` function --- .../pkg/controller/dnsrecord/controller.go | 3 +- pkg/controllerutils/predicate/or.go | 77 ------------------- pkg/controllerutils/predicate/or_test.go | 63 --------------- 3 files changed, 1 insertion(+), 142 deletions(-) delete mode 100644 pkg/controllerutils/predicate/or.go delete mode 100644 pkg/controllerutils/predicate/or_test.go diff --git a/extensions/pkg/controller/dnsrecord/controller.go b/extensions/pkg/controller/dnsrecord/controller.go index b8406869f38..72e7fbe04ff 100644 --- a/extensions/pkg/controller/dnsrecord/controller.go +++ b/extensions/pkg/controller/dnsrecord/controller.go @@ -24,7 +24,6 @@ import ( extensionspredicate "github.com/gardener/gardener/extensions/pkg/predicate" extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1" "github.com/gardener/gardener/pkg/controllerutils/mapper" - predicateutils "github.com/gardener/gardener/pkg/controllerutils/predicate" ) const ( @@ -60,7 +59,7 @@ func DefaultPredicates(ignoreOperationAnnotation bool) []predicate.Predicate { // 'garden' namespace and don't belong to a Shoot. Most other DNSRecord resources are created in regular shoot // namespaces (in such cases we want to check whether the respective Shoot is failed). Consequently, we add both // preconditions and ensure at least one of them applies. - predicateutils.Or( + predicate.Or( extensionspredicate.IsInGardenNamespacePredicate, extensionspredicate.ShootNotFailedPredicate(), ), diff --git a/pkg/controllerutils/predicate/or.go b/pkg/controllerutils/predicate/or.go deleted file mode 100644 index 7e07feaa317..00000000000 --- a/pkg/controllerutils/predicate/or.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) 2022 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package predicate - -import ( - "sigs.k8s.io/controller-runtime/pkg/event" - "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/runtime/inject" -) - -// Or returns a composite predicate that implements a logical OR of the predicates passed to it. -// TODO: This is a copy of "sigs.k8s.io/controller-runtime/pkg/predicate.Or" with the addition of the InjectFunc. -// Delete this code once the upstream library supports the InjectFunc as well. -func Or(predicates ...predicate.Predicate) predicate.Predicate { - return or{predicates} -} - -type or struct { - predicates []predicate.Predicate -} - -func (o or) InjectFunc(f inject.Func) error { - for _, p := range o.predicates { - if err := f(p); err != nil { - return err - } - } - return nil -} - -func (o or) Create(e event.CreateEvent) bool { - for _, p := range o.predicates { - if p.Create(e) { - return true - } - } - return false -} - -func (o or) Update(e event.UpdateEvent) bool { - for _, p := range o.predicates { - if p.Update(e) { - return true - } - } - return false -} - -func (o or) Delete(e event.DeleteEvent) bool { - for _, p := range o.predicates { - if p.Delete(e) { - return true - } - } - return false -} - -func (o or) Generic(e event.GenericEvent) bool { - for _, p := range o.predicates { - if p.Generic(e) { - return true - } - } - return false -} diff --git a/pkg/controllerutils/predicate/or_test.go b/pkg/controllerutils/predicate/or_test.go deleted file mode 100644 index 86208b1c6e8..00000000000 --- a/pkg/controllerutils/predicate/or_test.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2018 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. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package predicate_test - -import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "sigs.k8s.io/controller-runtime/pkg/event" - "sigs.k8s.io/controller-runtime/pkg/predicate" - - predicateutils "github.com/gardener/gardener/pkg/controllerutils/predicate" -) - -var _ = Describe("Or", func() { - Describe("#Or", func() { - funcs := func(pass bool) predicate.Funcs { - return predicate.Funcs{ - CreateFunc: func(event.CreateEvent) bool { - return pass - }, - DeleteFunc: func(event.DeleteEvent) bool { - return pass - }, - UpdateFunc: func(event.UpdateEvent) bool { - return pass - }, - GenericFunc: func(event.GenericEvent) bool { - return pass - }, - } - } - passFuncs := funcs(true) - failFuncs := funcs(false) - - It("should return true when one of its predicates returns true", func() { - o := predicateutils.Or(passFuncs, failFuncs) - Expect(o.Create(event.CreateEvent{})).To(BeTrue()) - Expect(o.Update(event.UpdateEvent{})).To(BeTrue()) - Expect(o.Delete(event.DeleteEvent{})).To(BeTrue()) - Expect(o.Generic(event.GenericEvent{})).To(BeTrue()) - }) - - It("should return false when all of its predicates return false", func() { - o := predicateutils.Or(failFuncs, failFuncs) - Expect(o.Create(event.CreateEvent{})).To(BeFalse()) - Expect(o.Update(event.UpdateEvent{})).To(BeFalse()) - Expect(o.Delete(event.DeleteEvent{})).To(BeFalse()) - Expect(o.Generic(event.GenericEvent{})).To(BeFalse()) - }) - }) -})