Path: blob/main/install/installer/pkg/components/ws-manager-mk2/deployment.go
2501 views
// Copyright (c) 2021 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 wsmanagermk256import (7appsv1 "k8s.io/api/apps/v1"8corev1 "k8s.io/api/core/v1"9"k8s.io/apimachinery/pkg/api/resource"10metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"11"k8s.io/apimachinery/pkg/runtime"12"k8s.io/apimachinery/pkg/util/intstr"13"k8s.io/utils/pointer"1415"github.com/gitpod-io/gitpod/installer/pkg/cluster"16"github.com/gitpod-io/gitpod/installer/pkg/common"17wsdaemon "github.com/gitpod-io/gitpod/installer/pkg/components/ws-daemon"18"github.com/gitpod-io/gitpod/installer/pkg/config/v1"19)2021func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {22labels := common.DefaultLabels(Component)2324configHash, err := common.ObjectHash(configmap(ctx))25if err != nil {26return nil, err27}2829var volumes []corev1.Volume30var volumeMounts []corev1.VolumeMount31if ctx.Config.Kind == config.InstallationWorkspace {32// Image builder TLS is only enabled in workspace clusters. This check33// can be removed once image-builder-mk3 has been removed from application clusters34// (https://github.com/gitpod-io/gitpod/issues/7845).35volumes = append(volumes, corev1.Volume{36Name: common.ImageBuilderVolumeTLSCerts,37VolumeSource: corev1.VolumeSource{38Secret: &corev1.SecretVolumeSource{SecretName: common.ImageBuilderTLSSecret},39},40})41volumeMounts = append(volumeMounts, corev1.VolumeMount{42Name: common.ImageBuilderVolumeTLSCerts,43MountPath: "/image-builder-mk3-tls-certs",44ReadOnly: true,45})46}47if ctx.Config.SSHGatewayCAKey != nil {48volumes = append(volumes, corev1.Volume{49Name: "ca-key",50VolumeSource: corev1.VolumeSource{51Secret: &corev1.SecretVolumeSource{52SecretName: ctx.Config.SSHGatewayCAKey.Name,53Optional: pointer.Bool(true),54},55},56})5758volumeMounts = append(volumeMounts, corev1.VolumeMount{59Name: "ca-key",60MountPath: "/mnt/ca-key/ca.pem",61SubPath: "ca.pem",62ReadOnly: true,63})64}6566podSpec := corev1.PodSpec{67PriorityClassName: common.SystemNodeCritical,68Affinity: cluster.WithNodeAffinityHostnameAntiAffinity(Component, cluster.AffinityLabelServices),69TopologySpreadConstraints: cluster.WithHostnameTopologySpread(Component),70EnableServiceLinks: pointer.Bool(false),71ServiceAccountName: Component,72SecurityContext: &corev1.PodSecurityContext{73RunAsUser: pointer.Int64(31002),74},75Containers: []corev1.Container{{76Name: Component,77Args: []string{78"--config", "/config/config.json",79},80Image: ctx.ImageName(ctx.Config.Repository, Component, ctx.VersionManifest.Components.WSManagerMk2.Version),81ImagePullPolicy: corev1.PullIfNotPresent,82Resources: common.ResourceRequirements(ctx, Component, Component, corev1.ResourceRequirements{83Requests: corev1.ResourceList{84"cpu": resource.MustParse("100m"),85"memory": resource.MustParse("32Mi"),86},87}),88LivenessProbe: &corev1.Probe{89ProbeHandler: corev1.ProbeHandler{90HTTPGet: &corev1.HTTPGetAction{91Path: "/healthz",92Port: intstr.FromInt(HealthPort),93},94},95InitialDelaySeconds: 15,96PeriodSeconds: 20,97},98ReadinessProbe: &corev1.Probe{99ProbeHandler: corev1.ProbeHandler{100HTTPGet: &corev1.HTTPGetAction{101Path: "/readyz",102Port: intstr.FromInt(HealthPort),103},104},105InitialDelaySeconds: 5,106PeriodSeconds: 10,107},108Ports: []corev1.ContainerPort{109{110Name: RPCPortName,111ContainerPort: RPCPort,112},113},114SecurityContext: &corev1.SecurityContext{115Privileged: pointer.Bool(false),116},117Env: common.MergeEnv(118common.DefaultEnv(&ctx.Config),119common.WorkspaceTracingEnv(ctx, Component),120[]corev1.EnvVar{{Name: "GRPC_GO_RETRY", Value: "on"}},121),122VolumeMounts: append([]corev1.VolumeMount{123{124Name: VolumeConfig,125MountPath: "/config",126ReadOnly: true,127},128{129Name: VolumeWorkspaceTemplate,130MountPath: WorkspaceTemplatePath,131ReadOnly: true,132},133{134Name: wsdaemon.VolumeTLSCerts,135MountPath: "/ws-daemon-tls-certs",136ReadOnly: true,137},138{139Name: VolumeTLSCerts,140MountPath: "/certs",141ReadOnly: true,142},143common.CAVolumeMount(),144}, volumeMounts...),145},146*common.KubeRBACProxyContainer(ctx),147},148Tolerations: common.WithTolerationWorkspaceComponentNotReady(ctx),149Volumes: append([]corev1.Volume{150{151Name: VolumeConfig,152VolumeSource: corev1.VolumeSource{153ConfigMap: &corev1.ConfigMapVolumeSource{154LocalObjectReference: corev1.LocalObjectReference{Name: Component},155},156},157},158{159Name: VolumeWorkspaceTemplate,160VolumeSource: corev1.VolumeSource{161ConfigMap: &corev1.ConfigMapVolumeSource{162LocalObjectReference: corev1.LocalObjectReference{Name: WorkspaceTemplateConfigMap},163},164},165},166{167Name: wsdaemon.VolumeTLSCerts,168VolumeSource: corev1.VolumeSource{169Secret: &corev1.SecretVolumeSource{SecretName: wsdaemon.TLSSecretName},170},171},172{173Name: VolumeTLSCerts,174VolumeSource: corev1.VolumeSource{175Secret: &corev1.SecretVolumeSource{SecretName: TLSSecretNameSecret},176},177},178common.CAVolume(),179}, volumes...),180}181182err = common.AddStorageMounts(ctx, &podSpec, Component)183if err != nil {184return nil, err185}186187return []runtime.Object{188&appsv1.Deployment{189TypeMeta: common.TypeMetaDeployment,190ObjectMeta: metav1.ObjectMeta{191Name: Component,192Namespace: ctx.Namespace,193Labels: labels,194},195Spec: appsv1.DeploymentSpec{196Selector: &metav1.LabelSelector{MatchLabels: labels},197Replicas: pointer.Int32(2),198Strategy: common.DeploymentStrategy,199Template: corev1.PodTemplateSpec{200ObjectMeta: metav1.ObjectMeta{201Name: Component,202Namespace: ctx.Namespace,203Labels: labels,204Annotations: map[string]string{205common.AnnotationConfigChecksum: configHash,206},207},208Spec: podSpec,209},210},211},212}, nil213}214215216