Skip to content
Open
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
5 changes: 5 additions & 0 deletions api/disaggregated/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ type CommonSpec struct {
//+optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`

// (Optional) TopologySpreadConstraints describes how a group of pods ought to spread across topology
// domains. Scheduler will schedule pods in a way which abides by the constraints.
// +optional
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`

// export service for accessing from outside k8s.
Service *ExportService `json:"service,omitempty"`

Expand Down
5 changes: 5 additions & 0 deletions api/doris/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ type BaseSpec struct {
//+optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`

// (Optional) TopologySpreadConstraints describes how a group of pods ought to spread across topology
// domains. Scheduler will schedule pods in a way which abides by the constraints.
// +optional
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`

//+optional
// podLabels for user selector or classify pods
PodLabels map[string]string `json:"podLabels,omitempty"`
Expand Down
58 changes: 25 additions & 33 deletions pkg/common/utils/resource/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,16 @@ func NewPodTemplateSpec(dcr *v1.DorisCluster, config map[string]interface{}, com
},

Spec: corev1.PodSpec{
ImagePullSecrets: spec.ImagePullSecrets,
NodeSelector: spec.NodeSelector,
Volumes: volumes,
ServiceAccountName: spec.ServiceAccount,
Affinity: spec.Affinity.DeepCopy(),
Tolerations: spec.Tolerations,
HostAliases: spec.HostAliases,
InitContainers: defaultInitContainers,
SecurityContext: SecurityContext,
ImagePullSecrets: spec.ImagePullSecrets,
NodeSelector: spec.NodeSelector,
Volumes: volumes,
ServiceAccountName: spec.ServiceAccount,
Affinity: spec.Affinity.DeepCopy(),
Tolerations: spec.Tolerations,
TopologySpreadConstraints: spec.TopologySpreadConstraints,
HostAliases: spec.HostAliases,
InitContainers: defaultInitContainers,
SecurityContext: SecurityContext,
},
}

Expand All @@ -210,15 +211,16 @@ func NewPodTemplateSpecWithCommonSpec(skipDefaultInit bool, cs *dv1.CommonSpec,
},

Spec: corev1.PodSpec{
ImagePullSecrets: cs.ImagePullSecrets,
NodeSelector: cs.NodeSelector,
ServiceAccountName: cs.ServiceAccount,
Affinity: cs.Affinity.DeepCopy(),
Tolerations: cs.Tolerations,
HostAliases: cs.HostAliases,
InitContainers: defaultInitContainers,
SecurityContext: cs.SecurityContext,
Volumes: vs,
ImagePullSecrets: cs.ImagePullSecrets,
NodeSelector: cs.NodeSelector,
ServiceAccountName: cs.ServiceAccount,
Affinity: cs.Affinity.DeepCopy(),
Tolerations: cs.Tolerations,
TopologySpreadConstraints: cs.TopologySpreadConstraints,
HostAliases: cs.HostAliases,
InitContainers: defaultInitContainers,
SecurityContext: cs.SecurityContext,
Volumes: vs,
},
}
constructDisaggregatedInitContainers(skipDefaultInit, componentType, &pts.Spec, si)
Expand Down Expand Up @@ -1201,22 +1203,12 @@ func getDefaultAffinity(componentType v1.ComponentType) *corev1.Affinity {
}

func constructAffinity(dcrAffinity *corev1.Affinity, componentType v1.ComponentType) *corev1.Affinity {
affinity := getDefaultAffinity(componentType)

if dcrAffinity == nil {
return affinity
}

dcrPodAntiAffinity := dcrAffinity.PodAntiAffinity
if dcrPodAntiAffinity != nil {
affinity.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution = dcrPodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution
affinity.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution = append(affinity.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution, dcrPodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution...)
// If user provides affinity, respect it completely without injecting defaults
if dcrAffinity != nil {
return dcrAffinity.DeepCopy()
}

affinity.NodeAffinity = dcrAffinity.NodeAffinity
affinity.PodAffinity = dcrAffinity.PodAffinity

return affinity
// Only apply defaults when user hasn't specified any affinity
return getDefaultAffinity(componentType)
}

func constructBeDefaultInitContainer(defaultImage string) corev1.Container {
Expand Down
20 changes: 5 additions & 15 deletions pkg/controller/sub_controller/disaggregated_subcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,22 +189,12 @@ func (d *DisaggregatedSubDefaultController) BuildDefaultConfigMapVolumesVolumeMo
}

func (d *DisaggregatedSubDefaultController) ConstructDefaultAffinity(matchKey, value string, ddcAffinity *corev1.Affinity) *corev1.Affinity {
affinity := d.newDefaultAffinity(matchKey, value)

if ddcAffinity == nil {
return affinity
}

ddcPodAntiAffinity := ddcAffinity.PodAntiAffinity
if ddcPodAntiAffinity != nil {
affinity.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution = ddcPodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution
affinity.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution = append(affinity.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution, ddcPodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution...)
// If user provides affinity, respect it completely without injecting defaults
if ddcAffinity != nil {
return ddcAffinity.DeepCopy()
}

affinity.NodeAffinity = ddcAffinity.NodeAffinity
affinity.PodAffinity = ddcAffinity.PodAffinity

return affinity
// Only apply defaults when user hasn't specified any affinity
return d.newDefaultAffinity(matchKey, value)
}

func (d *DisaggregatedSubDefaultController) newDefaultAffinity(matchKey, value string) *corev1.Affinity {
Expand Down