Skip to content

Commit

Permalink
fix: kubernetes部署configmap调整 & 修复 boltdb 存储在的 clients 查询问题 (#368)
Browse files Browse the repository at this point in the history
* fix: kubernetes部署configmap调整

* fix: 修复api_mock编辑脚本

* refactor: 修复store中的api_mock问题

* fix: 修复boltdb存储clients无法查询问题

* fix: 修复github-action

* fix: 修复鉴权问题

* fix: 移除错误的权限判断逻辑

* refactor: 调整方法名称

* refactor: 调整prometheus的默认端口

* fix: 修复cache中遗漏client配置

* fix: 单机版本client查询修复
  • Loading branch information
chuntaojun authored May 7, 2022
1 parent dce2672 commit 83df2b2
Show file tree
Hide file tree
Showing 17 changed files with 158 additions and 45 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ jobs:
with:
go-version: 1.16.5

- name: Get version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}

- name: Build
id: build
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
VERSION: ${{ steps.get_version.outputs.VERSION }}
run: |
bash build.sh
bash build.sh ${VERSION}
PACKAGE_NAME=$(ls | grep polaris-server-release*.zip | sed -n '1p')
echo ::set-output name=name::${PACKAGE_NAME}
Expand Down
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ workdir=$(dirname $(realpath $0))
version=$(cat version 2>/dev/null)
bin_name="polaris-server"

if [ $# == 1 ]; then
version=$1
fi

if [ "${GOOS}" == "windows" ]; then
bin_name="polaris-server.exe"
fi
Expand Down
23 changes: 17 additions & 6 deletions cache/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,15 +487,26 @@ func (sc *strategyCache) getStrategyDetails(uid string, gid string) []*model.Str
func (sc *strategyCache) IsResourceLinkStrategy(resType api.ResourceType, resId string) bool {
switch resType {
case api.ResourceType_Namespaces:
_, ok := sc.namespace2Strategy.Load(resId)
return ok
val, ok := sc.namespace2Strategy.Load(resId)
return ok && hasLinkRule(val.(*sync.Map))
case api.ResourceType_Services:
_, ok := sc.service2Strategy.Load(resId)
return ok
val, ok := sc.service2Strategy.Load(resId)
return ok && hasLinkRule(val.(*sync.Map))
case api.ResourceType_ConfigGroups:
_, ok := sc.configGroup2Strategy.Load(resId)
return ok
val, ok := sc.configGroup2Strategy.Load(resId)
return ok && hasLinkRule(val.(*sync.Map))
default:
return true
}
}

func hasLinkRule(val *sync.Map) bool {
count := 0

val.Range(func(key, value interface{}) bool {
count++
return true
})

return count != 0
}
4 changes: 4 additions & 0 deletions common/model/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func (c *Client) Proto() *api.Client {
return c.proto
}

func (c *Client) SetValid(v bool) {
c.valid = v
}

func (c *Client) Valid() bool {
return c.valid
}
Expand Down
2 changes: 2 additions & 0 deletions deploy/helm/README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ $ helm uninstall `${release_name}`
|polaris.storage.service.httpPort | polaris service 暴露,polaris-server 监听的 http 端口|
|polaris.storage.service.grpcPort | polaris service 暴露,polaris-server 监听的 grpc 端口|
|polaris.storage.service.webPort | polaris service 暴露,polaris-server 监听的 web 端口|
|polaris.auth.consoleOpen | polaris 打开控制台接口鉴权,默认开启|
|polaris.auth.clientOpen | polaris 打开客户端接口鉴权,默认关闭|
|monitor.port | 客户端上报监控信息的端口|
|installation.namespace | 部署polaris组件所在的namespace|

Expand Down
2 changes: 2 additions & 0 deletions deploy/helm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,7 @@ The currently supported configurations are as follows:
|polaris.storage.service.httpPort | polaris service expose, polaris-server listening http port number|
|polaris.storage.service.grpcPort | polaris service expose, polaris-server listening grpc port number|
|polaris.storage.service.webPort | polaris service expose, polaris-server listening web port number|
|polaris.auth.consoleOpen | polaris open the console interface auth, open the default|
|polaris.auth.clientOpen | polaris open the client interface auth, close the default|
|monitor.port | The port through which the client reports monitoring information|
|installation.namespace | namespace for polaris installation|
15 changes: 13 additions & 2 deletions deploy/helm/templates/polaris-server-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ data:
openConnLimit: false
maxConnPerHost: 128
maxConnLimit: 10240
- name: prometheusserver
option:
listenIP: "0.0.0.0"
listenPort: {{ .Values.service.prometheusPort }}
connLimit:
openConnLimit: false
maxConnPerHost: 128
maxConnLimit: 10240
# - name: l5pbserver
# option:
# listenIP: 0.0.0.0
Expand All @@ -162,8 +170,10 @@ data:
name: defaultAuth
option:
salt: polarismesh@2021
consoleOpen: true
clientOpen: false
consoleOpen: {{ .Values.polaris.auth.consoleOpen }}
clientOpen: {{ .Values.polaris.auth.clientOpen }}
namespace:
autoCreate: true
naming:
auth:
open: false
Expand Down Expand Up @@ -234,6 +244,7 @@ data:
- name: users
- name: strategyRule
- name: namespace
- name: client
# - name: l5 # 加载l5数据
# 存储配置
store:
Expand Down
4 changes: 4 additions & 0 deletions deploy/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ polaris:
cpu: "500m"
memory: "1000Mi"
replicaCount: 1
auth:
consoleOpen: true
clientOpen: false
storage:
db:
address: localhost:3306
Expand All @@ -41,6 +44,7 @@ service:
webPort: 8080
xdsv3Port: 15010
configGrpcPort: 8093
prometheusPort: 9000

monitor:
port: 9091
Expand Down
11 changes: 11 additions & 0 deletions deploy/standalone/k8s/01-polaris-server-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ data:
openConnLimit: false
maxConnPerHost: 128
maxConnLimit: 10240
- name: prometheusserver
option:
listenIP: "0.0.0.0"
listenPort: 9000
connLimit:
openConnLimit: false
maxConnPerHost: 128
maxConnLimit: 10240
# - name: l5pbserver
# option:
# listenIP: 0.0.0.0
Expand All @@ -169,6 +177,8 @@ data:
salt: polarismesh@2021
consoleOpen: true
clientOpen: false
namespace:
autoCreate: true
naming:
auth:
open: false
Expand Down Expand Up @@ -236,6 +246,7 @@ data:
- name: users
- name: strategyRule
- name: namespace
- name: client
# - name: l5 # 加载l5数据
# 存储配置
store:
Expand Down
4 changes: 0 additions & 4 deletions namespace/namespace_authability.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ func (svr *serverAuthAbility) GetNamespaces(ctx context.Context, query map[strin
api.ResourceType_Namespaces, ns.Id.GetValue())
}
ns.Editable = utils.NewBoolValue(editable)
// 如果当前登录账户为该资源的主账户,则允许直接进行操作
if ns.Owners.GetValue() == utils.ParseUserID(ctx) {
ns.Editable = utils.NewBoolValue(true)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion polaris-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ apiservers:
- name: prometheusserver
option:
listenIP: "0.0.0.0"
listenPort: 19090
listenPort: 9000
connLimit:
openConnLimit: false
maxConnPerHost: 128
Expand Down
4 changes: 3 additions & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ func (s *Server) CreateService(ctx context.Context, req *api.Service) *api.Respo
Token: utils.NewStringValue(data.Token),
}

s.afterServiceResource(ctx, req, data, false)
if err := s.afterServiceResource(ctx, req, data, false); err != nil {
return api.NewResponseWithMsg(api.ExecuteException, err.Error())
}

return api.NewServiceResponse(api.ExecuteSuccess, out)
}
Expand Down
4 changes: 0 additions & 4 deletions service/service_alias_authability.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ func (svr *serverAuthAbility) GetServiceAliases(ctx context.Context,
api.ResourceType_Services, svc.ID)
}
alias.Editable = utils.NewBoolValue(editable)
// 如果当前登录账户为该资源的主账户,则允许直接进行操作
if alias.Owners.GetValue() == utils.ParseUserID(ctx) {
alias.Editable = utils.NewBoolValue(true)
}
}
}
return resp
Expand Down
4 changes: 0 additions & 4 deletions service/service_authability.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ func (svr *serverAuthAbility) GetServices(ctx context.Context, query map[string]
api.ResourceType_Services, svc.Id.GetValue())
}
svc.Editable = utils.NewBoolValue(editable)
// 如果当前登录账户为该资源的主账户,则允许直接进行操作
if svc.Owners.GetValue() == utils.ParseUserID(ctx) {
svc.Editable = utils.NewBoolValue(true)
}
}
}
return resp
Expand Down
52 changes: 31 additions & 21 deletions store/boltdb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,23 @@ import (
"github.com/boltdb/bolt"
api "github.com/polarismesh/polaris-server/common/api/v1"
"github.com/polarismesh/polaris-server/common/model"
commontime "github.com/polarismesh/polaris-server/common/time"
"github.com/polarismesh/polaris-server/common/utils"
"go.uber.org/zap"
)

const (
tblClient string = "client"

ClientFieldHost string = "Host"
ClientFieldType string = "Type"
ClientFieldVersion string = "Version"
ClientFieldLocation string = "Location"
ClientFieldId string = "Id"
ClientFieldStat string = "Stat"
ClientFieldCtime string = "Ctime"
ClientFieldMtime string = "Mtime"
ClientFieldHost string = "Host"
ClientFieldType string = "Type"
ClientFieldVersion string = "Version"
ClientFieldLocation string = "Location"
ClientFieldId string = "Id"
ClientFieldStatArrStr string = "StatArrStr"
ClientFieldCtime string = "Ctime"
ClientFieldMtime string = "Mtime"
ClientFieldValid string = "Valid"
)

type clientObject struct {
Expand All @@ -58,7 +61,7 @@ type clientStore struct {

// BatchAddClients insert the client info
func (cs *clientStore) BatchAddClients(clients []*model.Client) error {
err := cs.handler.Execute(true, func(tx *bolt.Tx) error {
if err := cs.handler.Execute(true, func(tx *bolt.Tx) error {
for i := range clients {
client := clients[i]
saveVal, err := convertToClientObject(client)
Expand All @@ -71,9 +74,8 @@ func (cs *clientStore) BatchAddClients(clients []*model.Client) error {
}
}
return nil
})

if err != nil {
}); err != nil {
log.Error("[Client] batch add clients", zap.Error(err))
return err
}

Expand All @@ -82,7 +84,12 @@ func (cs *clientStore) BatchAddClients(clients []*model.Client) error {

// BatchDeleteClients delete the client info
func (cs *clientStore) BatchDeleteClients(ids []string) error {
return cs.handler.DeleteValues(tblClient, ids, true)
if err := cs.handler.DeleteValues(tblClient, ids, true); err != nil {
log.Error("[Client] batch delete clients", zap.Error(err))
return err
}

return nil
}

// GetMoreClients 根据mtime获取增量clients,返回所有store的变更信息
Expand All @@ -99,22 +106,23 @@ func (cs *clientStore) GetMoreClients(mtime time.Time, firstUpdate bool) (map[st
})

if err != nil {
log.Error("[Client] get more clients for cache", zap.Error(err))
return nil, err
}

clients := make([]*model.Client, 0, len(ret))
clients := make(map[string]*model.Client, len(ret))

for _, v := range ret {
for k, v := range ret {
client, err := convertToModelClient(v.(*clientObject))

if err != nil {
log.Error("[Client] convert clientObject to model.Client", zap.Error(err))
return nil, err
}

clients = append(clients, client)
clients[k] = client
}

return nil, nil
return clients, nil
}

func convertToClientObject(client *model.Client) (*clientObject, error) {
Expand Down Expand Up @@ -155,8 +163,8 @@ func convertToModelClient(client *clientObject) (*model.Client, error) {
Host: utils.NewStringValue(client.Host),
Type: api.Client_ClientType(api.Client_ClientType_value[client.Type]),
Version: utils.NewStringValue(client.Version),
Ctime: utils.NewStringValue(client.Ctime.Format("2006-01-02 15:04:05")),
Mtime: utils.NewStringValue(client.Mtime.Format("2006-01-02 15:04:05")),
Ctime: utils.NewStringValue(commontime.Time2String(client.Ctime)),
Mtime: utils.NewStringValue(commontime.Time2String(client.Mtime)),
Location: &api.Location{
Region: utils.NewStringValue(client.Location["region"]),
Zone: utils.NewStringValue(client.Location["zone"]),
Expand All @@ -165,5 +173,7 @@ func convertToModelClient(client *clientObject) (*model.Client, error) {
Stat: stat,
}

return model.NewClient(c), nil
mc := model.NewClient(c)
mc.SetValid(client.Valid)
return mc, nil
}
Loading

0 comments on commit 83df2b2

Please sign in to comment.