Skip to content

Commit

Permalink
Refactor v1.14.0 (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun authored Feb 21, 2023
1 parent bc1e845 commit 8b6389a
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 7 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ polaris-sidecar
test/cover.out
test/index.html
deploy/test.sh
*.log*
*.log*

logs/

.vscode
3 changes: 2 additions & 1 deletion deploy/vm/install-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ function install_polaris_sidecar() {
pushd ${polaris_sidecar_dirname}

# 修改 polaris_server_addr 地址
sed -i "s/##POLARIS_SERVER_ADDR##/${polaris_server_addr}/g" polaris.yaml
export POLARIS_ADDRESS="${polaris_server_addr}"
echo "POLARIS_ADDRESS=${POLARIS_ADDRESS}"
/bin/bash ./tool/start.sh
echo -e "[INFO] install polaris sidecar success"
popd
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRu
golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
Expand Down
3 changes: 1 addition & 2 deletions polaris-sidecar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ resolvers:
enable: true
suffix: "."
# option:
# route_labels:
# key: value
# route_labels: "key:value,key:value"
- name: meshproxy
dns_ttl: 120
enable: false
Expand Down
96 changes: 96 additions & 0 deletions resolver/meshproxy/base_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* Tencent is pleased to support the open source community by making Polaris available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package meshproxy

import (
"testing"

"github.com/polarismesh/polaris-go"
"github.com/polarismesh/polaris-go/api"
"github.com/polarismesh/polaris-go/pkg/model"
)

type MeshTestSuit struct {
r *envoyRegistry
}

func newMeshTestSuit(t *testing.T, conf *resolverConfig) (*MeshTestSuit, *MockConsumerAPI) {
mockConsumer := &MockConsumerAPI{}
r := &envoyRegistry{
conf: conf,
consumer: mockConsumer,
business: "",
}

return &MeshTestSuit{
r: r,
}, mockConsumer
}

type MockConsumerAPI struct {
mockRetSupplier func() *model.ServicesResponse
}

// GetOneInstance 同步获取单个服务
func (m *MockConsumerAPI) GetOneInstance(req *polaris.GetOneInstanceRequest) (*model.OneInstanceResponse, error) {
return nil, nil
}

// GetInstances 同步获取可用的服务列表
func (m *MockConsumerAPI) GetInstances(req *polaris.GetInstancesRequest) (*model.InstancesResponse, error) {
return nil, nil
}

// GetAllInstances 同步获取完整的服务列表
func (m *MockConsumerAPI) GetAllInstances(req *polaris.GetAllInstancesRequest) (*model.InstancesResponse, error) {
return nil, nil
}

// GetRouteRule 同步获取服务路由规则
func (m *MockConsumerAPI) GetRouteRule(req *polaris.GetServiceRuleRequest) (*model.ServiceRuleResponse, error) {
return nil, nil
}

// UpdateServiceCallResult 上报服务调用结果
func (m *MockConsumerAPI) UpdateServiceCallResult(req *polaris.ServiceCallResult) error {
return nil
}

// WatchService 订阅服务消息
func (m *MockConsumerAPI) WatchService(req *polaris.WatchServiceRequest) (*model.WatchServiceResponse, error) {
return nil, nil
}

// GetServices 根据业务同步获取批量服务
func (m *MockConsumerAPI) GetServices(req *polaris.GetServicesRequest) (*model.ServicesResponse, error) {
return m.mockRetSupplier(), nil
}

// InitCalleeService 初始化服务运行中需要的被调服务
func (m *MockConsumerAPI) InitCalleeService(req *polaris.InitCalleeServiceRequest) error {
return nil
}

// Destroy 销毁API,销毁后无法再进行调用
func (m *MockConsumerAPI) Destroy() {
}

// SDKContext 获取SDK上下文
func (m *MockConsumerAPI) SDKContext() api.SDKContext {
return nil
}
1 change: 1 addition & 0 deletions resolver/meshproxy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
)

type resolverConfig struct {
Namespace string `json:"namespace"`
RegistryHost string `json:"registry_host"`
RegistryPort int `json:"registry_port"`
ReloadIntervalSec int `json:"reload_interval_sec"`
Expand Down
10 changes: 9 additions & 1 deletion resolver/meshproxy/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ package meshproxy

import (
"context"
"github.com/polarismesh/polaris-go"
"time"

"github.com/polarismesh/polaris-go"

"github.com/miekg/dns"

"github.com/polarismesh/polaris-sidecar/log"
Expand Down Expand Up @@ -50,6 +51,7 @@ func (r *resolverMesh) Initialize(c *resolver.ConfigEntry) error {
if nil != err {
return err
}
r.config.Namespace = c.Namespace
r.consumer, err = polaris.NewConsumerAPI()
if nil != err {
return err
Expand Down Expand Up @@ -88,6 +90,12 @@ func (r *resolverMesh) ServeDNS(ctx context.Context, question dns.Question, qnam
log.Infof("[Mesh] suffix not matched for name %s, suffix %s", qname, r.suffix)
return nil
}
ret := r.localDNSServer.ServeDNS(ctx, &question, qname)
if ret != nil {
return ret
}
// 可能这个时候 qname 只有服务名称,这里手动补充 Namespace 信息
qname = qname + "." + r.config.Namespace
return r.localDNSServer.ServeDNS(ctx, &question, qname)
}

Expand Down
26 changes: 26 additions & 0 deletions resolver/meshproxy/plugin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Tencent is pleased to support the open source community by making Polaris available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package meshproxy

import (
"testing"
)

func Test_resolverMesh_ServeDNS(t *testing.T) {

}
2 changes: 1 addition & 1 deletion resolver/meshproxy/registry_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (r *envoyRegistry) GetCurrentNsService() (map[string]struct{}, error) {
}
services = make(map[string]struct{}, len(resp.GetValue()))
for _, svc := range resp.GetValue() {
services[svc.Service] = struct{}{}
// 这里必须全匹配的模式存储
services[svc.Service+"."+svc.Namespace] = struct{}{}
}
return services, nil
Expand Down

0 comments on commit 8b6389a

Please sign in to comment.