Skip to content

Commit

Permalink
removed antiaffinity (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
enrichman authored Jan 22, 2025
1 parent c285004 commit fd6ed81
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 43 deletions.
32 changes: 11 additions & 21 deletions pkg/controller/cluster/agent/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,10 @@ func (s *SharedAgent) Resources() ([]ctrlruntimeclient.Object, error) {
}

func (s *SharedAgent) deployment() *apps.Deployment {
selector := &metav1.LabelSelector{
MatchLabels: map[string]string{
"cluster": s.cluster.Name,
"type": "agent",
"mode": "shared",
},
labels := map[string]string{
"cluster": s.cluster.Name,
"type": "agent",
"mode": "shared",
}

return &apps.Deployment{
Expand All @@ -102,34 +100,26 @@ func (s *SharedAgent) deployment() *apps.Deployment {
ObjectMeta: metav1.ObjectMeta{
Name: s.Name(),
Namespace: s.cluster.Namespace,
Labels: selector.MatchLabels,
Labels: labels,
},
Spec: apps.DeploymentSpec{
Selector: selector,
Selector: &metav1.LabelSelector{
MatchLabels: labels,
},
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: selector.MatchLabels,
Labels: labels,
},
Spec: s.podSpec(selector),
Spec: s.podSpec(),
},
},
}
}

func (s *SharedAgent) podSpec(affinitySelector *metav1.LabelSelector) v1.PodSpec {
func (s *SharedAgent) podSpec() v1.PodSpec {
var limit v1.ResourceList

return v1.PodSpec{
Affinity: &v1.Affinity{
PodAntiAffinity: &v1.PodAntiAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{
{
LabelSelector: affinitySelector,
TopologyKey: "kubernetes.io/hostname",
},
},
},
},
ServiceAccountName: s.Name(),
Volumes: []v1.Volume{
{
Expand Down
10 changes: 0 additions & 10 deletions pkg/controller/cluster/agent/virtual.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,6 @@ func (v *VirtualAgent) podSpec(image, name string, args []string, affinitySelect
var limit v1.ResourceList
args = append([]string{"agent", "--config", "/opt/rancher/k3s/config.yaml"}, args...)
podSpec := v1.PodSpec{
Affinity: &v1.Affinity{
PodAntiAffinity: &v1.PodAntiAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{
{
LabelSelector: affinitySelector,
TopologyKey: "kubernetes.io/hostname",
},
},
},
},
Volumes: []v1.Volume{
{
Name: "config",
Expand Down
14 changes: 2 additions & 12 deletions pkg/controller/cluster/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,14 @@ func New(cluster *v1alpha1.Cluster, client client.Client, token, mode string) *S
}
}

func (s *Server) podSpec(image, name string, persistent bool, affinitySelector *metav1.LabelSelector) v1.PodSpec {
func (s *Server) podSpec(image, name string, persistent bool) v1.PodSpec {
var limit v1.ResourceList
if s.cluster.Spec.Limit != nil && s.cluster.Spec.Limit.ServerLimit != nil {
limit = s.cluster.Spec.Limit.ServerLimit
}
podSpec := v1.PodSpec{
NodeSelector: s.cluster.Spec.NodeSelector,
PriorityClassName: s.cluster.Spec.PriorityClass,
Affinity: &v1.Affinity{
PodAntiAffinity: &v1.PodAntiAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{
{
LabelSelector: affinitySelector,
TopologyKey: "kubernetes.io/hostname",
},
},
},
},
Volumes: []v1.Volume{
{
Name: "initconfig",
Expand Down Expand Up @@ -347,7 +337,7 @@ func (s *Server) StatefulServer(ctx context.Context) (*apps.StatefulSet, error)
},
}

podSpec := s.podSpec(image, name, persistent, &selector)
podSpec := s.podSpec(image, name, persistent)
podSpec.Volumes = append(podSpec.Volumes, volumes...)
podSpec.Containers[0].VolumeMounts = append(podSpec.Containers[0].VolumeMounts, volumeMounts...)

Expand Down

0 comments on commit fd6ed81

Please sign in to comment.