Path: blob/main/install/installer/pkg/components/usage/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 usage56import (7"fmt"89"github.com/gitpod-io/gitpod/common-go/baseserver"10"github.com/gitpod-io/gitpod/installer/pkg/cluster"11"github.com/gitpod-io/gitpod/installer/pkg/common"12"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"13appsv1 "k8s.io/api/apps/v1"14corev1 "k8s.io/api/core/v1"15"k8s.io/apimachinery/pkg/api/resource"16metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"17"k8s.io/apimachinery/pkg/runtime"18"k8s.io/apimachinery/pkg/util/intstr"19"k8s.io/utils/pointer"20)2122const (23usageConfigmapVolume = "config"24usageConfigMountPath = "/config.json"25)2627func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {28labels := common.CustomizeLabel(ctx, Component, common.TypeMetaDeployment)2930args := []string{31"run",32fmt.Sprintf("--config=%s", usageConfigMountPath),33}3435volumes := []corev1.Volume{36{37Name: usageConfigmapVolume,38VolumeSource: corev1.VolumeSource{39ConfigMap: &corev1.ConfigMapVolumeSource{40LocalObjectReference: corev1.LocalObjectReference{41Name: Component,42},43},44},45},46}47volumeMounts := []corev1.VolumeMount{48{49Name: usageConfigmapVolume,50ReadOnly: true,51MountPath: usageConfigMountPath,52SubPath: configJSONFilename,53},54}55_ = ctx.WithExperimental(func(cfg *experimental.Config) error {56volume, mount, _, ok := getStripeConfig(cfg)57if !ok {58return nil59}6061volumes = append(volumes, volume)62volumeMounts = append(volumeMounts, mount)63return nil64})6566configHash, err := common.ObjectHash(configmap(ctx))67if err != nil {68return nil, err69}7071return []runtime.Object{72&appsv1.Deployment{73TypeMeta: common.TypeMetaDeployment,74ObjectMeta: metav1.ObjectMeta{75Name: Component,76Namespace: ctx.Namespace,77Labels: labels,78Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment, func() map[string]string {79return map[string]string{80common.AnnotationConfigChecksum: configHash,81}82}),83},84Spec: appsv1.DeploymentSpec{85Selector: &metav1.LabelSelector{MatchLabels: common.DefaultLabels(Component)},86Replicas: common.Replicas(ctx, Component),87Strategy: common.DeploymentStrategy,88Template: corev1.PodTemplateSpec{89ObjectMeta: metav1.ObjectMeta{90Name: Component,91Namespace: ctx.Namespace,92Labels: labels,93Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment),94},95Spec: corev1.PodSpec{96Affinity: cluster.WithNodeAffinityHostnameAntiAffinity(Component, cluster.AffinityLabelMeta),97TopologySpreadConstraints: cluster.WithHostnameTopologySpread(Component),98ServiceAccountName: Component,99EnableServiceLinks: pointer.Bool(false),100DNSPolicy: corev1.DNSClusterFirst,101RestartPolicy: corev1.RestartPolicyAlways,102TerminationGracePeriodSeconds: pointer.Int64(30),103InitContainers: []corev1.Container{*common.DatabaseMigrationWaiterContainer(ctx)},104Volumes: volumes,105Containers: []corev1.Container{{106Name: Component,107Image: ctx.ImageName(ctx.Config.Repository, Component, ctx.VersionManifest.Components.Usage.Version),108Args: args,109ImagePullPolicy: corev1.PullIfNotPresent,110Resources: common.ResourceRequirements(ctx, Component, Component, corev1.ResourceRequirements{111Requests: corev1.ResourceList{112"cpu": resource.MustParse("100m"),113"memory": resource.MustParse("64Mi"),114},115}),116Ports: []corev1.ContainerPort{},117SecurityContext: &corev1.SecurityContext{118Privileged: pointer.Bool(false),119AllowPrivilegeEscalation: pointer.Bool(false),120},121Env: common.CustomizeEnvvar(ctx, Component, common.MergeEnv(122common.DefaultEnv(&ctx.Config),123common.DatabaseEnv(&ctx.Config),124common.ConfigcatEnv(ctx),125)),126VolumeMounts: volumeMounts,127LivenessProbe: &corev1.Probe{128ProbeHandler: corev1.ProbeHandler{129HTTPGet: &corev1.HTTPGetAction{130Path: "/live",131Port: intstr.IntOrString{IntVal: baseserver.BuiltinHealthPort},132Scheme: corev1.URISchemeHTTP,133},134},135FailureThreshold: 3,136SuccessThreshold: 1,137TimeoutSeconds: 1,138},139ReadinessProbe: &corev1.Probe{140ProbeHandler: corev1.ProbeHandler{141HTTPGet: &corev1.HTTPGetAction{142Path: "/ready",143Port: intstr.IntOrString{IntVal: baseserver.BuiltinHealthPort},144Scheme: corev1.URISchemeHTTP,145},146},147FailureThreshold: 3,148SuccessThreshold: 1,149TimeoutSeconds: 1,150},151},152*common.KubeRBACProxyContainerWithConfig(ctx),153},154Tolerations: common.WithTolerationWorkspaceComponentNotReady(ctx),155},156},157},158},159}, nil160}161162163