Skip to content

Commit fa8620a

Browse files
authored
Merge pull request #1438 from Flying-Tom/dual-engine-dns
Feat: Add Workload DnsController
2 parents 3d9cfcd + b74f106 commit fa8620a

File tree

13 files changed

+852
-42
lines changed

13 files changed

+852
-42
lines changed

.githooks/pre-commit

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
#
3+
# Kmesh pre-commit hook
4+
# This hook runs 'make clean' and 'make gen-check' before each commit
5+
# to ensure generated files are up-to-date and temporary files are cleaned up.
6+
#
7+
8+
set -e
9+
10+
echo "Running pre-commit checks..."
11+
12+
# Change to repository root
13+
REPO_ROOT=$(git rev-parse --show-toplevel)
14+
cd "$REPO_ROOT"
15+
16+
# Run make clean to restore auto-generated files
17+
echo "→ Running 'make clean'..."
18+
if ! make clean; then
19+
echo "❌ 'make clean' failed"
20+
exit 1
21+
fi
22+
23+
# Run make gen-check to verify generated files are up-to-date
24+
echo "→ Running 'make gen-check'..."
25+
if ! make gen-check; then
26+
echo "❌ 'make gen-check' failed"
27+
echo ""
28+
echo "Generated files are out of date. Please run 'make gen' and commit the changes."
29+
exit 1
30+
fi
31+
32+
echo "✅ Pre-commit checks passed"
33+
exit 0

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ oncn-mda/build/
5454
oncn-mda/deploy/
5555
test/mugen-master/
5656

57+
.github/copilot-instructions.md

README-zh.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ Kmesh创新性的提出将流量治理下沉OS,在数据路径上无需经过
115115
time="2024-02-19T10:16:53Z" level=info msg="bpf Start successful" subsys=manager
116116
time="2024-02-19T10:16:53Z" level=info msg="controller Start successful" subsys=manager
117117
time="2024-02-19T10:16:53Z" level=info msg="command StartServer successful" subsys=manager
118-
time="2024-02-19T10:16:53Z" level=info msg="start write CNI config\n" subsys="cni installer"
119-
time="2024-02-19T10:16:53Z" level=info msg="kmesh cni use chained\n" subsys="cni installer"
118+
time="2024-02-19T10:16:53Z" level=info msg="start write CNI config" subsys="cni installer"
119+
time="2024-02-19T10:16:53Z" level=info msg="kmesh cni use chained" subsys="cni installer"
120120
time="2024-02-19T10:16:54Z" level=info msg="Copied /usr/bin/kmesh-cni to /opt/cni/bin." subsys="cni installer"
121121
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"
122122
time="2024-02-19T10:16:54Z" level=info msg="wrote kubeconfig file /etc/cni/net.d/kmesh-cni-kubeconfig" subsys="cni installer"

pkg/cni/install.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ func (i *Installer) addCniConfig() error {
3535
if i.CniConfigChained {
3636
// "chained" is an cni type
3737
// information: www.cni.dev/docs/spec/#overview-1
38-
log.Infof("kmesh cni use chained\n")
38+
log.Infof("kmesh cni use chained")
3939
err = i.chainedKmeshCniPlugin(i.Mode, i.CniMountNetEtcDIR)
4040
if err != nil {
4141
return err
4242
}
4343
} else {
44-
log.Error("currently kmesh only support chained cni mode\n")
44+
log.Error("currently kmesh only support chained cni mode")
4545
}
4646
return nil
4747
}

pkg/controller/client.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,26 @@ type XdsClient struct {
5050
xdsConfig *config.XdsConfig
5151
}
5252

53-
func NewXdsClient(mode string, bpfAds *bpfads.BpfAds, bpfWorkload *bpfwl.BpfWorkload, enableMonitoring, enableProfiling bool) *XdsClient {
53+
func NewXdsClient(mode string, bpfAds *bpfads.BpfAds, bpfWorkload *bpfwl.BpfWorkload, enableMonitoring, enableProfiling bool) (*XdsClient, error) {
5454
client := &XdsClient{
5555
mode: mode,
5656
xdsConfig: config.GetConfig(mode),
5757
}
5858

59-
if mode == constants.DualEngineMode {
60-
client.WorkloadController = workload.NewController(bpfWorkload, enableMonitoring, enableProfiling)
61-
} else if mode == constants.KernelNativeMode {
59+
switch mode {
60+
case constants.DualEngineMode:
61+
var err error
62+
client.WorkloadController, err = workload.NewController(bpfWorkload, enableMonitoring, enableProfiling)
63+
if err != nil {
64+
return nil, fmt.Errorf("failed to create workload controller: %w", err)
65+
}
66+
case constants.KernelNativeMode:
6267
client.AdsController = ads.NewController(bpfAds)
6368
}
6469

6570
client.ctx, client.cancel = context.WithCancel(context.Background())
6671
client.ctx = metadata.AppendToOutgoingContext(client.ctx, "ClusterID", client.xdsConfig.Metadata.ClusterID.String())
67-
return client
72+
return client, nil
6873
}
6974

7075
func (c *XdsClient) createGrpcStreamClient() error {

pkg/controller/client_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ import (
3838

3939
func TestRecoverConnection(t *testing.T) {
4040
t.Run("test reconnect success", func(t *testing.T) {
41-
utClient := NewXdsClient(constants.KernelNativeMode, &bpfads.BpfAds{}, &bpfwl.BpfWorkload{}, false, false)
41+
utClient, err := NewXdsClient(constants.KernelNativeMode, &bpfads.BpfAds{}, &bpfwl.BpfWorkload{}, false, false)
42+
assert.NoError(t, err)
4243
patches := gomonkey.NewPatches()
4344
defer patches.Reset()
4445
iteration := 0
@@ -79,8 +80,9 @@ func TestClientResponseProcess(t *testing.T) {
7980
}))
8081
})
8182

82-
utClient := NewXdsClient(constants.KernelNativeMode, &bpfads.BpfAds{}, &bpfwl.BpfWorkload{}, false, false)
83-
err := utClient.createGrpcStreamClient()
83+
utClient, err := NewXdsClient(constants.KernelNativeMode, &bpfads.BpfAds{}, &bpfwl.BpfWorkload{}, false, false)
84+
assert.NoError(t, err)
85+
err = utClient.createGrpcStreamClient()
8486
assert.NoError(t, err)
8587

8688
reConnectPatches := gomonkey.NewPatches()
@@ -126,8 +128,9 @@ func TestClientResponseProcess(t *testing.T) {
126128
}))
127129
})
128130

129-
utClient := NewXdsClient(constants.DualEngineMode, &bpfads.BpfAds{}, &bpfwl.BpfWorkload{}, false, false)
130-
err := utClient.createGrpcStreamClient()
131+
utClient, err := NewXdsClient(constants.DualEngineMode, &bpfads.BpfAds{}, &bpfwl.BpfWorkload{}, false, false)
132+
assert.NoError(t, err)
133+
err = utClient.createGrpcStreamClient()
131134
assert.NoError(t, err)
132135

133136
reConnectPatches := gomonkey.NewPatches()

pkg/controller/controller.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,13 @@ func (c *Controller) Start(stopCh <-chan struct{}) error {
159159
}
160160
}
161161

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

164167
if c.client.WorkloadController != nil {
165-
if err := c.client.WorkloadController.Run(ctx); err != nil {
168+
if err := c.client.WorkloadController.Run(ctx, stopCh); err != nil {
166169
return fmt.Errorf("failed to start workload controller: %+v", err)
167170
}
168171
} else {

0 commit comments

Comments
 (0)