Skip to content

Commit 5dd9465

Browse files
csweichelroboquat
authored andcommitted
[public-api] Adapt to new baseserver structure
1 parent 4960dce commit 5dd9465

File tree

12 files changed

+41
-36
lines changed

12 files changed

+41
-36
lines changed

components/common-go/baseserver/testing.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ func NewForTests(t *testing.T, opts ...Option) *Server {
3737
return srv
3838
}
3939

40+
func MustUseRandomLocalAddress(t *testing.T) *ServerConfiguration {
41+
t.Helper()
42+
43+
return &ServerConfiguration{
44+
Address: fmt.Sprintf("localhost:%d", MustFindFreePort(t)),
45+
}
46+
}
47+
4048
func MustFindFreePort(t *testing.T) int {
4149
t.Helper()
4250

components/public-api-server/pkg/apiv1/workspace_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ package apiv1
77
import (
88
"context"
99
"errors"
10+
"testing"
11+
1012
"github.com/gitpod-io/gitpod/common-go/baseserver"
1113
gitpod "github.com/gitpod-io/gitpod/gitpod-protocol"
1214
v1 "github.com/gitpod-io/gitpod/public-api/v1"
@@ -18,7 +20,6 @@ import (
1820
"google.golang.org/grpc/metadata"
1921
"google.golang.org/grpc/status"
2022
"google.golang.org/protobuf/testing/protocmp"
21-
"testing"
2223
)
2324

2425
func TestWorkspaceService_GetWorkspace(t *testing.T) {
@@ -30,7 +31,9 @@ func TestWorkspaceService_GetWorkspace(t *testing.T) {
3031
description = "This is the description"
3132
)
3233

33-
srv := baseserver.NewForTests(t)
34+
srv := baseserver.NewForTests(t,
35+
baseserver.WithGRPC(baseserver.MustUseRandomLocalAddress(t)),
36+
)
3437

3538
connPool := &FakeServerConnPool{
3639
api: &FakeGitpodAPI{workspaces: map[string]*gitpod.WorkspaceInfo{
@@ -113,7 +116,9 @@ func TestWorkspaceService_GetWorkspace(t *testing.T) {
113116
}
114117

115118
func TestWorkspaceService_GetOwnerToken(t *testing.T) {
116-
srv := baseserver.NewForTests(t)
119+
srv := baseserver.NewForTests(t,
120+
baseserver.WithGRPC(baseserver.MustUseRandomLocalAddress(t)),
121+
)
117122
var connPool *FakeServerConnPool
118123

119124
v1.RegisterWorkspacesServiceServer(srv.GRPC(), NewWorkspaceService(connPool))

components/public-api-server/pkg/proxy/prometheusmetrics_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package proxy
66

77
import (
88
"context"
9+
"testing"
10+
911
"github.com/gitpod-io/gitpod/common-go/baseserver"
1012
v1 "github.com/gitpod-io/gitpod/public-api/v1"
1113
"github.com/prometheus/client_golang/prometheus"
@@ -14,12 +16,13 @@ import (
1416
"google.golang.org/grpc"
1517
"google.golang.org/grpc/credentials/insecure"
1618
"google.golang.org/grpc/metadata"
17-
"testing"
1819
)
1920

2021
func TestConnectionCreationWasTracked(t *testing.T) {
2122
// Set up server
22-
srv := baseserver.NewForTests(t)
23+
srv := baseserver.NewForTests(t,
24+
baseserver.WithGRPC(baseserver.MustUseRandomLocalAddress(t)),
25+
)
2326
baseserver.StartServerForTests(t, srv)
2427

2528
// Set up Prometheus registry

components/public-api-server/pkg/server/integration_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ package server
66

77
import (
88
"context"
9+
"net/url"
10+
"testing"
11+
912
"github.com/gitpod-io/gitpod/common-go/baseserver"
1013
v1 "github.com/gitpod-io/gitpod/public-api/v1"
1114
"github.com/prometheus/client_golang/prometheus"
@@ -15,13 +18,13 @@ import (
1518
"google.golang.org/grpc/credentials/insecure"
1619
"google.golang.org/grpc/metadata"
1720
"google.golang.org/grpc/status"
18-
"net/url"
19-
"testing"
2021
)
2122

2223
func TestPublicAPIServer_v1_WorkspaceService(t *testing.T) {
2324
ctx := metadata.AppendToOutgoingContext(context.Background(), "authorization", "some-token")
24-
srv := baseserver.NewForTests(t)
25+
srv := baseserver.NewForTests(t,
26+
baseserver.WithGRPC(baseserver.MustUseRandomLocalAddress(t)),
27+
)
2528
registry := prometheus.NewRegistry()
2629

2730
gitpodAPI, err := url.Parse("wss://main.preview.gitpod-dev.com/api/v1")
@@ -68,7 +71,7 @@ func TestPublicAPIServer_v1_WorkspaceService(t *testing.T) {
6871

6972
func TestPublicAPIServer_v1_PrebuildService(t *testing.T) {
7073
ctx := context.Background()
71-
srv := baseserver.NewForTests(t)
74+
srv := baseserver.NewForTests(t, baseserver.WithGRPC(baseserver.MustUseRandomLocalAddress(t)))
7275
registry := prometheus.NewRegistry()
7376

7477
gitpodAPI, err := url.Parse("wss://main.preview.gitpod-dev.com/api/v1")

install/installer/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ require (
131131
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
132132
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
133133
github.com/hashicorp/golang-lru v0.5.4 // indirect
134+
github.com/heptiolabs/healthcheck v0.0.0-20211123025425-613501dd5deb // indirect
134135
github.com/huandu/xstrings v1.3.2 // indirect
135136
github.com/imdario/mergo v0.3.12 // indirect
136137
github.com/inconshreveable/mousetrap v1.0.0 // indirect

install/installer/go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,8 @@ github.com/hashicorp/vault/api v1.0.4/go.mod h1:gDcqh3WGcR1cpF5AJz/B1UFheUEneMoI
843843
github.com/hashicorp/vault/sdk v0.1.13/go.mod h1:B+hVj7TpuQY1Y/GPbCpffmgd+tSEwvhkWnjtSYCaS2M=
844844
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
845845
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
846+
github.com/heptiolabs/healthcheck v0.0.0-20211123025425-613501dd5deb h1:tsEKRC3PU9rMw18w/uAptoijhgG4EvlA5kfJPtwrMDk=
847+
github.com/heptiolabs/healthcheck v0.0.0-20211123025425-613501dd5deb/go.mod h1:NtmN9h8vrTveVQRLHcX2HQ5wIPBDCsZ351TGbZWgg38=
846848
github.com/howeyc/gopass v0.0.0-20170109162249-bf9dde6d0d2c/go.mod h1:lADxMC39cJJqL93Duh1xhAs4I2Zs8mKS89XWXFGp9cs=
847849
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
848850
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
@@ -2638,6 +2640,7 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
26382640
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
26392641
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
26402642
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
2643+
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0 h1:FVCohIoYO7IJoDDVpV2pdq7SgrMH6wHnuTyrdrxJNoY=
26412644
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
26422645
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
26432646
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw=

install/installer/pkg/components/public-api-server/constants.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ package public_api_server
77
const (
88
Component = "public-api-server"
99

10-
DebugPortName = "debug"
11-
DebugContainerPort = 9000
12-
DebugServicePort = 9000
13-
1410
GRPCPortName = "grpc"
1511
GRPCContainerPort = 9001
1612
GRPCServicePort = 9001

install/installer/pkg/components/public-api-server/deployment.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package public_api_server
55

66
import (
77
"fmt"
8+
9+
"github.com/gitpod-io/gitpod/common-go/baseserver"
810
"github.com/gitpod-io/gitpod/installer/pkg/cluster"
911
"github.com/gitpod-io/gitpod/installer/pkg/common"
1012
appsv1 "k8s.io/api/apps/v1"
@@ -47,7 +49,6 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
4749
Name: Component,
4850
Image: ctx.ImageName(ctx.Config.Repository, Component, ctx.VersionManifest.Components.PublicAPIServer.Version),
4951
Args: []string{
50-
fmt.Sprintf("--debug-port=%d", DebugContainerPort),
5152
fmt.Sprintf("--grpc-port=%d", GRPCContainerPort),
5253
fmt.Sprintf("--gitpod-api-url=wss://%s/api/v1", ctx.Config.Domain),
5354
},
@@ -59,10 +60,6 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
5960
},
6061
}),
6162
Ports: []corev1.ContainerPort{
62-
{
63-
ContainerPort: DebugContainerPort,
64-
Name: DebugPortName,
65-
},
6663
{
6764
ContainerPort: GRPCContainerPort,
6865
Name: GRPCPortName,
@@ -78,7 +75,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
7875
ProbeHandler: corev1.ProbeHandler{
7976
HTTPGet: &corev1.HTTPGetAction{
8077
Path: "/live",
81-
Port: intstr.IntOrString{IntVal: DebugContainerPort},
78+
Port: intstr.IntOrString{IntVal: baseserver.BuiltinHealthPort},
8279
Scheme: corev1.URISchemeHTTP,
8380
},
8481
},
@@ -90,7 +87,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
9087
ProbeHandler: corev1.ProbeHandler{
9188
HTTPGet: &corev1.HTTPGetAction{
9289
Path: "/ready",
93-
Port: intstr.IntOrString{IntVal: DebugContainerPort},
90+
Port: intstr.IntOrString{IntVal: baseserver.BuiltinHealthPort},
9491
Scheme: corev1.URISchemeHTTP,
9592
},
9693
},
@@ -99,7 +96,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
9996
TimeoutSeconds: 1,
10097
},
10198
},
102-
*common.KubeRBACProxyContainerWithConfig(ctx, 9500, fmt.Sprintf("http://127.0.0.1:%d/", DebugContainerPort)),
99+
*common.KubeRBACProxyContainerWithConfig(ctx, 9500, fmt.Sprintf("http://127.0.0.1:%d/", baseserver.BuiltinDebugPort)),
103100
},
104101
},
105102
},

install/installer/pkg/components/public-api-server/deployment_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
package public_api_server
55

66
import (
7+
"testing"
8+
79
"github.com/stretchr/testify/require"
810
appsv1 "k8s.io/api/apps/v1"
9-
"testing"
1011
)
1112

1213
func TestDeployment(t *testing.T) {
@@ -35,7 +36,6 @@ func TestDeployment_ServerArguments(t *testing.T) {
3536

3637
apiContainer := containers[0]
3738
require.EqualValues(t, []string{
38-
"--debug-port=9000",
3939
"--grpc-port=9001",
4040
`--gitpod-api-url=wss://test.domain.everything.awesome.is/api/v1`,
4141
}, apiContainer.Args)

install/installer/pkg/components/public-api-server/networkpolicy.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ func networkpolicy(ctx *common.RenderContext) ([]runtime.Object, error) {
2929
Ingress: []networkingv1.NetworkPolicyIngressRule{
3030
{
3131
Ports: []networkingv1.NetworkPolicyPort{
32-
{
33-
Protocol: common.TCPProtocol,
34-
Port: &intstr.IntOrString{IntVal: DebugContainerPort},
35-
},
3632
{
3733
Protocol: common.TCPProtocol,
3834
Port: &intstr.IntOrString{IntVal: GRPCContainerPort},

install/installer/pkg/components/public-api-server/networkpolicy_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
package public_api_server
55

66
import (
7+
"testing"
8+
79
"github.com/gitpod-io/gitpod/installer/pkg/common"
810
"github.com/stretchr/testify/require"
911
networkingv1 "k8s.io/api/networking/v1"
1012
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1113
"k8s.io/apimachinery/pkg/util/intstr"
12-
"testing"
1314
)
1415

1516
func TestNetworkPolicy(t *testing.T) {
@@ -25,10 +26,6 @@ func TestNetworkPolicy(t *testing.T) {
2526

2627
require.Equal(t, networkingv1.NetworkPolicyIngressRule{
2728
Ports: []networkingv1.NetworkPolicyPort{
28-
{
29-
Protocol: common.TCPProtocol,
30-
Port: &intstr.IntOrString{IntVal: DebugContainerPort},
31-
},
3229
{
3330
Protocol: common.TCPProtocol,
3431
Port: &intstr.IntOrString{IntVal: GRPCContainerPort},

install/installer/pkg/components/public-api-server/service.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import (
1010

1111
func service(ctx *common.RenderContext) ([]runtime.Object, error) {
1212
return common.GenerateService(Component, map[string]common.ServicePort{
13-
DebugPortName: {
14-
ContainerPort: DebugContainerPort,
15-
ServicePort: DebugServicePort,
16-
},
1713
GRPCPortName: {
1814
ContainerPort: GRPCContainerPort,
1915
ServicePort: GRPCServicePort,

0 commit comments

Comments
 (0)