1
// Copyright Istio Authors
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
7
// http://www.apache.org/licenses/LICENSE-2.0
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.
23
"github.com/spf13/cobra"
24
// To install the xds resolvers and balancers.
25
_ "google.golang.org/grpc/xds"
27
"istio.io/istio/pkg/cmd"
28
"istio.io/istio/pkg/config/protocol"
29
"istio.io/istio/pkg/log"
30
"istio.io/istio/pkg/test/echo/common"
31
"istio.io/istio/pkg/test/echo/server"
42
localhostIPPorts []int
43
serverFirstPorts []int
54
loggingOptions = log.DefaultOptions()
56
rootCmd = &cobra.Command{
58
Short: "Echo server application.",
60
Long: `Echo application for testing Istio E2E`,
61
PersistentPreRunE: configureLogging,
62
Run: func(cmd *cobra.Command, args []string) {
63
ports := make(common.PortList, len(httpPorts)+len(grpcPorts)+len(tcpPorts)+len(udpPorts)+len(hbonePorts))
64
tlsByPort := map[int]bool{}
65
for _, p := range tlsPorts {
68
serverFirstByPort := map[int]bool{}
69
for _, p := range serverFirstPorts {
70
serverFirstByPort[p] = true
72
xdsGRPCByPort := map[int]bool{}
73
for _, p := range xdsGRPCServers {
74
xdsGRPCByPort[p] = true
77
for i, p := range httpPorts {
78
ports[portIndex] = &common.Port{
79
Name: "http-" + strconv.Itoa(i),
80
Protocol: protocol.HTTP,
83
ServerFirst: serverFirstByPort[p],
87
for i, p := range grpcPorts {
88
ports[portIndex] = &common.Port{
89
Name: "grpc-" + strconv.Itoa(i),
90
Protocol: protocol.GRPC,
93
ServerFirst: serverFirstByPort[p],
94
XDSServer: xdsGRPCByPort[p],
98
for i, p := range tcpPorts {
99
ports[portIndex] = &common.Port{
100
Name: "tcp-" + strconv.Itoa(i),
101
Protocol: protocol.TCP,
104
ServerFirst: serverFirstByPort[p],
108
for i, p := range udpPorts {
109
ports[portIndex] = &common.Port{
110
Name: "udp-" + strconv.Itoa(i),
111
Protocol: protocol.UDP,
116
for i, p := range hbonePorts {
117
ports[portIndex] = &common.Port{
118
Name: "hbone-" + strconv.Itoa(i),
119
Protocol: protocol.HBONE,
125
instanceIPByPort := map[int]struct{}{}
126
for _, p := range instanceIPPorts {
127
instanceIPByPort[p] = struct{}{}
129
localhostIPByPort := map[int]struct{}{}
130
for _, p := range localhostIPPorts {
131
localhostIPByPort[p] = struct{}{}
134
s := server.New(server.Config{
136
Metrics: metricsPort,
137
BindIPPortsMap: instanceIPByPort,
138
BindLocalhostPortsMap: localhostIPByPort,
143
IstioVersion: istioVersion,
144
Namespace: os.Getenv("NAMESPACE"),
146
DisableALPN: disableALPN,
149
if err := s.Start(); err != nil {
157
// Wait for the process to be shutdown.
158
sigs := make(chan os.Signal, 1)
159
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
165
func configureLogging(_ *cobra.Command, _ []string) error {
166
if err := log.Configure(loggingOptions); err != nil {
173
rootCmd.PersistentFlags().IntSliceVar(&httpPorts, "port", []int{8080}, "HTTP/1.1 ports")
174
rootCmd.PersistentFlags().IntSliceVar(&grpcPorts, "grpc", []int{7070}, "GRPC ports")
175
rootCmd.PersistentFlags().IntSliceVar(&tcpPorts, "tcp", []int{9090}, "TCP ports")
176
rootCmd.PersistentFlags().IntSliceVar(&udpPorts, "udp", []int{}, "UDP ports")
177
rootCmd.PersistentFlags().IntSliceVar(&hbonePorts, "hbone", []int{}, "HBONE ports")
178
rootCmd.PersistentFlags().IntSliceVar(&tlsPorts, "tls", []int{}, "Ports that are using TLS. These must be defined as http/grpc/tcp.")
179
rootCmd.PersistentFlags().IntSliceVar(&instanceIPPorts, "bind-ip", []int{}, "Ports that are bound to INSTANCE_IP rather than wildcard IP.")
180
rootCmd.PersistentFlags().IntSliceVar(&localhostIPPorts, "bind-localhost", []int{}, "Ports that are bound to localhost rather than wildcard IP.")
181
rootCmd.PersistentFlags().IntSliceVar(&serverFirstPorts, "server-first", []int{}, "Ports that are server first. These must be defined as tcp.")
182
rootCmd.PersistentFlags().IntSliceVar(&xdsGRPCServers, "xds-grpc-server", []int{}, "Ports that should rely on XDS configuration to serve.")
183
rootCmd.PersistentFlags().IntVar(&metricsPort, "metrics", 0, "Metrics port")
184
rootCmd.PersistentFlags().StringVar(&uds, "uds", "", "HTTP server on unix domain socket")
185
rootCmd.PersistentFlags().StringVar(&version, "version", "", "Version string")
186
rootCmd.PersistentFlags().StringVar(&cluster, "cluster", "", "Cluster where this server is deployed")
187
rootCmd.PersistentFlags().StringVar(&crt, "crt", "", "gRPC TLS server-side certificate")
188
rootCmd.PersistentFlags().StringVar(&key, "key", "", "gRPC TLS server-side key")
189
rootCmd.PersistentFlags().StringVar(&istioVersion, "istio-version", "", "Istio sidecar version")
190
rootCmd.PersistentFlags().BoolVar(&disableALPN, "disable-alpn", disableALPN, "disable ALPN negotiation")
192
loggingOptions.AttachCobraFlags(rootCmd)
194
cmd.AddFlags(rootCmd)
198
if err := rootCmd.Execute(); err != nil {