Skip to content

Commit df7df11

Browse files
author
Simon Emms
committed
[installer]: set affinities for pods and jobs
1 parent 85714ab commit df7df11

File tree

18 files changed

+82
-15
lines changed

18 files changed

+82
-15
lines changed

installer/pkg/components/blobserve/deployment.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package blobserve
66

77
import (
88
"fmt"
9+
"github.com/gitpod-io/gitpod/installer/pkg/cluster"
910
"github.com/gitpod-io/gitpod/installer/pkg/common"
1011
dockerregistry "github.com/gitpod-io/gitpod/installer/pkg/components/docker-registry"
1112
appsv1 "k8s.io/api/apps/v1"
@@ -69,7 +70,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
6970
},
7071
},
7172
Spec: corev1.PodSpec{
72-
Affinity: &corev1.Affinity{},
73+
Affinity: common.Affinity(cluster.AffinityLabelWorkspaceServices),
7374
ServiceAccountName: Component,
7475
EnableServiceLinks: pointer.Bool(false),
7576
Volumes: []corev1.Volume{{

installer/pkg/components/content-service/deployment.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package content_service
66

77
import (
8+
"github.com/gitpod-io/gitpod/installer/pkg/cluster"
89
"github.com/gitpod-io/gitpod/installer/pkg/common"
910

1011
v1 "k8s.io/api/apps/v1"
@@ -24,7 +25,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
2425
}
2526

2627
podSpec := corev1.PodSpec{
27-
Affinity: &corev1.Affinity{},
28+
Affinity: common.Affinity(cluster.AffinityLabelMeta),
2829
ServiceAccountName: Component,
2930
EnableServiceLinks: pointer.Bool(false),
3031
DNSPolicy: "ClusterFirst",

installer/pkg/components/dashboard/deployment.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package dashboard
66

77
import (
8+
"github.com/gitpod-io/gitpod/installer/pkg/cluster"
89
"github.com/gitpod-io/gitpod/installer/pkg/common"
910

1011
appsv1 "k8s.io/api/apps/v1"
@@ -39,7 +40,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
3940
Labels: labels,
4041
},
4142
Spec: corev1.PodSpec{
42-
Affinity: &corev1.Affinity{},
43+
Affinity: common.Affinity(cluster.AffinityLabelMeta),
4344
ServiceAccountName: Component,
4445
EnableServiceLinks: pointer.Bool(false),
4546
DNSPolicy: "ClusterFirst",

installer/pkg/components/database/incluster/helm.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package incluster
66

77
import (
8+
"github.com/gitpod-io/gitpod/installer/pkg/cluster"
89
"github.com/gitpod-io/gitpod/installer/pkg/common"
910
"github.com/gitpod-io/gitpod/installer/pkg/helm"
1011
"github.com/gitpod-io/gitpod/installer/third_party/charts"
@@ -13,6 +14,16 @@ import (
1314

1415
var Helm = common.CompositeHelmFunc(
1516
helm.ImportTemplate(charts.MySQL(), helm.TemplateConfig{}, func(cfg *common.RenderContext) (*common.HelmConfig, error) {
17+
affinity, err := helm.AffinityYaml(cluster.AffinityLabelMeta)
18+
if err != nil {
19+
return nil, err
20+
}
21+
22+
primaryAffinityTemplate, err := helm.KeyFileValue("mysql.primary.affinity", affinity)
23+
if err != nil {
24+
return nil, err
25+
}
26+
1627
return &common.HelmConfig{
1728
Enabled: true,
1829
Values: &values.Options{
@@ -23,6 +34,10 @@ var Helm = common.CompositeHelmFunc(
2334
helm.KeyValue("mysql.initdbScriptsConfigMap", SQLInitScripts),
2435
helm.KeyValue("mysql.serviceAccount.name", Component),
2536
},
37+
// This is too complex to be sent as a string
38+
FileValues: []string{
39+
primaryAffinityTemplate,
40+
},
2641
},
2742
}, nil
2843
}),

installer/pkg/components/database/init/job.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package init
88

99
import (
1010
"fmt"
11+
"github.com/gitpod-io/gitpod/installer/pkg/cluster"
1112

1213
"github.com/gitpod-io/gitpod/installer/pkg/common"
1314
batchv1 "k8s.io/api/batch/v1"
@@ -32,7 +33,7 @@ func job(ctx *common.RenderContext) ([]runtime.Object, error) {
3233
Template: corev1.PodTemplateSpec{
3334
ObjectMeta: objectMeta,
3435
Spec: corev1.PodSpec{
35-
Affinity: &corev1.Affinity{},
36+
Affinity: common.Affinity(cluster.AffinityLabelMeta),
3637
RestartPolicy: corev1.RestartPolicyNever,
3738
ServiceAccountName: Component,
3839
EnableServiceLinks: pointer.Bool(false),

installer/pkg/components/image-builder-mk3/deployment.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package image_builder_mk3
66

77
import (
88
"fmt"
9+
"github.com/gitpod-io/gitpod/installer/pkg/cluster"
910

1011
"github.com/gitpod-io/gitpod/installer/pkg/common"
1112
dockerregistry "github.com/gitpod-io/gitpod/installer/pkg/components/docker-registry"
@@ -78,7 +79,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
7879
},
7980
},
8081
Spec: corev1.PodSpec{
81-
Affinity: &corev1.Affinity{},
82+
Affinity: common.Affinity(cluster.AffinityLabelMeta),
8283
ServiceAccountName: Component,
8384
EnableServiceLinks: pointer.Bool(false),
8485
DNSPolicy: "ClusterFirst",

installer/pkg/components/migrations/job.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package migrations
66

77
import (
8+
"github.com/gitpod-io/gitpod/installer/pkg/cluster"
89
"github.com/gitpod-io/gitpod/installer/pkg/common"
910
batchv1 "k8s.io/api/batch/v1"
1011
corev1 "k8s.io/api/core/v1"
@@ -28,7 +29,7 @@ func job(ctx *common.RenderContext) ([]runtime.Object, error) {
2829
Template: corev1.PodTemplateSpec{
2930
ObjectMeta: objectMeta,
3031
Spec: corev1.PodSpec{
31-
Affinity: &corev1.Affinity{},
32+
Affinity: common.Affinity(cluster.AffinityLabelMeta),
3233
RestartPolicy: corev1.RestartPolicyNever,
3334
ServiceAccountName: Component,
3435
EnableServiceLinks: pointer.Bool(false),

installer/pkg/components/minio/incluster/minio.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package incluster
66

77
import (
88
"fmt"
9+
"github.com/gitpod-io/gitpod/installer/pkg/cluster"
910
"github.com/gitpod-io/gitpod/installer/pkg/common"
1011
"github.com/gitpod-io/gitpod/installer/pkg/helm"
1112
"github.com/gitpod-io/gitpod/installer/third_party/charts"
@@ -15,6 +16,16 @@ import (
1516
var Helm = func(apiPort int32, consolePort int32) common.HelmFunc {
1617
return common.CompositeHelmFunc(
1718
helm.ImportTemplate(charts.Minio(), helm.TemplateConfig{}, func(cfg *common.RenderContext) (*common.HelmConfig, error) {
19+
affinity, err := helm.AffinityYaml(cluster.AffinityLabelMeta)
20+
if err != nil {
21+
return nil, err
22+
}
23+
24+
affinityTemplate, err := helm.KeyFileValue("minio.affinity", affinity)
25+
if err != nil {
26+
return nil, err
27+
}
28+
1829
return &common.HelmConfig{
1930
Enabled: true,
2031
Values: &values.Options{
@@ -24,6 +35,10 @@ var Helm = func(apiPort int32, consolePort int32) common.HelmFunc {
2435
helm.KeyValue("minio.service.ports.api", fmt.Sprintf("%d", apiPort)),
2536
helm.KeyValue("minio.service.ports.console", fmt.Sprintf("%d", consolePort)),
2637
},
38+
// This is too complex to be sent as a string
39+
FileValues: []string{
40+
affinityTemplate,
41+
},
2742
},
2843
}, nil
2944
}),

installer/pkg/components/openvsx-proxy/statefulset.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package openvsx_proxy
66

77
import (
88
"fmt"
9+
"github.com/gitpod-io/gitpod/installer/pkg/cluster"
910

1011
"github.com/gitpod-io/gitpod/installer/pkg/common"
1112
appsv1 "k8s.io/api/apps/v1"
@@ -50,7 +51,7 @@ func statefulset(ctx *common.RenderContext) ([]runtime.Object, error) {
5051
},
5152
},
5253
Spec: v1.PodSpec{
53-
Affinity: &v1.Affinity{},
54+
Affinity: common.Affinity(cluster.AffinityLabelIDE),
5455
ServiceAccountName: Component,
5556
EnableServiceLinks: pointer.Bool(false),
5657
DNSPolicy: "ClusterFirst",

installer/pkg/components/proxy/deployment.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package proxy
66

77
import (
88
"fmt"
9+
"github.com/gitpod-io/gitpod/installer/pkg/cluster"
910

1011
"github.com/gitpod-io/gitpod/installer/pkg/common"
1112

@@ -115,7 +116,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
115116
},
116117
},
117118
Spec: corev1.PodSpec{
118-
Affinity: &corev1.Affinity{},
119+
Affinity: common.Affinity(cluster.AffinityLabelMeta),
119120
PriorityClassName: common.SystemNodeCritical,
120121
ServiceAccountName: Component,
121122
EnableServiceLinks: pointer.Bool(false),

0 commit comments

Comments
 (0)