Skip to content

[installer] Allow configuration of affinity for server and proxy components #9558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion install/installer/pkg/components/proxy/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"

"github.com/gitpod-io/gitpod/installer/pkg/cluster"
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"

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

Expand Down Expand Up @@ -95,6 +96,28 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
return nil, err
}

var podAntiAffinity *corev1.PodAntiAffinity
_ = ctx.WithExperimental(func(cfg *experimental.Config) error {
if cfg.WebApp != nil && cfg.WebApp.UsePodAffinity {
podAntiAffinity = &corev1.PodAntiAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{{
Weight: 100,
PodAffinityTerm: corev1.PodAffinityTerm{
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{{
Key: "component",
Operator: "In",
Values: []string{Component},
}},
},
TopologyKey: cluster.AffinityLabelMeta,
},
}},
}
}
return nil
})

const kubeRbacProxyContainerName = "kube-rbac-proxy"
return []runtime.Object{
&appsv1.Deployment{
Expand All @@ -118,7 +141,10 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
},
},
Spec: corev1.PodSpec{
Affinity: common.NodeAffinity(cluster.AffinityLabelMeta),
Affinity: &corev1.Affinity{
NodeAffinity: common.NodeAffinity(cluster.AffinityLabelMeta).NodeAffinity,
PodAntiAffinity: podAntiAffinity,
},
PriorityClassName: common.SystemNodeCritical,
ServiceAccountName: Component,
EnableServiceLinks: pointer.Bool(false),
Expand Down
28 changes: 27 additions & 1 deletion install/installer/pkg/components/server/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
wsmanager "github.com/gitpod-io/gitpod/installer/pkg/components/ws-manager"
wsmanagerbridge "github.com/gitpod-io/gitpod/installer/pkg/components/ws-manager-bridge"
configv1 "github.com/gitpod-io/gitpod/installer/pkg/config/v1"
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -163,6 +164,28 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
env = append(env, *envv)
}

var podAntiAffinity *corev1.PodAntiAffinity
_ = ctx.WithExperimental(func(cfg *experimental.Config) error {
if cfg.WebApp != nil && cfg.WebApp.UsePodAffinity {
podAntiAffinity = &corev1.PodAntiAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{{
Weight: 100,
PodAffinityTerm: corev1.PodAffinityTerm{
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{{
Key: "component",
Operator: "In",
Values: []string{Component},
}},
},
TopologyKey: cluster.AffinityLabelMeta,
},
}},
}
}
return nil
})

return []runtime.Object{
&appsv1.Deployment{
TypeMeta: common.TypeMetaDeployment,
Expand All @@ -185,7 +208,10 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
},
},
Spec: corev1.PodSpec{
Affinity: common.NodeAffinity(cluster.AffinityLabelMeta),
Affinity: &corev1.Affinity{
NodeAffinity: common.NodeAffinity(cluster.AffinityLabelMeta).NodeAffinity,
PodAntiAffinity: podAntiAffinity,
},
PriorityClassName: common.SystemNodeCritical,
ServiceAccountName: Component,
EnableServiceLinks: pointer.Bool(false),
Expand Down
5 changes: 3 additions & 2 deletions install/installer/pkg/config/v1/experimental/experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ type WorkspaceConfig struct {
}

type WebAppConfig struct {
PublicAPI *PublicAPIConfig `json:"publicApi,omitempty"`
Server *ServerConfig `json:"server,omitempty"`
PublicAPI *PublicAPIConfig `json:"publicApi,omitempty"`
Server *ServerConfig `json:"server,omitempty"`
UsePodAffinity bool `json:"usePodAffinity"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should read anti: UsePodAntiAffinity bool json:"usePodAntiAffinity"`

}

type ServerConfig struct {
Expand Down