func Run()

in grpc-xds/greeter-go/pkg/server/server.go [69:111]


func Run(ctx context.Context, c Config) error {
	logger := logging.FromContext(ctx)
	healthServer := health.NewServer()
	serverOptions, err := configureServerOptions(logger, healthServer)
	if err != nil {
		return fmt.Errorf("could not set gRPC server options: %w", err)
	}

	servingGRPCServer, err := newGRPCServer(logger, c.UseXDS, serverOptions...)
	if err != nil {
		return fmt.Errorf("could not create the serving gRPC server: %w", err)
	}
	healthGRPCServer := grpc.NewServer() // naming is hard :-(
	addServerStopBehavior(ctx, logger, servingGRPCServer, healthGRPCServer, healthServer)

	if err := greeter.RegisterServer(ctx, logger, c.GreeterName, c.NextHop, servingGRPCServer); err != nil {
		return fmt.Errorf("could not register Greeter server: %w", err)
	}

	// Register health server on both serving and health ports
	// Set serving status for k8s startup and liveness probes:
	healthServer.SetServingStatus("", healthpb.HealthCheckResponse_SERVING)
	// Set serving status for k8s readiness probes:
	healthServer.SetServingStatus(helloworldpb.Greeter_ServiceDesc.ServiceName, healthpb.HealthCheckResponse_NOT_SERVING)
	healthpb.RegisterHealthServer(servingGRPCServer, healthServer)
	healthpb.RegisterHealthServer(healthGRPCServer, healthServer)

	// Register admin services on both serving and health ports
	cleanupAdminServers, err := registerAdminServers(c.UseXDS, servingGRPCServer, healthGRPCServer)
	if err != nil {
		return fmt.Errorf("could not register admin servers: %w", err)
	}
	defer func() {
		logger.V(2).Info("Cleaning up admin servers as the gRPC server is stopping")
		cleanupAdminServers()
	}()

	// Enable reflection on both serving and health ports
	reflection.Register(servingGRPCServer)
	reflection.Register(healthGRPCServer)

	return serve(logger, c, servingGRPCServer, healthServer, healthGRPCServer)
}