StartXDSServer starts an xDS server at the given port.
(port uint)
| 52 | |
| 53 | // StartXDSServer starts an xDS server at the given port. |
| 54 | func (x *XDSServer) StartXDSServer(port uint) error { |
| 55 | logger := x.logger.WithField("func", "StartXDSServer") |
| 56 | var err error |
| 57 | protocol := seldontls.GetSecurityProtocolFromEnv(seldontls.EnvSecurityPrefixEnvoy) |
| 58 | if protocol == seldontls.SecurityProtocolSSL { |
| 59 | x.certificateStore, err = seldontls.NewCertificateStore(seldontls.Prefix(seldontls.EnvSecurityPrefixControlPlaneServer), |
| 60 | seldontls.ValidationPrefix(seldontls.EnvSecurityPrefixControlPlaneClient)) |
| 61 | if err != nil { |
| 62 | return err |
| 63 | } |
| 64 | } |
| 65 | kaep := util.GetServerKeepAliveEnforcementPolicy() |
| 66 | secure := x.certificateStore != nil |
| 67 | var grpcOptions []grpc.ServerOption |
| 68 | if secure { |
| 69 | grpcOptions = append(grpcOptions, grpc.Creds(x.certificateStore.CreateServerTransportCredentials())) |
| 70 | } |
| 71 | grpcOptions = append(grpcOptions, grpc.MaxConcurrentStreams(grpcMaxConcurrentStreams)) |
| 72 | grpcOptions = append(grpcOptions, grpc.KeepaliveEnforcementPolicy(kaep)) |
| 73 | grpcServer := grpc.NewServer(grpcOptions...) |
| 74 | |
| 75 | lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) |
| 76 | if err != nil { |
| 77 | return err |
| 78 | } |
| 79 | registerServer(grpcServer, x.srv3) |
| 80 | logger.Infof("Starting xDS envoy server on port %d with secure: %v", port, secure) |
| 81 | go func() { |
| 82 | if err = grpcServer.Serve(lis); err != nil { |
| 83 | logger.WithError(err).Fatalf("Envoy xDS server failed on port %d mtls:%v", port, secure) |
| 84 | } |
| 85 | }() |
| 86 | return nil |
| 87 | } |