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 7043eb3e [navi] fmt replace klog library (#778)
7043eb3e is described below

commit 7043eb3ea245f38eb6d4ec85632858dcd51074c4
Author: Jian Zhong <[email protected]>
AuthorDate: Wed Aug 13 01:16:37 2025 +0800

    [navi] fmt replace klog library (#778)
---
 README.md                                       |  8 +++----
 navigator/pkg/bootstrap/mesh.go                 | 10 +++++++--
 navigator/pkg/bootstrap/server.go               | 29 +++++++++++++------------
 navigator/pkg/model/context.go                  | 15 +++++++++++++
 pkg/config/mesh/kubemesh/watcher.go             |  2 +-
 pkg/{ => config}/mesh/mesh.go                   |  0
 pkg/{ => config}/mesh/meshwatcher/collection.go | 15 +++++--------
 pkg/config/mesh/meshwatcher/mesh.go             | 21 +++++++++---------
 pkg/config/mesh/watchers.go                     |  9 --------
 pkg/kube/client.go                              |  5 +++--
 pkg/kube/krt/collection.go                      |  3 ++-
 pkg/kube/krt/helpers.go                         |  7 +++---
 pkg/kube/krt/informer.go                        |  3 ++-
 13 files changed, 70 insertions(+), 57 deletions(-)

diff --git a/README.md b/README.md
index 76f0eec8..c189fc97 100644
--- a/README.md
+++ b/README.md
@@ -11,11 +11,11 @@ Provides support for building and deploying Dubbo 
applications in various enviro
 ## Repositories
 The main code repositories of Dubbo on Kubernetes include:
 
-- Dubbod — The Dubbo control plane. It is built on Istio to implement a 
proxyless service mesh and includes the following components:
+- [dubboctl](dubboctl/): This directory contains code for the command line 
utility.
+- [helm-charts](manifests/charts): This directory contains the [Helm 
chart](https://github.com/apache/dubbo-helm-charts) sources, which are 
versioned, built, and pushed to the following Helm repositories with each Dubbo 
release.
+- dubbod — The dubbo control plane. It is built on Istio to implement a 
proxyless service mesh and includes the following components:
   - [navigator](navigator/) (under development): Responsible for configuring 
proxies at runtime.
-- [dubboctl](dubboctl/). This directory contains code for the command line 
utility.
-- [operator](operator/). Dubbo operator provides user friendly options to 
operate the Dubbo proxyless mesh
-- [helm-charts](manifests/charts). This directory contains the [Helm 
chart](https://github.com/apache/dubbo-helm-charts) sources, which are 
versioned, built, and pushed to the following Helm repositories with each Dubbo 
release.
+- [Operator](operator/): Dubbo operator provides user friendly options to 
operate the Dubbo proxyless mesh.
 
 ## Quick Start
 Please refer to [official 
website](https://cn.dubbo.apache.org/zh-cn/overview/home/)
diff --git a/navigator/pkg/bootstrap/mesh.go b/navigator/pkg/bootstrap/mesh.go
index f3655124..d4343461 100644
--- a/navigator/pkg/bootstrap/mesh.go
+++ b/navigator/pkg/bootstrap/mesh.go
@@ -21,11 +21,13 @@ import (
        "fmt"
        "github.com/apache/dubbo-kubernetes/navigator/pkg/features"
        "github.com/apache/dubbo-kubernetes/pkg/config/mesh/kubemesh"
+       "github.com/apache/dubbo-kubernetes/pkg/config/mesh/meshwatcher"
        "github.com/apache/dubbo-kubernetes/pkg/filewatcher"
        "github.com/apache/dubbo-kubernetes/pkg/kube/krt"
-       "github.com/apache/dubbo-kubernetes/pkg/mesh/meshwatcher"
        "github.com/apache/dubbo-kubernetes/pkg/ptr"
+       "k8s.io/klog/v2"
        "os"
+       "sigs.k8s.io/yaml"
 )
 
 const (
@@ -33,9 +35,13 @@ const (
 )
 
 func (s *Server) initMeshConfiguration(args *NaviArgs, fileWatcher 
filewatcher.FileWatcher) {
-       fmt.Printf("\ninitializing mesh configuration %v\n", 
args.MeshConfigFile)
+       klog.Infof("initializing mesh configuration %v", args.MeshConfigFile)
        col := s.getMeshConfiguration(args, fileWatcher)
        col.AsCollection().WaitUntilSynced(s.internalStop)
+
+       klog.Infof("mesh configuration: %s", 
meshwatcher.PrettyFormatOfMeshConfig(s.environment.Mesh()))
+       argsdump, _ := yaml.Marshal(args)
+       klog.Infof("flags: \n%s", argsdump)
 }
 
 func (s *Server) getMeshConfiguration(args *NaviArgs, fileWatcher 
filewatcher.FileWatcher) krt.Singleton[meshwatcher.MeshConfigResource] {
diff --git a/navigator/pkg/bootstrap/server.go 
b/navigator/pkg/bootstrap/server.go
index ed91ad34..949be4e8 100644
--- a/navigator/pkg/bootstrap/server.go
+++ b/navigator/pkg/bootstrap/server.go
@@ -25,15 +25,16 @@ import (
        
"github.com/apache/dubbo-kubernetes/navigator/pkg/serviceregistry/providers"
        "github.com/apache/dubbo-kubernetes/navigator/pkg/xds"
        "github.com/apache/dubbo-kubernetes/pkg/cluster"
+       "github.com/apache/dubbo-kubernetes/pkg/config/mesh"
        "github.com/apache/dubbo-kubernetes/pkg/filewatcher"
        "github.com/apache/dubbo-kubernetes/pkg/h2c"
        dubbokeepalive "github.com/apache/dubbo-kubernetes/pkg/keepalive"
        kubelib "github.com/apache/dubbo-kubernetes/pkg/kube"
-       "github.com/apache/dubbo-kubernetes/pkg/mesh"
        "github.com/apache/dubbo-kubernetes/pkg/network"
        "golang.org/x/net/http2"
        "google.golang.org/grpc"
        "k8s.io/client-go/rest"
+       "k8s.io/klog/v2"
        "net"
        "net/http"
        "os"
@@ -92,7 +93,7 @@ func NewServer(args *NaviArgs, initFuncs ...func(*Server)) 
(*Server, error) {
 }
 
 func (s *Server) Start(stop <-chan struct{}) error {
-       fmt.Printf("\nStarting Dubbod Server with primary cluster %s\n", 
s.clusterID)
+       klog.Infof("Starting Dubbod Server with primary cluster %s", 
s.clusterID)
        if err := s.server.Start(stop); err != nil {
                return err
        }
@@ -107,9 +108,9 @@ func (s *Server) Start(stop <-chan struct{}) error {
                        return err
                }
                go func() {
-                       fmt.Printf("starting secure gRPC discovery service at 
%s", grpcListener.Addr())
+                       klog.Infof("starting secure gRPC discovery service at 
%s", grpcListener.Addr())
                        if err := s.secureGrpcServer.Serve(grpcListener); err 
!= nil {
-                               fmt.Errorf("error serving secure GRPC server: 
%v", err)
+                               klog.Errorf("error serving secure GRPC server: 
%v", err)
                        }
                }()
        }
@@ -120,9 +121,9 @@ func (s *Server) Start(stop <-chan struct{}) error {
                        return err
                }
                go func() {
-                       fmt.Printf("starting gRPC discovery service at %s", 
grpcListener.Addr())
+                       klog.Infof("starting gRPC discovery service at %s", 
grpcListener.Addr())
                        if err := s.grpcServer.Serve(grpcListener); err != nil {
-                               fmt.Errorf("error serving GRPC server: %v", err)
+                               klog.Errorf("error serving GRPC server: %v", 
err)
                        }
                }()
        }
@@ -133,9 +134,9 @@ func (s *Server) Start(stop <-chan struct{}) error {
                        return err
                }
                go func() {
-                       fmt.Printf("starting webhook service at %s", 
httpsListener.Addr())
+                       klog.Infof("starting webhook service at %s", 
httpsListener.Addr())
                        if err := s.httpsServer.ServeTLS(httpsListener, "", 
""); network.IsUnexpectedListenerError(err) {
-                               fmt.Errorf("error serving https server: %v", 
err)
+                               klog.Errorf("error serving https server: %v", 
err)
                        }
                }()
                s.httpsAddr = httpsListener.Addr().String()
@@ -197,7 +198,7 @@ func (s *Server) initServers(args *NaviArgs) {
        } else {
                // This happens only if the GRPC port (15010) is disabled. We 
will multiplex
                // it on the HTTP port. Does not impact the HTTPS gRPC or HTTPS.
-               fmt.Printf("multiplexing gRPC on http addr %v", 
args.ServerOptions.HTTPAddr)
+               klog.Infof("multiplexing gRPC on http addr %v", 
args.ServerOptions.HTTPAddr)
                multiplexGRPC = true
        }
        h2s := &http2.Server{
@@ -233,9 +234,9 @@ func (s *Server) serveHTTP() error {
                return err
        }
        go func() {
-               fmt.Printf("starting HTTP service at %s", httpListener.Addr())
+               klog.Infof("starting HTTP service at %s", httpListener.Addr())
                if err := s.httpServer.Serve(httpListener); 
network.IsUnexpectedListenerError(err) {
-                       fmt.Errorf("error serving http server: %v", err)
+                       klog.Errorf("error serving http server: %v", err)
                }
        }()
        s.httpAddr = httpListener.Addr().String()
@@ -261,12 +262,12 @@ func (s *Server) cachesSynced() bool {
 
 func (s *Server) waitForCacheSync(stop <-chan struct{}) bool {
        start := time.Now()
-       fmt.Println("\nWaiting for caches to be synced")
+       klog.Info("Waiting for caches to be synced")
        if !kubelib.WaitForCacheSync("server", stop, s.cachesSynced) {
-               fmt.Println("\nFailed waiting for cache sync")
+               klog.Info("Failed waiting for cache sync")
                return false
        }
-       fmt.Printf("\nAll controller caches have been synced up in %v\n", 
time.Since(start))
+       klog.Infof("All controller caches have been synced up in %v", 
time.Since(start))
        // TODO XDSServer.InboundUpdates.Load
        // TODO return kubelib.WaitForCacheSync("push context", stop, func() 
bool { return s.pushContextReady(expected) })
        return false
diff --git a/navigator/pkg/model/context.go b/navigator/pkg/model/context.go
index 959517c6..21db5c9d 100644
--- a/navigator/pkg/model/context.go
+++ b/navigator/pkg/model/context.go
@@ -19,9 +19,15 @@ package model
 
 import (
        "github.com/apache/dubbo-kubernetes/navigator/pkg/features"
+       "github.com/apache/dubbo-kubernetes/pkg/config/mesh"
+       "github.com/apache/dubbo-kubernetes/pkg/config/mesh/meshwatcher"
+       meshconfig "istio.io/api/mesh/v1alpha1"
 )
 
+type Watcher = meshwatcher.WatcherCollection
+
 type Environment struct {
+       Watcher
        Cache XdsCache
 }
 
@@ -43,3 +49,12 @@ func NewEnvironment() *Environment {
                Cache: cache,
        }
 }
+
+var _ mesh.Holder = &Environment{}
+
+func (e *Environment) Mesh() *meshconfig.MeshConfig {
+       if e != nil && e.Watcher != nil {
+               return e.Watcher.Mesh()
+       }
+       return nil
+}
diff --git a/pkg/config/mesh/kubemesh/watcher.go 
b/pkg/config/mesh/kubemesh/watcher.go
index 06797646..bbc43055 100644
--- a/pkg/config/mesh/kubemesh/watcher.go
+++ b/pkg/config/mesh/kubemesh/watcher.go
@@ -19,10 +19,10 @@ package kubemesh
 
 import (
        "fmt"
+       "github.com/apache/dubbo-kubernetes/pkg/config/mesh/meshwatcher"
        "github.com/apache/dubbo-kubernetes/pkg/kube"
        "github.com/apache/dubbo-kubernetes/pkg/kube/kclient"
        "github.com/apache/dubbo-kubernetes/pkg/kube/krt"
-       "github.com/apache/dubbo-kubernetes/pkg/mesh/meshwatcher"
        "github.com/apache/dubbo-kubernetes/pkg/ptr"
        v1 "k8s.io/api/core/v1"
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
diff --git a/pkg/mesh/mesh.go b/pkg/config/mesh/mesh.go
similarity index 100%
rename from pkg/mesh/mesh.go
rename to pkg/config/mesh/mesh.go
diff --git a/pkg/mesh/meshwatcher/collection.go 
b/pkg/config/mesh/meshwatcher/collection.go
similarity index 86%
rename from pkg/mesh/meshwatcher/collection.go
rename to pkg/config/mesh/meshwatcher/collection.go
index 1e4964fb..0c7d610d 100644
--- a/pkg/mesh/meshwatcher/collection.go
+++ b/pkg/config/mesh/meshwatcher/collection.go
@@ -18,22 +18,17 @@
 package meshwatcher
 
 import (
-       "fmt"
+       "github.com/apache/dubbo-kubernetes/pkg/config/mesh"
        "github.com/apache/dubbo-kubernetes/pkg/filewatcher"
        "github.com/apache/dubbo-kubernetes/pkg/kube/krt"
        krtfiles "github.com/apache/dubbo-kubernetes/pkg/kube/krt/files"
-       "github.com/apache/dubbo-kubernetes/pkg/mesh"
-       meshconfig "istio.io/api/mesh/v1alpha1"
+       "k8s.io/klog/v2"
        "os"
        "path"
 )
 
 type MeshConfigSource = krt.Singleton[string]
 
-type MeshConfigResource struct {
-       *meshconfig.MeshConfig
-}
-
 func NewFileSource(fileWatcher filewatcher.FileWatcher, filename string, opts 
krt.OptionsBuilder) (MeshConfigSource, error) {
        return krtfiles.NewFileSingleton[string](fileWatcher, filename, 
func(filename string) (string, error) {
                b, err := os.ReadFile(filename)
@@ -55,17 +50,17 @@ func NewCollection(opts krt.OptionsBuilder, sources 
...MeshConfigSource) krt.Sin
                        for _, attempt := range sources {
                                s := krt.FetchOne(ctx, attempt.AsCollection())
                                if s == nil {
-                                       fmt.Println("mesh configuration source 
missing")
+                                       klog.Info("mesh configuration source 
missing")
                                        continue
                                }
                                n, err := mesh.ApplyMeshConfig(*s, meshCfg)
                                if err != nil {
                                        if len(sources) == 1 {
-                                               fmt.Errorf("invalid mesh 
config, using last known state: %v", err)
+                                               klog.Errorf("invalid mesh 
config, using last known state: %v", err)
                                                ctx.DiscardResult()
                                                return 
&MeshConfigResource{mesh.DefaultMeshConfig()}
                                        }
-                                       fmt.Printf("invalid mesh config, 
ignoring: %v", err)
+                                       klog.Errorf("invalid mesh config, 
ignoring: %v", err)
                                        continue
                                }
                                meshCfg = n
diff --git a/pkg/config/mesh/meshwatcher/mesh.go 
b/pkg/config/mesh/meshwatcher/mesh.go
index 91cf13b0..dbaa07c4 100644
--- a/pkg/config/mesh/meshwatcher/mesh.go
+++ b/pkg/config/mesh/meshwatcher/mesh.go
@@ -18,11 +18,18 @@
 package meshwatcher
 
 import (
+       "github.com/apache/dubbo-kubernetes/pkg/config/mesh"
+       "github.com/apache/dubbo-kubernetes/pkg/kube/krt"
+       "github.com/apache/dubbo-kubernetes/pkg/util/protomarshal"
        "google.golang.org/protobuf/proto"
-
        meshconfig "istio.io/api/mesh/v1alpha1"
 )
 
+type WatcherCollection interface {
+       mesh.Watcher
+       krt.Singleton[MeshConfigResource]
+}
+
 // MeshConfigResource holds the current MeshConfig state
 type MeshConfigResource struct {
        *meshconfig.MeshConfig
@@ -34,13 +41,7 @@ func (m MeshConfigResource) Equals(other MeshConfigResource) 
bool {
        return proto.Equal(m.MeshConfig, other.MeshConfig)
 }
 
-// MeshNetworksResource holds the current MeshNetworks state
-type MeshNetworksResource struct {
-       *meshconfig.MeshNetworks
-}
-
-func (m MeshNetworksResource) ResourceName() string { return 
"MeshNetworksResource" }
-
-func (m MeshNetworksResource) Equals(other MeshNetworksResource) bool {
-       return proto.Equal(m.MeshNetworks, other.MeshNetworks)
+func PrettyFormatOfMeshConfig(meshConfig *meshconfig.MeshConfig) string {
+       meshConfigDump, _ := protomarshal.ToYAML(meshConfig)
+       return meshConfigDump
 }
diff --git a/pkg/config/mesh/watchers.go b/pkg/config/mesh/watchers.go
index ef0f2cec..45bbcabf 100644
--- a/pkg/config/mesh/watchers.go
+++ b/pkg/config/mesh/watchers.go
@@ -21,15 +21,6 @@ import (
        "istio.io/api/mesh/v1alpha1"
 )
 
-// NetworksWatcher watches changes to the mesh networks config.
-type NetworksWatcher interface {
-       // AddNetworksHandler registers a callback handler for changes to the 
networks config.
-       AddNetworksHandler(func()) *WatcherHandlerRegistration
-
-       // DeleteNetworksHandler unregisters a callback handler when remote 
cluster is removed.
-       DeleteNetworksHandler(registration *WatcherHandlerRegistration)
-}
-
 // Holder of a mesh configuration.
 type Holder interface {
        Mesh() *v1alpha1.MeshConfig
diff --git a/pkg/kube/client.go b/pkg/kube/client.go
index a4bf722e..ed208da9 100644
--- a/pkg/kube/client.go
+++ b/pkg/kube/client.go
@@ -37,6 +37,7 @@ import (
        "k8s.io/client-go/rest"
        "k8s.io/client-go/tools/cache"
        "k8s.io/client-go/tools/clientcmd"
+       "k8s.io/klog/v2"
        "net/http"
        "time"
 )
@@ -243,9 +244,9 @@ func WaitForCacheSync(name string, stop <-chan struct{}, 
cacheSyncs ...cache.Inf
        attempt := 0
        defer func() {
                if r {
-                       fmt.Printf("\nsync complete: name=%s, time=%v", name, 
time.Since(t0))
+                       klog.Infof("sync complete: name=%s, time=%v", name, 
time.Since(t0))
                } else {
-                       fmt.Printf("\nsync failed: name=%s, time=%v", name, 
time.Since(t0))
+                       klog.Infof("sync failed: name=%s, time=%v", name, 
time.Since(t0))
                }
        }()
        for {
diff --git a/pkg/kube/krt/collection.go b/pkg/kube/krt/collection.go
index fc0ae845..de44a063 100644
--- a/pkg/kube/krt/collection.go
+++ b/pkg/kube/krt/collection.go
@@ -25,6 +25,7 @@ import (
        "github.com/apache/dubbo-kubernetes/pkg/queue"
        "github.com/apache/dubbo-kubernetes/pkg/util/sets"
        "github.com/apache/dubbo-kubernetes/pkg/util/slices"
+       "k8s.io/klog/v2"
        "sync"
 )
 
@@ -592,7 +593,7 @@ func newManyCollection[I, O any](
 
        h.queue = queue.NewWithSync(func() {
                close(h.synced)
-               fmt.Printf("%v synced (uid %v)\n", h.name(), h.uid())
+               klog.Infof("%v synced (uid %v)", h.name(), h.uid())
        }, h.collectionName)
 
        go h.runQueue()
diff --git a/pkg/kube/krt/helpers.go b/pkg/kube/krt/helpers.go
index 1e70c5ef..3ad642bc 100644
--- a/pkg/kube/krt/helpers.go
+++ b/pkg/kube/krt/helpers.go
@@ -19,6 +19,7 @@ package krt
 
 import (
        "fmt"
+       "k8s.io/klog/v2"
        "reflect"
        "strconv"
        "strings"
@@ -148,16 +149,16 @@ func waitForCacheSync(name string, stop <-chan struct{}, 
collections ...<-chan s
        t0 := time.Now()
        defer func() {
                if r {
-                       fmt.Printf("\nsync complete: name=%s, time=%v\n", name, 
time.Since(t0))
+                       klog.Infof("sync complete: name=%s, time=%v", name, 
time.Since(t0))
                } else {
-                       fmt.Printf("\nsync failed: name=%s, time=%v\n", name, 
time.Since(t0))
+                       klog.Infof("sync failed: name=%s, time=%v", name, 
time.Since(t0))
                }
        }()
        for _, col := range collections {
                for {
                        select {
                        case <-t.C:
-                               fmt.Printf("waiting for sync...: name=%s, 
time=%v\n", name, time.Since(t0))
+                               klog.Infof("waiting for sync...: name=%s, 
time=%v\n", name, time.Since(t0))
                                continue
                        case <-stop:
                                return false
diff --git a/pkg/kube/krt/informer.go b/pkg/kube/krt/informer.go
index 231b9142..2dd05260 100644
--- a/pkg/kube/krt/informer.go
+++ b/pkg/kube/krt/informer.go
@@ -27,6 +27,7 @@ import (
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
        klabels "k8s.io/apimachinery/pkg/labels"
        "k8s.io/client-go/tools/cache"
+       "k8s.io/klog/v2"
 )
 
 var _ internalCollection[controllers.Object] = &informer[controllers.Object]{}
@@ -69,7 +70,7 @@ func WrapClient[I controllers.ComparableObject](c 
kclient.Informer[I], opts ...C
                        return
                }
                close(h.synced)
-               fmt.Printf("\n%v synced\n", h.name())
+               klog.Infof("%v synced", h.name())
 
                <-o.stop
        }()

Reply via email to