Path: blob/main/install/installer/pkg/components/ide-metrics/deployment.go
2501 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package ide_metrics56import (7"github.com/gitpod-io/gitpod/installer/pkg/cluster"8"github.com/gitpod-io/gitpod/installer/pkg/common"910appsv1 "k8s.io/api/apps/v1"11corev1 "k8s.io/api/core/v1"12"k8s.io/apimachinery/pkg/api/resource"13metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"14"k8s.io/apimachinery/pkg/runtime"15"k8s.io/apimachinery/pkg/util/intstr"16"k8s.io/utils/pointer"17)1819func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {20labels := common.CustomizeLabel(ctx, Component, common.TypeMetaDeployment)2122configHash, err := common.ObjectHash(configmap(ctx))23if err != nil {24return nil, err25}2627volumes := make([]corev1.Volume, 0)28volumeMounts := make([]corev1.VolumeMount, 0)2930volumes = append(volumes, corev1.Volume{31Name: VolumeConfig,32VolumeSource: corev1.VolumeSource{33ConfigMap: &corev1.ConfigMapVolumeSource{34LocalObjectReference: corev1.LocalObjectReference{Name: Component},35},36},37})3839volumeMounts = append(volumeMounts, corev1.VolumeMount{40Name: VolumeConfig,41MountPath: "/config",42ReadOnly: true,43})4445env := common.CustomizeEnvvar(ctx, Component, common.MergeEnv(46common.DefaultEnv(&ctx.Config),47))4849if ctx.Config.Components != nil && ctx.Config.Components.IDE != nil && ctx.Config.Components.IDE.Metrics != nil && ctx.Config.Components.IDE.Metrics.ErrorReportingEnabled {50env = append(env, corev1.EnvVar{51Name: "GITPOD_ENABLED_ERROR_REPORTING",52Value: "true",53})54}5556return []runtime.Object{57&appsv1.Deployment{58TypeMeta: common.TypeMetaDeployment,59ObjectMeta: metav1.ObjectMeta{60Name: Component,61Namespace: ctx.Namespace,62Labels: labels,63Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment),64},65Spec: appsv1.DeploymentSpec{66Selector: &metav1.LabelSelector{MatchLabels: common.DefaultLabels(Component)},67Replicas: common.Replicas(ctx, Component),68Strategy: common.DeploymentStrategy,69Template: corev1.PodTemplateSpec{70ObjectMeta: metav1.ObjectMeta{71Name: Component,72Namespace: ctx.Namespace,73Labels: labels,74Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment, func() map[string]string {75return map[string]string{76common.AnnotationConfigChecksum: configHash,77}78}),79},80Spec: corev1.PodSpec{81Affinity: cluster.WithNodeAffinityHostnameAntiAffinity(Component, cluster.AffinityLabelMeta),82TopologySpreadConstraints: cluster.WithHostnameTopologySpread(Component),83ServiceAccountName: Component,84EnableServiceLinks: pointer.Bool(false),85DNSPolicy: corev1.DNSClusterFirst,86RestartPolicy: corev1.RestartPolicyAlways,87TerminationGracePeriodSeconds: pointer.Int64(30),88Containers: []corev1.Container{{89Args: []string{"run", "--config", "/config/config.json"},90Name: Component,91Image: ctx.ImageName(ctx.Config.Repository, Component, ctx.VersionManifest.Components.IDEMetrics.Version),92ImagePullPolicy: corev1.PullIfNotPresent,93Resources: common.ResourceRequirements(ctx, Component, Component, corev1.ResourceRequirements{94Requests: corev1.ResourceList{95"cpu": resource.MustParse("100m"),96"memory": resource.MustParse("128Mi"),97},98}),99Ports: []corev1.ContainerPort{{100ContainerPort: ContainerPort,101Name: PortName,102}},103SecurityContext: &corev1.SecurityContext{104Privileged: pointer.Bool(false),105AllowPrivilegeEscalation: pointer.Bool(false),106},107Env: env,108VolumeMounts: volumeMounts,109ReadinessProbe: &corev1.Probe{110ProbeHandler: corev1.ProbeHandler{111TCPSocket: &corev1.TCPSocketAction{112Port: intstr.IntOrString{IntVal: ReadinessPort},113},114},115FailureThreshold: 3,116SuccessThreshold: 1,117TimeoutSeconds: 1,118},119},120*common.KubeRBACProxyContainerWithConfig(ctx),121},122Volumes: volumes,123Tolerations: common.WithTolerationWorkspaceComponentNotReady(ctx),124},125},126},127},128}, nil129}130131132