Path: blob/main/install/installer/pkg/components/agent-smith/daemonset.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 agentsmith56import (7"github.com/gitpod-io/gitpod/installer/pkg/cluster"8"github.com/gitpod-io/gitpod/installer/pkg/common"9wsmanagermk2 "github.com/gitpod-io/gitpod/installer/pkg/components/ws-manager-mk2"1011appsv1 "k8s.io/api/apps/v1"12corev1 "k8s.io/api/core/v1"13"k8s.io/apimachinery/pkg/api/resource"14metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"15"k8s.io/apimachinery/pkg/runtime"16"k8s.io/utils/pointer"17)1819func daemonset(ctx *common.RenderContext) ([]runtime.Object, error) {20labels := common.CustomizeLabel(ctx, Component, common.TypeMetaDaemonset)2122configHash, err := common.ObjectHash(configmap(ctx))23if err != nil {24return nil, err25}26volumeMounts := []corev1.VolumeMount{27{28Name: "config",29MountPath: "/config",30},31{32Name: "wsman-tls-certs",33MountPath: "/wsman-certs",34ReadOnly: true,35},36common.CAVolumeMount(),37}3839filesystemScanningEnabled := ctx.Config.Components != nil &&40ctx.Config.Components.AgentSmith != nil &&41ctx.Config.Components.AgentSmith.FilesystemScanning != nil &&42ctx.Config.Components.AgentSmith.FilesystemScanning.Enabled4344if filesystemScanningEnabled {45volumeMounts = append(volumeMounts, corev1.VolumeMount{46Name: "working-area",47MountPath: ContainerWorkingAreaMk2,48ReadOnly: true,49})50}5152volumes := []corev1.Volume{53{54Name: "config",55VolumeSource: corev1.VolumeSource{ConfigMap: &corev1.ConfigMapVolumeSource{56LocalObjectReference: corev1.LocalObjectReference{Name: Component},57}},58},59{60Name: "wsman-tls-certs",61VolumeSource: corev1.VolumeSource{62Secret: &corev1.SecretVolumeSource{63SecretName: wsmanagermk2.TLSSecretNameClient,64},65},66},67common.CAVolume(),68}6970if filesystemScanningEnabled {71volumes = append(volumes, corev1.Volume{72Name: "working-area",73VolumeSource: corev1.VolumeSource{74HostPath: &corev1.HostPathVolumeSource{75Path: HostWorkingAreaMk2,76Type: func() *corev1.HostPathType { t := corev1.HostPathDirectory; return &t }(),77},78},79})80}8182return []runtime.Object{&appsv1.DaemonSet{83TypeMeta: common.TypeMetaDaemonset,84ObjectMeta: metav1.ObjectMeta{85Name: Component,86Namespace: ctx.Namespace,87Labels: labels,88Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDaemonset, func() map[string]string {89return map[string]string{90common.AnnotationConfigChecksum: configHash,91}92}),93},94Spec: appsv1.DaemonSetSpec{95Selector: &metav1.LabelSelector{MatchLabels: common.DefaultLabels(Component)},96Template: corev1.PodTemplateSpec{97ObjectMeta: metav1.ObjectMeta{98Name: Component,99Labels: labels,100Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDaemonset),101},102Spec: corev1.PodSpec{103Affinity: cluster.WithNodeAffinity(cluster.AffinityLabelWorkspacesRegular, cluster.AffinityLabelWorkspacesHeadless),104ServiceAccountName: Component,105HostPID: true,106EnableServiceLinks: pointer.Bool(false),107DNSPolicy: corev1.DNSClusterFirst,108RestartPolicy: corev1.RestartPolicyAlways,109TerminationGracePeriodSeconds: pointer.Int64(30),110Containers: []corev1.Container{{111Name: Component,112Image: ctx.ImageName(ctx.Config.Repository, Component, ctx.VersionManifest.Components.AgentSmith.Version),113ImagePullPolicy: corev1.PullIfNotPresent,114Args: []string{"run", "--config", "/config/config.json"},115Resources: common.ResourceRequirements(ctx, Component, Component, corev1.ResourceRequirements{116Requests: corev1.ResourceList{117"cpu": resource.MustParse("100m"),118"memory": resource.MustParse("32Mi"),119},120}),121VolumeMounts: volumeMounts,122Env: common.CustomizeEnvvar(ctx, Component, common.MergeEnv(123common.DefaultEnv(&ctx.Config),124common.WorkspaceTracingEnv(ctx, Component),125common.NodeNameEnv(ctx),126)),127SecurityContext: &corev1.SecurityContext{128Privileged: pointer.Bool(true),129ProcMount: func() *corev1.ProcMountType { r := corev1.DefaultProcMount; return &r }(),130},131},132*common.KubeRBACProxyContainer(ctx),133},134Volumes: volumes,135Tolerations: []corev1.Toleration{136{137Effect: corev1.TaintEffectNoSchedule,138Operator: corev1.TolerationOpExists,139},140},141},142},143UpdateStrategy: common.DaemonSetRolloutStrategy(),144},145}}, nil146}147148149