Skip to content

Commit

Permalink
refactor:优化鉴权相关功能开关以及修复NPE问题
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun committed Jun 15, 2023
1 parent 952fce5 commit 3bba163
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
12 changes: 5 additions & 7 deletions apiserver/xdsserverv3/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,14 @@ func (x *XDSServer) getRegistryInfoWithCache(ctx context.Context, registryInfo m
}

// 获取routing配置
routeResp := x.namingServer.GetRoutingConfigWithCache(ctx, s)
if routeResp.GetCode().Value != api.ExecuteSuccess {
log.Errorf("error sync routing for %s, info : %s", svc.Name, routeResp.Info.GetValue())
routerRule, err := x.namingServer.Cache().RoutingConfig().GetRouterConfigV2("", svc.Name, svc.Namespace)
if err != nil {
log.Errorf("error sync routing for %s, info : %s", svc.Name, err.Error())
return fmt.Errorf("[XDSV3] error sync routing for %s", svc.Name)
}

if routeResp.Routing != nil {
svc.SvcRoutingRevision = routeResp.Routing.Revision.Value
svc.Routing = routeResp.Routing
}
svc.SvcRoutingRevision = routerRule.GetRevision().GetValue()
svc.Routing = routerRule

// 获取instance配置
resp := x.namingServer.ServiceInstancesCache(ctx, s)
Expand Down
16 changes: 14 additions & 2 deletions cache/routing_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type (
Cache
// GetRouterConfig Obtain routing configuration based on serviceid
GetRouterConfig(id, service, namespace string) (*apitraffic.Routing, error)
// GetRouterConfig Obtain routing configuration based on serviceid
GetRouterConfigV2(id, service, namespace string) (*apitraffic.Routing, error)
// GetRoutingConfigCount Get the total number of routing configuration cache
GetRoutingConfigCount() int
// QueryRoutingConfigsV2 Query Route Configuration List
Expand Down Expand Up @@ -147,8 +149,8 @@ func (rc *routingConfigCache) name() string {
return RoutingConfigName
}

// GetRouterConfig Obtain routing configuration based on serviceid
func (rc *routingConfigCache) GetRouterConfig(id, service, namespace string) (*apitraffic.Routing, error) {
// GetRouterConfigV2 Obtain routing configuration based on serviceid
func (rc *routingConfigCache) GetRouterConfigV2(id, service, namespace string) (*apitraffic.Routing, error) {
if id == "" && service == "" && namespace == "" {
return nil, nil
}
Expand Down Expand Up @@ -186,6 +188,16 @@ func (rc *routingConfigCache) GetRouterConfig(id, service, namespace string) (*a
return formatRoutingResponseV1(resp), nil
}

// GetRouterConfig Obtain routing configuration based on serviceid
func (rc *routingConfigCache) GetRouterConfig(id, service, namespace string) (*apitraffic.Routing, error) {
ret, err := rc.GetRouterConfigV2(id, service, namespace)
if err != nil {
return nil, err
}
ret.Rules = nil
return ret, nil
}

// formatRoutingResponseV1 Give the client's cache, no need to expose EXTENDINFO information data
func formatRoutingResponseV1(ret *apitraffic.Routing) *apitraffic.Routing {
inBounds := ret.Inbounds
Expand Down

0 comments on commit 3bba163

Please sign in to comment.