Skip to content
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

[installer] Allow extra service annotations for ide-proxy and openvsx-proxy #9788

Merged
merged 3 commits into from
May 5, 2022
Merged
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
7 changes: 1 addition & 6 deletions install/installer/pkg/components/ide-proxy/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import "github.com/gitpod-io/gitpod/installer/pkg/common"
var Objects = common.CompositeRenderFunc(
deployment,
rolebinding,
common.GenerateService(Component, map[string]common.ServicePort{
PortName: {
ContainerPort: ContainerPort,
ServicePort: ServicePort,
},
}),
service,
common.DefaultServiceAccount(Component),
)
36 changes: 36 additions & 0 deletions install/installer/pkg/components/ide-proxy/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package ide_proxy

import (
"github.com/gitpod-io/gitpod/installer/pkg/common"
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
)

func service(ctx *common.RenderContext) ([]runtime.Object, error) {
var annotations map[string]string
_ = ctx.WithExperimental(func(cfg *experimental.Config) error {
if cfg.IDE != nil && cfg.IDE.IDEProxyConfig != nil {
annotations = cfg.IDE.IDEProxyConfig.ServiceAnnotations
}
return nil
})

ports := map[string]common.ServicePort{
PortName: {
ContainerPort: ContainerPort,
ServicePort: ServicePort,
},
}

return common.GenerateService(Component, ports, func(service *corev1.Service) {
for k, v := range annotations {
service.Annotations[k] = v
}
})(ctx)
}
51 changes: 51 additions & 0 deletions install/installer/pkg/components/ide-proxy/service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the MIT License. See License-MIT.txt in the project root for license information.

package ide_proxy

import (
"testing"

"github.com/gitpod-io/gitpod/installer/pkg/common"
"github.com/gitpod-io/gitpod/installer/pkg/config/v1"
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"
"github.com/gitpod-io/gitpod/installer/pkg/config/versions"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
)

func TestServiceAnnotations(t *testing.T) {
annotations := map[string]string{"hello": "world"}

ctx := renderContextWithIDEProxyConfig(t, &experimental.IDEProxyConfig{ServiceAnnotations: annotations})

objects, err := service(ctx)
require.NoError(t, err)

require.Len(t, objects, 1, "must render only one object")

svc := objects[0].(*corev1.Service)
for k, v := range annotations {
require.Equalf(t, annotations[k], svc.Annotations[k],
"expected to find annotation %q:%q on ide-proxy service, but found %q:%q", k, v, k, svc.Annotations[k])
}
}

func renderContextWithIDEProxyConfig(t *testing.T, proxyConfig *experimental.IDEProxyConfig) *common.RenderContext {
ctx, err := common.NewRenderContext(config.Config{
Experimental: &experimental.Config{
IDE: &experimental.IDEConfig{
IDEProxyConfig: proxyConfig,
},
},
}, versions.Manifest{
Components: versions.Components{
PublicAPIServer: versions.Versioned{
Version: "commit-test-latest",
},
},
}, "test-namespace")
require.NoError(t, err)

return ctx
}
11 changes: 1 addition & 10 deletions install/installer/pkg/components/openvsx-proxy/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ var Objects = common.CompositeRenderFunc(
networkpolicy,
rolebinding,
statefulset,
common.GenerateService(Component, map[string]common.ServicePort{
PortName: {
ContainerPort: ContainerPort,
ServicePort: ServicePort,
},
PrometheusPortName: {
ContainerPort: PrometheusPort,
ServicePort: PrometheusPort,
},
}),
service,
common.DefaultServiceAccount(Component),
)
40 changes: 40 additions & 0 deletions install/installer/pkg/components/openvsx-proxy/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package openvsx_proxy

import (
"github.com/gitpod-io/gitpod/installer/pkg/common"
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
)

func service(ctx *common.RenderContext) ([]runtime.Object, error) {
var annotations map[string]string
_ = ctx.WithExperimental(func(cfg *experimental.Config) error {
if cfg.IDE != nil && cfg.IDE.VSXProxyConfig != nil {
annotations = cfg.IDE.VSXProxyConfig.ServiceAnnotations
}
return nil
})

ports := map[string]common.ServicePort{
PortName: {
ContainerPort: ContainerPort,
ServicePort: ServicePort,
},
PrometheusPortName: {
ContainerPort: PrometheusPort,
ServicePort: PrometheusPort,
},
}

return common.GenerateService(Component, ports, func(service *corev1.Service) {
for k, v := range annotations {
service.Annotations[k] = v
}
})(ctx)
}
51 changes: 51 additions & 0 deletions install/installer/pkg/components/openvsx-proxy/service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the MIT License. See License-MIT.txt in the project root for license information.

package openvsx_proxy

import (
"testing"

"github.com/gitpod-io/gitpod/installer/pkg/common"
"github.com/gitpod-io/gitpod/installer/pkg/config/v1"
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"
"github.com/gitpod-io/gitpod/installer/pkg/config/versions"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
)

func TestServiceAnnotations(t *testing.T) {
annotations := map[string]string{"hello": "world"}

ctx := renderContextWithVSXProxyConfig(t, &experimental.VSXProxyConfig{ServiceAnnotations: annotations})

objects, err := service(ctx)
require.NoError(t, err)

require.Len(t, objects, 1, "must render only one object")

svc := objects[0].(*corev1.Service)
for k, v := range annotations {
require.Equalf(t, annotations[k], svc.Annotations[k],
"expected to find annotation %q:%q on openvsx-proxy service, but found %q:%q", k, v, k, svc.Annotations[k])
}
}

func renderContextWithVSXProxyConfig(t *testing.T, proxyConfig *experimental.VSXProxyConfig) *common.RenderContext {
ctx, err := common.NewRenderContext(config.Config{
Experimental: &experimental.Config{
IDE: &experimental.IDEConfig{
VSXProxyConfig: proxyConfig,
},
},
}, versions.Manifest{
Components: versions.Components{
PublicAPIServer: versions.Versioned{
Version: "commit-test-latest",
},
},
}, "test-namespace")
require.NoError(t, err)

return ctx
}
12 changes: 11 additions & 1 deletion install/installer/pkg/config/v1/experimental/experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,17 @@ type PublicAPIConfig struct {

type IDEConfig struct {
// Disable resolution of latest images and use bundled latest versions instead
ResolveLatest *bool `json:"resolveLatest,omitempty"`
ResolveLatest *bool `json:"resolveLatest,omitempty"`
IDEProxyConfig *IDEProxyConfig `json:"ideProxy,omitempty"`
VSXProxyConfig *VSXProxyConfig `json:"openvsxProxy,omitempty"`
}

type IDEProxyConfig struct {
ServiceAnnotations map[string]string `json:"serviceAnnotations"`
}

type VSXProxyConfig struct {
ServiceAnnotations map[string]string `json:"serviceAnnotations"`
}

type TracingSampleType string
Expand Down