istio
92 строки · 3.4 Кб
1// Copyright Istio Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package options
16
17import (
18"os"
19"path/filepath"
20"strings"
21
22meshconfig "istio.io/api/mesh/v1alpha1"
23"istio.io/istio/pilot/pkg/features"
24"istio.io/istio/pilot/pkg/model"
25"istio.io/istio/pkg/bootstrap/platform"
26istioagent "istio.io/istio/pkg/istio-agent"
27"istio.io/istio/pkg/util/sets"
28"istio.io/istio/pkg/wasm"
29)
30
31// Similar with ISTIO_META_, which is used to customize the node metadata - this customizes extra header.
32const xdsHeaderPrefix = "XDS_HEADER_"
33
34func NewAgentOptions(proxy *model.Proxy, cfg *meshconfig.ProxyConfig) *istioagent.AgentOptions {
35var insecureRegistries []string
36if wasmInsecureRegistries != "" {
37insecureRegistries = strings.Split(wasmInsecureRegistries, ",")
38}
39o := &istioagent.AgentOptions{
40XDSRootCerts: xdsRootCA,
41CARootCerts: caRootCA,
42XDSHeaders: map[string]string{},
43XdsUdsPath: filepath.Join(cfg.ConfigPath, "XDS"),
44IsIPv6: proxy.IsIPv6(),
45ProxyType: proxy.Type,
46EnableDynamicProxyConfig: enableProxyConfigXdsEnv,
47WASMOptions: wasm.Options{
48InsecureRegistries: sets.New(insecureRegistries...),
49ModuleExpiry: wasmModuleExpiry,
50PurgeInterval: wasmPurgeInterval,
51HTTPRequestTimeout: wasmHTTPRequestTimeout,
52HTTPRequestMaxRetries: wasmHTTPRequestMaxRetries,
53},
54ProxyIPAddresses: proxy.IPAddresses,
55ServiceNode: proxy.ServiceNode(),
56EnvoyStatusPort: envoyStatusPortEnv,
57EnvoyPrometheusPort: envoyPrometheusPortEnv,
58MinimumDrainDuration: minimumDrainDurationEnv,
59ExitOnZeroActiveConnections: exitOnZeroActiveConnectionsEnv,
60Platform: platform.Discover(proxy.SupportsIPv6()),
61GRPCBootstrapPath: grpcBootstrapEnv,
62DisableEnvoy: disableEnvoyEnv,
63ProxyXDSDebugViaAgent: proxyXDSDebugViaAgent,
64ProxyXDSDebugViaAgentPort: proxyXDSDebugViaAgentPort,
65DNSCapture: DNSCaptureByAgent.Get(),
66DNSForwardParallel: DNSForwardParallel.Get(),
67DNSAddr: DNSCaptureAddr.Get(),
68ProxyNamespace: PodNamespaceVar.Get(),
69ProxyDomain: proxy.DNSDomain,
70IstiodSAN: istiodSAN.Get(),
71DualStack: features.EnableDualStack,
72UseExternalWorkloadSDS: useExternalWorkloadSDSEnv,
73MetadataDiscovery: enableWDSEnv,
74}
75extractXDSHeadersFromEnv(o)
76return o
77}
78
79// Simplified extraction of gRPC headers from environment.
80// Unlike ISTIO_META, where we need JSON and advanced features - this is just for small string headers.
81func extractXDSHeadersFromEnv(o *istioagent.AgentOptions) {
82envs := os.Environ()
83for _, e := range envs {
84if strings.HasPrefix(e, xdsHeaderPrefix) {
85parts := strings.SplitN(e, "=", 2)
86if len(parts) != 2 {
87continue
88}
89o.XDSHeaders[parts[0][len(xdsHeaderPrefix):]] = parts[1]
90}
91}
92}
93