Skip to content

Commit 444cf76

Browse files
authored
Merge branch 'main' into TestCoverage2
2 parents 4f41f72 + 352bd8d commit 444cf76

File tree

12 files changed

+379
-38
lines changed

12 files changed

+379
-38
lines changed

ctl/secret/secret.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3131

3232
"kmesh.net/kmesh/ctl/utils"
33-
"kmesh.net/kmesh/pkg/controller/encryption/ipsec"
33+
"kmesh.net/kmesh/pkg/controller/encryption"
3434
"kmesh.net/kmesh/pkg/kube"
3535
"kmesh.net/kmesh/pkg/logger"
3636
)
@@ -118,7 +118,7 @@ func createKubeClientOrExit() kube.CLIClient {
118118
}
119119

120120
func CreateOrUpdateSecret(cmd *cobra.Command, args []string) {
121-
var ipSecKey, ipSecKeyOld ipsec.IpSecKey
121+
var ipSecKey, ipSecKeyOld encryption.IpSecKey
122122
var err error
123123

124124
ipSecKey.AeadKeyName = AeadAlgoName
@@ -215,7 +215,7 @@ func GetSecret() {
215215
}
216216

217217
// Parse the IPsec data
218-
var ipSecKey ipsec.IpSecKey
218+
var ipSecKey encryption.IpSecKey
219219
if err := json.Unmarshal(secret.Data["ipSec"], &ipSecKey); err != nil {
220220
log.Errorf("failed to unmarshal secret data: %v", err)
221221
os.Exit(1)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ require (
162162
github.com/prometheus/procfs v0.15.1 // indirect
163163
github.com/prometheus/prometheus v0.300.1 // indirect
164164
github.com/quic-go/qpack v0.5.1 // indirect
165-
github.com/quic-go/quic-go v0.48.2 // indirect
165+
github.com/quic-go/quic-go v0.49.1 // indirect
166166
github.com/rivo/uniseg v0.4.7 // indirect
167167
github.com/russross/blackfriday/v2 v2.1.0 // indirect
168168
github.com/ryanuber/go-glob v1.0.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ github.com/prometheus/prometheus v0.300.1 h1:9KKcTTq80gkzmXW0Et/QCFSrBPgmwiS3Hlc
369369
github.com/prometheus/prometheus v0.300.1/go.mod h1:gtTPY/XVyCdqqnjA3NzDMb0/nc5H9hOu1RMame+gHyM=
370370
github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=
371371
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
372-
github.com/quic-go/quic-go v0.48.2 h1:wsKXZPeGWpMpCGSWqOcqpW2wZYic/8T3aqiOID0/KWE=
373-
github.com/quic-go/quic-go v0.48.2/go.mod h1:yBgs3rWBOADpga7F+jJsb6Ybg1LSYiQvwWlLX+/6HMs=
372+
github.com/quic-go/quic-go v0.49.1 h1:e5JXpUyF0f2uFjckQzD8jTghZrOUK1xxDqqZhlwixo0=
373+
github.com/quic-go/quic-go v0.49.1/go.mod h1:s2wDnmCdooUQBmQfpUSTCYBl1/D4FcqbULMMkASvR6s=
374374
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
375375
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
376376
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=

hack/gen_bpf_specs.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ func main() {
167167
importPath := filepath.ToSlash(filepath.Join(modulePrefix, "bpf", "kmesh", "bpf2go", real))
168168
pi := pkgInfo{Alias: alias, ImportPath: importPath, OutputDir: real, Entries: list}
169169
pkgsDefault = append(pkgsDefault, pi)
170-
pkgsEnhanced = append(pkgsEnhanced, pi)
170+
if !strings.HasPrefix(real, "dualengine") {
171+
pkgsEnhanced = append(pkgsEnhanced, pi)
172+
}
171173
}
172174
}
173175
}

pkg/bpf/restart/new_version_mapspec_loader_enhanced.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/controller.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,13 @@ func (c *Controller) Start(stopCh <-chan struct{}) error {
168168
if err := c.client.WorkloadController.Run(ctx, stopCh); err != nil {
169169
return fmt.Errorf("failed to start workload controller: %+v", err)
170170
}
171+
if err := c.setupDNSProxy(); err != nil {
172+
return fmt.Errorf("failed to start dns proxy: %+v", err)
173+
}
171174
} else {
172175
c.client.AdsController.StartDnsController(stopCh)
173176
}
174177

175-
if err := c.setupDNSProxy(); err != nil {
176-
return fmt.Errorf("failed to start dns proxy: %+v", err)
177-
}
178-
179178
return c.client.Run(stopCh)
180179
}
181180

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright The Kmesh Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at:
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package encryption
18+
19+
type IpSecKey struct {
20+
Spi int `json:"spi"`
21+
AeadKeyName string `json:"aeadKeyName"`
22+
AeadKey []byte `json:"aeadKey"`
23+
Length int `json:"length"`
24+
}

pkg/controller/encryption/ipsec/ipsec_controller_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
"kmesh.net/kmesh/daemon/options"
4545
"kmesh.net/kmesh/pkg/bpf"
4646
"kmesh.net/kmesh/pkg/constants"
47+
"kmesh.net/kmesh/pkg/controller/encryption"
4748
"kmesh.net/kmesh/pkg/kube"
4849
v1alpha1 "kmesh.net/kmesh/pkg/kube/apis/kmeshnodeinfo/v1alpha1"
4950
fakeKmeshClientset "kmesh.net/kmesh/pkg/kube/nodeinfo/clientset/versioned/fake"
@@ -96,7 +97,7 @@ var (
9697
},
9798
}
9899

99-
testKey = IpSecKey{
100+
testKey = encryption.IpSecKey{
100101
Spi: 1,
101102
AeadKeyName: "rfc4106(gcm(aes))",
102103
AeadKey: DecodeHex("abc9410d7cd6b324461bf16db518646594276c5362c30fc476ebca3f1a394b6ed4462161"),

pkg/controller/encryption/ipsec/ipsec_handler.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,24 @@ import (
3232
"istio.io/istio/pkg/filewatcher"
3333

3434
"kmesh.net/kmesh/pkg/constants"
35+
"kmesh.net/kmesh/pkg/controller/encryption"
3536
"kmesh.net/kmesh/pkg/kube/apis/kmeshnodeinfo/v1alpha1"
3637
)
3738

3839
const (
3940
IpSecKeyFile = "./kmesh-ipsec/ipSec"
4041
)
4142

42-
type IpSecKey struct {
43-
Spi int `json:"spi"`
44-
AeadKeyName string `json:"aeadKeyName"`
45-
AeadKey []byte `json:"aeadKey"`
46-
Length int `json:"length"`
47-
}
48-
4943
type IpSecHandler struct {
5044
Spi int
5145
mutex sync.RWMutex
5246
watcher filewatcher.FileWatcher
53-
historyIpSecKey map[int]IpSecKey
47+
historyIpSecKey map[int]encryption.IpSecKey
5448
}
5549

5650
func NewIpSecHandler() *IpSecHandler {
5751
return &IpSecHandler{
58-
historyIpSecKey: make(map[int]IpSecKey),
52+
historyIpSecKey: make(map[int]encryption.IpSecKey),
5953
}
6054
}
6155

@@ -76,7 +70,7 @@ func (is *IpSecHandler) LoadIPSecKeyFromFile(filePath string) error {
7670
func (is *IpSecHandler) loadIPSecKeyFromIO(file *os.File) error {
7771
reader := bufio.NewReader(file)
7872
decoder := json.NewDecoder(reader)
79-
var key IpSecKey
73+
var key encryption.IpSecKey
8074
if err := decoder.Decode(&key); err != nil {
8175
return fmt.Errorf("ipsec config file decoder error, %v, please use Kmesh tool generate ipsec secret key", err)
8276
}
@@ -231,7 +225,7 @@ func (is *IpSecHandler) createXfrmRuleIngress(rawRemoteIP, rawLocalNicIP, remote
231225
* ip xfrm state add src {localNicIP} dst {remoteNicIP} proto esp spi {remoteSpi} mode tunnel reqid 1 {aead-algo} {aead-key} {aead-key-length}
232226
* ip xfrm policy add src 0.0.0.0/0 dst {remoteCIDR} dir out tmpl src {localNicIP} dst {remoteNicIP} proto esp spi {remoteSpi} reqid 1 mode tunnel mark 0x{remoteNodeID}00e0
233227
*/
234-
func (is *IpSecHandler) createXfrmRuleEgress(rawLocalNicIP, rawRemoteIP, localBootID, remoteBootID string, ipsecKey IpSecKey, podCIDRs []string) error {
228+
func (is *IpSecHandler) createXfrmRuleEgress(rawLocalNicIP, rawRemoteIP, localBootID, remoteBootID string, ipsecKey encryption.IpSecKey, podCIDRs []string) error {
235229
src := net.ParseIP(rawLocalNicIP)
236230
if src == nil {
237231
return fmt.Errorf("failed to parser ip in inserting xfrm rule, input: %v", rawLocalNicIP)
@@ -267,7 +261,7 @@ func (is *IpSecHandler) createXfrmRuleEgress(rawLocalNicIP, rawRemoteIP, localBo
267261
return nil
268262
}
269263

270-
func (is *IpSecHandler) createStateRule(src net.IP, dst net.IP, key []byte, ipsecKey IpSecKey, ingress bool) error {
264+
func (is *IpSecHandler) createStateRule(src net.IP, dst net.IP, key []byte, ipsecKey encryption.IpSecKey, ingress bool) error {
271265
state := &netlink.XfrmState{
272266
Src: src,
273267
Dst: dst,

pkg/controller/encryption/ipsec/ipsec_handler_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/vishvananda/netlink"
3333

3434
"kmesh.net/kmesh/pkg/constants"
35+
"kmesh.net/kmesh/pkg/controller/encryption"
3536
)
3637

3738
// DecodeHex is a utility function to decode a hex string into bytes.
@@ -48,13 +49,13 @@ func TestLoadIPSecKey(t *testing.T) {
4849
aeadKey := DecodeHex("2dc9410d7cd6b324461bf16db518646594276c5362c30fc476ebca3f1a394b6ed4462161")
4950
tests := []struct {
5051
name string
51-
keyData IpSecKey
52+
keyData encryption.IpSecKey
5253
expectError bool
5354
errorMsg string
5455
}{
5556
{ // Valid
5657
name: "valid_rfc4106_key",
57-
keyData: IpSecKey{
58+
keyData: encryption.IpSecKey{
5859
Spi: 1,
5960
AeadKeyName: "rfc4106(gcm(aes))",
6061
AeadKey: aeadKey,
@@ -64,7 +65,7 @@ func TestLoadIPSecKey(t *testing.T) {
6465
},
6566
{
6667
name: "invalid_algo_name",
67-
keyData: IpSecKey{
68+
keyData: encryption.IpSecKey{
6869
Spi: 3,
6970
AeadKeyName: "aes-gcm", // should start with "rfc"
7071
AeadKey: aeadKey,
@@ -75,7 +76,7 @@ func TestLoadIPSecKey(t *testing.T) {
7576
},
7677
{
7778
name: "empty_algo_name",
78-
keyData: IpSecKey{
79+
keyData: encryption.IpSecKey{
7980
Spi: 4,
8081
AeadKeyName: "",
8182
AeadKey: aeadKey,
@@ -161,13 +162,13 @@ func TestLoadIPSecKey(t *testing.T) {
161162
// Test multiple key loading (should update history)
162163
tests = []struct {
163164
name string
164-
keyData IpSecKey
165+
keyData encryption.IpSecKey
165166
expectError bool
166167
errorMsg string
167168
}{
168169
{
169170
name: "first_key",
170-
keyData: IpSecKey{
171+
keyData: encryption.IpSecKey{
171172
Spi: 1,
172173
AeadKeyName: "rfc4106(gcm(aes))",
173174
AeadKey: aeadKey,
@@ -177,7 +178,7 @@ func TestLoadIPSecKey(t *testing.T) {
177178
},
178179
{
179180
name: "second_key",
180-
keyData: IpSecKey{
181+
keyData: encryption.IpSecKey{
181182
Spi: 2,
182183
AeadKeyName: "rfc4106(gcm(aes))",
183184
AeadKey: DecodeHex("abc9410d7cd6b324461bf16db518646594276c5362c30fc476ebca3f1a394b6ed4462161"),
@@ -334,7 +335,7 @@ func hasStateRule(state *netlink.XfrmState) (bool, error) {
334335
func TestCreateStateRule(t *testing.T) {
335336
handler := NewIpSecHandler()
336337
testKey := DecodeHex("2dc9410d7cd6b324461bf16db518646594276c5362c30fc476ebca3f1a394b6ed4462161")
337-
ipsecKey := IpSecKey{
338+
ipsecKey := encryption.IpSecKey{
338339
Spi: 1001,
339340
AeadKeyName: "rfc4106(gcm(aes))",
340341
AeadKey: testKey,
@@ -536,7 +537,7 @@ func TestFlush(t *testing.T) {
536537

537538
// create state rule
538539
testKey := DecodeHex("2dc9410d7cd6b324461bf16db518646594276c5362c30fc476ebca3f1a394b6ed4462161")
539-
ipsecKey := IpSecKey{
540+
ipsecKey := encryption.IpSecKey{
540541
Spi: 1001,
541542
AeadKeyName: "rfc4106(gcm(aes))",
542543
AeadKey: testKey,

0 commit comments

Comments
 (0)