From 1f8ce4e01c9d56a3fca8aa83e0af75a1e64928c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Luk=C5=A1a?= Date: Wed, 21 Sep 2022 18:33:08 +0200 Subject: [PATCH] OSSM-2006 Fix multiNamespaceInformer.HasSynced() --- licenses/github.com/stretchr/testify/LICENSE | 21 ++++++++++++++++++++ pilot/pkg/config/kube/ior/fake.go | 11 +++++----- pilot/pkg/config/kube/ior/ior_test.go | 2 +- pilot/pkg/config/kube/ior/route.go | 8 ++++++-- pkg/kube/client.go | 17 ---------------- pkg/kube/mock_client.go | 4 ---- 6 files changed, 33 insertions(+), 30 deletions(-) create mode 100644 licenses/github.com/stretchr/testify/LICENSE diff --git a/licenses/github.com/stretchr/testify/LICENSE b/licenses/github.com/stretchr/testify/LICENSE new file mode 100644 index 00000000000..4b0421cf9ee --- /dev/null +++ b/licenses/github.com/stretchr/testify/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2012-2020 Mat Ryer, Tyler Bunnell and contributors. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/pilot/pkg/config/kube/ior/fake.go b/pilot/pkg/config/kube/ior/fake.go index 34d837b479a..8c0f7990ad2 100644 --- a/pilot/pkg/config/kube/ior/fake.go +++ b/pilot/pkg/config/kube/ior/fake.go @@ -200,6 +200,10 @@ func (fk *fakeMemberRollController) Register(listener controller.MemberRollListe if listener == nil { return } + + // ensure that listener has no namespaces until the smmrc initializes it with the actual list of namespaces in the member roll + listener.SetNamespaces(nil) + fk.listeners = append(fk.listeners, listener) } @@ -208,11 +212,6 @@ func (fk *fakeMemberRollController) Start(stopCh <-chan struct{}) { panic("not implemented") } -func (fk *fakeMemberRollController) addNamespaces(namespaces ...string) { - fk.namespaces = append(fk.namespaces, namespaces...) - fk.invokeListeners() -} - func (fk *fakeMemberRollController) setNamespaces(namespaces ...string) { fk.namespaces = namespaces fk.invokeListeners() @@ -223,7 +222,7 @@ func (fk *fakeMemberRollController) invokeListeners() { defer fk.lock.Unlock() for _, l := range fk.listeners { - l.SetNamespaces(fk.namespaces...) + l.SetNamespaces(fk.namespaces) } } diff --git a/pilot/pkg/config/kube/ior/ior_test.go b/pilot/pkg/config/kube/ior/ior_test.go index d179ac005a6..0a0d7e24f46 100644 --- a/pilot/pkg/config/kube/ior/ior_test.go +++ b/pilot/pkg/config/kube/ior/ior_test.go @@ -52,7 +52,7 @@ func initClients(t *testing.T, k8sClient := kube.NewFakeClient() iorKubeClient := NewFakeKubeClient(k8sClient) routerClient := NewFakeRouterClient() - store, err := crdclient.New(k8sClient, "", "", false) + store, err := crdclient.New(k8sClient, crdclient.Option{}) if err != nil { t.Fatal(err) } diff --git a/pilot/pkg/config/kube/ior/route.go b/pilot/pkg/config/kube/ior/route.go index 66d3d48d3ee..18d450aa2f2 100644 --- a/pilot/pkg/config/kube/ior/route.go +++ b/pilot/pkg/config/kube/ior/route.go @@ -409,11 +409,15 @@ func (r *route) handleEvent(event model.Event, cfg config.Config) error { } // Trigerred by SMMR controller when SMMR changes -func (r *route) SetNamespaces(namespaces ...string) { +func (r *route) SetNamespaces(namespaces []string) { if !r.alive { return } + if namespaces == nil { + return + } + IORLog.Debugf("UpdateNamespaces(%v)", namespaces) r.namespaceLock.Lock() r.namespaces = namespaces @@ -435,7 +439,7 @@ func (r *route) SetNamespaces(namespaces ...string) { IORLog.Debug("Gateway store cache synced. Performing our initial sync now") if err := r.initialSync(namespaces); err != nil { - IORLog.Errora(err) + IORLog.Error(err) if r.errorChannel != nil { r.errorChannel <- err } diff --git a/pkg/kube/client.go b/pkg/kube/client.go index f822721c8b0..403a9800544 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -157,9 +157,6 @@ type Client interface { // GetKubernetesVersion returns the Kubernetes server version GetKubernetesVersion() (*kubeVersion.Info, error) - // SetNamespaces sets watched namespaces if no MemberRoll controller exists. - SetNamespaces(namespaces []string) - // AddMemberRoll creates a MemberRollController and adds it to the client. AddMemberRoll(namespace, memberRollName string) error @@ -554,20 +551,6 @@ func (c *client) HasStarted() bool { return c.started.Load() } -func (c *client) SetNamespaces(namespaces []string) { - // This is a no-op if a MemberRoll controller exists. - if c.memberRoll != nil { - return - } - - c.kubeInformer.SetNamespaces(namespaces) - c.istioInformer.SetNamespaces(namespaces) - c.dynamicInformer.SetNamespaces(namespaces) - if features.EnableGatewayAPI { - c.gatewayapiInformer.SetNamespaces(namespaces) - } -} - func (c *client) AddMemberRoll(namespace, memberRollName string) (err error) { c.memberRoll, err = memberroll.NewMemberRollController(c.config, namespace, memberRollName, resyncInterval) if err != nil { diff --git a/pkg/kube/mock_client.go b/pkg/kube/mock_client.go index a518e04766d..d847f639407 100644 --- a/pkg/kube/mock_client.go +++ b/pkg/kube/mock_client.go @@ -152,10 +152,6 @@ func (c MockClient) MetadataClient() metadata.Interface { panic("not used in mock") } -func (c MockClient) SetNamespaces(namespaces []string) { - panic("not used in mock") -} - func (c MockClient) AddMemberRoll(namespace, memberRollName string) error { panic("not used in mock") }