From 60187a6d0d96822ae88cf62970c8afb920593abd Mon Sep 17 00:00:00 2001 From: Cybwan Date: Mon, 16 Sep 2024 08:56:09 +0800 Subject: [PATCH] optimized sidecar's config.json. --- .../repo/codebase/modules/outbound-http-routing.js | 3 ++- pkg/sidecar/providers/pipy/repo/jobs.go | 3 ++- pkg/sidecar/providers/pipy/repo/policy.go | 11 +++++++---- pkg/sidecar/providers/pipy/repo/types.go | 4 ++-- pkg/sidecar/providers/pipy/repo/util.go | 3 +-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/pkg/sidecar/providers/pipy/repo/codebase/modules/outbound-http-routing.js b/pkg/sidecar/providers/pipy/repo/codebase/modules/outbound-http-routing.js index 83f2c86f8..fd591231c 100644 --- a/pkg/sidecar/providers/pipy/repo/codebase/modules/outbound-http-routing.js +++ b/pkg/sidecar/providers/pipy/repo/codebase/modules/outbound-http-routing.js @@ -1,5 +1,6 @@ (( config = pipy.solve('config.js'), + specServiceIdentity = config?.Spec?.ServiceIdentity, { shuffle, failover, @@ -72,7 +73,7 @@ (method, path, headers) => void ( tree[method]?.find?.(rule => rule(path, headers)), __service && ( - headers['serviceidentity'] = __service.ServiceIdentity + headers['serviceidentity'] = specServiceIdentity ) ) ) diff --git a/pkg/sidecar/providers/pipy/repo/jobs.go b/pkg/sidecar/providers/pipy/repo/jobs.go index 4d448933a..19e2bc532 100644 --- a/pkg/sidecar/providers/pipy/repo/jobs.go +++ b/pkg/sidecar/providers/pipy/repo/jobs.go @@ -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 { @@ -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) diff --git a/pkg/sidecar/providers/pipy/repo/policy.go b/pkg/sidecar/providers/pipy/repo/policy.go index 4d032b3fe..229018cdd 100644 --- a/pkg/sidecar/providers/pipy/repo/policy.go +++ b/pkg/sidecar/providers/pipy/repo/policy.go @@ -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 @@ -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) { diff --git a/pkg/sidecar/providers/pipy/repo/types.go b/pkg/sidecar/providers/pipy/repo/types.go index 3a5b71bb6..37f8da614 100644 --- a/pkg/sidecar/providers/pipy/repo/types.go +++ b/pkg/sidecar/providers/pipy/repo/types.go @@ -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 @@ -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 } diff --git a/pkg/sidecar/providers/pipy/repo/util.go b/pkg/sidecar/providers/pipy/repo/util.go index c5fb508db..352e6584b 100644 --- a/pkg/sidecar/providers/pipy/repo/util.go +++ b/pkg/sidecar/providers/pipy/repo/util.go @@ -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 @@ -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)