Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
#
# Kmesh pre-commit hook
# This hook runs 'make clean' and 'make gen-check' before each commit
# to ensure generated files are up-to-date and temporary files are cleaned up.
#

set -e

echo "Running pre-commit checks..."

# Change to repository root
REPO_ROOT=$(git rev-parse --show-toplevel)
cd "$REPO_ROOT"

# Run make clean to restore auto-generated files
echo "→ Running 'make clean'..."
if ! make clean; then
echo "❌ 'make clean' failed"
exit 1
fi

# Run make gen-check to verify generated files are up-to-date
echo "→ Running 'make gen-check'..."
if ! make gen-check; then
echo "❌ 'make gen-check' failed"
echo ""
echo "Generated files are out of date. Please run 'make gen' and commit the changes."
exit 1
fi

echo "✅ Pre-commit checks passed"
exit 0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ oncn-mda/build/
oncn-mda/deploy/
test/mugen-master/

.github/copilot-instructions.md
4 changes: 2 additions & 2 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ Kmesh创新性的提出将流量治理下沉OS,在数据路径上无需经过
time="2024-02-19T10:16:53Z" level=info msg="bpf Start successful" subsys=manager
time="2024-02-19T10:16:53Z" level=info msg="controller Start successful" subsys=manager
time="2024-02-19T10:16:53Z" level=info msg="command StartServer successful" subsys=manager
time="2024-02-19T10:16:53Z" level=info msg="start write CNI config\n" subsys="cni installer"
time="2024-02-19T10:16:53Z" level=info msg="kmesh cni use chained\n" subsys="cni installer"
time="2024-02-19T10:16:53Z" level=info msg="start write CNI config" subsys="cni installer"
time="2024-02-19T10:16:53Z" level=info msg="kmesh cni use chained" subsys="cni installer"
time="2024-02-19T10:16:54Z" level=info msg="Copied /usr/bin/kmesh-cni to /opt/cni/bin." subsys="cni installer"
time="2024-02-19T10:16:54Z" level=info msg="kubeconfig either does not exist or is out of date, writing a new one" subsys="cni installer"
time="2024-02-19T10:16:54Z" level=info msg="wrote kubeconfig file /etc/cni/net.d/kmesh-cni-kubeconfig" subsys="cni installer"
Expand Down
4 changes: 2 additions & 2 deletions pkg/cni/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ func (i *Installer) addCniConfig() error {
if i.CniConfigChained {
// "chained" is an cni type
// information: www.cni.dev/docs/spec/#overview-1
log.Infof("kmesh cni use chained\n")
log.Infof("kmesh cni use chained")
err = i.chainedKmeshCniPlugin(i.Mode, i.CniMountNetEtcDIR)
if err != nil {
return err
}
} else {
log.Error("currently kmesh only support chained cni mode\n")
log.Error("currently kmesh only support chained cni mode")
}
return nil
}
Expand Down
15 changes: 10 additions & 5 deletions pkg/controller/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,26 @@ type XdsClient struct {
xdsConfig *config.XdsConfig
}

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

if mode == constants.DualEngineMode {
client.WorkloadController = workload.NewController(bpfWorkload, enableMonitoring, enableProfiling)
} else if mode == constants.KernelNativeMode {
switch mode {
case constants.DualEngineMode:
var err error
client.WorkloadController, err = workload.NewController(bpfWorkload, enableMonitoring, enableProfiling)
if err != nil {
return nil, fmt.Errorf("failed to create workload controller: %w", err)
}
case constants.KernelNativeMode:
client.AdsController = ads.NewController(bpfAds)
}

client.ctx, client.cancel = context.WithCancel(context.Background())
client.ctx = metadata.AppendToOutgoingContext(client.ctx, "ClusterID", client.xdsConfig.Metadata.ClusterID.String())
return client
return client, nil
}

func (c *XdsClient) createGrpcStreamClient() error {
Expand Down
13 changes: 8 additions & 5 deletions pkg/controller/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ import (

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

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

reConnectPatches := gomonkey.NewPatches()
Expand Down Expand Up @@ -126,8 +128,9 @@ func TestClientResponseProcess(t *testing.T) {
}))
})

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

reConnectPatches := gomonkey.NewPatches()
Expand Down
7 changes: 5 additions & 2 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,13 @@ func (c *Controller) Start(stopCh <-chan struct{}) error {
}
}

c.client = NewXdsClient(c.mode, c.bpfAdsObj, c.bpfWorkloadObj, c.bpfConfig.EnableMonitoring, c.bpfConfig.EnableProfiling)
c.client, err = NewXdsClient(c.mode, c.bpfAdsObj, c.bpfWorkloadObj, c.bpfConfig.EnableMonitoring, c.bpfConfig.EnableProfiling)
if err != nil {
return fmt.Errorf("failed to create XDS client: %w", err)
}

if c.client.WorkloadController != nil {
if err := c.client.WorkloadController.Run(ctx); err != nil {
if err := c.client.WorkloadController.Run(ctx, stopCh); err != nil {
return fmt.Errorf("failed to start workload controller: %+v", err)
}
} else {
Expand Down
Loading
Loading