Skip to content

Commit 441d806

Browse files
authored
Refactor v1.14.0 (#65)
* mod:update go.mod file * fix:修复mesh模式服务名错误匹配问题 * fix:修复mesh模式服务名错误匹配问题 * fix:search name需要递归处理
1 parent 24660e1 commit 441d806

File tree

3 files changed

+105
-10
lines changed

3 files changed

+105
-10
lines changed

bootstrap/dns.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,23 @@ func (d *dnsHandler) preprocess(qname string) string {
4242
if len(d.searchNames) == 0 {
4343
return qname
4444
}
45-
for _, searchName := range d.searchNames {
46-
if strings.HasSuffix(qname, searchName) {
47-
return qname[:len(qname)-len(searchName)]
45+
46+
var matched bool
47+
48+
for {
49+
for _, searchName := range d.searchNames {
50+
if strings.HasSuffix(qname, searchName) {
51+
matched = true
52+
qname = qname[:len(qname)-len(searchName)]
53+
}
4854
}
55+
56+
if !matched {
57+
break
58+
}
59+
matched = false
4960
}
61+
5062
return qname
5163
}
5264

bootstrap/dns_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* Tencent is pleased to support the open source community by making Polaris available.
3+
*
4+
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5+
*
6+
* Licensed under the BSD 3-Clause License (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://opensource.org/licenses/BSD-3-Clause
11+
*
12+
* Unless required by applicable law or agreed to in writing, software distributed
13+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations under the License.
16+
*/
17+
18+
package bootstrap
19+
20+
import (
21+
"testing"
22+
)
23+
24+
func Test_dnsHandler_preprocess(t *testing.T) {
25+
type fields struct {
26+
searchNames []string
27+
}
28+
type args struct {
29+
qname string
30+
}
31+
tests := []struct {
32+
name string
33+
fields fields
34+
args args
35+
want string
36+
}{
37+
{
38+
name: "",
39+
fields: fields{
40+
searchNames: []string{"polaris-system.svc.cluster.local.", "svc.cluster.local.", "cluster.local."},
41+
},
42+
args: args{
43+
qname: "polaris.polaris-system.polaris-system.svc.cluster.local.",
44+
},
45+
want: "polaris.polaris-system.",
46+
},
47+
{
48+
name: "",
49+
fields: fields{
50+
searchNames: []string{"polaris-system.svc.cluster.local.", "svc.cluster.local.", "cluster.local."},
51+
},
52+
args: args{
53+
qname: "polaris.polaris-system.",
54+
},
55+
want: "polaris.polaris-system.",
56+
},
57+
{
58+
name: "",
59+
fields: fields{
60+
searchNames: []string{"polaris-system.svc.cluster.local.", "svc.cluster.local.", "cluster.local."},
61+
},
62+
args: args{
63+
qname: "polaris.polaris-system.svc.cluster.local.",
64+
},
65+
want: "polaris.",
66+
},
67+
{
68+
name: "",
69+
fields: fields{
70+
searchNames: []string{"svc.cluster.local.", "polaris-system.svc.cluster.local.", "cluster.local."},
71+
},
72+
args: args{
73+
qname: "polaris.polaris-system.svc.cluster.local.",
74+
},
75+
want: "polaris.polaris-system.",
76+
},
77+
}
78+
for _, tt := range tests {
79+
t.Run(tt.name, func(t *testing.T) {
80+
d := &dnsHandler{
81+
searchNames: tt.fields.searchNames,
82+
}
83+
if got := d.preprocess(tt.args.qname); got != tt.want {
84+
t.Errorf("dnsHandler.preprocess() = %v, want %v", got, tt.want)
85+
}
86+
})
87+
}
88+
}

deploy/k8s/deployment-dnsagent.yaml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ metadata:
2626
app: polaris-sidecar-dns
2727
name: polaris-sidecar-dns
2828
spec:
29-
podManagementPolicy: OrderedReady
3029
replicas: 1
3130
selector:
3231
matchLabels:
@@ -37,7 +36,7 @@ spec:
3736
app: polaris-sidecar-dns
3837
spec:
3938
containers:
40-
- image: polarismesh/polaris-sidecar:lastest
39+
- image: polarismesh/polaris-sidecar:latest
4140
imagePullPolicy: Always
4241
name: polaris-sidecar
4342
command: ["./polaris-sidecar"]
@@ -72,7 +71,7 @@ spec:
7271
runAsNonRoot: false
7372
runAsUser: 0
7473
volumeMounts:
75-
- mountPath: /root/polaris.yaml
74+
- mountPath: /data/polaris.yaml
7675
name: polaris-client-config
7776
subPath: polaris.yaml
7877
terminationMessagePath: /dev/termination-log
@@ -83,7 +82,3 @@ spec:
8382
defaultMode: 420
8483
name: polaris-client-config
8584
name: polaris-client-config
86-
updateStrategy:
87-
rollingUpdate:
88-
partition: 0
89-
type: RollingUpdate

0 commit comments

Comments
 (0)