-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Use TLS for websocket and gRPC tests #11322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b1c88b6
12e906b
9f4255f
91b18bf
8e9156c
1094643
ba200a5
9483bd3
eddd5fd
cd63ee5
73315d3
e6014e0
debaa23
09c9c39
46e3826
4119f08
6f0d9e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ import ( | |
|
|
||
| "golang.org/x/sync/errgroup" | ||
| "google.golang.org/grpc" | ||
| "google.golang.org/grpc/credentials" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
|
|
||
|
|
@@ -49,7 +50,6 @@ import ( | |
| const ( | ||
| grpcContainerConcurrency = 1 | ||
| grpcMinScale = 3 | ||
| defaultPort = "80" | ||
| ) | ||
|
|
||
| type grpcTest func(*TestContext, string, string) | ||
|
|
@@ -64,30 +64,35 @@ func hasPort(u string) bool { | |
| return err == nil | ||
| } | ||
|
|
||
| func dial(host, domain string) (*grpc.ClientConn, error) { | ||
| func dial(ctx *TestContext, host, domain string) (*grpc.ClientConn, error) { | ||
| defaultPort := "80" | ||
| if test.ServingFlags.HTTPS { | ||
| defaultPort = "443" | ||
| } | ||
| if !hasPort(host) { | ||
| host = net.JoinHostPort(host, defaultPort) | ||
| } | ||
| if !hasPort(domain) { | ||
| domain = net.JoinHostPort(domain, defaultPort) | ||
| } | ||
|
|
||
| if host != domain { | ||
| // The host to connect and the domain accepted differ. | ||
| // We need to do grpc.WithAuthority(...) here. | ||
| return grpc.Dial( | ||
| host, | ||
| grpc.WithAuthority(domain), | ||
| grpc.WithInsecure(), | ||
| // Retrying DNS errors to avoid .xip.io issues. | ||
| grpc.WithDefaultCallOptions(grpc.WaitForReady(true)), | ||
| ) | ||
| secureOpt := grpc.WithInsecure() | ||
| if test.ServingFlags.HTTPS { | ||
| tlsConfig := test.TLSClientConfig(context.Background(), ctx.t.Logf, ctx.clients) | ||
| // Set ServerName for pseudo hostname with TLS. | ||
| var err error | ||
| tlsConfig.ServerName, _, err = net.SplitHostPort(domain) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| secureOpt = grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)) | ||
| } | ||
| // This is a more preferred usage of the go-grpc client. | ||
|
|
||
| return grpc.Dial( | ||
| host, | ||
| grpc.WithInsecure(), | ||
| // Retrying DNS errors to avoid .xip.io issues. | ||
| grpc.WithAuthority(domain), | ||
| secureOpt, | ||
| // Retrying DNS errors to avoid .sslip.io issues. | ||
| grpc.WithDefaultCallOptions(grpc.WaitForReady(true)), | ||
| ) | ||
| } | ||
|
|
@@ -96,7 +101,7 @@ func unaryTest(ctx *TestContext, host, domain string) { | |
| ctx.t.Helper() | ||
| ctx.t.Logf("Connecting to grpc-ping using host %q and authority %q", host, domain) | ||
| const want = "Hello!" | ||
| got, err := pingGRPC(host, domain, want) | ||
| got, err := pingGRPC(ctx, host, domain, want) | ||
| if err != nil { | ||
| ctx.t.Fatal("gRPC ping =", err) | ||
| } | ||
|
|
@@ -150,7 +155,7 @@ func loadBalancingTest(ctx *TestContext, host, domain string) { | |
| case <-stopChan: | ||
| return nil | ||
| default: | ||
| got, err := pingGRPC(host, domain, wantPrefix) | ||
| got, err := pingGRPC(ctx, host, domain, wantPrefix) | ||
| if err != nil { | ||
| return fmt.Errorf("ping gRPC error: %w", err) | ||
| } | ||
|
|
@@ -190,7 +195,7 @@ func loadBalancingTest(ctx *TestContext, host, domain string) { | |
| } | ||
| } | ||
|
|
||
| func generateGRPCTraffic(concurrentRequests int, host, domain string, stopChan chan struct{}) error { | ||
| func generateGRPCTraffic(ctx *TestContext, concurrentRequests int, host, domain string, stopChan chan struct{}) error { | ||
| var grp errgroup.Group | ||
|
|
||
| for i := 0; i < concurrentRequests; i++ { | ||
|
|
@@ -202,7 +207,7 @@ func generateGRPCTraffic(concurrentRequests int, host, domain string, stopChan c | |
| return nil | ||
| default: | ||
| want := fmt.Sprintf("Hello! stream:%d request: %d", i, j) | ||
| got, err := pingGRPC(host, domain, want) | ||
| got, err := pingGRPC(ctx, host, domain, want) | ||
|
|
||
| if err != nil { | ||
| return fmt.Errorf("ping gRPC error: %w", err) | ||
|
|
@@ -220,8 +225,8 @@ func generateGRPCTraffic(concurrentRequests int, host, domain string, stopChan c | |
| return nil | ||
| } | ||
|
|
||
| func pingGRPC(host, domain, message string) (string, error) { | ||
| conn, err := dial(host, domain) | ||
| func pingGRPC(ctx *TestContext, host, domain, message string) (string, error) { | ||
| conn, err := dial(ctx, host, domain) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
@@ -251,7 +256,7 @@ func assertGRPCAutoscaleUpToNumPods(ctx *TestContext, curPods, targetPods float6 | |
| var grp errgroup.Group | ||
|
|
||
| grp.Go(func() error { | ||
| return generateGRPCTraffic(int(targetPods*grpcContainerConcurrency), host, domain, stopChan) | ||
| return generateGRPCTraffic(ctx, int(targetPods*grpcContainerConcurrency), host, domain, stopChan) | ||
| }) | ||
|
|
||
| grp.Go(func() error { | ||
|
|
@@ -267,7 +272,7 @@ func assertGRPCAutoscaleUpToNumPods(ctx *TestContext, curPods, targetPods float6 | |
| func streamTest(tc *TestContext, host, domain string) { | ||
| tc.t.Helper() | ||
| tc.t.Logf("Connecting to grpc-ping using host %q and authority %q", host, domain) | ||
| conn, err := dial(host, domain) | ||
| conn, err := dial(tc, host, domain) | ||
| if err != nil { | ||
| tc.t.Fatal("Fail to dial:", err) | ||
| } | ||
|
|
@@ -317,15 +322,25 @@ func streamTest(tc *TestContext, host, domain string) { | |
|
|
||
| func testGRPC(t *testing.T, f grpcTest, fopts ...rtesting.ServiceOption) { | ||
| t.Helper() | ||
| t.Parallel() | ||
| // TODO: https option with parallel leads to flakes. | ||
| // https://github.com/knative/serving/issues/11387 | ||
| if !test.ServingFlags.HTTPS { | ||
| t.Parallel() | ||
| } | ||
|
|
||
| // Setup | ||
| clients := Setup(t) | ||
|
|
||
| t.Log("Creating service for grpc-ping") | ||
|
|
||
| svcName := test.ObjectNameForTest(t) | ||
| // Long name hits this issue https://github.com/knative-sandbox/net-certmanager/issues/214 | ||
| if t.Name() == "TestGRPCStreamingPingViaActivator" { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This very specific check makes me somewhat uncomfortable. Can we do something more generic? Do we need to make sure that the entire domain is < 64 bytes?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we need to make sure that the entire domain is 64 bytes...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reverted my change. I think that the current specific workaround is simple and better. (But please let me know if you have a better idea 😅 ) |
||
| svcName = test.AppendRandomString("grpc-streaming-pig-act") | ||
| } | ||
|
|
||
| names := &test.ResourceNames{ | ||
| Service: test.ObjectNameForTest(t), | ||
| Service: svcName, | ||
| Image: "grpc-ping", | ||
| } | ||
|
|
||
|
|
@@ -357,7 +372,11 @@ func testGRPC(t *testing.T, f grpcTest, fopts ...rtesting.ServiceOption) { | |
| if err != nil { | ||
| t.Fatal("Could not get service endpoint:", err) | ||
| } | ||
| host = net.JoinHostPort(addr, mapper("80")) | ||
| if test.ServingFlags.HTTPS { | ||
| host = net.JoinHostPort(addr, mapper("443")) | ||
| } else { | ||
| host = net.JoinHostPort(addr, mapper("80")) | ||
| } | ||
| } | ||
|
|
||
| f(&TestContext{ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.