Skip to content

Commit

Permalink
OSSM-2006 Fix multiNamespaceInformer.HasSynced()
Browse files Browse the repository at this point in the history
  • Loading branch information
luksa authored and jwendell committed Nov 15, 2022
1 parent c496447 commit 1f8ce4e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 30 deletions.
21 changes: 21 additions & 0 deletions licenses/github.com/stretchr/testify/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 5 additions & 6 deletions pilot/pkg/config/kube/ior/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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()
Expand All @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pilot/pkg/config/kube/ior/ior_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 6 additions & 2 deletions pilot/pkg/config/kube/ior/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
17 changes: 0 additions & 17 deletions pkg/kube/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions pkg/kube/mock_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 1f8ce4e

Please sign in to comment.