Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
multicluster: Small tweaks to MeshConfig client for clarity and bette…
Browse files Browse the repository at this point in the history
…r logging (#3819)

Signed-off-by: Delyan Raychev <[email protected]>
  • Loading branch information
draychev authored Jul 21, 2021
1 parent 07591b2 commit 44a6696
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions pkg/config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
const (
// apiGroup is the k8s API group that this package interacts with
apiGroup = "config.openservicemesh.io"

multiclusterInformerName = `MulticlusterService`
)

// NewConfigController returns a config.Controller struct related to functionality provided by the resources in the config.openservicemesh.io API group
Expand All @@ -29,40 +31,36 @@ func NewConfigController(kubeConfig *rest.Config, kubeController k8s.Controller,

shouldObserve := func(obj interface{}) bool {
object, ok := obj.(metav1.Object)
if !ok {
return false
}
return kubeController.IsMonitoredNamespace(object.GetNamespace())
return ok && kubeController.IsMonitoredNamespace(object.GetNamespace())
}

remoteServiceEventTypes := k8s.EventTypes{
multiclusterServiceEventTypes := k8s.EventTypes{
Add: announcements.MultiClusterServiceAdded,
Update: announcements.MultiClusterServiceUpdated,
Delete: announcements.MultiClusterServiceDeleted,
}
client.informer.Informer().AddEventHandler(k8s.GetKubernetesEventHandlers("MultiClusterService", "Kube", shouldObserve, remoteServiceEventTypes))
client.informer.Informer().AddEventHandler(k8s.GetKubernetesEventHandlers(multiclusterInformerName, "Kube", shouldObserve, multiclusterServiceEventTypes))

err := client.run(stop)
if err != nil {
if err := client.run(stop); err != nil {
return client, errors.Errorf("Could not start %s client: %s", apiGroup, err)
}
return client, err
return client, nil
}

func (c client) run(stop <-chan struct{}) error {
log.Info().Msgf("%s client started", apiGroup)
log.Info().Msgf("Starting informers for %s", apiGroup)

if c.informer == nil {
return errInitInformers
}

go c.informer.Informer().Run(stop)

log.Info().Msgf("Waiting for %s RemoteService informers' cache to sync", apiGroup)
log.Info().Msgf("Waiting for %s %s informers' cache to sync", apiGroup, multiclusterInformerName)
if !cache.WaitForCacheSync(stop, c.informer.Informer().HasSynced) {
return errSyncingCaches
}

log.Info().Msgf("Cache sync finished for %s RemoteService informers", apiGroup)
log.Info().Msgf("Cache sync finished for %s %s informers", apiGroup, multiclusterInformerName)
return nil
}

0 comments on commit 44a6696

Please sign in to comment.