Skip to content

Commit 019ea9b

Browse files
committed
[navi] fmt replace klog library
1 parent 1a425a1 commit 019ea9b

File tree

13 files changed

+70
-57
lines changed

13 files changed

+70
-57
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ Provides support for building and deploying Dubbo applications in various enviro
1111
## Repositories
1212
The main code repositories of Dubbo on Kubernetes include:
1313

14-
- Dubbod — The Dubbo control plane. It is built on Istio to implement a proxyless service mesh and includes the following components:
14+
- [dubboctl](dubboctl/): This directory contains code for the command line utility.
15+
- [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.
16+
- dubbod — The dubbo control plane. It is built on Istio to implement a proxyless service mesh and includes the following components:
1517
- [navigator](navigator/) (under development): Responsible for configuring proxies at runtime.
16-
- [dubboctl](dubboctl/). This directory contains code for the command line utility.
17-
- [operator](operator/). Dubbo operator provides user friendly options to operate the Dubbo proxyless mesh
18-
- [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.
18+
- [Operator](operator/): Dubbo operator provides user friendly options to operate the Dubbo proxyless mesh.
1919

2020
## Quick Start
2121
Please refer to [official website](https://cn.dubbo.apache.org/zh-cn/overview/home/)

navigator/pkg/bootstrap/mesh.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,27 @@ import (
2121
"fmt"
2222
"github.com/apache/dubbo-kubernetes/navigator/pkg/features"
2323
"github.com/apache/dubbo-kubernetes/pkg/config/mesh/kubemesh"
24+
"github.com/apache/dubbo-kubernetes/pkg/config/mesh/meshwatcher"
2425
"github.com/apache/dubbo-kubernetes/pkg/filewatcher"
2526
"github.com/apache/dubbo-kubernetes/pkg/kube/krt"
26-
"github.com/apache/dubbo-kubernetes/pkg/mesh/meshwatcher"
2727
"github.com/apache/dubbo-kubernetes/pkg/ptr"
28+
"k8s.io/klog/v2"
2829
"os"
30+
"sigs.k8s.io/yaml"
2931
)
3032

3133
const (
3234
defaultMeshConfigMapName = "dubbo"
3335
)
3436

3537
func (s *Server) initMeshConfiguration(args *NaviArgs, fileWatcher filewatcher.FileWatcher) {
36-
fmt.Printf("\ninitializing mesh configuration %v\n", args.MeshConfigFile)
38+
klog.Infof("initializing mesh configuration %v", args.MeshConfigFile)
3739
col := s.getMeshConfiguration(args, fileWatcher)
3840
col.AsCollection().WaitUntilSynced(s.internalStop)
41+
42+
klog.Infof("mesh configuration: %s", meshwatcher.PrettyFormatOfMeshConfig(s.environment.Mesh()))
43+
argsdump, _ := yaml.Marshal(args)
44+
klog.Infof("flags: \n%s", argsdump)
3945
}
4046

4147
func (s *Server) getMeshConfiguration(args *NaviArgs, fileWatcher filewatcher.FileWatcher) krt.Singleton[meshwatcher.MeshConfigResource] {

navigator/pkg/bootstrap/server.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ import (
2525
"github.com/apache/dubbo-kubernetes/navigator/pkg/serviceregistry/providers"
2626
"github.com/apache/dubbo-kubernetes/navigator/pkg/xds"
2727
"github.com/apache/dubbo-kubernetes/pkg/cluster"
28+
"github.com/apache/dubbo-kubernetes/pkg/config/mesh"
2829
"github.com/apache/dubbo-kubernetes/pkg/filewatcher"
2930
"github.com/apache/dubbo-kubernetes/pkg/h2c"
3031
dubbokeepalive "github.com/apache/dubbo-kubernetes/pkg/keepalive"
3132
kubelib "github.com/apache/dubbo-kubernetes/pkg/kube"
32-
"github.com/apache/dubbo-kubernetes/pkg/mesh"
3333
"github.com/apache/dubbo-kubernetes/pkg/network"
3434
"golang.org/x/net/http2"
3535
"google.golang.org/grpc"
3636
"k8s.io/client-go/rest"
37+
"k8s.io/klog/v2"
3738
"net"
3839
"net/http"
3940
"os"
@@ -92,7 +93,7 @@ func NewServer(args *NaviArgs, initFuncs ...func(*Server)) (*Server, error) {
9293
}
9394

9495
func (s *Server) Start(stop <-chan struct{}) error {
95-
fmt.Printf("\nStarting Dubbod Server with primary cluster %s\n", s.clusterID)
96+
klog.Infof("Starting Dubbod Server with primary cluster %s", s.clusterID)
9697
if err := s.server.Start(stop); err != nil {
9798
return err
9899
}
@@ -107,9 +108,9 @@ func (s *Server) Start(stop <-chan struct{}) error {
107108
return err
108109
}
109110
go func() {
110-
fmt.Printf("starting secure gRPC discovery service at %s", grpcListener.Addr())
111+
klog.Infof("starting secure gRPC discovery service at %s", grpcListener.Addr())
111112
if err := s.secureGrpcServer.Serve(grpcListener); err != nil {
112-
fmt.Errorf("error serving secure GRPC server: %v", err)
113+
klog.Errorf("error serving secure GRPC server: %v", err)
113114
}
114115
}()
115116
}
@@ -120,9 +121,9 @@ func (s *Server) Start(stop <-chan struct{}) error {
120121
return err
121122
}
122123
go func() {
123-
fmt.Printf("starting gRPC discovery service at %s", grpcListener.Addr())
124+
klog.Infof("starting gRPC discovery service at %s", grpcListener.Addr())
124125
if err := s.grpcServer.Serve(grpcListener); err != nil {
125-
fmt.Errorf("error serving GRPC server: %v", err)
126+
klog.Errorf("error serving GRPC server: %v", err)
126127
}
127128
}()
128129
}
@@ -133,9 +134,9 @@ func (s *Server) Start(stop <-chan struct{}) error {
133134
return err
134135
}
135136
go func() {
136-
fmt.Printf("starting webhook service at %s", httpsListener.Addr())
137+
klog.Infof("starting webhook service at %s", httpsListener.Addr())
137138
if err := s.httpsServer.ServeTLS(httpsListener, "", ""); network.IsUnexpectedListenerError(err) {
138-
fmt.Errorf("error serving https server: %v", err)
139+
klog.Errorf("error serving https server: %v", err)
139140
}
140141
}()
141142
s.httpsAddr = httpsListener.Addr().String()
@@ -197,7 +198,7 @@ func (s *Server) initServers(args *NaviArgs) {
197198
} else {
198199
// This happens only if the GRPC port (15010) is disabled. We will multiplex
199200
// it on the HTTP port. Does not impact the HTTPS gRPC or HTTPS.
200-
fmt.Printf("multiplexing gRPC on http addr %v", args.ServerOptions.HTTPAddr)
201+
klog.Infof("multiplexing gRPC on http addr %v", args.ServerOptions.HTTPAddr)
201202
multiplexGRPC = true
202203
}
203204
h2s := &http2.Server{
@@ -233,9 +234,9 @@ func (s *Server) serveHTTP() error {
233234
return err
234235
}
235236
go func() {
236-
fmt.Printf("starting HTTP service at %s", httpListener.Addr())
237+
klog.Infof("starting HTTP service at %s", httpListener.Addr())
237238
if err := s.httpServer.Serve(httpListener); network.IsUnexpectedListenerError(err) {
238-
fmt.Errorf("error serving http server: %v", err)
239+
klog.Errorf("error serving http server: %v", err)
239240
}
240241
}()
241242
s.httpAddr = httpListener.Addr().String()
@@ -261,12 +262,12 @@ func (s *Server) cachesSynced() bool {
261262

262263
func (s *Server) waitForCacheSync(stop <-chan struct{}) bool {
263264
start := time.Now()
264-
fmt.Println("\nWaiting for caches to be synced")
265+
klog.Info("Waiting for caches to be synced")
265266
if !kubelib.WaitForCacheSync("server", stop, s.cachesSynced) {
266-
fmt.Println("\nFailed waiting for cache sync")
267+
klog.Info("Failed waiting for cache sync")
267268
return false
268269
}
269-
fmt.Printf("\nAll controller caches have been synced up in %v\n", time.Since(start))
270+
klog.Infof("All controller caches have been synced up in %v", time.Since(start))
270271
// TODO XDSServer.InboundUpdates.Load
271272
// TODO return kubelib.WaitForCacheSync("push context", stop, func() bool { return s.pushContextReady(expected) })
272273
return false

navigator/pkg/model/context.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ package model
1919

2020
import (
2121
"github.com/apache/dubbo-kubernetes/navigator/pkg/features"
22+
"github.com/apache/dubbo-kubernetes/pkg/config/mesh"
23+
"github.com/apache/dubbo-kubernetes/pkg/config/mesh/meshwatcher"
24+
meshconfig "istio.io/api/mesh/v1alpha1"
2225
)
2326

27+
type Watcher = meshwatcher.WatcherCollection
28+
2429
type Environment struct {
30+
Watcher
2531
Cache XdsCache
2632
}
2733

@@ -43,3 +49,12 @@ func NewEnvironment() *Environment {
4349
Cache: cache,
4450
}
4551
}
52+
53+
var _ mesh.Holder = &Environment{}
54+
55+
func (e *Environment) Mesh() *meshconfig.MeshConfig {
56+
if e != nil && e.Watcher != nil {
57+
return e.Watcher.Mesh()
58+
}
59+
return nil
60+
}

pkg/config/mesh/kubemesh/watcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ package kubemesh
1919

2020
import (
2121
"fmt"
22+
"github.com/apache/dubbo-kubernetes/pkg/config/mesh/meshwatcher"
2223
"github.com/apache/dubbo-kubernetes/pkg/kube"
2324
"github.com/apache/dubbo-kubernetes/pkg/kube/kclient"
2425
"github.com/apache/dubbo-kubernetes/pkg/kube/krt"
25-
"github.com/apache/dubbo-kubernetes/pkg/mesh/meshwatcher"
2626
"github.com/apache/dubbo-kubernetes/pkg/ptr"
2727
v1 "k8s.io/api/core/v1"
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
File renamed without changes.

pkg/mesh/meshwatcher/collection.go renamed to pkg/config/mesh/meshwatcher/collection.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,17 @@
1818
package meshwatcher
1919

2020
import (
21-
"fmt"
21+
"github.com/apache/dubbo-kubernetes/pkg/config/mesh"
2222
"github.com/apache/dubbo-kubernetes/pkg/filewatcher"
2323
"github.com/apache/dubbo-kubernetes/pkg/kube/krt"
2424
krtfiles "github.com/apache/dubbo-kubernetes/pkg/kube/krt/files"
25-
"github.com/apache/dubbo-kubernetes/pkg/mesh"
26-
meshconfig "istio.io/api/mesh/v1alpha1"
25+
"k8s.io/klog/v2"
2726
"os"
2827
"path"
2928
)
3029

3130
type MeshConfigSource = krt.Singleton[string]
3231

33-
type MeshConfigResource struct {
34-
*meshconfig.MeshConfig
35-
}
36-
3732
func NewFileSource(fileWatcher filewatcher.FileWatcher, filename string, opts krt.OptionsBuilder) (MeshConfigSource, error) {
3833
return krtfiles.NewFileSingleton[string](fileWatcher, filename, func(filename string) (string, error) {
3934
b, err := os.ReadFile(filename)
@@ -55,17 +50,17 @@ func NewCollection(opts krt.OptionsBuilder, sources ...MeshConfigSource) krt.Sin
5550
for _, attempt := range sources {
5651
s := krt.FetchOne(ctx, attempt.AsCollection())
5752
if s == nil {
58-
fmt.Println("mesh configuration source missing")
53+
klog.Info("mesh configuration source missing")
5954
continue
6055
}
6156
n, err := mesh.ApplyMeshConfig(*s, meshCfg)
6257
if err != nil {
6358
if len(sources) == 1 {
64-
fmt.Errorf("invalid mesh config, using last known state: %v", err)
59+
klog.Errorf("invalid mesh config, using last known state: %v", err)
6560
ctx.DiscardResult()
6661
return &MeshConfigResource{mesh.DefaultMeshConfig()}
6762
}
68-
fmt.Printf("invalid mesh config, ignoring: %v", err)
63+
klog.Errorf("invalid mesh config, ignoring: %v", err)
6964
continue
7065
}
7166
meshCfg = n

pkg/config/mesh/meshwatcher/mesh.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,18 @@
1818
package meshwatcher
1919

2020
import (
21+
"github.com/apache/dubbo-kubernetes/pkg/config/mesh"
22+
"github.com/apache/dubbo-kubernetes/pkg/kube/krt"
23+
"github.com/apache/dubbo-kubernetes/pkg/util/protomarshal"
2124
"google.golang.org/protobuf/proto"
22-
2325
meshconfig "istio.io/api/mesh/v1alpha1"
2426
)
2527

28+
type WatcherCollection interface {
29+
mesh.Watcher
30+
krt.Singleton[MeshConfigResource]
31+
}
32+
2633
// MeshConfigResource holds the current MeshConfig state
2734
type MeshConfigResource struct {
2835
*meshconfig.MeshConfig
@@ -34,13 +41,7 @@ func (m MeshConfigResource) Equals(other MeshConfigResource) bool {
3441
return proto.Equal(m.MeshConfig, other.MeshConfig)
3542
}
3643

37-
// MeshNetworksResource holds the current MeshNetworks state
38-
type MeshNetworksResource struct {
39-
*meshconfig.MeshNetworks
40-
}
41-
42-
func (m MeshNetworksResource) ResourceName() string { return "MeshNetworksResource" }
43-
44-
func (m MeshNetworksResource) Equals(other MeshNetworksResource) bool {
45-
return proto.Equal(m.MeshNetworks, other.MeshNetworks)
44+
func PrettyFormatOfMeshConfig(meshConfig *meshconfig.MeshConfig) string {
45+
meshConfigDump, _ := protomarshal.ToYAML(meshConfig)
46+
return meshConfigDump
4647
}

pkg/config/mesh/watchers.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ import (
2121
"istio.io/api/mesh/v1alpha1"
2222
)
2323

24-
// NetworksWatcher watches changes to the mesh networks config.
25-
type NetworksWatcher interface {
26-
// AddNetworksHandler registers a callback handler for changes to the networks config.
27-
AddNetworksHandler(func()) *WatcherHandlerRegistration
28-
29-
// DeleteNetworksHandler unregisters a callback handler when remote cluster is removed.
30-
DeleteNetworksHandler(registration *WatcherHandlerRegistration)
31-
}
32-
3324
// Holder of a mesh configuration.
3425
type Holder interface {
3526
Mesh() *v1alpha1.MeshConfig

pkg/kube/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"k8s.io/client-go/rest"
3838
"k8s.io/client-go/tools/cache"
3939
"k8s.io/client-go/tools/clientcmd"
40+
"k8s.io/klog/v2"
4041
"net/http"
4142
"time"
4243
)
@@ -243,9 +244,9 @@ func WaitForCacheSync(name string, stop <-chan struct{}, cacheSyncs ...cache.Inf
243244
attempt := 0
244245
defer func() {
245246
if r {
246-
fmt.Printf("\nsync complete: name=%s, time=%v", name, time.Since(t0))
247+
klog.Infof("sync complete: name=%s, time=%v", name, time.Since(t0))
247248
} else {
248-
fmt.Printf("\nsync failed: name=%s, time=%v", name, time.Since(t0))
249+
klog.Infof("sync failed: name=%s, time=%v", name, time.Since(t0))
249250
}
250251
}()
251252
for {

0 commit comments

Comments
 (0)