diff --git a/pkg/fake/conflict_reactor.go b/pkg/fake/conflict_reactor.go index 37dad289..c4c278dd 100644 --- a/pkg/fake/conflict_reactor.go +++ b/pkg/fake/conflict_reactor.go @@ -30,6 +30,9 @@ import ( ) func ConflictOnUpdateReactor(f *testing.Fake, resource string) { + f.Lock() + defer f.Unlock() + reactors := f.ReactionChain[0:] resourceVersion := "100" state := sync.Map{} diff --git a/pkg/fake/create_reactor.go b/pkg/fake/create_reactor.go index 42affc92..81af129f 100644 --- a/pkg/fake/create_reactor.go +++ b/pkg/fake/create_reactor.go @@ -36,6 +36,9 @@ type createReactor struct { // AddCreateReactor adds a reactor to mimic real K8s create behavior to handle GenerateName, validation et al. func AddCreateReactor(f *testing.Fake) { + f.Lock() + defer f.Unlock() + r := &createReactor{reactors: f.ReactionChain[0:]} f.PrependReactor("create", "*", r.react) } diff --git a/pkg/fake/delete_colection_reactor.go b/pkg/fake/delete_colection_reactor.go index b5e1d8b5..8acdad1f 100644 --- a/pkg/fake/delete_colection_reactor.go +++ b/pkg/fake/delete_colection_reactor.go @@ -43,8 +43,10 @@ type DeleteCollectionReactor struct { } func AddDeleteCollectionReactor(f *testing.Fake) { + f.Lock() r := &DeleteCollectionReactor{gvrToGVK: map[schema.GroupVersionResource]schema.GroupVersionKind{}, reactors: f.ReactionChain[0:]} f.PrependReactor("delete-collection", "*", r.react) + f.Unlock() for gvk := range scheme.Scheme.AllKnownTypes() { if !strings.HasSuffix(gvk.Kind, "List") { diff --git a/pkg/fake/delete_reactor.go b/pkg/fake/delete_reactor.go index 125551c4..73e63451 100644 --- a/pkg/fake/delete_reactor.go +++ b/pkg/fake/delete_reactor.go @@ -34,6 +34,9 @@ type deleteReactor struct { // AddDeleteReactor adds a reactor to mimic real K8s delete behavior to handle ResourceVersion, DeletionTimestamp et al. func AddDeleteReactor(f *testing.Fake) { + f.Lock() + defer f.Unlock() + r := &deleteReactor{reactors: f.ReactionChain[0:]} f.PrependReactor("delete", "*", r.react) } diff --git a/pkg/fake/fail_on_action_reactor.go b/pkg/fake/fail_on_action_reactor.go index 5400b307..fd404839 100644 --- a/pkg/fake/fail_on_action_reactor.go +++ b/pkg/fake/fail_on_action_reactor.go @@ -43,22 +43,20 @@ func FailOnAction(f *testing.Fake, resource, verb string, customErr error, autoR retErr = errors.New("fake error") } - chain := []testing.Reactor{&testing.SimpleReactor{ - Verb: verb, - Resource: resource, - Reaction: func(action testing.Action) (bool, runtime.Object, error) { - if r.fail.Load().(bool) { - if autoReset { - r.fail.Store(false) - } - - return true, nil, retErr + f.Lock() + defer f.Unlock() + + f.PrependReactor(verb, resource, func(action testing.Action) (bool, runtime.Object, error) { + if r.fail.Load().(bool) { + if autoReset { + r.fail.Store(false) } - return false, nil, nil - }, - }} - f.ReactionChain = append(chain, f.ReactionChain...) + return true, nil, retErr + } + + return false, nil, nil + }) return r } diff --git a/pkg/fake/failing_reactor.go b/pkg/fake/failing_reactor.go index 46e468a5..7dfd7274 100644 --- a/pkg/fake/failing_reactor.go +++ b/pkg/fake/failing_reactor.go @@ -41,8 +41,11 @@ func NewFailingReactor(f *testing.Fake) *FailingReactor { func NewFailingReactorForResource(f *testing.Fake, resource string) *FailingReactor { r := &FailingReactor{} - chain := []testing.Reactor{&testing.SimpleReactor{Verb: "*", Resource: resource, Reaction: r.react}} - f.ReactionChain = append(chain, f.ReactionChain...) + + f.Lock() + defer f.Unlock() + + f.PrependReactor("*", resource, r.react) return r } diff --git a/pkg/fake/list_reactor.go b/pkg/fake/list_reactor.go index 9ecedf21..466875eb 100644 --- a/pkg/fake/list_reactor.go +++ b/pkg/fake/list_reactor.go @@ -33,6 +33,9 @@ type filteringListReactor struct { } func AddFilteringListReactor(f *testing.Fake) { + f.Lock() + defer f.Unlock() + r := &filteringListReactor{reactors: f.ReactionChain[0:]} f.PrependReactor("list", "*", r.react) } diff --git a/pkg/fake/update_reactor.go b/pkg/fake/update_reactor.go index 349b3a60..cbbb535b 100644 --- a/pkg/fake/update_reactor.go +++ b/pkg/fake/update_reactor.go @@ -37,6 +37,9 @@ type updateReactor struct { // AddUpdateReactor adds a reactor to mimic real K8s update behavior to handle ResourceVersion et al. func AddUpdateReactor(f *testing.Fake) { + f.Lock() + defer f.Unlock() + r := &updateReactor{reactors: f.ReactionChain[0:]} f.PrependReactor("update", "*", r.react) } diff --git a/pkg/federate/cluster_informer.go b/pkg/federate/cluster_informer.go deleted file mode 100644 index 30c3795a..00000000 --- a/pkg/federate/cluster_informer.go +++ /dev/null @@ -1,43 +0,0 @@ -/* -SPDX-License-Identifier: Apache-2.0 - -Copyright Contributors to the Submariner project. - -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 federate - -import ( - "k8s.io/client-go/rest" -) - -// ClusterEventHandler handles federated cluster lifecycle event notifications. -type ClusterEventHandler interface { - // OnAdd is called when a cluster is added. The given 'kubeConfig' can be used to access - // the cluster's kube API endpoint. - OnAdd(clusterID string, kubeConfig *rest.Config) - - // OnUpdate is called when some aspect of a cluster's kube API endpoint configuration has changed. - OnUpdate(clusterID string, kubeConfig *rest.Config) - - // OnRemove is called when a cluster is removed. - OnRemove(clusterID string) -} - -// ClusterInformer provides functionality to inform on federated cluster lifecycle events. -type ClusterInformer interface { - // AddHandler adds a ClusterEventHandler to be notified when cluster lifecycle events occur. - // The handler is notified asynchronously of the existing set of clusters via OnAdd events, one per cluster. - AddHandler(handler ClusterEventHandler) error -}