This is an automated email from the ASF dual-hosted git repository.

zhongxjian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-kubernetes.git


The following commit(s) were added to refs/heads/master by this push:
     new eca33910 [navi] add xds server logic (#780)
eca33910 is described below

commit eca3391059a7e4b356792551119f31223f7e1ef7
Author: Jian Zhong <[email protected]>
AuthorDate: Mon Aug 25 00:40:18 2025 +0800

    [navi] add xds server logic (#780)
---
 .asf.yaml                           |   2 +-
 LICENSE                             |  21 +-----
 navigator/pkg/bootstrap/server.go   |  70 +++++++++++++++++-
 navigator/pkg/model/context.go      |  45 +++++++++++-
 navigator/pkg/model/push_context.go |  11 +++
 navigator/pkg/xds/ads.go            |  25 +++++++
 navigator/pkg/xds/discovery.go      |  33 ++++++++-
 navigator/pkg/xds/pushqueue.go      | 139 ++++++++++++++++++++++++++++++++++++
 navigator/pkg/xds/server.go         |  33 +++++++++
 pkg/config/constants/constants.go   |   1 -
 pkg/config/host/name.go             |  98 +++++++++++++++++++++++++
 pkg/config/mesh/mesh.go             |   1 -
 pkg/config/mesh/meshwatcher/mesh.go |  28 ++++++++
 13 files changed, 479 insertions(+), 28 deletions(-)

diff --git a/.asf.yaml b/.asf.yaml
index 933e7253..979ec402 100644
--- a/.asf.yaml
+++ b/.asf.yaml
@@ -28,7 +28,7 @@ github:
     # Enable issue management
     issues: true
     # Enable projects for project management boards
-    projects: true
+    projects: false
   protected_branches:
     master: {}
       # only disable force push
diff --git a/LICENSE b/LICENSE
index 6b0cc584..f49a4e16 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,3 @@
-
                                  Apache License
                            Version 2.0, January 2004
                         http://www.apache.org/licenses/
@@ -199,22 +198,4 @@
    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.
-
-
-Apache Dubbo Admin Submodules:
-
-Apache Dubbo Admin includes a number of submodules with separate copyright 
notices
-and license terms. Your use of these submodules is subject to the terms and
-conditions of the following licenses.
-
-================================================================
-For dubbo-admin-ui/static/fonts
-This product bundles files from google fonts roboto which is licensed under 
the Apache License v2
-For details, see https://github.com/google/fonts/tree/master/apache/roboto
-
-For dubbo-admin-ui/static/OpenSans.css
-This product bundles files from google material design icons which is licensed 
under the Apache License v2
-For details, see 
https://github.com/google/material-design-icons/blob/3.0.1/LICENSE
-
-
+   limitations under the License.
\ No newline at end of file
diff --git a/navigator/pkg/bootstrap/server.go 
b/navigator/pkg/bootstrap/server.go
index 949be4e8..e95c18be 100644
--- a/navigator/pkg/bootstrap/server.go
+++ b/navigator/pkg/bootstrap/server.go
@@ -18,6 +18,7 @@
 package bootstrap
 
 import (
+       "context"
        "fmt"
        "github.com/apache/dubbo-kubernetes/navigator/pkg/features"
        "github.com/apache/dubbo-kubernetes/navigator/pkg/model"
@@ -75,7 +76,7 @@ func NewServer(args *NaviArgs, initFuncs ...func(*Server)) 
(*Server, error) {
        for _, fn := range initFuncs {
                fn(s)
        }
-       s.XDSServer = xds.NewDiscoveryServer(e, 
args.RegistryOptions.KubeOptions.ClusterAliases)
+       s.XDSServer = xds.NewDiscoveryServer(e, 
args.RegistryOptions.KubeOptions.ClusterAliases, args.KrtDebugger)
        // TODO configGen
        // TODO initReadinessProbes
        s.initServers(args)
@@ -97,10 +98,12 @@ func (s *Server) Start(stop <-chan struct{}) error {
        if err := s.server.Start(stop); err != nil {
                return err
        }
+
        if !s.waitForCacheSync(stop) {
                return fmt.Errorf("failed to sync cache")
        }
-       // TODO XDSserver CacheSynced
+
+       s.XDSServer.CachesSynced()
 
        if s.secureGrpcAddress != "" {
                grpcListener, err := net.Listen("tcp", s.secureGrpcAddress)
@@ -141,6 +144,9 @@ func (s *Server) Start(stop <-chan struct{}) error {
                }()
                s.httpsAddr = httpsListener.Addr().String()
        }
+
+       s.waitForShutdown(stop)
+
        return nil
 }
 
@@ -253,6 +259,66 @@ func getClusterID(args *NaviArgs) cluster.ID {
        return clusterID
 }
 
+func (s *Server) waitForShutdown(stop <-chan struct{}) {
+       go func() {
+               <-stop
+               close(s.internalStop)
+               _ = s.fileWatcher.Close()
+
+               if s.cacertsWatcher != nil {
+                       _ = s.cacertsWatcher.Close()
+               }
+               // Stop gRPC services.  If gRPC services fail to stop in the 
shutdown duration,
+               // force stop them. This does not happen normally.
+               stopped := make(chan struct{})
+               go func() {
+                       // Some grpcServer implementations do not support 
GracefulStop. Unfortunately, this is not
+                       // exposed; they just panic. To avoid this, we will 
recover and do a standard Stop when its not
+                       // support.
+                       defer func() {
+                               if r := recover(); r != nil {
+                                       s.grpcServer.Stop()
+                                       if s.secureGrpcServer != nil {
+                                               s.secureGrpcServer.Stop()
+                                       }
+                                       close(stopped)
+                               }
+                       }()
+                       s.grpcServer.GracefulStop()
+                       if s.secureGrpcServer != nil {
+                               s.secureGrpcServer.GracefulStop()
+                       }
+                       close(stopped)
+               }()
+
+               t := time.NewTimer(s.shutdownDuration)
+               select {
+               case <-t.C:
+                       s.grpcServer.Stop()
+                       if s.secureGrpcServer != nil {
+                               s.secureGrpcServer.Stop()
+                       }
+               case <-stopped:
+                       t.Stop()
+               }
+
+               // Stop HTTP services.
+               ctx, cancel := context.WithTimeout(context.Background(), 
s.shutdownDuration)
+               defer cancel()
+               if err := s.httpServer.Shutdown(ctx); err != nil {
+                       klog.Error(err)
+               }
+               if s.httpsServer != nil {
+                       if err := s.httpsServer.Shutdown(ctx); err != nil {
+                               klog.Error(err)
+                       }
+               }
+
+               // Shutdown the DiscoveryServer.
+               s.XDSServer.Shutdown()
+       }()
+}
+
 func (s *Server) cachesSynced() bool {
        // TODO multiclusterController HasSynced
        // TODO ServiceController().HasSynced
diff --git a/navigator/pkg/model/context.go b/navigator/pkg/model/context.go
index 21db5c9d..0c640a15 100644
--- a/navigator/pkg/model/context.go
+++ b/navigator/pkg/model/context.go
@@ -18,17 +18,24 @@
 package model
 
 import (
+       "fmt"
        "github.com/apache/dubbo-kubernetes/navigator/pkg/features"
+       "github.com/apache/dubbo-kubernetes/pkg/config/host"
        "github.com/apache/dubbo-kubernetes/pkg/config/mesh"
        "github.com/apache/dubbo-kubernetes/pkg/config/mesh/meshwatcher"
        meshconfig "istio.io/api/mesh/v1alpha1"
+       "net"
+       "strconv"
+       "sync"
 )
 
 type Watcher = meshwatcher.WatcherCollection
 
 type Environment struct {
        Watcher
-       Cache XdsCache
+       mutex       sync.RWMutex
+       pushContext *PushContext
+       Cache       XdsCache
 }
 
 type XdsCacheImpl struct {
@@ -52,9 +59,45 @@ func NewEnvironment() *Environment {
 
 var _ mesh.Holder = &Environment{}
 
+func (e *Environment) SetPushContext(pc *PushContext) {
+       e.mutex.Lock()
+       defer e.mutex.Unlock()
+       e.pushContext = pc
+}
+
+func (e *Environment) PushContext() *PushContext {
+       e.mutex.RLock()
+       defer e.mutex.RUnlock()
+       return e.pushContext
+}
+
 func (e *Environment) Mesh() *meshconfig.MeshConfig {
        if e != nil && e.Watcher != nil {
                return e.Watcher.Mesh()
        }
        return nil
 }
+
+func (e *Environment) AddMeshHandler(h func()) {
+       if e != nil && e.Watcher != nil {
+               e.Watcher.AddMeshHandler(h)
+       }
+}
+
+func (e *Environment) GetDiscoveryAddress() (host.Name, string, error) {
+       proxyConfig := mesh.DefaultProxyConfig()
+       if e.Mesh().DefaultConfig != nil {
+               proxyConfig = e.Mesh().DefaultConfig
+       }
+       hostname, port, err := net.SplitHostPort(proxyConfig.DiscoveryAddress)
+       if err != nil {
+               return "", "", fmt.Errorf("invalid Dubbod Address: %s, %v", 
proxyConfig.DiscoveryAddress, err)
+       }
+       if _, err := strconv.Atoi(port); err != nil {
+               return "", "", fmt.Errorf("invalid Dubbod Port: %s, %s, %v", 
port, proxyConfig.DiscoveryAddress, err)
+       }
+       return host.Name(hostname), port, nil
+}
+
+type Proxy struct {
+}
diff --git a/navigator/pkg/model/push_context.go 
b/navigator/pkg/model/push_context.go
new file mode 100644
index 00000000..0714d265
--- /dev/null
+++ b/navigator/pkg/model/push_context.go
@@ -0,0 +1,11 @@
+package model
+
+import meshconfig "istio.io/api/mesh/v1alpha1"
+
+type PushContext struct {
+       Mesh *meshconfig.MeshConfig `json:"-"`
+}
+
+func NewPushContext() *PushContext {
+       return &PushContext{}
+}
diff --git a/navigator/pkg/xds/ads.go b/navigator/pkg/xds/ads.go
new file mode 100644
index 00000000..8dae7ed8
--- /dev/null
+++ b/navigator/pkg/xds/ads.go
@@ -0,0 +1,25 @@
+package xds
+
+import (
+       "github.com/apache/dubbo-kubernetes/navigator/pkg/model"
+       "github.com/apache/dubbo-kubernetes/navigator/pkg/xds"
+       discovery 
"github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
+)
+
+type Connection struct {
+       xds.Connection
+       node         *core.Node
+       proxy        *model.Proxy
+       deltaStream  DeltaDiscoveryStream
+       deltaReqChan chan *discovery.DeltaDiscoveryRequest
+       s            *DiscoveryServer
+       ids          []string
+}
+
+func (conn *Connection) XdsConnection() *xds.Connection {
+       return &conn.Connection
+}
+
+func (conn *Connection) Proxy() *model.Proxy {
+       return conn.proxy
+}
diff --git a/navigator/pkg/xds/discovery.go b/navigator/pkg/xds/discovery.go
index b3e4080b..d72040c5 100644
--- a/navigator/pkg/xds/discovery.go
+++ b/navigator/pkg/xds/discovery.go
@@ -19,12 +19,41 @@ package xds
 
 import (
        "github.com/apache/dubbo-kubernetes/navigator/pkg/model"
+       "github.com/apache/dubbo-kubernetes/pkg/cluster"
+       "github.com/apache/dubbo-kubernetes/pkg/kube/krt"
+       "go.uber.org/atomic"
+       "k8s.io/klog/v2"
+       "time"
 )
 
 type DiscoveryServer struct {
+       Env                *model.Environment
+       serverReady        atomic.Bool
+       DiscoveryStartTime time.Time
+       ClusterAliases     map[cluster.ID]cluster.ID
+       Cache              model.XdsCache
+       pushQueue          *PushQueue
+       krtDebugger        *krt.DebugHandler
 }
 
-func NewDiscoveryServer(env *model.Environment, clusterAliases 
map[string]string) *DiscoveryServer {
-       out := &DiscoveryServer{}
+func NewDiscoveryServer(env *model.Environment, clusterAliases 
map[string]string, debugger *krt.DebugHandler) *DiscoveryServer {
+       out := &DiscoveryServer{
+               Env:         env,
+               Cache:       env.Cache,
+               krtDebugger: debugger,
+       }
+       out.ClusterAliases = make(map[cluster.ID]cluster.ID)
+       for alias := range clusterAliases {
+               out.ClusterAliases[cluster.ID(alias)] = 
cluster.ID(clusterAliases[alias])
+       }
        return out
 }
+
+func (s *DiscoveryServer) CachesSynced() {
+       klog.Infof("All caches have been synced up in %v, marking server 
ready", time.Since(s.DiscoveryStartTime))
+       s.serverReady.Store(true)
+}
+
+func (s *DiscoveryServer) Shutdown() {
+       s.pushQueue.ShutDown()
+}
diff --git a/navigator/pkg/xds/pushqueue.go b/navigator/pkg/xds/pushqueue.go
new file mode 100644
index 00000000..98e5c710
--- /dev/null
+++ b/navigator/pkg/xds/pushqueue.go
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 xds
+
+import (
+       "sync"
+
+       "istio.io/istio/pilot/pkg/model"
+)
+
+type PushQueue struct {
+       cond *sync.Cond
+
+       // pending stores all connections in the queue. If the same connection 
is enqueued again,
+       // the PushRequest will be merged.
+       pending map[*Connection]*model.PushRequest
+
+       // queue maintains ordering of the queue
+       queue []*Connection
+
+       // processing stores all connections that have been Dequeue(), but not 
MarkDone().
+       // The value stored will be initially be nil, but may be populated if 
the connection is Enqueue().
+       // If model.PushRequest is not nil, it will be Enqueued again once 
MarkDone has been called.
+       processing map[*Connection]*model.PushRequest
+
+       shuttingDown bool
+}
+
+func NewPushQueue() *PushQueue {
+       return &PushQueue{
+               pending:    make(map[*Connection]*model.PushRequest),
+               processing: make(map[*Connection]*model.PushRequest),
+               cond:       sync.NewCond(&sync.Mutex{}),
+       }
+}
+
+// Enqueue will mark a proxy as pending a push. If it is already pending, 
pushInfo will be merged.
+// ServiceEntry updates will be added together, and full will be set if either 
were full
+func (p *PushQueue) Enqueue(con *Connection, pushRequest *model.PushRequest) {
+       p.cond.L.Lock()
+       defer p.cond.L.Unlock()
+
+       if p.shuttingDown {
+               return
+       }
+
+       // If its already in progress, merge the info and return
+       if request, f := p.processing[con]; f {
+               p.processing[con] = request.CopyMerge(pushRequest)
+               return
+       }
+
+       if request, f := p.pending[con]; f {
+               p.pending[con] = request.CopyMerge(pushRequest)
+               return
+       }
+
+       p.pending[con] = pushRequest
+       p.queue = append(p.queue, con)
+       // Signal waiters on Dequeue that a new item is available
+       p.cond.Signal()
+}
+
+// Remove a proxy from the queue. If there are no proxies ready to be removed, 
this will block
+func (p *PushQueue) Dequeue() (con *Connection, request *model.PushRequest, 
shutdown bool) {
+       p.cond.L.Lock()
+       defer p.cond.L.Unlock()
+
+       // Block until there is one to remove. Enqueue will signal when one is 
added.
+       for len(p.queue) == 0 && !p.shuttingDown {
+               p.cond.Wait()
+       }
+
+       if len(p.queue) == 0 {
+               // We must be shutting down.
+               return nil, nil, true
+       }
+
+       con = p.queue[0]
+       // The underlying array will still exist, despite the slice changing, 
so the object may not GC without this
+       // See https://github.com/grpc/grpc-go/issues/4758
+       p.queue[0] = nil
+       p.queue = p.queue[1:]
+
+       request = p.pending[con]
+       delete(p.pending, con)
+
+       // Mark the connection as in progress
+       p.processing[con] = nil
+
+       return con, request, false
+}
+
+func (p *PushQueue) MarkDone(con *Connection) {
+       p.cond.L.Lock()
+       defer p.cond.L.Unlock()
+       request := p.processing[con]
+       delete(p.processing, con)
+
+       // If the info is present, that means Enqueue was called while 
connection was not yet marked done.
+       // This means we need to add it back to the queue.
+       if request != nil {
+               p.pending[con] = request
+               p.queue = append(p.queue, con)
+               p.cond.Signal()
+       }
+}
+
+// Get number of pending proxies
+func (p *PushQueue) Pending() int {
+       p.cond.L.Lock()
+       defer p.cond.L.Unlock()
+       return len(p.queue)
+}
+
+// ShutDown will cause queue to ignore all new items added to it. As soon as 
the
+// worker goroutines have drained the existing items in the queue, they will be
+// instructed to exit.
+func (p *PushQueue) ShutDown() {
+       p.cond.L.Lock()
+       defer p.cond.L.Unlock()
+       p.shuttingDown = true
+       p.cond.Broadcast()
+}
diff --git a/navigator/pkg/xds/server.go b/navigator/pkg/xds/server.go
new file mode 100644
index 00000000..fdccba96
--- /dev/null
+++ b/navigator/pkg/xds/server.go
@@ -0,0 +1,33 @@
+package xds
+
+import (
+       discovery 
"github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
+       "time"
+)
+
+type DiscoveryStream = 
discovery.AggregatedDiscoveryService_StreamAggregatedResourcesServer
+
+type Connection struct {
+       peerAddr    string
+       connectedAt time.Time
+       conID       string
+       pushChannel chan any
+       stream      DiscoveryStream
+       initialized chan struct{}
+       stop        chan struct{}
+       reqChan     chan *discovery.DiscoveryRequest
+       errorChan   chan error
+}
+
+func NewConnection(peerAddr string, stream DiscoveryStream) Connection {
+       return Connection{
+               pushChannel: make(chan any),
+               initialized: make(chan struct{}),
+               stop:        make(chan struct{}),
+               reqChan:     make(chan *discovery.DiscoveryRequest, 1),
+               errorChan:   make(chan error, 1),
+               peerAddr:    peerAddr,
+               connectedAt: time.Now(),
+               stream:      stream,
+       }
+}
diff --git a/pkg/config/constants/constants.go 
b/pkg/config/constants/constants.go
index 8a787e5a..cd795585 100644
--- a/pkg/config/constants/constants.go
+++ b/pkg/config/constants/constants.go
@@ -23,5 +23,4 @@ const (
        DefaultClusterName        = "Kubernetes"
        ServiceClusterName        = "dubbo-proxy"
        ConfigPathDir             = "./etc/dubbo/proxy"
-       BinaryPathFilename        = "/usr/local/bin/envoy"
 )
diff --git a/pkg/config/host/name.go b/pkg/config/host/name.go
new file mode 100644
index 00000000..f7fd087a
--- /dev/null
+++ b/pkg/config/host/name.go
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 host
+
+import (
+       "strings"
+)
+
+// Name describes a (possibly wildcarded) hostname
+type Name string
+
+// Matches returns true if this hostname overlaps with the other hostname. 
Names overlap if:
+// - they're fully resolved (i.e. not wildcarded) and match exactly (i.e. an 
exact string match)
+// - one or both are wildcarded (e.g. "*.foo.com"), in which case we use 
wildcard resolution rules
+// to determine if n is covered by o or o is covered by n.
+// e.g.:
+//
+//     Name("foo.com").Matches("foo.com")   = true
+//     Name("foo.com").Matches("bar.com")   = false
+//     Name("*.com").Matches("foo.com")     = true
+//     Name("bar.com").Matches("*.com")     = true
+//     Name("*.foo.com").Matches("foo.com") = false
+//     Name("*").Matches("foo.com")         = true
+//     Name("*").Matches("*.com")           = true
+func (n Name) Matches(o Name) bool {
+       hWildcard := n.IsWildCarded()
+       oWildcard := o.IsWildCarded()
+
+       if hWildcard {
+               if oWildcard {
+                       // both n and o are wildcards
+                       if len(n) < len(o) {
+                               return strings.HasSuffix(string(o[1:]), 
string(n[1:]))
+                       }
+                       return strings.HasSuffix(string(n[1:]), string(o[1:]))
+               }
+               // only n is wildcard
+               return strings.HasSuffix(string(o), string(n[1:]))
+       }
+
+       if oWildcard {
+               // only o is wildcard
+               return strings.HasSuffix(string(n), string(o[1:]))
+       }
+
+       // both are non-wildcards, so do normal string comparison
+       return n == o
+}
+
+// SubsetOf returns true if this hostname is a valid subset of the other 
hostname. The semantics are
+// the same as "Matches", but only in one direction (i.e., n is covered by o).
+func (n Name) SubsetOf(o Name) bool {
+       hWildcard := n.IsWildCarded()
+       oWildcard := o.IsWildCarded()
+
+       if hWildcard {
+               if oWildcard {
+                       // both n and o are wildcards
+                       if len(n) < len(o) {
+                               return false
+                       }
+                       return strings.HasSuffix(string(n[1:]), string(o[1:]))
+               }
+               // only n is wildcard
+               return false
+       }
+
+       if oWildcard {
+               // only o is wildcard
+               return strings.HasSuffix(string(n), string(o[1:]))
+       }
+
+       // both are non-wildcards, so do normal string comparison
+       return n == o
+}
+
+func (n Name) IsWildCarded() bool {
+       return len(n) > 0 && n[0] == '*'
+}
+
+func (n Name) String() string {
+       return string(n)
+}
diff --git a/pkg/config/mesh/mesh.go b/pkg/config/mesh/mesh.go
index 738372a5..23438ee5 100644
--- a/pkg/config/mesh/mesh.go
+++ b/pkg/config/mesh/mesh.go
@@ -42,7 +42,6 @@ func DefaultProxyConfig() *meshconfig.ProxyConfig {
                ProxyAdminPort:           15000,
                // TODO authpolicy
                DiscoveryAddress: "dubbod.dubbo-system.svc:15012",
-               BinaryPath:       constants.BinaryPathFilename,
                StatNameLength:   189,
                StatusPort:       15020,
        }
diff --git a/pkg/config/mesh/meshwatcher/mesh.go 
b/pkg/config/mesh/meshwatcher/mesh.go
index dbaa07c4..1b0e8711 100644
--- a/pkg/config/mesh/meshwatcher/mesh.go
+++ b/pkg/config/mesh/meshwatcher/mesh.go
@@ -25,11 +25,39 @@ import (
        meshconfig "istio.io/api/mesh/v1alpha1"
 )
 
+type adapter struct {
+       krt.Singleton[MeshConfigResource]
+}
+
+var _ mesh.Watcher = adapter{}
+
 type WatcherCollection interface {
        mesh.Watcher
        krt.Singleton[MeshConfigResource]
 }
 
+func (a adapter) Mesh() *meshconfig.MeshConfig {
+       // Just get the value; we know there is always one set due to the way 
the collection is setup.
+       v := a.Singleton.Get()
+       return v.MeshConfig
+}
+
+func (a adapter) AddMeshHandler(h func()) *mesh.WatcherHandlerRegistration {
+       // Do not run initial state to match existing semantics
+       colReg := a.Singleton.AsCollection().RegisterBatch(func(o 
[]krt.Event[MeshConfigResource]) {
+               h()
+       }, false)
+       reg := mesh.NewWatcherHandlerRegistration(func() {
+               colReg.UnregisterHandler()
+       })
+       return reg
+}
+
+// DeleteMeshHandler removes a previously registered handler.
+func (a adapter) DeleteMeshHandler(registration 
*mesh.WatcherHandlerRegistration) {
+       registration.Remove()
+}
+
 // MeshConfigResource holds the current MeshConfig state
 type MeshConfigResource struct {
        *meshconfig.MeshConfig

Reply via email to