diff --git a/cli/cmd/get.go b/cli/cmd/get.go index bf5d6079d..108bc991d 100644 --- a/cli/cmd/get.go +++ b/cli/cmd/get.go @@ -107,7 +107,7 @@ func isInjectedPod(pod corev1.Pod) bool { return true } for _, container := range allContainers(pod) { - if container.Name == inject.ProxylessXServerContainerName { + if container.Name == inject.ProxylessGRPCInboundContainerName { return true } for _, env := range container.Env { diff --git a/cli/cmd/get_test.go b/cli/cmd/get_test.go index 9b8b5a15f..ef9af75c8 100644 --- a/cli/cmd/get_test.go +++ b/cli/cmd/get_test.go @@ -29,10 +29,10 @@ func TestIsInjectedPod(t *testing.T) { want: true, }, { - name: "xserver container", + name: "grpc-inbound container", pod: corev1.Pod{ Spec: corev1.PodSpec{ - Containers: []corev1.Container{{Name: inject.ProxylessXServerContainerName}}, + Containers: []corev1.Container{{Name: inject.ProxylessGRPCInboundContainerName}}, }, }, want: true, @@ -80,14 +80,14 @@ func TestPrintInjectedPods(t *testing.T) { }, Spec: corev1.PodSpec{ NodeName: "node-a", - Containers: []corev1.Container{{Name: "app"}, {Name: inject.ProxylessXServerContainerName}}, + Containers: []corev1.Container{{Name: "app"}, {Name: inject.ProxylessGRPCInboundContainerName}}, }, Status: corev1.PodStatus{ Phase: corev1.PodRunning, PodIP: "10.0.0.7", ContainerStatuses: []corev1.ContainerStatus{ {Name: "app", Ready: true, RestartCount: 1}, - {Name: inject.ProxylessXServerContainerName, Ready: true}, + {Name: inject.ProxylessGRPCInboundContainerName, Ready: true}, }, }, } diff --git a/cli/cmd/multicluster.go b/cli/cmd/multicluster.go index e51bfe95b..1d3766b10 100644 --- a/cli/cmd/multicluster.go +++ b/cli/cmd/multicluster.go @@ -136,7 +136,7 @@ func generateEastWestGatewayCmd() *cobra.Command { namespace: "dubbo-system", serviceType: "LoadBalancer", port: 15443, - targetPort: inject.ProxylessXServerPort, + targetPort: inject.ProxylessGRPCInboundPort, } command := &cobra.Command{ Use: "generate-eastwest-gateway", @@ -160,7 +160,7 @@ func generateEastWestGatewayCmd() *cobra.Command { flags.StringVarP(&args.namespace, "namespace", "n", args.namespace, "Gateway namespace") flags.StringVar(&args.serviceType, "service-type", args.serviceType, "Managed gateway Service type") flags.Int32Var(&args.port, "port", args.port, "Externally reachable east-west Gateway port") - flags.IntVar(&args.targetPort, "target-port", args.targetPort, "Injected xserver target port used by the managed gateway Service") + flags.IntVar(&args.targetPort, "target-port", args.targetPort, "Injected grpc-inbound target port used by the managed gateway Service") flags.Int32Var(&args.nodePort, "node-port", 0, "Optional managed gateway Service nodePort") flags.StringVar(&args.xdsAddress, "xds-address", "", "ADS address used by the remote dxgate data plane") _ = command.MarkFlagRequired("xds-address") diff --git a/cni/main.go b/cni/main.go index 7e512f4ee..094372693 100644 --- a/cni/main.go +++ b/cni/main.go @@ -129,7 +129,7 @@ func installerFlagSet(name string, opts *cni.InstallerOptions) *flag.FlagSet { flags.StringVar(&opts.ManagedLabelValue, "managed-label-value", opts.ManagedLabelValue, "label value that marks mesh-managed Pods") flags.StringVar(&opts.IPTablesPath, "iptables-path", opts.IPTablesPath, "iptables binary used by the CNI plugin") flags.StringVar(&opts.IPSetPath, "ipset-path", opts.IPSetPath, "ipset binary used by the CNI plugin") - flags.IntVar(&opts.XServerPort, "xserver-port", opts.XServerPort, "xserver inbound port") + flags.IntVar(&opts.GRPCInboundPort, "grpc-inbound-port", opts.GRPCInboundPort, "grpc-inbound inbound port") return flags } diff --git a/dubbod/discovery/cmd/app/cmd.go b/dubbod/discovery/cmd/app/cmd.go index 3a5dbe09e..0751fe52e 100644 --- a/dubbod/discovery/cmd/app/cmd.go +++ b/dubbod/discovery/cmd/app/cmd.go @@ -34,10 +34,10 @@ var ( ) const ( - executeLogScope = "setup" - waitLogScope = "wait" - xclientLogScope = "xclient" - xserverLogScope = "xserver" + executeLogScope = "setup" + waitLogScope = "wait" + grpcOutboundLogScope = "grpc-outbound" + grpcInboundLogScope = "grpc-inbound" ) func NewRootCommand() *cobra.Command { @@ -61,8 +61,8 @@ func NewRootCommand() *cobra.Command { cmd.AddFlags(rootCmd) rootCmd.AddCommand(waitCmd) - rootCmd.AddCommand(newXClientCommand()) - rootCmd.AddCommand(newXServerCommand()) + rootCmd.AddCommand(newGRPCOutboundCommand()) + rootCmd.AddCommand(newGRPCInboundCommand()) return rootCmd } diff --git a/dubbod/discovery/cmd/app/cmd_test.go b/dubbod/discovery/cmd/app/cmd_test.go index dda5b982e..654ddd419 100644 --- a/dubbod/discovery/cmd/app/cmd_test.go +++ b/dubbod/discovery/cmd/app/cmd_test.go @@ -32,12 +32,12 @@ func TestRootCommandRegistersRenamedCommands(t *testing.T) { commands[command.Name()] = true } - for _, name := range []string{"execute", "xclient", "xserver"} { + for _, name := range []string{"execute", "grpc-outbound", "grpc-inbound"} { if !commands[name] { t.Fatalf("expected command %q to be registered; commands=%v", name, commands) } } - for _, name := range []string{"discovery", "startup", "xds-client"} { + for _, name := range []string{"discovery", "startup"} { if commands[name] { t.Fatalf("old command %q is still registered; commands=%v", name, commands) } @@ -47,7 +47,7 @@ func TestRootCommandRegistersRenamedCommands(t *testing.T) { func TestCommandsSetLogScopes(t *testing.T) { defer func() { log.SetDefaultScope("log") - for _, name := range []string{"log", executeLogScope, waitLogScope, xclientLogScope, xserverLogScope} { + for _, name := range []string{"log", executeLogScope, waitLogScope, grpcOutboundLogScope, grpcInboundLogScope} { if scope := log.FindScope(name); scope != nil { scope.SetOutput(os.Stderr) } @@ -61,8 +61,8 @@ func TestCommandsSetLogScopes(t *testing.T) { }{ {command: "execute", scope: "setup"}, {command: "wait", scope: "wait"}, - {command: "xclient", scope: "xclient"}, - {command: "xserver", scope: "xserver"}, + {command: "grpc-outbound", scope: "grpc-outbound"}, + {command: "grpc-inbound", scope: "grpc-inbound"}, } { t.Run(tt.command, func(t *testing.T) { var out bytes.Buffer diff --git a/dubbod/discovery/cmd/app/xds_server.go b/dubbod/discovery/cmd/app/grpc_inbound.go similarity index 63% rename from dubbod/discovery/cmd/app/xds_server.go rename to dubbod/discovery/cmd/app/grpc_inbound.go index 29ac6bed2..f31736b98 100644 --- a/dubbod/discovery/cmd/app/xds_server.go +++ b/dubbod/discovery/cmd/app/grpc_inbound.go @@ -36,7 +36,7 @@ import ( "github.com/spf13/cobra" ) -type xdsServerOptions struct { +type grpcInboundOptions struct { listen string upstream string bootstrapPath string @@ -46,30 +46,30 @@ type xdsServerOptions struct { connectTimeout time.Duration } -type xserverMTLSMode string +type grpcInboundMTLSMode string const ( - xserverMTLSModeDisable xserverMTLSMode = "DISABLE" - xserverMTLSModePermissive xserverMTLSMode = "PERMISSIVE" - xserverMTLSModeStrict xserverMTLSMode = "STRICT" + grpcInboundMTLSModeDisable grpcInboundMTLSMode = "DISABLE" + grpcInboundMTLSModePermissive grpcInboundMTLSMode = "PERMISSIVE" + grpcInboundMTLSModeStrict grpcInboundMTLSMode = "STRICT" ) -func newXServerCommand() *cobra.Command { - opts := &xdsServerOptions{ - listen: firstNonEmpty(os.Getenv("DUBBO_XSERVER_LISTEN"), fmt.Sprintf(":%d", inject.ProxylessXServerPort)), - upstream: firstNonEmpty(os.Getenv("DUBBO_XSERVER_UPSTREAM"), "127.0.0.1:80"), +func newGRPCInboundCommand() *cobra.Command { + opts := &grpcInboundOptions{ + listen: firstNonEmpty(os.Getenv("DUBBO_GRPC_INBOUND_LISTEN"), fmt.Sprintf(":%d", inject.ProxylessGRPCInboundPort)), + upstream: firstNonEmpty(os.Getenv("DUBBO_GRPC_INBOUND_UPSTREAM"), "127.0.0.1:80"), bootstrapPath: os.Getenv("GRPC_XDS_BOOTSTRAP"), runtimeConfig: firstNonEmpty(os.Getenv(inject.ProxylessGRPCConfigEnvName), inject.ProxylessGRPCConfigPath), - mtlsMode: os.Getenv("DUBBO_XSERVER_MTLS_MODE"), - acceptTimeout: durationSecondsFromEnv("DUBBO_XSERVER_ACCEPT_TIMEOUT", 0), - connectTimeout: durationSecondsFromEnv("DUBBO_XSERVER_CONNECT_TIMEOUT", 5*time.Second), + mtlsMode: os.Getenv("DUBBO_GRPC_INBOUND_MTLS_MODE"), + acceptTimeout: durationSecondsFromEnv("DUBBO_GRPC_INBOUND_ACCEPT_TIMEOUT", 0), + connectTimeout: durationSecondsFromEnv("DUBBO_GRPC_INBOUND_CONNECT_TIMEOUT", 5*time.Second), } c := &cobra.Command{ - Use: "xserver", + Use: "grpc-inbound", Short: "run an inbound mTLS data-plane proxy for proxyless workloads", Args: cobra.NoArgs, PreRunE: func(cmd *cobra.Command, args []string) error { - log.SetDefaultScope(xserverLogScope) + log.SetDefaultScope(grpcInboundLogScope) return nil }, RunE: func(cmd *cobra.Command, _ []string) error { @@ -86,33 +86,33 @@ func newXServerCommand() *cobra.Command { return c } -func (o *xdsServerOptions) run(ctx context.Context) error { +func (o *grpcInboundOptions) run(ctx context.Context) error { if o.bootstrapPath == "" { - return fmt.Errorf("xserver requires GRPC_XDS_BOOTSTRAP or --bootstrap") + return fmt.Errorf("grpc-inbound requires GRPC_XDS_BOOTSTRAP or --bootstrap") } if o.listen == "" { - return fmt.Errorf("xserver listen address is required") + return fmt.Errorf("grpc-inbound listen address is required") } if o.upstream == "" { - return fmt.Errorf("xserver upstream address is required") + return fmt.Errorf("grpc-inbound upstream address is required") } bootstrap, err := xdsresolver.ParseBootstrap(o.bootstrapPath) if err != nil { return err } - tlsConfig, err := xserverTLSConfigFromBootstrap(bootstrap) + tlsConfig, err := grpcInboundTLSConfigFromBootstrap(bootstrap) if err != nil { return err } lis, err := net.Listen("tcp", o.listen) if err != nil { - return fmt.Errorf("listen xserver %s: %w", o.listen, err) + return fmt.Errorf("listen grpc-inbound %s: %w", o.listen, err) } defer lis.Close() - return serveXServer(ctx, lis, tlsConfig, o.upstream, o.effectiveMTLSMode, o.acceptTimeout, o.connectTimeout) + return serveGRPCInbound(ctx, lis, tlsConfig, o.upstream, o.effectiveMTLSMode, o.acceptTimeout, o.connectTimeout) } -func xserverTLSConfigFromBootstrap(bootstrap *xdsresolver.BootstrapConfig) (*tls.Config, error) { +func grpcInboundTLSConfigFromBootstrap(bootstrap *xdsresolver.BootstrapConfig) (*tls.Config, error) { if bootstrap == nil { return nil, fmt.Errorf("bootstrap config is nil") } @@ -121,22 +121,22 @@ func xserverTLSConfigFromBootstrap(bootstrap *xdsresolver.BootstrapConfig) (*tls return nil, fmt.Errorf("certificate_providers[default] not found") } if cfg.CertificateFile == "" || cfg.PrivateKeyFile == "" { - return nil, fmt.Errorf("xserver mTLS requires certificate_file and private_key_file") + return nil, fmt.Errorf("grpc-inbound mTLS requires certificate_file and private_key_file") } if cfg.CACertificateFile == "" { - return nil, fmt.Errorf("xserver mTLS requires ca_certificate_file") + return nil, fmt.Errorf("grpc-inbound mTLS requires ca_certificate_file") } cert, err := tls.LoadX509KeyPair(cfg.CertificateFile, cfg.PrivateKeyFile) if err != nil { - return nil, fmt.Errorf("load xserver certificate/key: %w", err) + return nil, fmt.Errorf("load grpc-inbound certificate/key: %w", err) } rootPEM, err := os.ReadFile(cfg.CACertificateFile) if err != nil { - return nil, fmt.Errorf("read xserver CA certificate %s: %w", cfg.CACertificateFile, err) + return nil, fmt.Errorf("read grpc-inbound CA certificate %s: %w", cfg.CACertificateFile, err) } clientCAs := x509.NewCertPool() if !clientCAs.AppendCertsFromPEM(rootPEM) { - return nil, fmt.Errorf("parse xserver CA certificate %s: no certificates found", cfg.CACertificateFile) + return nil, fmt.Errorf("parse grpc-inbound CA certificate %s: no certificates found", cfg.CACertificateFile) } return &tls.Config{ MinVersion: tls.VersionTLS12, @@ -146,7 +146,7 @@ func xserverTLSConfigFromBootstrap(bootstrap *xdsresolver.BootstrapConfig) (*tls }, nil } -func serveXServer(ctx context.Context, lis net.Listener, tlsConfig *tls.Config, upstream string, mode func() xserverMTLSMode, acceptTimeout, connectTimeout time.Duration) error { +func serveGRPCInbound(ctx context.Context, lis net.Listener, tlsConfig *tls.Config, upstream string, mode func() grpcInboundMTLSMode, acceptTimeout, connectTimeout time.Duration) error { go func() { <-ctx.Done() _ = lis.Close() @@ -161,11 +161,11 @@ func serveXServer(ctx context.Context, lis net.Listener, tlsConfig *tls.Config, return err } } - go proxyXServerConnection(conn, tlsConfig, upstream, mode(), acceptTimeout, connectTimeout) + go proxyGRPCInboundConnection(conn, tlsConfig, upstream, mode(), acceptTimeout, connectTimeout) } } -func proxyXServerConnection(inbound net.Conn, tlsConfig *tls.Config, upstream string, mode xserverMTLSMode, acceptTimeout, connectTimeout time.Duration) { +func proxyGRPCInboundConnection(inbound net.Conn, tlsConfig *tls.Config, upstream string, mode grpcInboundMTLSMode, acceptTimeout, connectTimeout time.Duration) { defer inbound.Close() if acceptTimeout > 0 { _ = inbound.SetDeadline(time.Now().Add(acceptTimeout)) @@ -178,7 +178,7 @@ func proxyXServerConnection(inbound net.Conn, tlsConfig *tls.Config, upstream st } buffered := &bufferedConn{Conn: inbound, reader: reader} if isTLSClientHello(first[0]) { - if mode == xserverMTLSModeDisable { + if mode == grpcInboundMTLSModeDisable { return } tlsConn := tls.Server(buffered, tlsConfig) @@ -187,7 +187,7 @@ func proxyXServerConnection(inbound net.Conn, tlsConfig *tls.Config, upstream st } inbound = tlsConn } else { - if mode == xserverMTLSModeStrict { + if mode == grpcInboundMTLSModeStrict { return } inbound = buffered @@ -216,24 +216,24 @@ func isTLSClientHello(first byte) bool { return first == 0x16 } -func (o *xdsServerOptions) effectiveMTLSMode() xserverMTLSMode { - if mode, ok := parseXServerMTLSMode(o.mtlsMode); ok { +func (o *grpcInboundOptions) effectiveMTLSMode() grpcInboundMTLSMode { + if mode, ok := parseGRPCInboundMTLSMode(o.mtlsMode); ok { return mode } - if mode, ok := xserverMTLSModeFromRuntimeConfig(o.runtimeConfig, upstreamPort(o.upstream)); ok { + if mode, ok := grpcInboundMTLSModeFromRuntimeConfig(o.runtimeConfig, upstreamPort(o.upstream)); ok { return mode } - return xserverMTLSModePermissive + return grpcInboundMTLSModePermissive } -func parseXServerMTLSMode(mode string) (xserverMTLSMode, bool) { +func parseGRPCInboundMTLSMode(mode string) (grpcInboundMTLSMode, bool) { switch strings.ToUpper(strings.TrimSpace(mode)) { - case string(xserverMTLSModeDisable): - return xserverMTLSModeDisable, true - case string(xserverMTLSModePermissive): - return xserverMTLSModePermissive, true - case string(xserverMTLSModeStrict): - return xserverMTLSModeStrict, true + case string(grpcInboundMTLSModeDisable): + return grpcInboundMTLSModeDisable, true + case string(grpcInboundMTLSModePermissive): + return grpcInboundMTLSModePermissive, true + case string(grpcInboundMTLSModeStrict): + return grpcInboundMTLSModeStrict, true default: return "", false } @@ -251,7 +251,7 @@ func upstreamPort(upstream string) int { return out } -func xserverMTLSModeFromRuntimeConfig(path string, port int) (xserverMTLSMode, bool) { +func grpcInboundMTLSModeFromRuntimeConfig(path string, port int) (grpcInboundMTLSMode, bool) { if path == "" { return "", false } @@ -278,22 +278,22 @@ func xserverMTLSModeFromRuntimeConfig(path string, port int) (xserverMTLSMode, b if port != 0 && svcPort.Port != port { continue } - mode, ok := parseXServerMTLSMode(svcPort.MTLSMode) + mode, ok := parseGRPCInboundMTLSMode(svcPort.MTLSMode) if !ok { continue } - if mode == xserverMTLSModeStrict { - return xserverMTLSModeStrict, true + if mode == grpcInboundMTLSModeStrict { + return grpcInboundMTLSModeStrict, true } - foundPermissive = foundPermissive || mode == xserverMTLSModePermissive - foundDisable = foundDisable || mode == xserverMTLSModeDisable + foundPermissive = foundPermissive || mode == grpcInboundMTLSModePermissive + foundDisable = foundDisable || mode == grpcInboundMTLSModeDisable } } if foundPermissive { - return xserverMTLSModePermissive, true + return grpcInboundMTLSModePermissive, true } if foundDisable { - return xserverMTLSModeDisable, true + return grpcInboundMTLSModeDisable, true } return "", false } diff --git a/dubbod/discovery/cmd/app/xds_server_test.go b/dubbod/discovery/cmd/app/grpc_inbound_test.go similarity index 84% rename from dubbod/discovery/cmd/app/xds_server_test.go rename to dubbod/discovery/cmd/app/grpc_inbound_test.go index 8b26fe036..fadac08f0 100644 --- a/dubbod/discovery/cmd/app/xds_server_test.go +++ b/dubbod/discovery/cmd/app/grpc_inbound_test.go @@ -22,10 +22,10 @@ import ( xdsresolver "github.com/kdubbo/xds-api/grpc/resolver" ) -func TestXServerRequiresClientCertificateAndProxiesHTTP(t *testing.T) { +func TestGRPCInboundRequiresClientCertificateAndProxiesHTTP(t *testing.T) { caCert, caKey := newTestCA(t) - serverCert, serverKey := newSignedCert(t, caCert, caKey, "xserver") - clientCert, clientKey := newSignedCert(t, caCert, caKey, "xclient") + serverCert, serverKey := newSignedCert(t, caCert, caKey, "grpc-inbound") + clientCert, clientKey := newSignedCert(t, caCert, caKey, "grpc-outbound") dir := t.TempDir() writePEM(t, filepath.Join(dir, "root-cert.pem"), "CERTIFICATE", caCert.Raw) writePEM(t, filepath.Join(dir, "cert-chain.pem"), "CERTIFICATE", serverCert.Raw) @@ -33,7 +33,7 @@ func TestXServerRequiresClientCertificateAndProxiesHTTP(t *testing.T) { writePEM(t, filepath.Join(dir, "client-cert.pem"), "CERTIFICATE", clientCert.Raw) writePEM(t, filepath.Join(dir, "client-key.pem"), "RSA PRIVATE KEY", x509.MarshalPKCS1PrivateKey(clientKey)) - tlsConfig, err := xserverTLSConfigFromBootstrap(&xdsresolver.BootstrapConfig{ + tlsConfig, err := grpcInboundTLSConfigFromBootstrap(&xdsresolver.BootstrapConfig{ CertProviders: map[string]xdsresolver.FileWatcherCertConfig{ "default": { CertificateFile: filepath.Join(dir, "cert-chain.pem"), @@ -43,7 +43,7 @@ func TestXServerRequiresClientCertificateAndProxiesHTTP(t *testing.T) { }, }) if err != nil { - t.Fatalf("xserverTLSConfigFromBootstrap() failed: %v", err) + t.Fatalf("grpcInboundTLSConfigFromBootstrap() failed: %v", err) } upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { @@ -60,8 +60,8 @@ func TestXServerRequiresClientCertificateAndProxiesHTTP(t *testing.T) { defer cancel() errCh := make(chan error, 1) go func() { - errCh <- serveXServer(ctx, listener, tlsConfig, upstreamAddr, func() xserverMTLSMode { - return xserverMTLSModeStrict + errCh <- serveGRPCInbound(ctx, listener, tlsConfig, upstreamAddr, func() grpcInboundMTLSMode { + return grpcInboundMTLSModeStrict }, time.Second, time.Second) }() t.Cleanup(func() { @@ -69,10 +69,10 @@ func TestXServerRequiresClientCertificateAndProxiesHTTP(t *testing.T) { select { case err := <-errCh: if err != nil { - t.Fatalf("serveXServer() error = %v", err) + t.Fatalf("serveGRPCInbound() error = %v", err) } case <-time.After(time.Second): - t.Fatalf("serveXServer() did not stop") + t.Fatalf("serveGRPCInbound() did not stop") } }) @@ -110,10 +110,10 @@ func TestXServerRequiresClientCertificateAndProxiesHTTP(t *testing.T) { } } -func TestXServerPermissiveAcceptsPlaintextAndMTLS(t *testing.T) { +func TestGRPCInboundPermissiveAcceptsPlaintextAndMTLS(t *testing.T) { caCert, caKey := newTestCA(t) - serverCert, serverKey := newSignedCert(t, caCert, caKey, "xserver") - clientCert, clientKey := newSignedCert(t, caCert, caKey, "xclient") + serverCert, serverKey := newSignedCert(t, caCert, caKey, "grpc-inbound") + clientCert, clientKey := newSignedCert(t, caCert, caKey, "grpc-outbound") dir := t.TempDir() writePEM(t, filepath.Join(dir, "root-cert.pem"), "CERTIFICATE", caCert.Raw) writePEM(t, filepath.Join(dir, "cert-chain.pem"), "CERTIFICATE", serverCert.Raw) @@ -121,7 +121,7 @@ func TestXServerPermissiveAcceptsPlaintextAndMTLS(t *testing.T) { writePEM(t, filepath.Join(dir, "client-cert.pem"), "CERTIFICATE", clientCert.Raw) writePEM(t, filepath.Join(dir, "client-key.pem"), "RSA PRIVATE KEY", x509.MarshalPKCS1PrivateKey(clientKey)) - tlsConfig, err := xserverTLSConfigFromBootstrap(&xdsresolver.BootstrapConfig{ + tlsConfig, err := grpcInboundTLSConfigFromBootstrap(&xdsresolver.BootstrapConfig{ CertProviders: map[string]xdsresolver.FileWatcherCertConfig{ "default": { CertificateFile: filepath.Join(dir, "cert-chain.pem"), @@ -131,7 +131,7 @@ func TestXServerPermissiveAcceptsPlaintextAndMTLS(t *testing.T) { }, }) if err != nil { - t.Fatalf("xserverTLSConfigFromBootstrap() failed: %v", err) + t.Fatalf("grpcInboundTLSConfigFromBootstrap() failed: %v", err) } upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { @@ -147,8 +147,8 @@ func TestXServerPermissiveAcceptsPlaintextAndMTLS(t *testing.T) { defer cancel() errCh := make(chan error, 1) go func() { - errCh <- serveXServer(ctx, listener, tlsConfig, upstream.Listener.Addr().String(), func() xserverMTLSMode { - return xserverMTLSModePermissive + errCh <- serveGRPCInbound(ctx, listener, tlsConfig, upstream.Listener.Addr().String(), func() grpcInboundMTLSMode { + return grpcInboundMTLSModePermissive }, time.Second, time.Second) }() t.Cleanup(func() { @@ -156,10 +156,10 @@ func TestXServerPermissiveAcceptsPlaintextAndMTLS(t *testing.T) { select { case err := <-errCh: if err != nil { - t.Fatalf("serveXServer() error = %v", err) + t.Fatalf("serveGRPCInbound() error = %v", err) } case <-time.After(time.Second): - t.Fatalf("serveXServer() did not stop") + t.Fatalf("serveGRPCInbound() did not stop") } }) @@ -197,7 +197,7 @@ func TestXServerPermissiveAcceptsPlaintextAndMTLS(t *testing.T) { } } -func TestXServerMTLSModeFromRuntimeConfig(t *testing.T) { +func TestGRPCInboundMTLSModeFromRuntimeConfig(t *testing.T) { path := filepath.Join(t.TempDir(), "dubbo-grpc-xds.json") if err := os.WriteFile(path, []byte(`{ "services": [ @@ -208,10 +208,10 @@ func TestXServerMTLSModeFromRuntimeConfig(t *testing.T) { t.Fatalf("os.WriteFile() failed: %v", err) } - if got, ok := xserverMTLSModeFromRuntimeConfig(path, 80); !ok || got != xserverMTLSModePermissive { + if got, ok := grpcInboundMTLSModeFromRuntimeConfig(path, 80); !ok || got != grpcInboundMTLSModePermissive { t.Fatalf("mode for 80 = %q, %v; want PERMISSIVE, true", got, ok) } - if got, ok := xserverMTLSModeFromRuntimeConfig(path, 8080); !ok || got != xserverMTLSModeStrict { + if got, ok := grpcInboundMTLSModeFromRuntimeConfig(path, 8080); !ok || got != grpcInboundMTLSModeStrict { t.Fatalf("mode for 8080 = %q, %v; want STRICT, true", got, ok) } } diff --git a/dubbod/discovery/cmd/app/xds_client.go b/dubbod/discovery/cmd/app/grpc_outbound.go similarity index 98% rename from dubbod/discovery/cmd/app/xds_client.go rename to dubbod/discovery/cmd/app/grpc_outbound.go index 02e68c72b..2974b95dc 100644 --- a/dubbod/discovery/cmd/app/xds_client.go +++ b/dubbod/discovery/cmd/app/grpc_outbound.go @@ -54,7 +54,7 @@ import ( "google.golang.org/protobuf/types/known/structpb" ) -type xdsClientOptions struct { +type grpcOutboundOptions struct { host string port int path string @@ -126,19 +126,19 @@ type sampleADSClient struct { bootstrap *xdsresolver.BootstrapConfig } -func newXClientCommand() *cobra.Command { +func newGRPCOutboundCommand() *cobra.Command { namespace := firstNonEmpty(os.Getenv("POD_NAMESPACE"), "default") trustDomain := firstNonEmpty(os.Getenv("TRUST_DOMAIN"), constants.DefaultClusterLocalDomain) domainSuffix := firstNonEmpty(os.Getenv("DOMAIN_SUFFIX"), trustDomain, constants.DefaultClusterLocalDomain) host, port, hostErr := autoDiscoverServiceTarget(os.Environ(), namespace, domainSuffix) - opts := &xdsClientOptions{ + opts := &grpcOutboundOptions{ host: firstNonEmpty(os.Getenv("DUBBO_SERVICE_HOST"), host), port: firstIntFromEnv(int(port), "DUBBO_SERVICE_PORT"), path: firstNonEmpty(os.Getenv("REQUEST_PATH"), "/"), xdsAddress: firstNonEmpty(os.Getenv("XDS_ADDRESS"), "dubbod.dubbo-system.svc:26010"), bootstrapPath: os.Getenv("GRPC_XDS_BOOTSTRAP"), namespace: namespace, - podName: firstNonEmpty(os.Getenv("POD_NAME"), os.Getenv("HOSTNAME"), "xclient"), + podName: firstNonEmpty(os.Getenv("POD_NAME"), os.Getenv("HOSTNAME"), "grpc-outbound"), podIP: firstNonEmpty(os.Getenv("INSTANCE_IP"), os.Getenv("POD_IP"), "127.0.0.1"), serviceAccount: firstNonEmpty(os.Getenv("SERVICE_ACCOUNT"), "default"), trustDomain: trustDomain, @@ -150,11 +150,11 @@ func newXClientCommand() *cobra.Command { } c := &cobra.Command{ - Use: "xclient [count]", + Use: "grpc-outbound [count]", Short: "run a no-proxy ADS stream client for service-to-service sample traffic", Args: cobra.MaximumNArgs(1), PreRunE: func(cmd *cobra.Command, args []string) error { - log.SetDefaultScope(xclientLogScope) + log.SetDefaultScope(grpcOutboundLogScope) return nil }, RunE: func(cmd *cobra.Command, args []string) error { @@ -195,7 +195,7 @@ func newXClientCommand() *cobra.Command { return c } -func (o *xdsClientOptions) run(ctx context.Context) error { +func (o *grpcOutboundOptions) run(ctx context.Context) error { if o.host == "" { return fmt.Errorf("target host is required; set --host or DUBBO_SERVICE_HOST, or expose exactly one Service in the namespace before starting the pod") } @@ -241,7 +241,7 @@ func (o *xdsClientOptions) run(ctx context.Context) error { return runSampleRequests(ctx, client, snapshot, o.count, o.requestInterval, o.requestTimeout) } -func newSampleADSClient(ctx context.Context, opts *xdsClientOptions) (*sampleADSClient, error) { +func newSampleADSClient(ctx context.Context, opts *grpcOutboundOptions) (*sampleADSClient, error) { node, addr, dialOpts, err := adsDialConfig(opts) if err != nil { return nil, err @@ -275,7 +275,7 @@ func newSampleADSClient(ctx context.Context, opts *xdsClientOptions) (*sampleADS }, nil } -func adsDialConfig(opts *xdsClientOptions) (*corev1.Node, string, []grpc.DialOption, error) { +func adsDialConfig(opts *grpcOutboundOptions) (*corev1.Node, string, []grpc.DialOption, error) { if opts.bootstrapPath != "" { if bootstrap, err := xdsresolver.ParseBootstrap(opts.bootstrapPath); err == nil { creds, err := xdsresolver.TransportCredentialsFromBootstrap(bootstrap) @@ -302,7 +302,7 @@ func adsDialConfig(opts *xdsClientOptions) (*corev1.Node, string, []grpc.DialOpt return node, opts.xdsAddress, []grpc.DialOption{creds}, nil } -func buildADSNode(opts *xdsClientOptions) (*corev1.Node, error) { +func buildADSNode(opts *grpcOutboundOptions) (*corev1.Node, error) { proxyConfig := meshconfig.DefaultProxyConfig() proxyConfig.DiscoveryAddress = opts.xdsAddress nodeID := strings.Join([]string{ diff --git a/dubbod/discovery/cmd/app/xds_client_test.go b/dubbod/discovery/cmd/app/grpc_outbound_test.go similarity index 100% rename from dubbod/discovery/cmd/app/xds_client_test.go rename to dubbod/discovery/cmd/app/grpc_outbound_test.go diff --git a/dubbod/discovery/cmd/app/xds_test_grpc.go b/dubbod/discovery/cmd/app/xds_test_grpc.go index b9732b546..3c0aa9b33 100644 --- a/dubbod/discovery/cmd/app/xds_test_grpc.go +++ b/dubbod/discovery/cmd/app/xds_test_grpc.go @@ -67,7 +67,7 @@ func startXDSTestGRPCServer(stop <-chan struct{}) error { } func (s *xdsTestGRPCServer) ForwardHTTP(ctx context.Context, req *testproto.ForwardHTTPRequest) (*testproto.ForwardHTTPResponse, error) { - opts, err := xdsOptionsFromForwardHTTPRequest(req) + opts, err := grpcOutboundOptionsFromForwardHTTPRequest(req) if err != nil { return nil, status.Error(codes.InvalidArgument, err.Error()) } @@ -94,7 +94,7 @@ func (s *xdsTestGRPCServer) ForwardHTTP(ctx context.Context, req *testproto.Forw return &testproto.ForwardHTTPResponse{Output: output}, nil } -func xdsOptionsFromForwardHTTPRequest(req *testproto.ForwardHTTPRequest) (*xdsClientOptions, error) { +func grpcOutboundOptionsFromForwardHTTPRequest(req *testproto.ForwardHTTPRequest) (*grpcOutboundOptions, error) { if req == nil { return nil, fmt.Errorf("request is required") } @@ -124,7 +124,7 @@ func xdsOptionsFromForwardHTTPRequest(req *testproto.ForwardHTTPRequest) (*xdsCl if count <= 0 { count = 1 } - return &xdsClientOptions{ + return &grpcOutboundOptions{ host: host, port: port, path: normalizeRequestPath(req.GetPath()), @@ -132,7 +132,7 @@ func xdsOptionsFromForwardHTTPRequest(req *testproto.ForwardHTTPRequest) (*xdsCl target: net.JoinHostPort(host, strconv.Itoa(port)), xdsAddress: firstNonEmpty(os.Getenv("XDS_TEST_XDS_ADDRESS"), "127.0.0.1:26010"), namespace: namespace, - podName: firstNonEmpty(os.Getenv("POD_NAME"), os.Getenv("HOSTNAME"), "xclient"), + podName: firstNonEmpty(os.Getenv("POD_NAME"), os.Getenv("HOSTNAME"), "grpc-outbound"), podIP: firstNonEmpty(os.Getenv("INSTANCE_IP"), os.Getenv("POD_IP"), "127.0.0.1"), serviceAccount: serviceAccount, trustDomain: firstNonEmpty(os.Getenv("TRUST_DOMAIN"), constants.DefaultClusterLocalDomain), diff --git a/dubbod/discovery/pkg/bootstrap/proxyless_grpc_controller.go b/dubbod/discovery/pkg/bootstrap/proxyless_grpc_controller.go index 20984967f..616c3f749 100644 --- a/dubbod/discovery/pkg/bootstrap/proxyless_grpc_controller.go +++ b/dubbod/discovery/pkg/bootstrap/proxyless_grpc_controller.go @@ -823,7 +823,7 @@ func rewriteRuntimeEndpointPortsForTLS(endpoints []proxylessGRPCEndpointRuntimeC out := make([]proxylessGRPCEndpointRuntimeConfig, len(endpoints)) copy(out, endpoints) for i := range out { - out[i].Port = inject.ProxylessXServerPort + out[i].Port = inject.ProxylessGRPCInboundPort } return out } diff --git a/dubbod/discovery/pkg/config/kube/gateway/deployment_controller.go b/dubbod/discovery/pkg/config/kube/gateway/deployment_controller.go index c5befbaa1..e6020d7b7 100644 --- a/dubbod/discovery/pkg/config/kube/gateway/deployment_controller.go +++ b/dubbod/discovery/pkg/config/kube/gateway/deployment_controller.go @@ -1093,7 +1093,7 @@ func gatewayServiceTargetPort(gw gateway.Gateway) intstr.IntOrString { return intstr.FromInt(port) } if gw.Annotations[eastWestGatewayAnnotation] == "true" { - return intstr.FromInt(inject.ProxylessXServerPort) + return intstr.FromInt(inject.ProxylessGRPCInboundPort) } return intstr.FromString("http") } diff --git a/dubbod/discovery/pkg/config/kube/gateway/deployment_controller_test.go b/dubbod/discovery/pkg/config/kube/gateway/deployment_controller_test.go index 31f8bc1a0..7d5879a92 100644 --- a/dubbod/discovery/pkg/config/kube/gateway/deployment_controller_test.go +++ b/dubbod/discovery/pkg/config/kube/gateway/deployment_controller_test.go @@ -275,7 +275,7 @@ func TestExtractServicePortsTargetsDxgateContainerPorts(t *testing.T) { } } -func TestExtractServicePortsTargetsXServerForEastWestGateway(t *testing.T) { +func TestExtractServicePortsTargetsGRPCInboundForEastWestGateway(t *testing.T) { gw := gatewayv1.Gateway{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ diff --git a/dubbod/discovery/pkg/xds/endpoints/endpoint_builder.go b/dubbod/discovery/pkg/xds/endpoints/endpoint_builder.go index 7c080f73e..a6d78d2cc 100644 --- a/dubbod/discovery/pkg/xds/endpoints/endpoint_builder.go +++ b/dubbod/discovery/pkg/xds/endpoints/endpoint_builder.go @@ -321,13 +321,13 @@ func (b *EndpointBuilder) eastWestGatewayForCluster(endpointCluster cluster.ID, } func (b *EndpointBuilder) endpointPort(ep *model.DubboEndpoint) uint32 { - if b.useXServerEndpointPort() { - return inject.ProxylessXServerPort + if b.useGRPCInboundEndpointPort() { + return inject.ProxylessGRPCInboundPort } return ep.EndpointPort } -func (b *EndpointBuilder) useXServerEndpointPort() bool { +func (b *EndpointBuilder) useGRPCInboundEndpointPort() bool { if b == nil || b.proxy == nil || !b.proxy.IsProxylessGrpc() || b.push == nil || b.service == nil { return false } diff --git a/manifests/charts/dubbod/files/grpc-engine.yaml b/manifests/charts/dubbod/files/grpc-engine.yaml index 997497cda..0fd76a830 100644 --- a/manifests/charts/dubbod/files/grpc-engine.yaml +++ b/manifests/charts/dubbod/files/grpc-engine.yaml @@ -75,7 +75,7 @@ spec: fieldPath: status.hostIP {{- if and (gt (len .Spec.Containers) 0) (contains "kdubbo/dubbod" ((index .Spec.Containers 0).Image | default "")) }} args: - - xclient + - grpc-outbound - --watch {{- end }} volumeMounts: @@ -86,17 +86,17 @@ spec: {{- if and (gt (len .Spec.Containers) 0) (gt (len ((index .Spec.Containers 0).Ports)) 0) }} {{- $appPort = int ((index ((index .Spec.Containers 0).Ports) 0).ContainerPort) }} {{- end }} - - name: dubbo-xserver + - name: dubbo-grpc-inbound image: {{ .ProxyImage | quote }} imagePullPolicy: IfNotPresent args: - - xserver + - grpc-inbound - --listen - :15080 - --upstream - 127.0.0.1:{{ $appPort }} ports: - - name: xserver + - name: grpc-inbound containerPort: 15080 protocol: TCP volumeMounts: diff --git a/manifests/charts/dubbod/templates/cni-daemonset.yaml b/manifests/charts/dubbod/templates/cni-daemonset.yaml index a4e9a7778..fd8986161 100644 --- a/manifests/charts/dubbod/templates/cni-daemonset.yaml +++ b/manifests/charts/dubbod/templates/cni-daemonset.yaml @@ -32,7 +32,7 @@ {{- $binDir := coalesce $cni.binDir $defaultCNI.binDir "/opt/cni/bin" }} {{- $confDir := coalesce $cni.confDir $defaultCNI.confDir "/etc/cni/net.d" }} {{- $stateDir := coalesce $cni.stateDir $defaultCNI.stateDir "/var/run/dubbo-cni" }} -{{- $xserverPort := int (coalesce $cni.xserverPort $defaultCNI.xserverPort 15080) }} +{{- $grpcInboundPort := int (coalesce $cni.grpcInboundPort $defaultCNI.grpcInboundPort 15080) }} {{- $managedLabel := coalesce $cni.managedLabel $defaultCNI.managedLabel "proxyless.dubbo.apache.org/managed" }} {{- $managedLabelValue := coalesce $cni.managedLabelValue $defaultCNI.managedLabelValue "true" }} {{- $iptablesPath := coalesce $cni.iptablesPath $defaultCNI.iptablesPath "iptables" }} @@ -76,7 +76,7 @@ spec: - --kubeconfig={{ printf "%s/dubbo-cni-kubeconfig" $confDir }} - --token-file={{ printf "%s/token" $stateDir }} - --ca-file={{ printf "%s/ca.crt" $stateDir }} - - --xserver-port={{ $xserverPort }} + - --grpc-inbound-port={{ $grpcInboundPort }} - --managed-label={{ $managedLabel }} - --managed-label-value={{ $managedLabelValue }} - --iptables-path={{ $iptablesPath }} diff --git a/manifests/charts/dubbod/templates/configmap-values.yaml b/manifests/charts/dubbod/templates/configmap-values.yaml index c740eea3d..f25278d61 100644 --- a/manifests/charts/dubbod/templates/configmap-values.yaml +++ b/manifests/charts/dubbod/templates/configmap-values.yaml @@ -58,7 +58,7 @@ data: binDir: {{ coalesce $cni.binDir $defaultCNI.binDir "/opt/cni/bin" | quote }} confDir: {{ coalesce $cni.confDir $defaultCNI.confDir "/etc/cni/net.d" | quote }} stateDir: {{ coalesce $cni.stateDir $defaultCNI.stateDir "/var/run/dubbo-cni" | quote }} - xserverPort: {{ int (coalesce $cni.xserverPort $defaultCNI.xserverPort 15080) }} + grpcInboundPort: {{ int (coalesce $cni.grpcInboundPort $defaultCNI.grpcInboundPort 15080) }} managedLabel: {{ coalesce $cni.managedLabel $defaultCNI.managedLabel "proxyless.dubbo.apache.org/managed" | quote }} managedLabelValue: {{ coalesce $cni.managedLabelValue $defaultCNI.managedLabelValue "true" | quote }} iptablesPath: {{ coalesce $cni.iptablesPath $defaultCNI.iptablesPath "iptables" | quote }} diff --git a/manifests/charts/dubbod/values.yaml b/manifests/charts/dubbod/values.yaml index 78b4c1cff..765a487e0 100644 --- a/manifests/charts/dubbod/values.yaml +++ b/manifests/charts/dubbod/values.yaml @@ -27,7 +27,7 @@ _internal_default_values_not_set: binDir: "/opt/cni/bin" confDir: "/etc/cni/net.d" stateDir: "/var/run/dubbo-cni" - xserverPort: 15080 + grpcInboundPort: 15080 managedLabel: "proxyless.dubbo.apache.org/managed" managedLabelValue: "true" iptablesPath: "iptables" diff --git a/operator/pkg/apis/proto/values_types.proto b/operator/pkg/apis/proto/values_types.proto index 02ff1bb22..29b596a0a 100644 --- a/operator/pkg/apis/proto/values_types.proto +++ b/operator/pkg/apis/proto/values_types.proto @@ -49,7 +49,7 @@ message MeshCNIConfig { string stateDir = 5; - int64 xserverPort = 6; + int64 grpcInboundPort = 6; string managedLabel = 7; diff --git a/operator/pkg/apis/values_types.pb.go b/operator/pkg/apis/values_types.pb.go index 0ad1cf1e9..9db76c533 100644 --- a/operator/pkg/apis/values_types.pb.go +++ b/operator/pkg/apis/values_types.pb.go @@ -185,7 +185,7 @@ type MeshCNIConfig struct { BinDir string `protobuf:"bytes,3,opt,name=binDir,proto3" json:"binDir,omitempty"` ConfDir string `protobuf:"bytes,4,opt,name=confDir,proto3" json:"confDir,omitempty"` StateDir string `protobuf:"bytes,5,opt,name=stateDir,proto3" json:"stateDir,omitempty"` - XserverPort int64 `protobuf:"varint,6,opt,name=xserverPort,proto3" json:"xserverPort,omitempty"` + GrpcInboundPort int64 `protobuf:"varint,6,opt,name=grpcInboundPort,proto3" json:"grpcInboundPort,omitempty"` ManagedLabel string `protobuf:"bytes,7,opt,name=managedLabel,proto3" json:"managedLabel,omitempty"` ManagedLabelValue string `protobuf:"bytes,8,opt,name=managedLabelValue,proto3" json:"managedLabelValue,omitempty"` IptablesPath string `protobuf:"bytes,9,opt,name=iptablesPath,proto3" json:"iptablesPath,omitempty"` @@ -260,9 +260,9 @@ func (x *MeshCNIConfig) GetStateDir() string { return "" } -func (x *MeshCNIConfig) GetXserverPort() int64 { +func (x *MeshCNIConfig) GetGrpcInboundPort() int64 { if x != nil { - return x.XserverPort + return x.GrpcInboundPort } return 0 } @@ -808,14 +808,14 @@ const file_values_types_proto_rawDesc = "" + "\vProxyConfig\x12$\n" + "\rclusterDomain\x18\x01 \x01(\tR\rclusterDomain\"K\n" + "\x0fProxylessConfig\x128\n" + - "\x03cni\x18\x01 \x01(\v2&.dubbo.operator.v1alpha1.MeshCNIConfigR\x03cni\"\xed\x02\n" + + "\x03cni\x18\x01 \x01(\v2&.dubbo.operator.v1alpha1.MeshCNIConfigR\x03cni\"\xf5\x02\n" + "\rMeshCNIConfig\x12\x18\n" + "\aenabled\x18\x01 \x01(\bR\aenabled\x12\x14\n" + "\x05image\x18\x02 \x01(\tR\x05image\x12\x16\n" + "\x06binDir\x18\x03 \x01(\tR\x06binDir\x12\x18\n" + "\aconfDir\x18\x04 \x01(\tR\aconfDir\x12\x1a\n" + - "\bstateDir\x18\x05 \x01(\tR\bstateDir\x12 \n" + - "\vxserverPort\x18\x06 \x01(\x03R\vxserverPort\x12\"\n" + + "\bstateDir\x18\x05 \x01(\tR\bstateDir\x12(\n" + + "\x0fgrpcInboundPort\x18\x06 \x01(\x03R\x0fgrpcInboundPort\x12\"\n" + "\fmanagedLabel\x18\a \x01(\tR\fmanagedLabel\x12,\n" + "\x11managedLabelValue\x18\b \x01(\tR\x11managedLabelValue\x12\"\n" + "\fiptablesPath\x18\t \x01(\tR\fiptablesPath\x12\x1c\n" + diff --git a/operator/pkg/render/manifest_test.go b/operator/pkg/render/manifest_test.go index 09b915545..55db157bb 100644 --- a/operator/pkg/render/manifest_test.go +++ b/operator/pkg/render/manifest_test.go @@ -214,7 +214,7 @@ func TestGenerateManifestProxylessCNIIsGlobalByDefault(t *testing.T) { "values.global.proxyless.cni.binDir=/var/lib/cni/bin", "values.global.proxyless.cni.confDir=/var/lib/cni/net.d", "values.global.proxyless.cni.stateDir=/run/dubbo-cni", - "values.global.proxyless.cni.xserverPort=16080", + "values.global.proxyless.cni.grpcInboundPort=16080", "values.global.proxyless.cni.ipsetPath=/usr/sbin/ipset", "values.global.proxyless.cni.refreshInterval=30s", }, nil, nil) @@ -239,7 +239,7 @@ func TestGenerateManifestProxylessCNIIsGlobalByDefault(t *testing.T) { "--bin-dir=/var/lib/cni/bin", "--conf-dir=/var/lib/cni/net.d", "--state-dir=/run/dubbo-cni", - "--xserver-port=16080", + "--grpc-inbound-port=16080", "--ipset-path=/usr/sbin/ipset", "--refresh-interval=30s", } { diff --git a/pkg/cni/config.go b/pkg/cni/config.go index 82620bdb3..669d0ac87 100644 --- a/pkg/cni/config.go +++ b/pkg/cni/config.go @@ -42,7 +42,7 @@ type NetConf struct { KubeConfig string `json:"kubeconfig,omitempty"` ManagedLabel string `json:"managedLabel,omitempty"` ManagedLabelValue string `json:"managedLabelValue,omitempty"` - XServerPort int `json:"xserverPort,omitempty"` + GRPCInboundPort int `json:"grpcInboundPort,omitempty"` StateDir string `json:"stateDir,omitempty"` IPTablesPath string `json:"iptablesPath,omitempty"` IPSetPath string `json:"ipsetPath,omitempty"` @@ -69,8 +69,8 @@ func ParseNetConf(data []byte) (NetConf, error) { if conf.ManagedLabelValue == "" { conf.ManagedLabelValue = inject.ProxylessManagedLabelValue } - if conf.XServerPort == 0 { - conf.XServerPort = inject.ProxylessXServerPort + if conf.GRPCInboundPort == 0 { + conf.GRPCInboundPort = inject.ProxylessGRPCInboundPort } if conf.IPTablesPath == "" { conf.IPTablesPath = defaultIPTablesPath diff --git a/pkg/cni/config_test.go b/pkg/cni/config_test.go index f4454a915..d0773c3df 100644 --- a/pkg/cni/config_test.go +++ b/pkg/cni/config_test.go @@ -34,8 +34,8 @@ func TestParseNetConfDefaults(t *testing.T) { t.Fatalf("managed label = %s/%s, want %s/%s", conf.ManagedLabel, conf.ManagedLabelValue, inject.ProxylessManagedLabel, inject.ProxylessManagedLabelValue) } - if conf.XServerPort != inject.ProxylessXServerPort { - t.Fatalf("xserverPort = %d, want %d", conf.XServerPort, inject.ProxylessXServerPort) + if conf.GRPCInboundPort != inject.ProxylessGRPCInboundPort { + t.Fatalf("grpcInboundPort = %d, want %d", conf.GRPCInboundPort, inject.ProxylessGRPCInboundPort) } if conf.IPTablesPath != defaultIPTablesPath || conf.IPSetPath != defaultIPSetPath { t.Fatalf("iptables/ipset path = %s/%s, want %s/%s", conf.IPTablesPath, conf.IPSetPath, defaultIPTablesPath, defaultIPSetPath) diff --git a/pkg/cni/install.go b/pkg/cni/install.go index df8bdb93c..2d9ef1166 100644 --- a/pkg/cni/install.go +++ b/pkg/cni/install.go @@ -54,7 +54,7 @@ type InstallerOptions struct { ManagedLabelValue string IPTablesPath string IPSetPath string - XServerPort int + GRPCInboundPort int } func DefaultInstallerOptions() InstallerOptions { @@ -68,7 +68,7 @@ func DefaultInstallerOptions() InstallerOptions { ManagedLabelValue: inject.ProxylessManagedLabelValue, IPTablesPath: defaultIPTablesPath, IPSetPath: defaultIPSetPath, - XServerPort: inject.ProxylessXServerPort, + GRPCInboundPort: inject.ProxylessGRPCInboundPort, } } @@ -124,8 +124,8 @@ func (o *InstallerOptions) applyDefaults(requireAPIServer bool) error { if o.IPSetPath == "" { o.IPSetPath = defaults.IPSetPath } - if o.XServerPort == 0 { - o.XServerPort = defaults.XServerPort + if o.GRPCInboundPort == 0 { + o.GRPCInboundPort = defaults.GRPCInboundPort } if requireAPIServer && o.APIServer == "" { return fmt.Errorf("kubernetes API server is required") @@ -391,7 +391,7 @@ func pluginConfig(opts InstallerOptions) map[string]any { "kubernetes": map[string]any{"kubeconfig": opts.KubeConfigPath}, "managedLabel": opts.ManagedLabel, "managedLabelValue": opts.ManagedLabelValue, - "xserverPort": opts.XServerPort, + "grpcInboundPort": opts.GRPCInboundPort, "stateDir": opts.StateDir, "iptablesPath": opts.IPTablesPath, "ipsetPath": opts.IPSetPath, diff --git a/pkg/cni/iptables.go b/pkg/cni/iptables.go index 85f976f80..9829b8b5c 100644 --- a/pkg/cni/iptables.go +++ b/pkg/cni/iptables.go @@ -24,8 +24,8 @@ import ( ) const ( - meshInboundChain = "DUBBO-XSERVER-INBOUND" - meshPodIPSet = "DUBBO-XSERVER-PODS" + meshInboundChain = "DUBBO-GRPC-INBOUND" + meshPodIPSet = "DUBBO-GRPC-INBOUND-PODS" ) type CommandRunner interface { @@ -40,20 +40,20 @@ func (execCommandRunner) Run(ctx context.Context, name string, args ...string) ( } type IPTablesRuleManager struct { - path string - ipsetPath string - xserverPort int - dryRun bool - runner CommandRunner + path string + ipsetPath string + grpcInboundPort int + dryRun bool + runner CommandRunner } func NewIPTablesRuleManager(conf NetConf) *IPTablesRuleManager { return &IPTablesRuleManager{ - path: conf.IPTablesPath, - ipsetPath: conf.IPSetPath, - xserverPort: conf.XServerPort, - dryRun: conf.DryRun, - runner: execCommandRunner{}, + path: conf.IPTablesPath, + ipsetPath: conf.IPSetPath, + grpcInboundPort: conf.GRPCInboundPort, + dryRun: conf.DryRun, + runner: execCommandRunner{}, } } @@ -97,11 +97,11 @@ func (m *IPTablesRuleManager) ensureBase(ctx context.Context) error { return err } } - allowXServer := []string{"-m", "set", "--match-set", meshPodIPSet, "dst", "-p", "tcp", "--dport", fmt.Sprint(m.xserverPort), "-j", "RETURN"} + allowGRPCInbound := []string{"-m", "set", "--match-set", meshPodIPSet, "dst", "-p", "tcp", "--dport", fmt.Sprint(m.grpcInboundPort), "-j", "RETURN"} rejectOtherTCP := []string{"-m", "set", "--match-set", meshPodIPSet, "dst", "-p", "tcp", "-j", "REJECT"} - m.deleteRepeated(ctx, allowXServer...) + m.deleteRepeated(ctx, allowGRPCInbound...) m.deleteRepeated(ctx, rejectOtherTCP...) - if err := m.appendRule(ctx, allowXServer...); err != nil { + if err := m.appendRule(ctx, allowGRPCInbound...); err != nil { return err } return m.appendRule(ctx, rejectOtherTCP...) diff --git a/pkg/cni/iptables_test.go b/pkg/cni/iptables_test.go index 845104f8a..56cc67fcd 100644 --- a/pkg/cni/iptables_test.go +++ b/pkg/cni/iptables_test.go @@ -21,9 +21,9 @@ import ( "testing" ) -func TestIPTablesRuleManagerAddsXServerBoundaryRules(t *testing.T) { +func TestIPTablesRuleManagerAddsGRPCInboundBoundaryRules(t *testing.T) { runner := &recordingRunner{} - conf, err := ParseNetConf([]byte(`{"xserverPort":15080}`)) + conf, err := ParseNetConf([]byte(`{"grpcInboundPort":15080}`)) if err != nil { t.Fatalf("ParseNetConf() failed: %v", err) } @@ -35,13 +35,13 @@ func TestIPTablesRuleManagerAddsXServerBoundaryRules(t *testing.T) { joined := strings.Join(runner.commands, "\n") for _, want := range []string{ - "ipset create DUBBO-XSERVER-PODS hash:ip -exist", - "-N DUBBO-XSERVER-INBOUND", - "-I FORWARD 1 -j DUBBO-XSERVER-INBOUND", - "-I OUTPUT 1 -j DUBBO-XSERVER-INBOUND", - "-A DUBBO-XSERVER-INBOUND -m set --match-set DUBBO-XSERVER-PODS dst -p tcp --dport 15080 -j RETURN", - "-A DUBBO-XSERVER-INBOUND -m set --match-set DUBBO-XSERVER-PODS dst -p tcp -j REJECT", - "ipset add DUBBO-XSERVER-PODS 10.244.0.12 -exist", + "ipset create DUBBO-GRPC-INBOUND-PODS hash:ip -exist", + "-N DUBBO-GRPC-INBOUND", + "-I FORWARD 1 -j DUBBO-GRPC-INBOUND", + "-I OUTPUT 1 -j DUBBO-GRPC-INBOUND", + "-A DUBBO-GRPC-INBOUND -m set --match-set DUBBO-GRPC-INBOUND-PODS dst -p tcp --dport 15080 -j RETURN", + "-A DUBBO-GRPC-INBOUND -m set --match-set DUBBO-GRPC-INBOUND-PODS dst -p tcp -j REJECT", + "ipset add DUBBO-GRPC-INBOUND-PODS 10.244.0.12 -exist", } { if !strings.Contains(joined, want) { t.Fatalf("commands missing %q:\n%s", want, joined) diff --git a/pkg/kube/inject/proxyless.go b/pkg/kube/inject/proxyless.go index 350041b9f..cb4aa98ff 100644 --- a/pkg/kube/inject/proxyless.go +++ b/pkg/kube/inject/proxyless.go @@ -42,8 +42,8 @@ const ( ProxylessGRPCKeepaliveTimeout = "10s" ProxylessGRPCConfigFileName = "dubbo-grpc-xds.json" ProxylessGRPCConfigPath = ProxylessXDSMountPath + "/" + ProxylessGRPCConfigFileName - ProxylessXServerContainerName = "dubbo-xserver" - ProxylessXServerPort = 15080 + ProxylessGRPCInboundContainerName = "dubbo-grpc-inbound" + ProxylessGRPCInboundPort = 15080 ProxylessManagedLabel = "proxyless.dubbo.apache.org/managed" ProxylessManagedLabelValue = "true" ) diff --git a/pkg/kube/inject/proxyless_test.go b/pkg/kube/inject/proxyless_test.go index 400ea1bb3..e67fe97ec 100644 --- a/pkg/kube/inject/proxyless_test.go +++ b/pkg/kube/inject/proxyless_test.go @@ -84,17 +84,17 @@ func TestInstallerGRPCEngineTemplateInjectsDirectXDSConnection(t *testing.T) { } if len(injectedPod.Spec.Containers) != 2 { - t.Fatalf("template containers = %d, want app overlay plus xserver", len(injectedPod.Spec.Containers)) + t.Fatalf("template containers = %d, want app overlay plus grpc-inbound", len(injectedPod.Spec.Containers)) } if err := postProcessPod(mergedPod, *injectedPod, req); err != nil { t.Fatalf("postProcessPod() failed: %v", err) } if len(mergedPod.Spec.Containers) != 2 { - t.Fatalf("containers = %d, want application container plus xserver", len(mergedPod.Spec.Containers)) + t.Fatalf("containers = %d, want application container plus grpc-inbound", len(mergedPod.Spec.Containers)) } assertDirectXDSConnection(t, mergedPod, "app", ProxylessGRPCSecretNameForMeta(pod.ObjectMeta)) - assertXServerContainer(t, mergedPod) + assertGRPCInboundContainer(t, mergedPod) } func TestInstallerGRPCEngineTemplateUsesGenerateNameForDeploymentPods(t *testing.T) { @@ -154,10 +154,10 @@ func TestInstallerGRPCEngineTemplateUsesGenerateNameForDeploymentPods(t *testing t.Fatalf("postProcessPod() failed: %v", err) } if len(mergedPod.Spec.Containers) != 2 { - t.Fatalf("containers = %d, want original nginx container plus xserver", len(mergedPod.Spec.Containers)) + t.Fatalf("containers = %d, want original nginx container plus grpc-inbound", len(mergedPod.Spec.Containers)) } assertDirectXDSConnection(t, mergedPod, "nginx", ProxylessGRPCSecretNameForMeta(pod.ObjectMeta)) - assertXServerContainer(t, mergedPod) + assertGRPCInboundContainer(t, mergedPod) if got := mergedPod.Spec.Volumes[0].Secret.SecretName; got == ProxylessGRPCSecretName("") { t.Fatalf("secret name = %q, want generateName-based secret", got) } @@ -242,21 +242,21 @@ func assertNoArgs(t *testing.T, pod *corev1.Pod) { } } -func assertXServerContainer(t *testing.T, pod *corev1.Pod) { +func assertGRPCInboundContainer(t *testing.T, pod *corev1.Pod) { t.Helper() - container := FindContainer(ProxylessXServerContainerName, pod.Spec.Containers) + container := FindContainer(ProxylessGRPCInboundContainerName, pod.Spec.Containers) if container == nil { - t.Fatalf("%s container missing", ProxylessXServerContainerName) + t.Fatalf("%s container missing", ProxylessGRPCInboundContainerName) } if container.Image != "kdubbo/dubbod:debug" { - t.Fatalf("xserver image = %q, want kdubbo/dubbod:debug", container.Image) + t.Fatalf("grpc-inbound image = %q, want kdubbo/dubbod:debug", container.Image) } - wantArgs := []string{"xserver", "--listen", ":15080", "--upstream", "127.0.0.1:80"} + wantArgs := []string{"grpc-inbound", "--listen", ":15080", "--upstream", "127.0.0.1:80"} if strings.Join(container.Args, ",") != strings.Join(wantArgs, ",") { - t.Fatalf("xserver args = %v, want %v", container.Args, wantArgs) + t.Fatalf("grpc-inbound args = %v, want %v", container.Args, wantArgs) } if !hasMount(container.VolumeMounts, ProxylessXDSVolumeName, ProxylessXDSMountPath, true) { - t.Fatalf("xserver proxyless xds mount missing") + t.Fatalf("grpc-inbound proxyless xds mount missing") } } @@ -445,7 +445,7 @@ func TestInstallerGRPCEngineTemplateConfiguresXDSClientForDubbodImage(t *testing } container := mergedPod.Spec.Containers[0] - wantArgs := []string{"xclient", "--watch"} + wantArgs := []string{"grpc-outbound", "--watch"} if strings.Join(container.Args, ",") != strings.Join(wantArgs, ",") { t.Fatalf("args = %v, want %v", container.Args, wantArgs) } diff --git a/pkg/kube/inject/service_test.go b/pkg/kube/inject/service_test.go index 5ed11441f..6e36c4916 100644 --- a/pkg/kube/inject/service_test.go +++ b/pkg/kube/inject/service_test.go @@ -28,7 +28,7 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" ) -func TestRewriteProxylessServiceTargetPortsRoutesTCPServiceToXServer(t *testing.T) { +func TestRewriteProxylessServiceTargetPortsRoutesTCPServiceToGRPCInbound(t *testing.T) { svc := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{Name: "nginx", Namespace: "app"}, Spec: corev1.ServiceSpec{ @@ -44,8 +44,8 @@ func TestRewriteProxylessServiceTargetPortsRoutesTCPServiceToXServer(t *testing. t.Fatalf("rewriteProxylessServiceTargetPorts() = false, want true") } for _, port := range svc.Spec.Ports { - if got := port.TargetPort.IntVal; got != ProxylessXServerPort { - t.Fatalf("port %s targetPort = %d, want %d", port.Name, got, ProxylessXServerPort) + if got := port.TargetPort.IntVal; got != ProxylessGRPCInboundPort { + t.Fatalf("port %s targetPort = %d, want %d", port.Name, got, ProxylessGRPCInboundPort) } } } @@ -110,7 +110,7 @@ func TestRewriteProxylessServiceTargetPortsSkipsNonTCPPorts(t *testing.T) { } } -func TestInjectServiceCreatesXServerTargetPortPatch(t *testing.T) { +func TestInjectServiceCreatesGRPCInboundTargetPortPatch(t *testing.T) { svc := corev1.Service{ ObjectMeta: metav1.ObjectMeta{Name: "nginx", Namespace: "app"}, Spec: corev1.ServiceSpec{ diff --git a/pkg/kube/inject/webhook.go b/pkg/kube/inject/webhook.go index 08f6fd338..8804891ab 100644 --- a/pkg/kube/inject/webhook.go +++ b/pkg/kube/inject/webhook.go @@ -700,7 +700,7 @@ func reorderPod(pod *corev1.Pod, req InjectionParameters) error { // Proxy container should be last to ensure `kubectl exec` and similar commands // continue to default to the user's container pod.Spec.Containers = modifyContainers(pod.Spec.Containers, ProxyContainerName, MoveLast) - pod.Spec.Containers = modifyContainers(pod.Spec.Containers, ProxylessXServerContainerName, MoveLast) + pod.Spec.Containers = modifyContainers(pod.Spec.Containers, ProxylessGRPCInboundContainerName, MoveLast) return nil } @@ -739,10 +739,10 @@ func rewriteProxylessServiceTargetPorts(svc *corev1.Service) bool { if port.Protocol != "" && port.Protocol != corev1.ProtocolTCP { continue } - if port.TargetPort.Type == intstr.Int && port.TargetPort.IntVal == ProxylessXServerPort { + if port.TargetPort.Type == intstr.Int && port.TargetPort.IntVal == ProxylessGRPCInboundPort { continue } - port.TargetPort = intstr.FromInt(ProxylessXServerPort) + port.TargetPort = intstr.FromInt(ProxylessGRPCInboundPort) changed = true } return changed