iQQBot 52a7727b4f
[node-labeler] Refactor node labeling to use taints instead of labels (#20652)
* [node-labeler] Refactor node labeling to use taints instead of labels

* [agent-smith] Add toleration to daemonset

* Add workspace component tolerations to various Gitpod components if it running in Full installation

* Apply suggestions from code review

Co-authored-by: Kyle Brennan <kyle@gitpod.io>

* Update components/node-labeler/cmd/run.go

Co-authored-by: Kyle Brennan <kyle@gitpod.io>

---------

Co-authored-by: Kyle Brennan <kyle@gitpod.io>
2025-03-11 03:30:39 -04:00

131 lines
4.4 KiB
Go

// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License.AGPL.txt in the project root for license information.
package ide_metrics
import (
"github.com/gitpod-io/gitpod/installer/pkg/cluster"
"github.com/gitpod-io/gitpod/installer/pkg/common"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/pointer"
)
func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
labels := common.CustomizeLabel(ctx, Component, common.TypeMetaDeployment)
configHash, err := common.ObjectHash(configmap(ctx))
if err != nil {
return nil, err
}
volumes := make([]corev1.Volume, 0)
volumeMounts := make([]corev1.VolumeMount, 0)
volumes = append(volumes, corev1.Volume{
Name: VolumeConfig,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{Name: Component},
},
},
})
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: VolumeConfig,
MountPath: "/config",
ReadOnly: true,
})
env := common.CustomizeEnvvar(ctx, Component, common.MergeEnv(
common.DefaultEnv(&ctx.Config),
))
if ctx.Config.Components != nil && ctx.Config.Components.IDE != nil && ctx.Config.Components.IDE.Metrics != nil && ctx.Config.Components.IDE.Metrics.ErrorReportingEnabled {
env = append(env, corev1.EnvVar{
Name: "GITPOD_ENABLED_ERROR_REPORTING",
Value: "true",
})
}
return []runtime.Object{
&appsv1.Deployment{
TypeMeta: common.TypeMetaDeployment,
ObjectMeta: metav1.ObjectMeta{
Name: Component,
Namespace: ctx.Namespace,
Labels: labels,
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment),
},
Spec: appsv1.DeploymentSpec{
Selector: &metav1.LabelSelector{MatchLabels: common.DefaultLabels(Component)},
Replicas: common.Replicas(ctx, Component),
Strategy: common.DeploymentStrategy,
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: Component,
Namespace: ctx.Namespace,
Labels: labels,
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment, func() map[string]string {
return map[string]string{
common.AnnotationConfigChecksum: configHash,
}
}),
},
Spec: corev1.PodSpec{
Affinity: cluster.WithNodeAffinityHostnameAntiAffinity(Component, cluster.AffinityLabelMeta),
TopologySpreadConstraints: cluster.WithHostnameTopologySpread(Component),
ServiceAccountName: Component,
EnableServiceLinks: pointer.Bool(false),
DNSPolicy: corev1.DNSClusterFirst,
RestartPolicy: corev1.RestartPolicyAlways,
TerminationGracePeriodSeconds: pointer.Int64(30),
Containers: []corev1.Container{{
Args: []string{"run", "--config", "/config/config.json"},
Name: Component,
Image: ctx.ImageName(ctx.Config.Repository, Component, ctx.VersionManifest.Components.IDEMetrics.Version),
ImagePullPolicy: corev1.PullIfNotPresent,
Resources: common.ResourceRequirements(ctx, Component, Component, corev1.ResourceRequirements{
Requests: corev1.ResourceList{
"cpu": resource.MustParse("100m"),
"memory": resource.MustParse("128Mi"),
},
}),
Ports: []corev1.ContainerPort{{
ContainerPort: ContainerPort,
Name: PortName,
}},
SecurityContext: &corev1.SecurityContext{
Privileged: pointer.Bool(false),
AllowPrivilegeEscalation: pointer.Bool(false),
},
Env: env,
VolumeMounts: volumeMounts,
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
TCPSocket: &corev1.TCPSocketAction{
Port: intstr.IntOrString{IntVal: ReadinessPort},
},
},
FailureThreshold: 3,
SuccessThreshold: 1,
TimeoutSeconds: 1,
},
},
*common.KubeRBACProxyContainerWithConfig(ctx),
},
Volumes: volumes,
Tolerations: common.WithTolerationWorkspaceComponentNotReady(ctx),
},
},
},
},
}, nil
}