@@ -47,16 +47,22 @@ func (t *Translator) ProcessGlobalResources(resources *resource.Resources, xdsIR
4747 }
4848
4949 for _ , xdsIR := range xdsIRs {
50- if containsGlobalRateLimit (xdsIR .HTTP ) || containsWasm (xdsIR .HTTP ) {
50+ hasRateLimit , hasWasm , hasSystemTrustStore := scanXdsIR (xdsIR )
51+ if hasRateLimit || hasWasm || hasSystemTrustStore {
5152 if xdsIR .GlobalResources == nil {
5253 xdsIR .GlobalResources = & ir.GlobalResources {}
5354 }
55+ }
56+ if hasRateLimit || hasWasm {
5457 xdsIR .GlobalResources .EnvoyClientCertificate = & ir.TLSCertificate {
5558 Name : irGlobalConfigName (envoyTLSSecret ),
5659 Certificate : envoyTLSSecret .Data [corev1 .TLSCertKey ],
5760 PrivateKey : envoyTLSSecret .Data [corev1 .TLSPrivateKeyKey ],
5861 }
5962 }
63+ if hasSystemTrustStore {
64+ xdsIR .GlobalResources .UseSystemTrustStore = true
65+ }
6066 }
6167
6268 return nil
@@ -101,27 +107,47 @@ func irGlobalConfigName(object metav1.Object) string {
101107 return fmt .Sprintf ("%s/%s" , object .GetNamespace (), object .GetName ())
102108}
103109
104- func containsGlobalRateLimit (httpListeners []* ir.HTTPListener ) bool {
105- for _ , httpListener := range httpListeners {
106- for _ , route := range httpListener .Routes {
107- if route .Traffic != nil &&
110+ // scanXdsIR scans the xDS IR in a single pass and returns flags for features
111+ // that require global resources to be created.
112+ func scanXdsIR (xdsIR * ir.Xds ) (hasGlobalRateLimit , hasWasm , hasSystemTrustStore bool ) {
113+ for _ , http := range xdsIR .HTTP {
114+ for _ , route := range http .Routes {
115+ if ! hasGlobalRateLimit && route .Traffic != nil &&
108116 route .Traffic .RateLimit != nil &&
109117 route .Traffic .RateLimit .Global != nil {
110- return true
118+ hasGlobalRateLimit = true
119+ }
120+ if ! hasWasm && route .EnvoyExtensions != nil &&
121+ len (route .EnvoyExtensions .Wasms ) > 0 {
122+ hasWasm = true
123+ }
124+ if ! hasSystemTrustStore && route .Destination != nil {
125+ for _ , ds := range route .Destination .Settings {
126+ if ds .TLS != nil && ds .TLS .UseSystemTrustStore {
127+ hasSystemTrustStore = true
128+ break
129+ }
130+ }
131+ }
132+ if hasGlobalRateLimit && hasWasm && hasSystemTrustStore {
133+ return hasGlobalRateLimit , hasWasm , hasSystemTrustStore
111134 }
112135 }
113136 }
114- return false
115- }
116-
117- func containsWasm (httpListeners []* ir.HTTPListener ) bool {
118- for _ , httpListener := range httpListeners {
119- for _ , route := range httpListener .Routes {
120- if route .EnvoyExtensions != nil &&
121- len (route .EnvoyExtensions .Wasms ) > 0 {
122- return true
137+ if ! hasSystemTrustStore {
138+ for _ , tcp := range xdsIR .TCP {
139+ for _ , route := range tcp .Routes {
140+ if route .Destination == nil {
141+ continue
142+ }
143+ for _ , ds := range route .Destination .Settings {
144+ if ds .TLS != nil && ds .TLS .UseSystemTrustStore {
145+ hasSystemTrustStore = true
146+ return hasGlobalRateLimit , hasWasm , hasSystemTrustStore
147+ }
148+ }
123149 }
124150 }
125151 }
126- return false
152+ return hasGlobalRateLimit , hasWasm , hasSystemTrustStore
127153}
0 commit comments