Skip to content

[werft] Set publicApi.httpPort #11833

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .werft/jobs/build/installer/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ EOF`);
exec(`yq w -i ${this.options.installerConfigPath} experimental.webapp.publicApi.enabled true`, {
slice: slice,
});
exec(`yq w -i ${this.options.installerConfigPath} experimental.webapp.publicApi.httpPort 9002`, {
slice: slice,
});
}

private configureUsage(slice: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
},
}

if exp := getExperimentalPublicAPIConfig(ctx); exp != nil && exp.HttpPort != 0 {
cfg.Server.Services.HTTP = &baseserver.ServerConfiguration{
Address: fmt.Sprintf(":%d", exp.HttpPort),
}
}

fc, err := common.ToJSONString(cfg)
if err != nil {
return nil, fmt.Errorf("failed to marshal config: %w", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/gitpod-io/gitpod/common-go/baseserver"
"github.com/gitpod-io/gitpod/installer/pkg/common"
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"
"github.com/gitpod-io/gitpod/public-api/config"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -50,3 +51,43 @@ func TestConfigMap(t *testing.T) {
},
}, cm)
}

func TestConfigMapWithHttpConfiguration(t *testing.T) {
ctx := renderContextWithPublicAPIConfig(t, &experimental.PublicAPIConfig{Enabled: true, HttpPort: 9002})

objs, err := configmap(ctx)
require.NoError(t, err)

require.Len(t, objs, 1, "must only render one configmap")

expectedConfiguration := config.Configuration{
GitpodServiceURL: "wss://test.domain.everything.awesome.is/api/v1",
Server: &baseserver.Configuration{
Services: baseserver.ServicesConfiguration{
GRPC: &baseserver.ServerConfiguration{
Address: fmt.Sprintf(":%d", GRPCContainerPort),
},
HTTP: &baseserver.ServerConfiguration{
Address: ":9002",
},
},
},
}

expectedJSON, err := common.ToJSONString(expectedConfiguration)
require.NoError(t, err)

cm := objs[0].(*corev1.ConfigMap)
require.Equal(t, &corev1.ConfigMap{
TypeMeta: common.TypeMetaConfigmap,
ObjectMeta: metav1.ObjectMeta{
Name: Component,
Namespace: ctx.Namespace,
Labels: common.CustomizeLabel(ctx, Component, common.TypeMetaConfigmap),
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaConfigmap),
},
Data: map[string]string{
"config.json": string(expectedJSON),
},
}, cm)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ const (
GRPCPortName = "grpc"
GRPCContainerPort = 9001
GRPCServicePort = 9001
HTTPServicePort = 9002
HTTPPortName = "http"
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ func TestObjects_RenderedWhenExperimentalConfigSet(t *testing.T) {
}

func renderContextWithPublicAPIEnabled(t *testing.T) *common.RenderContext {
return renderContextWithPublicAPIConfig(t, &experimental.PublicAPIConfig{Enabled: true})
}

func renderContextWithPublicAPIConfig(t *testing.T, cfg *experimental.PublicAPIConfig) *common.RenderContext {
ctx, err := common.NewRenderContext(config.Config{
Domain: "test.domain.everything.awesome.is",
Experimental: &experimental.Config{
WebApp: &experimental.WebAppConfig{
PublicAPI: &experimental.PublicAPIConfig{Enabled: true},
PublicAPI: cfg,
},
},
}, versions.Manifest{
Expand Down
14 changes: 12 additions & 2 deletions install/installer/pkg/components/public-api-server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@ import (
)

func service(ctx *common.RenderContext) ([]runtime.Object, error) {
return common.GenerateService(Component, []common.ServicePort{
servicePorts := []common.ServicePort{
{
Name: GRPCPortName,
ContainerPort: GRPCContainerPort,
ServicePort: GRPCServicePort,
},
})(ctx)
}

if exp := getExperimentalPublicAPIConfig(ctx); exp != nil && exp.HttpPort != 0 {
servicePorts = append(servicePorts, common.ServicePort{
Name: HTTPPortName,
ContainerPort: exp.HttpPort,
ServicePort: HTTPServicePort,
})
}

return common.GenerateService(Component, servicePorts)(ctx)
}
3 changes: 2 additions & 1 deletion install/installer/pkg/config/v1/experimental/experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ type ProxyConfig struct {
}

type PublicAPIConfig struct {
Enabled bool `json:"enabled"`
Enabled bool `json:"enabled"`
HttpPort int32 `json:"httpPort"`
}

type UsageConfig struct {
Expand Down