Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/components/openvsx-proxy/configmap.go
2501 views
1
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package openvsx_proxy
6
7
import (
8
"fmt"
9
"net/url"
10
"time"
11
12
"github.com/gitpod-io/gitpod/common-go/util"
13
"github.com/gitpod-io/gitpod/installer/pkg/common"
14
openvsx "github.com/gitpod-io/gitpod/openvsx-proxy/pkg"
15
corev1 "k8s.io/api/core/v1"
16
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17
"k8s.io/apimachinery/pkg/runtime"
18
)
19
20
func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
21
domain, err := url.Parse(ctx.Config.OpenVSX.URL)
22
if err != nil {
23
return nil, fmt.Errorf("cannot parse openvsx url: %w", err)
24
}
25
imgcfg := openvsx.Config{
26
LogDebug: false,
27
CacheDurationRegular: util.Duration(time.Minute * 5),
28
CacheDurationBackup: util.Duration(time.Hour * 72),
29
URLUpstream: ctx.Config.OpenVSX.URL,
30
MaxIdleConns: 1000,
31
MaxIdleConnsPerHost: 1000,
32
PrometheusAddr: common.LocalhostPrometheusAddr(),
33
RedisAddr: "localhost:6379",
34
AllowCacheDomain: []string{domain.Host},
35
}
36
37
redisCfg := `
38
maxmemory 100mb
39
maxmemory-policy allkeys-lfu
40
`
41
42
fc, err := common.ToJSONString(imgcfg)
43
if err != nil {
44
return nil, fmt.Errorf("failed to marshal openvsx config: %w", err)
45
}
46
47
data := map[string]string{
48
"config.json": string(fc),
49
"redis.conf": redisCfg,
50
}
51
52
return []runtime.Object{
53
&corev1.ConfigMap{
54
TypeMeta: common.TypeMetaConfigmap,
55
ObjectMeta: metav1.ObjectMeta{
56
Name: fmt.Sprintf("%s-config", Component),
57
Namespace: ctx.Namespace,
58
Labels: common.CustomizeLabel(ctx, Component, common.TypeMetaConfigmap),
59
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaConfigmap),
60
},
61
Data: data,
62
},
63
}, nil
64
}
65
66