Skip to content

Commit

Permalink
optimized sidecar's config.json.
Browse files Browse the repository at this point in the history
  • Loading branch information
cybwan committed Sep 16, 2024
1 parent 683b81a commit 60187a6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
((
config = pipy.solve('config.js'),
specServiceIdentity = config?.Spec?.ServiceIdentity,
{
shuffle,
failover,
Expand Down Expand Up @@ -72,7 +73,7 @@
(method, path, headers) => void (
tree[method]?.find?.(rule => rule(path, headers)),
__service && (
headers['serviceidentity'] = __service.ServiceIdentity
headers['serviceidentity'] = specServiceIdentity
)
)
)
Expand Down
3 changes: 2 additions & 1 deletion pkg/sidecar/providers/pipy/repo/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func outbound(cataloger catalog.MeshCataloger, s *Server, pipyConf *PipyConf, pr
}
}
}
outboundDependClusters := generatePipyOutboundTrafficRoutePolicy(cataloger, pipyConf, cfg, proxy, outboundTrafficPolicy, desiredSuffix)
outboundDependClusters := generatePipyOutboundTrafficRoutePolicy(cataloger, pipyConf, cfg, outboundTrafficPolicy, desiredSuffix)
if len(outboundDependClusters) > 0 {
if ready := generatePipyOutboundTrafficBalancePolicy(cataloger, cfg, proxy, pipyConf,
outboundTrafficPolicy, outboundDependClusters); !ready {
Expand Down Expand Up @@ -365,6 +365,7 @@ func features(s *Server, proxy *pipy.Proxy, pipyConf *PipyConf) {
if mc, ok := s.catalog.(*catalog.MeshCatalog); ok {
meshConf := mc.GetConfigurator()
proxy.MeshConf = meshConf
pipyConf.setServiceIdentity(proxy.Identity)
pipyConf.setSidecarLogLevel((*meshConf).GetMeshConfig().Spec.Sidecar.LogLevel)
pipyConf.setSidecarTimeout((*meshConf).GetMeshConfig().Spec.Sidecar.SidecarTimeout)
pipyConf.setEnableSidecarActiveHealthChecks((*meshConf).GetFeatureFlags().EnableSidecarActiveHealthChecks)
Expand Down
11 changes: 7 additions & 4 deletions pkg/sidecar/providers/pipy/repo/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ func (plugin *Pluggable) setPlugins(plugins map[string]*runtime.RawExtension) {
plugin.Plugins = plugins
}

func (p *PipyConf) setServiceIdentity(serviceIdentity identity.ServiceIdentity) (update bool) {
if update = p.Spec.ServiceIdentity != serviceIdentity; update {
p.Spec.ServiceIdentity = serviceIdentity
}
return
}

func (p *PipyConf) setSidecarLogLevel(sidecarLogLevel string) (update bool) {
if update = !strings.EqualFold(p.Spec.SidecarLogLevel, sidecarLogLevel); update {
p.Spec.SidecarLogLevel = sidecarLogLevel
Expand Down Expand Up @@ -727,10 +734,6 @@ func (hrrs *InboundHTTPRouteRules) newHTTPServiceRouteRule(matchRule *HTTPMatchR
return routeRule, false
}

func (hrrs *OutboundHTTPRouteRules) setServiceIdentity(serviceIdentity identity.ServiceIdentity) {
hrrs.ServiceIdentity = serviceIdentity
}

func (hrrs *OutboundHTTPRouteRules) newHTTPServiceRouteRule(matchRule *HTTPMatchRule) (route *OutboundHTTPRouteRule, duplicate bool) {
for _, routeRule := range hrrs.RouteRules {
if reflect.DeepEqual(*matchRule, routeRule.HTTPMatchRule) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/sidecar/providers/pipy/repo/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ type ObservabilitySpec struct {

// MeshConfigSpec represents the spec of mesh config
type MeshConfigSpec struct {
ServiceIdentity identity.ServiceIdentity
SidecarLogLevel string
SidecarTimeout int
Traffic TrafficSpec
Expand Down Expand Up @@ -364,8 +365,7 @@ type OutboundHTTPRouteRuleSlice []*OutboundHTTPRouteRule
// OutboundHTTPRouteRules is a wrapper type
type OutboundHTTPRouteRules struct {
RouteRules OutboundHTTPRouteRuleSlice `json:"RouteRules"`
ServiceIdentity identity.ServiceIdentity
EgressForwardGateway *string `json:"EgressForwardGateway,omitempty"`
EgressForwardGateway *string `json:"EgressForwardGateway,omitempty"`
Pluggable
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/sidecar/providers/pipy/repo/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func generatePipyInboundTrafficPolicy(meshCatalog catalog.MeshCataloger, pipyCon
}

func generatePipyOutboundTrafficRoutePolicy(_ catalog.MeshCataloger, pipyConf *PipyConf, cfg configurator.Configurator,
proxy *pipy.Proxy, outboundPolicy *trafficpolicy.OutboundMeshTrafficPolicy,
outboundPolicy *trafficpolicy.OutboundMeshTrafficPolicy,
desiredSuffix string) map[service.ClusterName]*WeightedCluster {
if len(outboundPolicy.TrafficMatches) == 0 {
return nil
Expand Down Expand Up @@ -171,7 +171,6 @@ func generatePipyOutboundTrafficRoutePolicy(_ catalog.MeshCataloger, pipyConf *P
for _, httpRouteConfig := range httpRouteConfigs {
ruleRef := &HTTPRouteRuleRef{RuleName: HTTPRouteRuleName(httpRouteConfig.Name)}
hsrrs := tm.newHTTPServiceRouteRules(ruleRef)
hsrrs.setServiceIdentity(proxy.Identity)
hsrrs.setPlugins(pipyConf.getTrafficMatchPluginConfigs(trafficMatch.Name))
for _, hostname := range httpRouteConfig.Hostnames {
tm.addHTTPHostPort2Service(HTTPHostPort(hostname), ruleRef, desiredSuffix)
Expand Down

0 comments on commit 60187a6

Please sign in to comment.