Support for configuring affinity for helm executor (#1989)
(cherry picked from commit e389253a4e)
This commit is contained in:
@@ -46,6 +46,9 @@ data:
|
||||
{{- if .Values.helmExecutor.resources }}
|
||||
resources: {{- toYaml .Values.helmExecutor.resources | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- if .Values.helmExecutor.affinity }}
|
||||
affinity: {{- toYaml .Values.helmExecutor.affinity | nindent 8 }}
|
||||
{{- end }}
|
||||
extension:
|
||||
imageRegistry: {{ default .Values.extension.imageRegistry "" | quote }}
|
||||
{{- if .Values.extension.nodeSelector }}
|
||||
|
||||
@@ -278,6 +278,17 @@ helmExecutor:
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 100Mi
|
||||
affinity:
|
||||
podAffinity:
|
||||
preferredDuringSchedulingIgnoredDuringExecution:
|
||||
- weight: 100
|
||||
podAffinityTerm:
|
||||
labelSelector:
|
||||
matchLabels:
|
||||
app: ks-controller-manager
|
||||
topologyKey: "kubernetes.io/hostname"
|
||||
namespaces:
|
||||
- kubesphere-system
|
||||
|
||||
composedApp:
|
||||
# Selector to filter k8s applications to reconcile
|
||||
|
||||
@@ -1556,6 +1556,7 @@ func (r *InstallPlanReconciler) newExecutor(plan *corev1alpha1.InstallPlan) (hel
|
||||
helm.SetExecutorNamespace(plan.Status.TargetNamespace),
|
||||
helm.SetExecutorBackoffLimit(0),
|
||||
helm.SetTTLSecondsAfterFinished(r.HelmExecutorOptions.JobTTLAfterFinished),
|
||||
helm.SetExecutorAffinity(r.HelmExecutorOptions.Affinity),
|
||||
}
|
||||
if r.HelmExecutorOptions.Resources != nil {
|
||||
executorOptions = append(executorOptions, helm.SetExecutorResources(corev1.ResourceRequirements{
|
||||
|
||||
@@ -38,6 +38,7 @@ type HelmExecutorOptions struct {
|
||||
HistoryMax uint `json:"historyMax,omitempty" yaml:"historyMax,omitempty" mapstructure:"historyMax,omitempty"`
|
||||
JobTTLAfterFinished time.Duration `json:"jobTTLAfterFinished,omitempty" yaml:"jobTTLAfterFinished,omitempty" mapstructure:"jobTTLAfterFinished,omitempty"`
|
||||
Resources *ResourceRequirements `json:"resources,omitempty" yaml:"resources,omitempty" mapstructure:"resources,omitempty"`
|
||||
Affinity *corev1.Affinity `json:"affinity,omitempty" yaml:"affinity,omitempty" mapstructure:"affinity,omitempty"`
|
||||
}
|
||||
|
||||
type ResourceRequirements struct {
|
||||
|
||||
@@ -92,6 +92,7 @@ type executor struct {
|
||||
client kubernetes.Interface
|
||||
helmImage string
|
||||
resources corev1.ResourceRequirements
|
||||
affinity *corev1.Affinity
|
||||
labels map[string]string
|
||||
owner *metav1.OwnerReference
|
||||
|
||||
@@ -116,6 +117,12 @@ func SetExecutorResources(resources corev1.ResourceRequirements) ExecutorOption
|
||||
}
|
||||
}
|
||||
|
||||
func SetExecutorAffinity(affinity *corev1.Affinity) ExecutorOption {
|
||||
return func(e *executor) {
|
||||
e.affinity = affinity
|
||||
}
|
||||
}
|
||||
|
||||
func SetExecutorLabels(labels map[string]string) ExecutorOption {
|
||||
return func(o *executor) {
|
||||
o.labels = labels
|
||||
@@ -659,6 +666,9 @@ func (e *executor) createInstallJob(ctx context.Context, release, chart string,
|
||||
if e.ttlSecondsAfterFinished > 0 {
|
||||
job.Spec.TTLSecondsAfterFinished = pointer.Int32(e.ttlSecondsAfterFinished)
|
||||
}
|
||||
if e.affinity != nil {
|
||||
job.Spec.Template.Spec.Affinity = e.affinity
|
||||
}
|
||||
if helmOptions.serviceAccount != "" {
|
||||
job.Spec.Template.Spec.ServiceAccountName = helmOptions.serviceAccount
|
||||
}
|
||||
@@ -856,6 +866,9 @@ func (e *executor) Uninstall(ctx context.Context, release string, options ...Hel
|
||||
if e.ttlSecondsAfterFinished > 0 {
|
||||
job.Spec.TTLSecondsAfterFinished = pointer.Int32(e.ttlSecondsAfterFinished)
|
||||
}
|
||||
if e.affinity != nil {
|
||||
job.Spec.Template.Spec.Affinity = e.affinity
|
||||
}
|
||||
if helmOptions.hookImage != "" {
|
||||
job.Spec.Template.Spec.InitContainers = []corev1.Container{
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user