Skip to content

Commit

Permalink
Merge pull request kmesh-net#1007 from hzxuzhonghu/minor-fixes
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
kmesh-bot authored Nov 7, 2024
2 parents 05da66b + cce43a9 commit 52d8f9e
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 168 deletions.
2 changes: 1 addition & 1 deletion daemon/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func Execute(configs *options.BootstrapConfigs) error {
stopCh := make(chan struct{})
defer close(stopCh)

c := controller.NewController(configs, bpfLoader.GetBpfKmesh(), bpfLoader.GetBpfWorkload(), configs.BpfConfig.BpfFsPath, configs.BpfConfig.EnableBpfLog, configs.BpfConfig.EnableAccesslog)
c := controller.NewController(configs, bpfLoader.GetBpfKmesh(), bpfLoader.GetBpfWorkload())
if err := c.Start(stopCh); err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions daemon/options/bpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type BpfConfig struct {
EnableMda bool
EnableBpfLog bool
EnableAccesslog bool
EnableProfiling bool
}

func (c *BpfConfig) AttachFlags(cmd *cobra.Command) {
Expand All @@ -41,6 +42,7 @@ func (c *BpfConfig) AttachFlags(cmd *cobra.Command) {
cmd.PersistentFlags().BoolVar(&c.EnableMda, "enable-mda", false, "enable mda")
cmd.PersistentFlags().BoolVar(&c.EnableBpfLog, "enable-bpf-log", false, "enable ebpf log in daemon process")
cmd.PersistentFlags().BoolVar(&c.EnableAccesslog, "enable-accesslog", false, "enable accesslog in daemon process")
cmd.PersistentFlags().BoolVar(&c.EnableProfiling, "profiling", false, "whether to enable profiling or not, default to false")
}

func (c *BpfConfig) ParseConfig() error {
Expand Down
7 changes: 2 additions & 5 deletions daemon/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type BootstrapConfigs struct {
CniConfig *cniConfig
ByPassConfig *byPassConfig
SecretManagerConfig *secretConfig
PerfConfig *perfConfig
}

func NewBootstrapConfigs() *BootstrapConfigs {
Expand All @@ -38,7 +37,6 @@ func NewBootstrapConfigs() *BootstrapConfigs {
CniConfig: &cniConfig{},
ByPassConfig: &byPassConfig{},
SecretManagerConfig: &secretConfig{},
PerfConfig: &perfConfig{},
}
}

Expand All @@ -56,15 +54,14 @@ func (c *BootstrapConfigs) AttachFlags(cmd *cobra.Command) {
c.CniConfig.AttachFlags(cmd)
c.ByPassConfig.AttachFlags(cmd)
c.SecretManagerConfig.AttachFlags(cmd)
c.PerfConfig.AttachFlags(cmd)
}

func (c *BootstrapConfigs) ParseConfigs() error {
if err := c.BpfConfig.ParseConfig(); err != nil {
return fmt.Errorf("parse BpfConfig failed, %s", err)
return fmt.Errorf("parse BpfConfig failed, %v", err)
}
if err := c.CniConfig.ParseConfig(); err != nil {
return fmt.Errorf("parse CniConfig failed, %s", err)
return fmt.Errorf("parse CniConfig failed, %v", err)
}
return nil
}
29 changes: 0 additions & 29 deletions daemon/options/perf.go

This file was deleted.

4 changes: 2 additions & 2 deletions pkg/controller/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ type XdsClient struct {
xdsConfig *config.XdsConfig
}

func NewXdsClient(mode string, bpfAds *bpfads.BpfAds, bpfWorkload *bpfwl.BpfWorkload, enableAccesslog bool) *XdsClient {
func NewXdsClient(mode string, bpfAds *bpfads.BpfAds, bpfWorkload *bpfwl.BpfWorkload, enableAccesslog, enableProfiling bool) *XdsClient {
client := &XdsClient{
mode: mode,
xdsConfig: config.GetConfig(mode),
}

if mode == constants.DualEngineMode {
client.WorkloadController = workload.NewController(bpfWorkload, enableAccesslog)
client.WorkloadController = workload.NewController(bpfWorkload, enableAccesslog, enableProfiling)
} else if mode == constants.KernelNativeMode {
client.AdsController = ads.NewController(bpfAds)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (

func TestRecoverConnection(t *testing.T) {
t.Run("test reconnect success", func(t *testing.T) {
utClient := NewXdsClient(constants.KernelNativeMode, &bpfads.BpfAds{}, &bpfwl.BpfWorkload{}, false)
utClient := NewXdsClient(constants.KernelNativeMode, &bpfads.BpfAds{}, &bpfwl.BpfWorkload{}, false, false)
patches := gomonkey.NewPatches()
defer patches.Reset()
iteration := 0
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestClientResponseProcess(t *testing.T) {
}))
})

utClient := NewXdsClient(constants.KernelNativeMode, &bpfads.BpfAds{}, &bpfwl.BpfWorkload{}, false)
utClient := NewXdsClient(constants.KernelNativeMode, &bpfads.BpfAds{}, &bpfwl.BpfWorkload{}, false, false)
err := utClient.createGrpcStreamClient()
assert.NoError(t, err)

Expand Down Expand Up @@ -126,7 +126,7 @@ func TestClientResponseProcess(t *testing.T) {
}))
})

utClient := NewXdsClient(constants.DualEngineMode, &bpfads.BpfAds{}, &bpfwl.BpfWorkload{}, false)
utClient := NewXdsClient(constants.DualEngineMode, &bpfads.BpfAds{}, &bpfwl.BpfWorkload{}, false, false)
err := utClient.createGrpcStreamClient()
assert.NoError(t, err)

Expand Down
16 changes: 11 additions & 5 deletions pkg/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"encoding/json"
"strings"

config_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
corev3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
"google.golang.org/protobuf/types/known/structpb"
"istio.io/istio/pkg/cluster"
"istio.io/istio/pkg/model"
Expand Down Expand Up @@ -53,6 +53,7 @@ type XdsConfig struct {
ServiceNode string
DiscoveryAddress string
Metadata *model.BootstrapNodeMetadata
Node *corev3.Node
}

func NewXDSConfig(mode string) *XdsConfig {
Expand All @@ -68,6 +69,7 @@ func NewXDSConfig(mode string) *XdsConfig {
nodeName := env.Register("NODE_NAME", "", "").Get()
meshID := env.Register("MESH_ID", "cluster.local", "").Get()

// TODO: fix it once we want to support VM application
ip := localHostIPv4
if podIP != "" {
ip = podIP
Expand All @@ -77,7 +79,7 @@ func NewXDSConfig(mode string) *XdsConfig {

c.ServiceNode = strings.Join([]string{getNodeRole(mode), ip, id, dnsDomain}, serviceNodeSeparator)

log.Infof("service node %v connect to discovery address %v", c.ServiceNode, c.DiscoveryAddress)
log.Infof("proxy %v connect to discovery address %v", c.ServiceNode, c.DiscoveryAddress)

c.Metadata.Namespace = podNamespace
c.Metadata.ClusterID = cluster.ID(clusterID)
Expand All @@ -99,16 +101,20 @@ func GetConfig(mode string) *XdsConfig {
return config
}

// TODO(hzxuzhonhu): this is frequently called, cache the node later
func (c *XdsConfig) GetNode() *config_core_v3.Node {
func (c *XdsConfig) GetNode() *corev3.Node {
if c.Node != nil {
return c.Node
}

nodeMetadata, err := nodeMetadataToStruct(c.Metadata)
if err != nil {
log.Fatalf("failed to convert node metadata to struct, %v", err)
}
return &config_core_v3.Node{
c.Node = &corev3.Node{
Id: c.ServiceNode,
Metadata: nodeMetadata,
}
return c.Node
}

func nodeMetadataToStruct(meta *model.BootstrapNodeMetadata) (*structpb.Struct, error) {
Expand Down
39 changes: 16 additions & 23 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,48 +44,41 @@ type Controller struct {
client *XdsClient
enableByPass bool
enableSecretManager bool
bpfFsPath string
enableBpfLog bool
enableAccesslog bool
enablePerfMonitor bool
bpfConfig *options.BpfConfig
}

func NewController(opts *options.BootstrapConfigs, bpfAdsObj *bpfads.BpfAds, bpfWorkloadObj *bpfwl.BpfWorkload, bpfFsPath string, enableBpfLog, enableAccesslog bool) *Controller {
func NewController(opts *options.BootstrapConfigs, bpfAdsObj *bpfads.BpfAds, bpfWorkloadObj *bpfwl.BpfWorkload) *Controller {
return &Controller{
mode: opts.BpfConfig.Mode,
enableByPass: opts.ByPassConfig.EnableByPass,
bpfAdsObj: bpfAdsObj,
bpfWorkloadObj: bpfWorkloadObj,
enableSecretManager: opts.SecretManagerConfig.Enable,
bpfFsPath: bpfFsPath,
enableBpfLog: enableBpfLog,
enableAccesslog: enableAccesslog,
enablePerfMonitor: opts.PerfConfig.EnablePerfMonitor,
bpfConfig: opts.BpfConfig,
}
}

func (c *Controller) Start(stopCh <-chan struct{}) error {
var secertManager *security.SecretManager
var err error
var kmeshManageController *manage.KmeshManageController

if c.mode == constants.DualEngineMode && c.enableSecretManager {
secertManager, err = security.NewSecretManager()
if err != nil {
return fmt.Errorf("secretManager create failed: %v", err)
}
go secertManager.Run(stopCh)
}

clientset, err := utils.GetK8sclient()
if err != nil {
return err
}

if c.mode == constants.DualEngineMode {
var secertManager *security.SecretManager
if c.enableSecretManager {
secertManager, err = security.NewSecretManager()
if err != nil {
return fmt.Errorf("secretManager create failed: %v", err)
}
go secertManager.Run(stopCh)
}
kmeshManageController, err = manage.NewKmeshManageController(clientset, secertManager, c.bpfWorkloadObj.XdpAuth.XdpShutdown.FD(), c.mode)
} else {
kmeshManageController, err = manage.NewKmeshManageController(clientset, secertManager, -1, c.mode)
kmeshManageController, err = manage.NewKmeshManageController(clientset, nil, -1, c.mode)
}
if err != nil {
return fmt.Errorf("failed to start kmesh manage controller: %v", err)
Expand All @@ -103,15 +96,15 @@ func (c *Controller) Start(stopCh <-chan struct{}) error {
return nil
}

if c.enableBpfLog {
if err := logger.StartRingBufReader(ctx, c.mode, c.bpfFsPath); err != nil {
if c.bpfConfig.EnableBpfLog {
if err := logger.StartRingBufReader(ctx, c.mode, c.bpfConfig.BpfFsPath); err != nil {
return fmt.Errorf("fail to start ringbuf reader: %v", err)
}
}
c.client = NewXdsClient(c.mode, c.bpfAdsObj, c.bpfWorkloadObj, c.enableAccesslog)
c.client = NewXdsClient(c.mode, c.bpfAdsObj, c.bpfWorkloadObj, c.bpfConfig.EnableAccesslog, c.bpfConfig.EnableProfiling)

if c.client.WorkloadController != nil {
c.client.WorkloadController.Run(ctx, c.enablePerfMonitor)
c.client.WorkloadController.Run(ctx)
}

if c.client.AdsController != nil {
Expand Down
Loading

0 comments on commit 52d8f9e

Please sign in to comment.